Skip to content

Commit 442ccde

Browse files
authored
chore(sweep): data fixes from the release quality pass (#2648)
* chore(sweep): data fixes from the release quality pass - CityGML: a `<!` markup error counts as a cut only at the end of the file; an unknown srsName is said as unknown, not as another system; an implicit geometry inside a prototype has its own notice, and the instance notice lists every reason a shape isn't placed. - KML/GPX: names, field names and values hold XML 1.0 characters as they are or are refused with a count, as descriptions are. - WKT: a TOWGS84 that isn't 3 or 7 numbers is said, not ignored. - Shapefile placement: a rollback names the file and says nothing changed; old parts that can't be removed are said by a publish. - GeoJSON publish: a type change, a number's spelling and a file that doesn't read whole are refused with the right reason. - Messages: date-time literals, GeoParquet streamed notes, GeoTIFF model type, Zarr shard errors, STAC index refusal. - Extent::beyond_lonlat replaces four copies of the test. - Docs, comments, stale test paths, dead constructors, a GDAL -if test, and a stale never-silent whitelist entry. * fix(data): keep the kept-backups note out of the browser build * Address review feedback - A Shapefile export over an existing file now says the old parts it couldn't remove: write_path_to returns notes, and both export commands give them. - A failed placement of a new Shapefile says nothing was written, not that an old file was put back; a new part that can't be removed in the rollback is named. - KML field names keep tabs and line breaks as references in their attribute; a value refusal escapes the field name as the name refusal does. - The provenance, date-time and beyond_lonlat docs and messages say exactly what holds.
1 parent 3150ece commit 442ccde

39 files changed

Lines changed: 490 additions & 108 deletions

‎.github/workflows/nightly.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
release-build: true
6161

6262
# Everyday jobs on real data: the Census Bureau's tracts for Shelby County, Tennessee, checked
63-
# against the areas it publishes (crates/engine/tests/workflows.rs). The files are public domain
63+
# against the areas it publishes (crates/engine/tests/integration/workflows.rs). The files are public domain
6464
# and pinned by checksum; a changed file fails the run, a download that fails skips the tests
6565
# (`tested` tells the report, which then neither opens nor closes an issue).
6666
workflows:

‎ROADMAP.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ A result is right, or RustGIS says what it lost or assumed
7171
([AGENTS.md](AGENTS.md#never-silent)).
7272
- Known silent losses: DuckDB queries (`ST_Force2D`) drop Z without a notice; the OSM reader leaves out rings that don't close, rings and member ways with
7373
nodes or ways the file doesn't hold, and inner rings outside every outer one; and the text
74-
readers' losses listed as `Silent` in `crates/engine/tests/never_silent_reading.rs`, among them
74+
readers' losses listed as `Silent` in `crates/engine/tests/integration/never_silent_reading.rs`, among them
7575
each vertex's Z in DXF and unreadable coordinates, holes and parts in KML, GeoRSS, MapInfo and
7676
DXF, plus geometry-collection members in XLSX/ODS/XLS/XLSB, error-valued attribute cells in XLSX,
7777
and attribute fields/values in XLSB short-cell workbooks (the original SheetJS 0.18.5 clean

‎crates/data/src/citygml.rs‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,13 @@ fn written_dim(e: &BytesStart) -> Option<Box<str>> {
569569
Some(written_attribute("srsDimension", value).into())
570570
}
571571

572+
/// Whether the `<!` markup error at `at` is the text ending at `<!` (a cut), not markup that `<!`
573+
/// starts and nothing knows, earlier in the text.
574+
fn bang_at_end(text: &str, at: u64) -> bool {
575+
// The error is placed at the `<` of the markup.
576+
usize::try_from(at).ok().and_then(|at| text.get(at..)).is_some_and(|rest| rest.trim_end() == "<!")
577+
}
578+
572579
fn position(reader: &Reader<&[u8]>) -> usize {
573580
usize::try_from(reader.buffer_position()).unwrap_or(usize::MAX)
574581
}
@@ -740,7 +747,10 @@ impl Index {
740747
// A syntax error is the text ending inside markup (a tag, a comment): a file cut
741748
// short, as one cut between tags is. But for `<!` followed by what no markup
742749
// starts with, which is a file broken there.
743-
Err(quick_xml::Error::Syntax(e)) if !matches!(e, SyntaxError::InvalidBangMarkup) || text.ends_with("<!") => {
750+
// The `<!` must be the one the text ends at, not one earlier in it.
751+
Err(quick_xml::Error::Syntax(e))
752+
if !matches!(e, SyntaxError::InvalidBangMarkup) || bang_at_end(text, reader.error_position()) =>
753+
{
744754
let at = usize::try_from(reader.error_position()).unwrap_or(usize::MAX);
745755
in_root_end = depth == 1 && text.get(at..).is_some_and(|rest| rest.starts_with("</"));
746756
break;
@@ -901,6 +911,21 @@ impl Index {
901911
self.other.get_or_insert_with(|| cut(srs));
902912
Ok(())
903913
}
914+
// One RustGIS doesn't know may be the same system as the other: said as unknown.
915+
(a, b) if a.is_none() || b.is_none() => {
916+
let (unknown, other) = if a.is_none() { (first.as_str(), srs) } else { (srs, first.as_str()) };
917+
let both = if a.is_none() && b.is_none() { "two coordinate systems" } else { "a coordinate system" };
918+
let then = if self.archive {
919+
"which aren't read together in a model in an archive"
920+
} else {
921+
"which aren't read together; give the coordinate system (crs) to read it in one"
922+
};
923+
Err(DataError::Unsupported(format!(
924+
"{file_name}: it names {both} RustGIS doesn't know ({} beside {}), {then}",
925+
cut(unknown),
926+
cut(other)
927+
)))
928+
}
904929
_ if self.archive => Err(DataError::Unsupported(format!(
905930
"{file_name}: it names different coordinate systems ({} and {}), which aren't read together; in an archive a model keeps the systems it names, so a coordinate system given doesn't apply to it",
906931
cut(first),
@@ -2599,7 +2624,7 @@ impl<'a, 'i> Walk<'_, 'a, 'i> {
25992624
fn implicit(&mut self, g: &Node<'a, 'i>) -> Option<()> {
26002625
if self.local {
26012626
// A prototype's geometries are GML's: one that is an implicit geometry places nothing.
2602-
self.counts.unknown.insert("ImplicitGeometry in a prototype".to_string());
2627+
self.counts.nested_instances += 1;
26032628
return Some(());
26042629
}
26052630
let at = elements(*g).find(|c| local(c) == "referencePoint")?;

‎crates/data/src/citygml/tests.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ fn a_compound_system_is_read_by_its_horizontal_part() {
210210
let other = inner.replace("EPSG:25832", "EPSG:25833");
211211
let err = read("model.gml", &model("EPSG:25832", &building("b1", &other)), None).unwrap_err().to_string();
212212
assert!(err.contains("different coordinate systems (EPSG:25832 and EPSG:25833)"), "{err}");
213+
// One RustGIS doesn't know beside a known one: said as unknown, not as another system.
214+
let unknown = inner.replace("EPSG:25832", "EPSG:999999");
215+
let err = read("model.gml", &model("EPSG:25832", &building("b1", &unknown)), None).unwrap_err().to_string();
216+
assert!(err.contains("a coordinate system RustGIS doesn't know (EPSG:999999 beside EPSG:25832)"), "{err}");
217+
assert!(err.contains("give the coordinate system (crs)") && !err.contains("different coordinate systems"), "{err}");
218+
// Given one, it is read in it.
219+
assert!(read("model.gml", &model("EPSG:25832", &building("b1", &unknown)), Some(Crs::Epsg(25832))).is_ok());
213220
}
214221

215222
/// A compound system's vertical part is said when its heights aren't metres upward: another unit, a
@@ -1109,6 +1116,11 @@ fn a_file_broken_in_the_middle_is_refused() {
11091116
// Markup that `<!` starts and nothing knows, in the middle: refused too. Ending at `<!`: cut.
11101117
let bang = lonlat(&[building("b1", &box_surfaces("b1")), "<!x>".to_string(), building("b2", &box_surfaces("b2"))].concat());
11111118
assert!(read("model.gml", &bang, None).is_err());
1119+
// Broken in the middle and ending at `<!` too: still refused, not read as cut short there.
1120+
let mut bang_cut = bang.clone();
1121+
bang_cut.extend_from_slice(b"<!");
1122+
let err = read("model.gml", &bang_cut, None).unwrap_err().to_string();
1123+
assert!(!err.contains("cut short"), "{err}");
11121124
let whole = lonlat(&[building("b1", &box_surfaces("b1")), "<!-- n -->".to_string(), building("b2", &box_surfaces("b2"))].concat());
11131125
let cut = whole.windows(4).position(|w| w == b"<!--").unwrap() + 2;
11141126
let out = read("model.gml", &whole[..cut], None).unwrap();
@@ -1935,6 +1947,21 @@ fn a_prototype_that_cant_be_read_is_said_once() {
19351947
assert!(says(&out, "2 geometry instances are drawn as a point"), "{:?}", messages_of(&out));
19361948
}
19371949

1950+
/// An implicit geometry inside a prototype places nothing: said as such, not as a geometry of an
1951+
/// unknown type.
1952+
#[test]
1953+
fn an_implicit_geometry_inside_a_prototype_is_said() {
1954+
let nested = format!(
1955+
"<core:relativeGMLGeometry><gml:MultiGeometry><gml:geometryMember><core:ImplicitGeometry>{}</core:ImplicitGeometry></gml:geometryMember></gml:MultiGeometry></core:relativeGMLGeometry>{}",
1956+
reference(1.0, 1.0, 0.0),
1957+
reference(5.0, 5.0, 0.0)
1958+
);
1959+
let out = read("model.gml", &lonlat(&furniture("t1", &nested)), None).unwrap();
1960+
assert!(says(&out, "1 implicit geometries inside a prototype aren't placed"), "{:?}", messages_of(&out));
1961+
assert!(!says(&out, "unknown types"), "{:?}", messages_of(&out));
1962+
assert!(says(&out, "its template or prototype is missing, in another file, can't be read or draws nothing"), "{:?}", messages_of(&out));
1963+
}
1964+
19381965
/// A prototype's geometry linked from outside an implicit geometry isn't read as the file's.
19391966
#[test]
19401967
fn a_prototype_linked_from_outside_is_said() {

‎crates/data/src/citymodel.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ pub(crate) struct Counts {
146146
pub(crate) dropped_rings: usize,
147147
pub(crate) instances: usize,
148148
pub(crate) tin_reliefs: usize,
149+
/// Implicit geometries inside a prototype (CityGML), which place nothing.
150+
pub(crate) nested_instances: usize,
149151
pub(crate) unconverted: usize,
150152
pub(crate) bad_heights: usize,
151153
/// Objects whose lowest and highest Z, or lowest Z and ground, are too far apart for their
@@ -1147,10 +1149,11 @@ pub(crate) fn messages(c: &Counts) -> Vec<String> {
11471149
say(
11481150
c.instances,
11491151
format!(
1150-
"{} geometry instances are drawn as a point at their reference point, with no height: their shape isn't placed (it is in another file, it or its matrix can't be read, or placing every instance would cost many times the file)",
1152+
"{} geometry instances are drawn as a point at their reference point, with no height: their shape isn't placed (its template or prototype is missing, in another file, can't be read or draws nothing; its matrix is missing or can't be read; its placed point isn't a finite number; or placing every instance would cost many times the file)",
11511153
c.instances
11521154
),
11531155
);
1156+
say(c.nested_instances, format!("{} implicit geometries inside a prototype aren't placed", c.nested_instances));
11541157
say(c.tin_reliefs, format!("{} TINRelief objects aren't drawn and are left out", c.tin_reliefs));
11551158
say(
11561159
c.unconverted,

‎crates/data/src/interop.rs‎

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,11 @@ use rustgis_geom::Coord;
66

77
use crate::{Dataset, Geometry};
88

9-
/// Text for XML: special characters escaped, control characters (invalid in XML 1.0) dropped.
10-
fn xml(s: &str) -> String {
11-
let clean: String = s.chars().filter(|c| !c.is_control() || matches!(c, '\t' | '\n' | '\r')).collect();
12-
escaped_xml(&clean)
13-
}
14-
15-
fn escaped_xml(s: &str) -> String {
16-
s.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;").replace('"', "&quot;").replace('\r', "&#13;")
17-
}
18-
9+
/// Text for XML, special characters escaped: kept exactly or refused, never cleaned without
10+
/// reporting its loss. `place` says where in the file of `format` the text goes, for the refusal.
11+
///
1912
/// XML 1.0 Char production: https://www.w3.org/TR/xml/#charsets.
20-
/// A description is kept exactly or refused, never cleaned without reporting its loss.
21-
fn description_xml(text: &str, layer: &str, feature: u64) -> crate::Result<String> {
13+
fn xml(text: &str, format: &str, place: impl FnOnce() -> String) -> crate::Result<String> {
2214
let mut invalid = text.chars().filter(|c| {
2315
!matches!(*c,
2416
'\t' | '\n' | '\r' | '\u{20}'..='\u{d7ff}' | '\u{e000}'..='\u{fffd}' | '\u{10000}'..='\u{10ffff}'
@@ -27,13 +19,23 @@ fn description_xml(text: &str, layer: &str, feature: u64) -> crate::Result<Strin
2719
if let Some(first) = invalid.next() {
2820
let count = invalid.count().saturating_add(1);
2921
return Err(crate::DataError::Format(format!(
30-
"KML: {layer}, feature id {feature}, description: {count} character(s) cannot be represented in XML 1.0 (first U+{:04X})",
22+
"{format}: {}: {count} character(s) cannot be represented in XML 1.0 (first U+{:04X})",
23+
place(),
3124
first as u32
3225
)));
3326
}
3427
Ok(escaped_xml(text))
3528
}
3629

30+
fn escaped_xml(s: &str) -> String {
31+
s.replace('&', "&amp;").replace('<', "&lt;").replace('>', "&gt;").replace('"', "&quot;").replace('\r', "&#13;")
32+
}
33+
34+
/// Where in a layer's file a feature's text goes, for [`xml`]'s refusal.
35+
fn feature_place(layer: &str, feature: u64, what: &str) -> String {
36+
format!("{layer}, feature id {feature}, {what}")
37+
}
38+
3739
fn coords(pts: &[Coord]) -> String {
3840
pts.iter().map(|c| format!("{},{}", c.x, c.y)).collect::<Vec<_>>().join(" ")
3941
}
@@ -77,7 +79,7 @@ fn kml_geometry(g: &Geometry) -> String {
7779
pub fn to_kml(ds: &Dataset, name_field: Option<usize>) -> crate::Result<String> {
7880
let mut out = format!(
7981
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><name>{}</name>\n",
80-
xml(&ds.name)
82+
xml(&ds.name, "KML", || "layer name".to_string())?
8183
);
8284
// KML's description is text. Other types and differently-cased columns stay in
8385
// ExtendedData, where the reader preserves their values and reports name collisions.
@@ -87,7 +89,9 @@ pub fn to_kml(ds: &Dataset, name_field: Option<usize>) -> crate::Result<String>
8789
let Some(g) = &f.geometry else { continue };
8890
let name = name_field.map(|fi| ds.value(r, fi).to_file_text()).unwrap_or_else(|| f.id.to_string());
8991
let description = match description.map(|fi| ds.value(r, fi)) {
90-
Some(crate::Value::Text(text)) => format!("<description>{}</description>", description_xml(text, &ds.name, f.id)?),
92+
Some(crate::Value::Text(text)) => {
93+
format!("<description>{}</description>", xml(text, "KML", || feature_place(&ds.name, f.id, "description"))?)
94+
}
9195
_ => String::new(),
9296
};
9397
let data: String = ds
@@ -98,16 +102,21 @@ pub fn to_kml(ds: &Dataset, name_field: Option<usize>) -> crate::Result<String>
98102
.map(|(fd, v)| {
99103
let value = match v {
100104
crate::Value::Text(text) if fd.name == "description" && fd.ty == crate::FieldType::Text => {
101-
description_xml(text, &ds.name, f.id)?
105+
xml(text, "KML", || feature_place(&ds.name, f.id, "description"))?
102106
}
103-
_ => xml(&v.to_file_text()),
107+
_ => xml(&v.to_file_text(), "KML", || feature_place(&ds.name, f.id, &format!("field '{}'", fd.name.escape_debug())))?,
104108
};
105-
Ok(format!("<Data name=\"{}\"><value>{value}</value></Data>", xml(&fd.name)))
109+
// In an attribute, where a reader turns tabs and line breaks into spaces unless
110+
// they are written as references.
111+
let name = xml(&fd.name, "KML", || format!("{}, field name '{}'", ds.name, fd.name.escape_debug()))?
112+
.replace('\t', "&#9;")
113+
.replace('\n', "&#10;");
114+
Ok(format!("<Data name=\"{name}\"><value>{value}</value></Data>"))
106115
})
107116
.collect::<crate::Result<String>>()?;
108117
out.push_str(&format!(
109118
"<Placemark><name>{}</name>{description}<ExtendedData>{data}</ExtendedData>{}</Placemark>\n",
110-
xml(&name),
119+
xml(&name, "KML", || feature_place(&ds.name, f.id, "name"))?,
111120
kml_geometry(g)
112121
));
113122
}
@@ -126,7 +135,8 @@ pub fn to_gpx(ds: &Dataset, name_field: Option<usize>) -> crate::Result<String>
126135
for (r, f) in ds.features.iter().enumerate() {
127136
crate::progress::step(1)?;
128137
let Some(g) = &f.geometry else { continue };
129-
let name = xml(&name_field.map(|fi| ds.value(r, fi).to_file_text()).unwrap_or_else(|| f.id.to_string()));
138+
let name = name_field.map(|fi| ds.value(r, fi).to_file_text()).unwrap_or_else(|| f.id.to_string());
139+
let name = xml(&name, "GPX", || feature_place(&ds.name, f.id, "name"))?;
130140
match g {
131141
Geometry::Point(c) => out.push_str(&format!("<wpt {}><name>{name}</name></wpt>\n", pt(c))),
132142
Geometry::MultiPoint(v) => v.iter().for_each(|c| out.push_str(&format!("<wpt {}><name>{name}</name></wpt>\n", pt(c)))),

0 commit comments

Comments
 (0)