Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ A result is right, or RustGIS says what it lost or assumed
FlatGeobuf, GeoParquet and FileGDB, Z/M-loss cases for Shapefile, and ring-loss cases for
OSM PBF, WKT height/member losses for XLSX and ODS, and error-cell losses for XLSX; other loss kinds remain.
Exports are checked by `never_silent_roundtrip.rs` _(open)_.
- A `--strict` option for `rustgis-cli run` that exits non-zero when a loss is reported, for
scheduled jobs. Notices carry a severity but not a kind today (`Notice` in
`crates/engine/src/lib.rs`): start with an issue on which notices count as a loss.
- Classify existing loss notices so scheduled jobs can detect them by code. Then add
`rustgis-cli run --strict`, which exits non-zero on a disallowed loss, and expose the codes
to Python and MCP ([#2371](https://github.com/opengeos/RustGIS/issues/2371)).
- Grid datum shifts (NTv2 and GeoTIFF grids) for NAD27, NAD83(HARN), GDA94↔GDA2020 and OSGB36
without the GDAL program (a layer read without its shift says so today). _Coordinate first_
(needs an issue).
Expand Down
4 changes: 2 additions & 2 deletions crates/analysis/src/dggs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ pub fn grid(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
if skipped > 0 {
msg.push_str(&format!("; {}", left_out(skipped, "polygon part", "outline")));
}
Ok(ToolResult { output: Output::Layer(out), messages: vec![msg] })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages: vec![msg] })
}

/// The Aggregate Points to A5 tool: a layer's points counted by the cell holding them (and a
Expand Down Expand Up @@ -404,7 +404,7 @@ pub fn aggregate(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
if outside > 0 {
msg.push_str(&format!("; {}", left_out(outside, "point", "position")));
}
Ok(ToolResult { output: Output::Layer(out), messages: vec![msg] })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages: vec![msg] })
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions crates/analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ pub struct RasterInput<'a> {
#[derive(Clone, Debug)]
pub struct ToolResult {
pub output: Output,
/// Ordinary messages. Classified losses appear in `losses` only.
pub messages: Vec<String>,
/// Losses identified by the producer. Consumers that display plain text read both
/// `messages` and the text of these losses.
pub losses: Vec<rustgis_data::loss::LossMessage>,
}

/// Access to the map's layers by name.
Expand Down
6 changes: 5 additions & 1 deletion crates/analysis/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ pub(crate) fn run(inputs: &dyn Inputs, params: &Json) -> Result<ToolResult, Stri
out.push_next(geometry, attrs);
}
}
Ok(ToolResult { output: Output::Layer(out), messages: vec![format!("Merge: {n} features from {} layers", layers.len())] })
Ok(ToolResult {
losses: Vec::new(),
output: Output::Layer(out),
messages: vec![format!("Merge: {n} features from {} layers", layers.len())],
})
}

/// Fallible geometry copies, so a large merge can return an allocation error.
Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/src/tissot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ pub fn run(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
if unmeasured > 0 {
msg.push_str(&format!("; {unmeasured} at the projection's edge or beyond it have none"));
}
Ok(ToolResult { output: Output::Layer(out), messages: vec![msg] })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages: vec![msg] })
}

#[cfg(test)]
Expand Down
41 changes: 25 additions & 16 deletions crates/analysis/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ fn vector_to_pmtiles(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let file_name = if output.is_empty() { format!("{default_name}.pmtiles") } else { output.to_string() };
let selected = inp.selection(s(p, "input"));
let (bytes, messages) = inp.vector_to_pmtiles(ds, selected, min_zoom, max_zoom, source_layer)?;
Ok(ToolResult { output: Output::File { file_name, bytes }, messages })
Ok(ToolResult { losses: Vec::new(), output: Output::File { file_name, bytes }, messages })
}

fn raster_to_pmtiles(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
Expand All @@ -1447,7 +1447,7 @@ fn raster_to_pmtiles(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let default_name = name.rsplit(['/', '\\']).find(|part| !part.is_empty()).unwrap_or("output");
let file_name = if output.is_empty() { format!("{default_name}.pmtiles") } else { output.to_string() };
let bytes = inp.raster_to_pmtiles(name, min_zoom, max_zoom)?;
Ok(ToolResult { output: Output::File { file_name, bytes }, messages: vec![] })
Ok(ToolResult { losses: Vec::new(), output: Output::File { file_name, bytes }, messages: vec![] })
}

/// The name of a tool's new layer, from its `output` parameter.
Expand Down Expand Up @@ -1475,7 +1475,7 @@ fn to_metres(d: f64, units: &str) -> Result<f64, String> {
}

fn result(ds: Dataset, msg: String) -> Result<ToolResult, String> {
Ok(ToolResult { output: Output::Layer(ds), messages: vec![msg] })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(ds), messages: vec![msg] })
}

/// A geometry's polygons, or none when it has no polygon to give: an empty polygon, or a point
Expand Down Expand Up @@ -2647,7 +2647,7 @@ fn update_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Result<ToolR
messages.push(format!("Update: '{}' holds dates, so {} kept only {their} day", f.name, features(days)));
}
}
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// The most split areas (split polygons, or values of the split field) Split takes: more is an
Expand Down Expand Up @@ -2948,7 +2948,11 @@ fn split_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Result<ToolRe
let areas = if empty == 1 { "split area" } else { "split areas" };
msg = format!("{msg} ({empty} {areas} held no features)");
}
Ok(ToolResult { output: Output::Layers(layers), messages: std::iter::once(msg).chain(left_out.notes("Split", &sp.name)).collect() })
Ok(ToolResult {
losses: Vec::new(),
output: Output::Layers(layers),
messages: std::iter::once(msg).chain(left_out.notes("Split", &sp.name)).collect(),
})
}

/// Dissolve: one feature for each value of the dissolve field (one for all without it), the union
Expand Down Expand Up @@ -3037,7 +3041,7 @@ fn dissolve(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
));
}
messages.extend(rounded_notice(&rounded, out.fields.get(first_added..).unwrap_or_default()));
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// The farthest (meters, either way) Minimum Bounding Geometry takes a point from the analysis
Expand Down Expand Up @@ -4065,7 +4069,7 @@ fn xy_table_to_point(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
if placed < total {
messages.push(format!("{} of {total} rows have no usable coordinates; they are in the table without a point", total - placed));
}
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// The distances a Douglas–Peucker run of `n` vertices may measure, `n` times this: far more than
Expand Down Expand Up @@ -4484,7 +4488,7 @@ fn simplify_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Result<Too
if without > 0 {
messages.push(format!("Simplify: {without} feature(s) left out: they have no geometry to simplify"));
}
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// A Select by Location selector: its shape and extent in the analysis plane, and the poles it
Expand Down Expand Up @@ -4632,14 +4636,15 @@ fn select_by_location_with_work_limit(inp: &dyn Inputs, p: &Json, limit: usize,
"{coarse} selecting features' buffers have outline edges left with fewer points along them than they need (the points a ring may add ran out, as on a ring of thousands of long edges, or a very long edge was halved as many times as it may be): features near their edges there may be selected or not by more than a buffer otherwise keeps to (0.012% of the distance, 0.05% along a line or outline buffered in stretches, or 1 cm)"
));
}
Ok(ToolResult { output: Output::Selection { layer: ds.name.clone(), rows: hits }, messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Selection { layer: ds.name.clone(), rows: hits }, messages })
}

fn select_by_attributes(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let ds = input(inp, p, "input")?;
let hits = rustgis_data::query::select(s(p, "where"), ds)?;
let n = hits.len();
Ok(ToolResult {
losses: Vec::new(),
output: Output::Selection { layer: ds.name.clone(), rows: hits },
messages: vec![format!("Selected {n} features in {}", ds.name)],
})
Expand Down Expand Up @@ -4697,6 +4702,7 @@ fn idw_interpolation(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let bytes = rustgis_data::raster::geotiff::write(&r, 0).map_err(|e| e.to_string())?;
let msg = format!("IDW Interpolation: {} × {} cells from {} points", r.width, r.height, pts.len());
Ok(ToolResult {
losses: Vec::new(),
output: Output::Layers(vec![OutputLayer::Raster { file_name: format!("{name}.tif"), name, bytes }]),
messages: std::iter::once(msg).chain(beyond_note).chain(crs_note).collect(),
})
Expand Down Expand Up @@ -4838,6 +4844,7 @@ fn kriging_interpolation(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, Strin
let var_name = format!("{name}_variance");
let msg = format!("Ordinary Kriging ({}): {} × {} cells from {} points", model.as_str(), r.width, r.height, pts.len());
Ok(ToolResult {
losses: Vec::new(),
output: Output::Layers(vec![
OutputLayer::Raster { file_name: format!("{name}.tif"), name, bytes: pred_bytes },
OutputLayer::Raster { file_name: format!("{var_name}.tif"), name: var_name, bytes: var_bytes },
Expand Down Expand Up @@ -5213,6 +5220,7 @@ fn kernel_density_tool(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String>
format!("Kernel Density: {} × {} cells from {} points (bandwidth: {:.2})", r.width, r.height, pts.len(), bandwidth)
};
Ok(ToolResult {
losses: Vec::new(),
output: Output::Layers(vec![OutputLayer::Raster { file_name: format!("{name}.tif"), name, bytes }]),
messages: std::iter::once(msg)
.chain(beyond_note)
Expand Down Expand Up @@ -5371,7 +5379,7 @@ fn count_points_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Result
}
let mut messages = vec![format!("Summarize Within: {total} points counted")];
messages.extend(rounded_notice(&rounded, out.fields.get(first..).unwrap_or_default()));
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// A lon/lat line or ring as a `geo` line string, in degrees.
Expand Down Expand Up @@ -5686,6 +5694,7 @@ fn calculate_geometry(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String>
}
}
Ok(ToolResult {
losses: Vec::new(),
output: Output::Update { layer: ds.name.clone(), dataset: out },
messages: vec![format!("Calculated geometry attributes for {}", ds.name)],
})
Expand Down Expand Up @@ -5752,7 +5761,7 @@ fn summary_statistics(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String>
let n = out.features.len();
let mut messages = vec![format!("Summary Statistics: {n} rows")];
messages.extend(rounded_notice(&rounded, out.fields.get(first_added..).unwrap_or_default()));
Ok(ToolResult { output: Output::Table(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Table(out), messages })
}

/// The output fields of a statistics list over `ds`: `<STAT>_<field>` for each request, typed by
Expand Down Expand Up @@ -6091,7 +6100,7 @@ fn pivot_table(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
let n = out.features.len();
let mut messages = vec![format!("Pivot Table: {n} rows, {} pivot fields", columns.len())];
messages.extend(rounded_notice(&rounded, out.fields.get(first_pivot_field..).unwrap_or_default()));
Ok(ToolResult { output: Output::Table(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Table(out), messages })
}

/// Whether a pivot value is missing: null, or a number that isn't one.
Expand Down Expand Up @@ -6590,7 +6599,7 @@ fn tabulate_intersection(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, Strin
1 => messages.push("1 class feature lies partly or wholly outside the zones: its value outside isn't shared out".into()),
n => messages.push(format!("{n} class features lie partly or wholly outside the zones: their values outside aren't shared out")),
}
Ok(ToolResult { output: Output::Table(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Table(out), messages })
}

fn export_features(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {
Expand Down Expand Up @@ -7555,7 +7564,7 @@ fn spatial_join_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Result
));
}
messages.extend(rounded_notice(&rounded, &merged_fields));
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -7845,7 +7854,7 @@ fn zonal_stats_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Result<
messages.push(format!("... and {} more feature failure(s)", failure_details.len() - 5));
}
}
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// Returns a borrowed dataset when rows match the full dataset in identity order, or a new dataset containing
Expand Down Expand Up @@ -8042,7 +8051,7 @@ fn join_field_tool(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, String> {

let output = if out.geometry_type == rustgis_data::GeometryType::None { Output::Table(out) } else { Output::Layer(out) };

Ok(ToolResult { output, messages })
Ok(ToolResult { losses: Vec::new(), output, messages })
}

/// Keeps polygon boundaries in stored coordinates, including interior rings.
Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/src/tools/check_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn run_with_room(

let mut messages = notices(&tally, &problem_field);
messages.extend(notes);
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// The memory an output row copying `attrs` (`width` of them, of `out_width` values in the
Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/src/tools/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fn finish(out: Dataset, skipped: usize, tool: &str) -> Result<ToolResult, String
return Err(format!("{tool}: no usable output; skipped {skipped} empty or degenerate features/parts"));
}
let messages = if skipped == 0 { vec![] } else { vec![format!("{tool}: skipped {skipped} empty or degenerate features/parts")] };
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// Hashes exact coordinates, normalizing signed zero to match coordinate equality.
Expand Down
4 changes: 2 additions & 2 deletions crates/analysis/src/tools/network_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub(super) fn service_area(inp: &dyn Inputs, p: &Json) -> Result<ToolResult, Str
facilities.len()
)];
messages.append(&mut net.notes);
Ok(ToolResult { output: Output::Layer(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Layer(out), messages })
}

/// OD Cost Matrix: the cost and length of the cheapest way from each origin to each destination,
Expand Down Expand Up @@ -461,7 +461,7 @@ pub(super) fn od_cost_matrix_on(inp: &dyn Inputs, p: &Json, threads: Option<usiz
});
}
messages.append(&mut net.notes);
Ok(ToolResult { output: Output::Table(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Table(out), messages })
}

#[cfg(test)]
Expand Down
18 changes: 11 additions & 7 deletions crates/analysis/src/tools/repair_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,17 @@ fn run_with_room(

let mut messages = notices(&tally, &field);
messages.extend(notes);
Ok(ToolResult { output: Output::Layer(out), messages })
let losses = (tally.extra > 0)
.then(|| rustgis_data::loss::LossMessage {
code: rustgis_data::loss::LossCode::DroppedExtraAttributes,
text: format!(
"{TOOL}: {} had more attribute values than the layer has fields; the extra values aren't in the output",
features(tally.extra)
),
})
.into_iter()
.collect();
Ok(ToolResult { output: Output::Layer(out), messages, losses })
}

/// The run's notices: the result in one line, then one notice per kind of feature not repaired,
Expand Down Expand Up @@ -289,12 +299,6 @@ fn notices(t: &Tally, field: &str) -> Vec<String> {
rounded_up(t.moved)
));
}
if t.extra > 0 {
messages.push(format!(
"{TOOL}: {} had more attribute values than the layer has fields; the extra values aren't in the output",
features(t.extra)
));
}
messages
}

Expand Down
2 changes: 1 addition & 1 deletion crates/analysis/src/tools/tabulate_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub(super) fn run_on(inp: &dyn Inputs, p: &Json, threads: Option<usize>) -> Resu
if empty > 0 {
messages.push(format!("{empty} zone(s) contained no valid raster cell centres; their class values are zero"));
}
Ok(ToolResult { output: Output::Table(out), messages })
Ok(ToolResult { losses: Vec::new(), output: Output::Table(out), messages })
}

/// All finite valid band values, sorted numerically. The wide table has Pivot Table's column
Expand Down
8 changes: 6 additions & 2 deletions crates/analysis/tests/repair_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,12 @@ fn attributes_crs_ids_and_names_are_kept() {
assert_eq!(ds.features[1].attrs, [Value::Text("bad".into()), Value::Float(2.5), Value::Null, Value::Text("self_intersection".into())]);
assert_eq!(ds.features[2].attrs, [Value::Text("none".into()), Value::Null, Value::Int(3), Value::Text("null_geometry".into())]);
assert_eq!(
r.messages.last().map(String::as_str),
Some("Repair Geometry: 1 feature had more attribute values than the layer has fields; the extra values aren't in the output")
r.losses,
[rustgis_data::loss::LossMessage {
code: rustgis_data::loss::LossCode::DroppedExtraAttributes,
text: "Repair Geometry: 1 feature had more attribute values than the layer has fields; the extra values aren't in the output"
.into(),
}]
);
assert_eq!(dataset(&named(Some(" Fixed parcels "))).name, "Fixed parcels");
}
Expand Down
6 changes: 5 additions & 1 deletion crates/analysis/tests/resolved_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ fn provider() -> Vec<ToolSpec> {

/// Reports which captured schema and defaults actually reached the runner.
fn runner(spec: &ToolSpec, _: &dyn Inputs, params: &Value) -> Result<ToolResult, String> {
Ok(ToolResult { output: Output::Layers(Vec::new()), messages: vec![format!("{}:{}", spec.summary, params["value"])] })
Ok(ToolResult {
losses: Vec::new(),
output: Output::Layers(Vec::new()),
messages: vec![format!("{}:{}", spec.summary, params["value"])],
})
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/assistant/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ fn undeclared_external_tools_refuse_by_id_and_display_name() {
}
/// A deterministic tool result makes unauthorized execution observable without I/O.
fn run(_: &ToolSpec, _: &dyn Inputs, _: &Value) -> Result<ToolResult, String> {
Ok(ToolResult { output: Output::Selection { layer: "Cities".into(), rows: vec![0, 2] }, messages: vec![] })
Ok(ToolResult { output: Output::Selection { layer: "Cities".into(), rows: vec![0, 2] }, messages: vec![], losses: vec![] })
}
analysis::register_external("assistant-containment", specs, run);
// Explicit native discovery publishes metadata; untrusted callers cannot discover it.
Expand Down
Loading
Loading