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
1 change: 1 addition & 0 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ of use.
|---|---|---|
| Paired binary reader-loss fixtures (`crates/engine/testdata/reading-losses/xy.*`, `xyz.*`) | The RustGIS project: one made-up point, written offline with [GDAL](https://gdal.org) 3.13.3 (FlatGeobuf and FileGDB) and [PyArrow](https://arrow.apache.org/docs/python/) 26.0.1 (GeoParquet); [fixture notes](crates/engine/testdata/reading-losses/README.md) describe the minimal data and retained files | Apache-2.0 |
| Historical release projects and preferences (`crates/engine/testdata/releases/v*.rgis`, `v*.prefs.json`) | The RustGIS project: unchanged output of the published binaries, with made-up layer data. The [fixture README](crates/engine/testdata/releases/README.md) lists writers and archive checksums. | Apache-2.0 |
| Shapefile Z/M reader-loss fixtures (`crates/engine/testdata/reading-losses/shp-*`) | The RustGIS project: independently encoded, made-up point and line records following the published Shapefile specification; byte layout in [SHAPEFILE.md](crates/engine/testdata/reading-losses/SHAPEFILE.md) | Apache-2.0 |
| OSM PBF ring-loss fixtures (`crates/engine/testdata/reading-losses/hole-*.osm.pbf`) | The RustGIS project: independently encoded, made-up nodes, ways and relation from the published OSM PBF schema; contents and checksums in [OSM.md](crates/engine/testdata/reading-losses/OSM.md) | Apache-2.0 |
| Interface themes (`crates/ui-egui/themes/light.json`, `dark.json`) | The RustGIS project | Apache-2.0 |
| Sample data (`countries`, `cities`, `rivers`, `lakes` GeoJSON), embedded at build time from [rustgis-assets](https://github.com/opengeos/rustgis-assets/tree/main/data) | Natural Earth 1:110m, attributes trimmed | Public domain |
Expand Down
5 changes: 3 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ A result is right, or RustGIS says what it lost or assumed
each vertex's Z in DXF and unreadable coordinates, holes and parts in KML, GeoRSS, MapInfo and
DXF. A fix makes its case `Said` _(open)_.
- Lossy sample files in `never_silent_reading.rs` for the readers it doesn't cover yet:
Shapefile and spreadsheets. It covers GeoJSON, TopoJSON, CSV, KML, KMZ, GPX, GML, GeoRSS,
spreadsheets. It covers GeoJSON, TopoJSON, CSV, KML, KMZ, GPX, GML, GeoRSS,
DXF, LandXML and MapInfo, with height-loss cases for CityJSON, CityGML, GeoPackage,
FlatGeobuf, GeoParquet and FileGDB, and ring-loss cases for OSM PBF; other loss kinds remain.
FlatGeobuf, GeoParquet and FileGDB, Z/M-loss cases for Shapefile, and ring-loss cases for
OSM PBF; 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
Expand Down
4 changes: 3 additions & 1 deletion crates/engine/testdata/reading-losses/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Paired reader-loss fixtures

Each format holds one point and no user attributes: `xy` has `(1, 2)` and `xyz` has
The `xy.*` and `xyz.*` pairs hold one point and no user attributes: `xy` has `(1, 2)` and `xyz` has
`(1, 2, 3)`, in WGS 84 longitude/latitude. The reading corpus opens each pair from the
same path and checks that only the XYZ file reports dropping Z or M. These test the
shared engine command, not just a reader's internal report.
Expand Down Expand Up @@ -37,3 +37,5 @@ statistics. The value is little-endian ISO WKB: byte order `1`, type `1` (Point)
metadata declares version `1.0.0`, primary column `geometry`, encoding `WKB` and
geometry type `Point` or `Point Z`. CRS is omitted, meaning the format's default
OGC:CRS84. This is not a fixture for an unknown CRS or for CRS fallback behavior.

The independently encoded [Shapefile pairs](SHAPEFILE.md) cover point and line Z/M loss.
38 changes: 38 additions & 0 deletions crates/engine/testdata/reading-losses/SHAPEFILE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Shapefile Z/M pairs

Made-up data, independently encoded as bytes for RustGIS (Apache-2.0), following
[Shapefile Technical Description](https://content.esri.com/support/whitepapers/ao_/shapefile.pdf),
file headers and Tables 4, 6, 8, 12 and 14. No production writer or third-party
code generated these fixtures; no generator is needed to run the tests.

Every `.shp` contains one record. Point XY is `(1, 2)`; the single-part line's XY
vertices are `(1, 2), (3, 4)`. Both clean and lossy inputs must import this geometry
and the one `ID=1` attribute row unchanged. All four lossy inputs currently import
and report dropping Z or M; clean inputs do not report that loss.

| Stem (`shp-`) | Shape type | Extra ordinates | `.shp` bytes |
| --- | --- | --- | --- |
| `point-xy` | 1, Point | None; clean partner for both points | 128 |
| `point-z` | 11, PointZ | Z=3; M=-1e39 (no-data sentinel) | 144 |
| `point-m` | 21, PointM | M=7 | 136 |
| `line-xy` | 3, PolyLine | None; clean partner for both lines | 188 |
| `line-z` | 13, PolyLineZ | Z=[5,9]; optional M section absent | 220 |
| `line-zm` | 13, PolyLineZ | Z=[5,9], M=[7,11] | 252 |

The first 100 bytes are the format's header: file code 9994 and file length in
big-endian 16-bit words, version 1000 and shape type in little endian, then XY,
Z and M bounds as little-endian float64. Record number 1 and content length are
big endian; record contents are little endian. Each matching `.shx` is 108 bytes:
the same header with file length 54 words, then offset 50 words and the record's
content length. Line contents have one part starting at vertex 0, the XY array,
and (for type 13) the Z bounds and array, followed by M bounds and array only in
`line-zm`. The PointZ M sentinel is below the specification's -1e38 no-data limit,
so this case exercises a height without a real measure.

The shared `shp-row.dbf` is 68 bytes: dBASE III, date 2026-11-18, one row, a
65-byte header and two-byte record; one numeric field `ID`, width 1, no decimals,
header terminator 0x0d, undeleted row ` 1`, EOF 0x1a. The harness supplies identical
WGS 84 `.prj` and UTF-8 `.cpg` text beside both files. This isolates ordinate loss
from coordinate-system assumptions and DBF encoding behavior. The corpus checks
the native reader first and then `layer.addData`, so external fallbacks or empty
imports cannot stand in for valid XY geometry.
Binary file not shown.
Binary file not shown.
Binary file added crates/engine/testdata/reading-losses/shp-line-z.shp
Binary file not shown.
Binary file added crates/engine/testdata/reading-losses/shp-line-z.shx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added crates/engine/testdata/reading-losses/shp-row.dbf
Binary file not shown.
103 changes: 91 additions & 12 deletions crates/engine/tests/never_silent_reading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//! fails here until the case is moved to [`Expect::Said`], so the list only shrinks. Exports have
//! their own test, `never_silent_roundtrip.rs`.
//!
//! The table includes text, CityJSON, CityGML, KMZ, GeoPackage, FlatGeobuf, GeoParquet, FileGDB
//! and OSM PBF. More formats and loss kinds remain to add (ROADMAP.md); one loss does not
//! The table includes text, CityJSON, CityGML, KMZ, GeoPackage, FlatGeobuf, GeoParquet, FileGDB,
//! Shapefile and OSM PBF. More formats and loss kinds remain to add (ROADMAP.md); one loss does not
//! certify a reader.
use rustgis_engine::{Project, Session};
use serde_json::json;
Expand All @@ -37,13 +37,13 @@ struct Case {
file: &'static str,
clean: Vec<u8>,
lossy: Vec<u8>,
/// Files beside it, the same in both (a MapInfo `.mid`).
beside: Vec<(&'static str, String)>,
/// Files beside the clean and lossy inputs (binary indexes can differ).
beside: [Vec<(&'static str, Vec<u8>)>; 2],
expect: Expect,
}

fn case(name: &'static str, file: &'static str, clean: impl AsRef<[u8]>, lossy: impl AsRef<[u8]>, expect: Expect) -> Case {
Case { name, file, clean: clean.as_ref().to_vec(), lossy: lossy.as_ref().to_vec(), beside: Vec::new(), expect }
Case { name, file, clean: clean.as_ref().to_vec(), lossy: lossy.as_ref().to_vec(), beside: [Vec::new(), Vec::new()], expect }
}

/// A GeoJSON feature collection of these geometries.
Expand Down Expand Up @@ -97,6 +97,7 @@ fn landxml(content: &str) -> String {
format!(r#"<?xml version="1.0"?><LandXML xmlns="http://www.landxml.org/schema/LandXML-1.2" version="1.2">{content}</LandXML>"#)
}

/// Builds paired inputs, keeping sidecars specific to each input when their binary layout differs.
fn cases(fixture_dir: &std::path::Path) -> Vec<Case> {
let point = r#"{"type":"Point","coordinates":[1,2]}"#;
let topo_line = |arcs: &str| format!(r#"{{"type":"Topology","objects":{{"o":{{"type":"LineString","arcs":[0]}}}},"arcs":[{arcs}]}}"#);
Expand Down Expand Up @@ -357,7 +358,9 @@ fn cases(fixture_dir: &std::path::Path) -> Vec<Case> {
// MapInfo: the .mid beside each .mif holds one row per object.
let mut mapinfo = |name, clean: &str, lossy: &str, mid: &str, expect| {
let mut c = case(name, "a.mif", mif(clean), mif(lossy), expect);
c.beside.push(("a.mid", mid.to_string()));
for beside in &mut c.beside {
beside.push(("a.mid", mid.as_bytes().to_vec()));
}
out.push(c);
};
mapinfo("MapInfo: an unreadable object", "Point 0 0\nPoint 1 1\n", "Point 0 0\nPoint 1 x\n", "1\n2\n", Said("couldn't be read"));
Expand Down Expand Up @@ -386,7 +389,7 @@ fn cases(fixture_dir: &std::path::Path) -> Vec<Case> {
file: "a.kmz",
clean: rustgis_engine::data::zip::write(&[("doc.kml".into(), c.clean.clone())]).unwrap(),
lossy: rustgis_engine::data::zip::write(&[("doc.kml".into(), c.lossy.clone())]).unwrap(),
beside: Vec::new(),
beside: [Vec::new(), Vec::new()],
expect: c.expect,
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -417,6 +420,48 @@ fn cases(fixture_dir: &std::path::Path) -> Vec<Case> {
Imported("Z or M"),
),
]);
// Independently encoded shapes: scalar Z, scalar M, and arrays with/without optional M.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage (medium confidence): these fixtures are small, so layer.addData takes the whole-file path (io::read_shapefile_parts). Files over the size threshold go through ShpSource::open_path (crates/data/src/source/mod.rs:439), which decides Z/M loss from the header's shape type (crates/data/src/source/shp.rs:211), not from each record. None of the four new cases reaches that path, and the only existing in-place Z/M check (crates/data/src/io.rs, ~line 5055) covers PointZ alone. Line-Z, PointM and PolylineZM are not tested on the in-place path.

Either add an in-place case for types 13 and 21, or say in SHAPEFILE.md / the ROADMAP line that the large-file reader is out of scope for this corpus. This is not a blocker for the PR as written.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed: these tiny fixtures exercise whole-file imports, not the size-triggered in-place ShpSource path. The PR description now states that limit explicitly. The in-place header logic includes types 13 and 21, but this corpus does not test that path; additional in-place cases and fixture-note clarification are left for the release quality pass.

for (name, clean, lossy, clean_index, lossy_index) in [
(
"Shapefile: a point height",
include_bytes!("../testdata/reading-losses/shp-point-xy.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-point-z.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-point-xy.shx"),
include_bytes!("../testdata/reading-losses/shp-point-z.shx"),
),
(
"Shapefile: a point measure",
include_bytes!("../testdata/reading-losses/shp-point-xy.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-point-m.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-point-xy.shx"),
include_bytes!("../testdata/reading-losses/shp-point-m.shx"),
),
(
"Shapefile: line heights without measures",
include_bytes!("../testdata/reading-losses/shp-line-xy.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-line-z.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-line-xy.shx"),
include_bytes!("../testdata/reading-losses/shp-line-z.shx"),
),
(
"Shapefile: line heights and measures",
include_bytes!("../testdata/reading-losses/shp-line-xy.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-line-zm.shp").as_slice(),
include_bytes!("../testdata/reading-losses/shp-line-xy.shx"),
include_bytes!("../testdata/reading-losses/shp-line-zm.shx"),
),
] {
let mut c = case(name, "a.shp", clean, lossy, Imported("Z or M"));
for (beside, index) in c.beside.iter_mut().zip([clean_index, lossy_index]) {
beside.extend([
("a.shx", index.to_vec()),
("a.dbf", include_bytes!("../testdata/reading-losses/shp-row.dbf").to_vec()),
("a.cpg", b"UTF-8\n".to_vec()),
("a.prj", br#"GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]"#.to_vec()),
]);
}
out.push(c);
}
out
}

Expand Down Expand Up @@ -476,6 +521,22 @@ fn gpkg(dir: &std::path::Path, z: bool) -> Vec<u8> {
std::fs::read(path).unwrap()
}

/// Both Shapefile inputs must retain the one attribute row and every XY vertex, through
/// the native reader and the command. A notice over an empty or partial import isn't enough.
fn check_shapefile_xy(ds: &rustgis_engine::data::Dataset, shape_type: Option<u8>) -> std::io::Result<()> {
use rustgis_engine::data::{Geometry, Value};
use rustgis_engine::geom::Coord;
let expected = match shape_type {
Some(1 | 11 | 21) => Geometry::Point(Coord::new(1.0, 2.0)),
Some(3 | 13) => Geometry::Line(vec![vec![Coord::new(1.0, 2.0), Coord::new(3.0, 4.0)]]),
_ => return Err(std::io::Error::other("Shapefile fixture has the wrong geometry type")),
};
if ds.features.len() != 1 || ds.features[0].geometry.as_ref() != Some(&expected) || ds.features[0].attrs != vec![Value::Int(1)] {
return Err(std::io::Error::other("Shapefile fixture didn't retain its XY geometry and ID"));
}
Ok(())
}

/// What `layer.addData` did with a file: the notices it gave and whether it added a layer or table,
/// or why it refused the file.
type Reading = Result<(Vec<String>, bool), String>;
Expand All @@ -485,11 +546,11 @@ type Reading = Result<(Vec<String>, bool), String>;
/// case is read from the same `dir`, so notices naming its path are the same for both.
/// A `.gdb` fixture is stored as a ZIP of its table files, extracted and checked with the native
/// reader before the command opens it, so an optional GDAL fallback cannot mask a regression.
fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, String)]) -> std::io::Result<Reading> {
fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, Vec<u8>)]) -> std::io::Result<Reading> {
let _ = std::fs::remove_dir_all(dir);
std::fs::create_dir_all(dir)?;
for (name, text) in beside {
std::fs::write(dir.join(name), text)?;
for (name, bytes) in beside {
std::fs::write(dir.join(name), bytes)?;
}
let path = dir.join(file);
if file.ends_with(".gdb") {
Expand All @@ -514,6 +575,18 @@ fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, Stri
} else {
std::fs::write(&path, content)?;
}
if file.ends_with(".shp") {
let (native, report) =
rustgis_engine::data::io::read_path(&path).map_err(|e| std::io::Error::other(format!("native Shapefile fixture: {e}")))?;
check_shapefile_xy(&native, content.get(32).copied())?;
let zm = matches!(content.get(32), Some(11 | 13 | 21));
if native.zm_dropped != zm || report.messages.iter().any(|m| m.contains("Z or M")) != zm {
return Err(std::io::Error::other(format!("native Shapefile fixture has the wrong loss report: {report:?}")));
}
if report.skipped != 0 {
return Err(std::io::Error::other("native Shapefile fixture skipped a record"));
}
}
let mut s = Session::new(Project::default());
// Layers and standalone tables (what a file without geometry adds).
let held = |s: &Session| s.map().layers.len() + s.project.tables.len();
Expand All @@ -522,6 +595,12 @@ fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, Stri
if let Err(e) = s.run("layer.addData", &json!({"path": path})) {
return Ok(Err(e));
}
if file.ends_with(".shp") {
if s.map().layers.len() != 1 {
return Err(std::io::Error::other("Shapefile fixture didn't add exactly one layer"));
}
check_shapefile_xy(&s.map().layers[0].dataset, content.get(32).copied())?;
}
let said = s.notices_since(mark).iter().map(|n| n.text.clone()).collect();
Ok(Ok((said, held(&s) > before)))
}
Expand All @@ -533,7 +612,7 @@ fn a_reading_that_loses_something_says_so() {
let mut failures = Vec::new();
for c in cases(&root.join("fixtures")) {
let name = format!("{} [{}]", c.name, c.file);
let clean = match read(&dir, c.file, &c.clean, &c.beside) {
let clean = match read(&dir, c.file, &c.clean, &c.beside[0]) {
Err(e) => {
failures.push(format!("{name}: the clean file couldn't be written: {e}"));
continue;
Expand All @@ -549,7 +628,7 @@ fn a_reading_that_loses_something_says_so() {
Ok(Ok((said, true))) => said,
};
// What the lossy file says that the clean one doesn't, and whether it added a layer.
let (new, added): (Vec<String>, bool) = match read(&dir, c.file, &c.lossy, &c.beside) {
let (new, added): (Vec<String>, bool) = match read(&dir, c.file, &c.lossy, &c.beside[1]) {
Err(e) => {
failures.push(format!("{name}: the lossy file couldn't be written: {e}"));
continue;
Expand Down
Loading