diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index fde228993e..1249ddb374 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -20,6 +20,7 @@ of use. | 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 | | XLSX reader-loss fixtures (`crates/engine/testdata/reading-losses/book-*.xlsx`) | The RustGIS project: made-up one-row workbooks, encoded as Office Open XML with Python standard-library ZIP/XML writing; [fixture notes](crates/engine/testdata/reading-losses/README.md#xlsx) describe their contents | Apache-2.0 | | ODS reader-loss fixtures (`crates/engine/testdata/reading-losses/book-*.ods`) | The RustGIS project: made-up one-row OpenDocument workbooks, independently encoded with Python standard-library ZIP/XML writing; [fixture notes](crates/engine/testdata/reading-losses/README.md#ods) describe their contents | Apache-2.0 | +| XLS/XLSB reader-loss fixtures (`crates/engine/testdata/reading-losses/book-*.xls`, `book-*.xlsb`) | The RustGIS project: made-up one-row workbooks generated offline with SheetJS CE 0.18.5; XLSB package parts were minimized; except in `book-short.xlsb`, short cell records were independently re-encoded to the published full-cell layout; [fixture notes](crates/engine/testdata/reading-losses/README.md#xls-and-xlsb) describe contents and checks | 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 | diff --git a/ROADMAP.md b/ROADMAP.md index 9749397777..178f2f4da8 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -73,14 +73,18 @@ A result is right, or RustGIS says what it lost or assumed nodes or ways the file doesn't hold, and inner rings outside every outer one; and the text readers' losses listed as `Silent` in `crates/engine/tests/never_silent_reading.rs`, among them each vertex's Z in DXF and unreadable coordinates, holes and parts in KML, GeoRSS, MapInfo and - DXF, plus geometry-collection members in XLSX/ODS and error-valued attribute cells in XLSX. A fix makes + DXF, plus geometry-collection members in XLSX/ODS/XLS/XLSB, error-valued attribute cells in XLSX, + and attribute fields/values in XLSB short-cell workbooks (the original SheetJS 0.18.5 clean + workbook retains its point but no attributes, without a notice). A fix makes its case `Said` _(open)_. - Lossy sample files in `never_silent_reading.rs` for the readers it doesn't cover yet: - remaining spreadsheet formats (XLS, XLSB and XLSM). It covers GeoJSON, TopoJSON, CSV, + remaining distinct loss families and parser paths (see the finite + [coverage inventory](crates/engine/testdata/reading-losses/README.md#coverage-boundaries)). 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, 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. + OSM PBF, WKT height/member losses for XLSX, ODS, XLS and XLSB, and error-cell losses for XLSX; other loss kinds remain. + XLSM shares the XLSX parser; macros are untested. 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 diff --git a/crates/engine/testdata/reading-losses/README.md b/crates/engine/testdata/reading-losses/README.md index 05c6baa31b..796d8d14cd 100644 --- a/crates/engine/testdata/reading-losses/README.md +++ b/crates/engine/testdata/reading-losses/README.md @@ -90,3 +90,85 @@ reader and `layer.addData`; native reports must also have zero skipped rows and expected height-loss flag and notice. Valid lossy files must import. WKT uses the existing reader convention without testing or changing CRS assumptions. This slice does not certify ODS completeness or cover malformed archives, formulas, dates or error cells. + +## XLS and XLSB + +Seven made-up workbooks written offline with SheetJS Community Edition `xlsx` 0.18.5: +`utils.aoa_to_sheet([['wkt','id','note'],[wkt,7]])`, appended as `Places`, then +`writeFile` with `bookType: 'biff8'` (XLS) or `'xlsb'` and compression enabled. +The writer is independent of RustGIS and is not needed by tests. No writer code or +third-party data is included. XLS exercises the compound-file/BIFF reader; XLSB +exercises the binary workbook/sheet parser inside ZIP, rather than XLSX's XML parser. + +XLS files retain the writer's small compound container. XLSB archives were minimized +offline with Python's standard-library `zipfile`: retain workbook, worksheet and style +binary parts, replace package relationships/content types with only those parts, and +remove the unused theme, document properties and sheet metadata. ZIP timestamps are +1980-01-01. Except in `book-short.xlsb`, the generated XLSB short string/RK cell +records were re-encoded as +full `BrtCellSt`/`BrtCellRk` records with explicit column indexes, following the +published [MS-XLSB Cell layout](https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-xlsb/1e3e0c46-6175-4123-b02b-903643a5cc07). +`book-short.xlsb` preserves the original worksheet records and tests the short-cell loss. +As a check independent of the handwritten full-cell rewrite, SheetJS CE 0.18.5's `readFile` +and `sheet_to_json` read all seven committed XLS/XLSB workbooks back to the documented +headers, WKT and numeric ID. This check uses a parser independent of RustGIS. +No macros, formulas or external links are included. + +The original SheetJS 0.18.5 short-cell worksheet, retained in `book-short.xlsb`, +pins a known reader gap: native +`sheets::read` retains `POINT(1 2)` but returns no attribute fields or values, +including the source `id=7`, with zero skipped rows and no messages. Its short +cell records are paired with the full-record `book-clean.xlsb`; both native and +command imports must retain exactly the point with no attribute fields/values or notices. + +| Files (`.xls` and `.xlsb` unless stated) | WKT | Current loss classification | +| --- | --- | --- | +| `book-clean` | `POINT(1 2)` | None; no native or command notice | +| `book-z` | `POINT Z(1 2 3)` | Imports with a Z/M-loss notice | +| `book-collection` | `GEOMETRYCOLLECTION(POINT(1 2),POINT(3 4))` | Silent: only the first member remains | +| `book-short.xlsb` (paired with `book-clean.xlsb`) | `POINT(1 2)` | Silent: all attribute fields and values are lost | + +The height/member pairs must retain exactly one point at (1, 2), integer `id=7`, +text `note=Null` and both field names/types, through `sheets::read` and `layer.addData`. +Native checks require zero skipped rows, the expected height flag and exactly one +Z/M message for the height variant (none otherwise). Valid lossy fixtures must import. +Dates, error cells, other sheets and broader type/encoding fidelity are not certified. + +## Coverage boundaries + +The corpus is a list of specific losses, not a format-completeness certificate. +Dispatch is defined by `data::io::{read_layers,read_bytes,read_path}`, `source::EXTENSIONS` +and `sheets::open_checked`. Aliases and sniffed formats share rows below; the table does +not claim that every alias or container has its own paired test. “Gap” means applicable +but not covered here, not necessarily a known bug. CRS assumptions remain separate work +(#2032). The exact tested loss and `Silent`/reported status live in the test case table. + +| Reader dispatch | Paired corpus coverage | Remaining applicable families | +| --- | --- | --- | +| GeoJSON | Z, unreadable geometry | M, members/holes, attributes | +| TopoJSON | Z, missing arcs, bad quantized positions, nested members | M, other parts, attributes | +| Delimited text (CSV/TSV/TXT/DAT, gzip wrapper) | CSV WKT Z, bad WKT/XY, later WKT members, extra cells | M, holes/curves, types/names/encoding, wrapper parity | +| Shapefile | Point Z/M, line Z/ZM | Other shapes/parts, attributes; DBF encoding tracked in #2325 | +| Standalone DBF | None | Names/types/encoding; geometry and Z/M inapplicable | +| KML/KMZ | Z, missing geometry, bad coordinate/hole/part, excess point coordinates | Other parts, attributes | +| GPX | Bad waypoint, short track segment | Elevation attributes, other parts, attributes | +| GeoRSS (RSS/Atom/GeoRSS, sniffed XML) | Unreadable place/hole, excess coordinate pairs | GML dimensions, other members, attributes | +| LandXML (including sniffed XML) | Unreadable point, parcel without geometry | Elevations, curves/parts, attributes | +| GML | Z | M, members/holes/curves, attributes | +| CityGML / CityJSON (distinct parsers) | Varying line Z in each | Other dimensions, surfaces/members/holes, attributes | +| DXF | Varying line Z, unreadable entity/vertex | Other entities/curves/parts, attributes | +| MapInfo MIF/MID | Unreadable object, arc, short part/ring | Other geometry and attribute conversion | +| OSM PBF | Missing member/node, unclosed/outside inner ring | Other relations, attributes; native coordinates are XY | +| Feature-service PBF (distinct sniffed PBF parser) | None | Dimensions, geometry members, attributes | +| GeoPackage / FlatGeobuf / GeoParquet / FileGDB (distinct readers) | Z in each | M, members/parts/curves where supported, attributes | +| LAS/LAZ | None in this paired corpus | Sampling, dimensions/attributes; geometry members/holes inapplicable | +| XLSX | WKT Z/members, error-valued attribute | M, other geometry, dates/formulas/names/encoding | +| ODS / XLS (distinct workbook parsers) | WKT Z/members in each | M, other geometry, dates/errors/names/encoding | +| XLSB | WKT Z/members with full cell records; short-cell attribute loss | Pinned silent short-cell loss; M, other geometry, dates/errors/names/encoding remain gaps | +| XLSM | Shared XLSX OOXML implementation only | No distinct fixture; macros and macro fidelity untested | +| Generic ZIP | Delegates to inner readers; KMZ covered above | Other wrapper parity | + +XLSM uses the same OOXML parser as XLSX; merely renaming a workbook would not establish +another parser's coverage. Raster/image/grid/PDF fidelity and external program, database +and network-provider losses are outside this local vector/table corpus. Existing tests +elsewhere (including LAS whole-read fidelity) do not count as paired coverage here. diff --git a/crates/engine/testdata/reading-losses/book-clean.xls b/crates/engine/testdata/reading-losses/book-clean.xls new file mode 100644 index 0000000000..f14a03f82d Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-clean.xls differ diff --git a/crates/engine/testdata/reading-losses/book-clean.xlsb b/crates/engine/testdata/reading-losses/book-clean.xlsb new file mode 100644 index 0000000000..d36f5863d1 Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-clean.xlsb differ diff --git a/crates/engine/testdata/reading-losses/book-collection.xls b/crates/engine/testdata/reading-losses/book-collection.xls new file mode 100644 index 0000000000..6173d294d8 Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-collection.xls differ diff --git a/crates/engine/testdata/reading-losses/book-collection.xlsb b/crates/engine/testdata/reading-losses/book-collection.xlsb new file mode 100644 index 0000000000..a84d12a38a Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-collection.xlsb differ diff --git a/crates/engine/testdata/reading-losses/book-short.xlsb b/crates/engine/testdata/reading-losses/book-short.xlsb new file mode 100644 index 0000000000..1503b93d98 Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-short.xlsb differ diff --git a/crates/engine/testdata/reading-losses/book-z.xls b/crates/engine/testdata/reading-losses/book-z.xls new file mode 100644 index 0000000000..1d2bab56b0 Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-z.xls differ diff --git a/crates/engine/testdata/reading-losses/book-z.xlsb b/crates/engine/testdata/reading-losses/book-z.xlsb new file mode 100644 index 0000000000..3c744e53b3 Binary files /dev/null and b/crates/engine/testdata/reading-losses/book-z.xlsb differ diff --git a/crates/engine/tests/never_silent_reading.rs b/crates/engine/tests/never_silent_reading.rs index 5fe2badde0..34c62110bb 100644 --- a/crates/engine/tests/never_silent_reading.rs +++ b/crates/engine/tests/never_silent_reading.rs @@ -12,7 +12,7 @@ //! their own test, `never_silent_roundtrip.rs`. //! //! The table includes text, CityJSON, CityGML, KMZ, GeoPackage, FlatGeobuf, GeoParquet, FileGDB, -//! Shapefile, XLSX, ODS and OSM PBF. More formats and loss kinds remain to add (ROADMAP.md); one loss +//! Shapefile, XLSX, ODS, XLS, XLSB 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; @@ -396,6 +396,44 @@ fn cases(fixture_dir: &std::path::Path) -> Vec { ), ]); + out.extend([ + case( + "XLS: a height in WKT", + "a.xls", + include_bytes!("../testdata/reading-losses/book-clean.xls"), + include_bytes!("../testdata/reading-losses/book-z.xls"), + Imported("Z or M"), + ), + case( + "XLS: a WKT geometry collection's later members", + "a.xls", + include_bytes!("../testdata/reading-losses/book-clean.xls"), + include_bytes!("../testdata/reading-losses/book-collection.xls"), + Silent("only the collection's first member is kept"), + ), + case( + "XLSB: a height in WKT", + "a.xlsb", + include_bytes!("../testdata/reading-losses/book-clean.xlsb"), + include_bytes!("../testdata/reading-losses/book-z.xlsb"), + Imported("Z or M"), + ), + case( + "XLSB: short cell records lose attribute fields and values", + "a.xlsb", + include_bytes!("../testdata/reading-losses/book-clean.xlsb"), + include_bytes!("../testdata/reading-losses/book-short.xlsb"), + Silent("the point remains but all attribute fields and values are lost"), + ), + case( + "XLSB: a WKT geometry collection's later members", + "a.xlsb", + include_bytes!("../testdata/reading-losses/book-clean.xlsb"), + include_bytes!("../testdata/reading-losses/book-collection.xlsb"), + Silent("only the collection's first member is kept"), + ), + ]); + // 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); @@ -578,17 +616,22 @@ fn check_shapefile_xy(ds: &rustgis_engine::data::Dataset, shape_type: Option Ok(()) } -/// All workbook variants retain the same point, row ID and two attribute columns. The -/// error-cell fixture differs from an empty note only in source content, not retained data. -fn check_workbook(ds: &rustgis_engine::data::Dataset) -> std::io::Result<()> { +/// Workbooks retain the point and two attributes except the pinned XLSB short-cell loss, +/// which retains the point but drops every attribute field and value. +fn check_workbook(ds: &rustgis_engine::data::Dataset, short_cells: bool) -> std::io::Result<()> { use rustgis_engine::data::{Field, FieldType, Geometry, Value}; use rustgis_engine::geom::Coord; - if ds.fields != vec![Field::new("id", FieldType::Integer), Field::new("note", FieldType::Text)] + let fields = if short_cells { vec![] } else { vec![Field::new("id", FieldType::Integer), Field::new("note", FieldType::Text)] }; + let attrs = if short_cells { vec![] } else { vec![Value::Int(7), Value::Null] }; + if ds.fields != fields || ds.features.len() != 1 || ds.features[0].geometry != Some(Geometry::Point(Coord::new(1.0, 2.0))) - || ds.features[0].attrs != vec![Value::Int(7), Value::Null] + || ds.features[0].attrs != attrs { - return Err(std::io::Error::other("spreadsheet fixture didn't retain exactly its point, ID and null note")); + return Err(std::io::Error::other(format!( + "spreadsheet fixture has unexpected retained data: fields={:?}, features={:?}", + ds.fields, ds.features + ))); } Ok(()) } @@ -609,6 +652,7 @@ fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, Vec< std::fs::write(dir.join(name), bytes)?; } let path = dir.join(file); + let short_cells = content == include_bytes!("../testdata/reading-losses/book-short.xlsb"); if file.ends_with(".gdb") { // The archive is fixture storage only: RustGIS opens the extracted folder. Its ZIP // importer deliberately refuses FileGDB folders, so do not test that refusal as a loss. @@ -643,12 +687,14 @@ fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, Vec< return Err(std::io::Error::other("native Shapefile fixture skipped a record")); } } - if file.ends_with(".xlsx") || file.ends_with(".ods") { + if rustgis_engine::data::sheets::is_sheet_name(file) { let (native, report) = rustgis_engine::data::sheets::read(content, "a", None, &Default::default()) .map_err(|e| std::io::Error::other(format!("native spreadsheet fixture: {e}")))?; - check_workbook(&native)?; + check_workbook(&native, short_cells)?; let height = content == include_bytes!("../testdata/reading-losses/book-z.xlsx") - || content == include_bytes!("../testdata/reading-losses/book-z.ods"); + || content == include_bytes!("../testdata/reading-losses/book-z.ods") + || content == include_bytes!("../testdata/reading-losses/book-z.xls") + || content == include_bytes!("../testdata/reading-losses/book-z.xlsb"); if report.skipped != 0 || native.zm_dropped != height || if height { report.messages.len() != 1 || !report.messages[0].contains("Z or M") } else { !report.messages.is_empty() } @@ -670,13 +716,15 @@ fn read(dir: &std::path::Path, file: &str, content: &[u8], beside: &[(&str, Vec< } check_shapefile_xy(&s.map().layers[0].dataset, content.get(32).copied())?; } - if file.ends_with(".xlsx") || file.ends_with(".ods") { + if rustgis_engine::data::sheets::is_sheet_name(file) { if s.map().layers.len() != 1 || !s.project.tables.is_empty() { return Err(std::io::Error::other("spreadsheet fixture didn't add exactly one layer")); } - check_workbook(&s.map().layers[0].dataset)?; + check_workbook(&s.map().layers[0].dataset, short_cells)?; if (content == include_bytes!("../testdata/reading-losses/book-clean.xlsx") - || content == include_bytes!("../testdata/reading-losses/book-clean.ods")) + || content == include_bytes!("../testdata/reading-losses/book-clean.ods") + || content == include_bytes!("../testdata/reading-losses/book-clean.xls") + || content == include_bytes!("../testdata/reading-losses/book-clean.xlsb")) && !s.notices_since(mark).is_empty() { return Err(std::io::Error::other("clean spreadsheet fixture gave a notice"));