Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b22b2cd
fix(data): release sweep follow-ups (data services)
giswqs Nov 30, 2026
ceda119
Merge remote-tracking branch 'origin/main' into sweep/2026-11-29-data…
giswqs Nov 30, 2026
4784b62
fix(engine): keep add_service_layer's attributes on it
giswqs Nov 30, 2026
7dae0d4
fix(data): review follow-ups on the service sweep
giswqs Nov 30, 2026
ce02c77
fix(engine): name the SRSNAME the refused WFS add needs, as the addre…
giswqs Nov 30, 2026
1812d62
fix(engine): an exception report after a byte order mark is one
giswqs Nov 30, 2026
834ddf6
fix(data): a WFS schema after a byte order mark sorts the retry too
giswqs Nov 30, 2026
194e0a7
refactor(map): test the own box in rustgis-data, not with a row field…
giswqs Nov 30, 2026
048b665
fix(engine): say what a refused WFS answer was, not a cause, and only…
giswqs Nov 30, 2026
821ded8
fix(data): every white-space control character keeps search words apart
giswqs Nov 30, 2026
bcc4c72
fix(map): walk a filtered window by its own box only where the source…
giswqs Nov 30, 2026
b9bcff1
fix(map): leave the own-box narrowing to the source that does it
giswqs Nov 30, 2026
7b41387
refactor: Fetching keeps the default visits_own_box; a refusal's stat…
giswqs Nov 30, 2026
16b3533
fix(engine): tell an exception report by its root element
giswqs Nov 30, 2026
4a6235f
fix(engine): skip a DOCTYPE's internal subset before an exception rep…
giswqs Nov 30, 2026
99b756f
fix(engine): say a coverageCrs the coverage's address overrules
giswqs Nov 30, 2026
a9d27a3
fix(engine): a coverage address naming another system isn't read in c…
giswqs Nov 30, 2026
557a5cd
test: indent the schema retry test; pin the coverageCrs notice whatev…
giswqs Nov 30, 2026
47070ad
docs(engine): say why the exception-report check scans rather than pa…
giswqs Nov 30, 2026
c11c449
refactor(data): one reader of the system a GetCoverage address names
giswqs Nov 30, 2026
751d7c0
test(engine): pin the refusal of a coverage asked in degrees
giswqs Nov 30, 2026
6da410c
fix(data): an empty OUTPUTCRS names no system
giswqs Nov 30, 2026
66bbdd8
refactor: walks_own_box, one wording for a refused answer, placed_as doc
giswqs Nov 30, 2026
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
4 changes: 3 additions & 1 deletion crates/analysis/src/rasterops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ pub(crate) fn stored_counting(v: f64, past: &std::sync::atomic::AtomicUsize) ->
}
}

/// A band arithmetic expression over `b1`, `b2`… (+ - * / and parentheses, numbers).
/// A band arithmetic expression over `b1`, `b2`… (+ - * / and parentheses, numbers). Discards how
/// many cells were stored as no-data past the f32 range: a caller that reports losses uses
/// [`band_math_reported`].
pub fn band_math(r: &Raster, expr: &str) -> Result<Vec<f32>, String> {
band_math_reported(r, expr).map(|(cells, _)| cells)
}
Expand Down
268 changes: 240 additions & 28 deletions crates/data/src/ogc.rs

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions crates/data/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,13 @@ pub trait FeatureSource: Send + Sync {
let in_own = req.own.is_some_and(|(crs, _)| crs == self.coord_crs());
self.visit_chunks(if in_own { None } else { req.extent }, bytes, visit)
}
/// Whether [`FeatureSource::visit_request_chunks`] narrows a box in the source's own system
/// itself (an index read by that box, as a Shapefile's), rather than visiting every feature:
/// a caller sampling a view walks the request only where this costs no more than the extent.
/// Not [`FeatureSource::reads_own_box`], which is about `read` and is true for more sources.
fn walks_own_box(&self) -> bool {
false
}
fn info(&self) -> &SourceInfo;
/// The coordinate system of the features it gives: a file read in place gives them as the file
/// holds them, in its own system (Shapefile, GeoPackage, FlatGeobuf, GeoParquet, GeoJSON); a
Expand Down Expand Up @@ -629,9 +636,10 @@ pub trait FeatureSource: Send + Sync {
fn field_range(&self, _field: &str) -> Option<(f64, f64)> {
None
}
/// Whether the source holds more features than the `n` read, asked of it when its count
/// ([`SourceInfo::count`]) may be wrong and it can tell without reading them all (a
/// GeoPackage's kept count, #2898); `None` when its count is taken as it is, or it can't tell.
/// Whether the source holds more features than the `n` read, where it can tell without reading
/// them all and its [`SourceInfo::count`] may be wrong (a GeoPackage's kept count, #2898).
/// Asked of every source by `SourceLayer::holds_only`; `None` when its count is taken as it
/// is, or it can't tell.
fn holds_more_than(&self, _n: u64) -> Option<bool> {
None
}
Expand Down
3 changes: 3 additions & 0 deletions crates/data/src/source/shp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@ impl FeatureSource for ShpSource {
fn visit_request_chunks(&self, req: &Request, bytes: usize, visit: &mut dyn FnMut(Vec<Feature>) -> Result<()>) -> Result<Batch> {
self.visit_with(req, None, bytes, visit)
}
fn walks_own_box(&self) -> bool {
true
}
fn visits_ids(&self) -> bool {
true
}
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/cmd/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ fn add_field(s: &mut Session, p: &Json) -> CmdResult {
if table {
rustgis_data::progress::begin(ds.features.len());
}
// A table's runs ahead on a worker, with progress and Cancel ([`table_ahead`]).
// A table's edit runs ahead on a worker, with progress and Cancel ([`table_ahead`]).
ds.features.try_add_columns(
1,
Value::Null,
Expand Down
21 changes: 17 additions & 4 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5554,7 +5554,7 @@ fn add_url_as_given(s: &mut Session, p: &Value) -> CmdResult {
let left_out = parts_left_out(url, &bytes, p);
let cut = url_name_cut("Add Data From URL", url, p, &bytes);
// A WCS coverage's own system it was asked for in, for an answer that doesn't say it.
let asked = if b(p, "coverage") == Some(true) { super::raster::coverage_system(p, url) } else { None };
let asked = if b(p, "coverage") == Some(true) { super::raster::coverage_system(s, p, url) } else { None };
let r = super::raster::add_named_bytes_read(s, p, name, bytes, b(p, "zoom"), None, asked).map_err(named)?;
if let Some(n) = left_out {
s.notify(n, false);
Expand Down Expand Up @@ -7240,6 +7240,18 @@ fn add_download(s: &mut Session, p: &Value) -> CmdResult {
// paging.
let bytes = if service {
let label = ps(p, "name").map(str::to_string).unwrap_or_else(|| crate::sources::address_in_message(&url));
// A WFS type asked in its own system answered with an exception report (which may refuse
// that system): said as `service.add` says it, with how to ask in degrees instead (the app
// downloaded this answer, so it isn't asked again here).
if super::service::is_exception_report(&bytes)
Comment thread
giswqs marked this conversation as resolved.
Resolved
&& let Some(lonlat) = rustgis_data::ogc::wfs_lonlat_fallback(&url)
{
let asked = rustgis_data::ogc::asked_system(&url).map(|c| c.label()).unwrap_or_default();
return Err(format!(
Comment thread
giswqs marked this conversation as resolved.
Resolved
"{label}: asked in its own system ({asked}), the server answered with an exception report, which may refuse that system; to ask for its features in EPSG:4326 instead, add the same address, its other parameters kept, with SRSNAME=EPSG:4326 ({})",
Comment thread
giswqs marked this conversation as resolved.
Resolved
Comment thread
giswqs marked this conversation as resolved.
Resolved
crate::sources::address_in_message(&lonlat)
));
}
super::service::features_answer(s, &label, &url, bytes, bounds)
} else {
bytes
Expand All @@ -7260,7 +7272,7 @@ fn add_download(s: &mut Session, p: &Value) -> CmdResult {
let drawn = s.landed_pages.iter().position(|(d, _)| *d == id).map(|i| s.landed_pages.remove(i).1);
#[cfg(target_arch = "wasm32")]
let drawn = None;
let asked = if coverage { super::raster::coverage_system(p, &url) } else { None };
let asked = if coverage { super::raster::coverage_system(s, p, &url) } else { None };
let r = super::raster::add_named_bytes_read(s, p, name, bytes, b(p, "zoom"), drawn, asked)?;
if let Some(n) = left_out {
s.notify(n, false);
Expand Down Expand Up @@ -8426,8 +8438,9 @@ fn symbology(s: &mut Session, p: &Value) -> CmdResult {
_ => String::new(),
};
let order = if rest.by_number { "by number" } else { "in text order" };
// A view that holds the whole source says nothing.
let part = l.source.as_ref().is_some_and(|src| !src.holds_only(l.dataset.features.len() as u64));
// A view that holds the whole source says nothing. Asked only when there is something to say
// (a GeoPackage's kept count steps through rows to tell).
let part = from_view.is_some() && l.source.as_ref().is_some_and(|src| !src.holds_only(l.dataset.features.len() as u64));
let from_view = from_view.filter(|_| part).map(|then| (l.dataset.kept_features(&l.visible_rows()).count(), then));
let mut dropped = None;
let out = with(s, p, |l| {
Expand Down
38 changes: 33 additions & 5 deletions crates/engine/src/cmd/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,16 +843,44 @@ fn add_bytes<const LIMIT: usize>(s: &mut Session, p: &Value) -> CmdResult {
add_named_bytes(s, p, name, bytes, b(p, "zoom"))
}

/// The system a WCS coverage was asked for in, for an answer that doesn't say its own:
/// `"coverageCrs"` (`service.coverage`'s, `EPSG:<code>`), else the one its GetCoverage address
/// `url` names ([`coverage_request_system`](rustgis_data::ogc::coverage_request_system)).
pub(crate) fn coverage_system(p: &Value, url: &str) -> Option<rustgis_data::raster::Crs> {
/// The system a WCS coverage was asked for in, for an answer that doesn't say its own: the one
/// its GetCoverage address `url` names ([`coverage_request_system`](rustgis_data::ogc::coverage_request_system)),
/// which is what the server was asked for; when the address names no system, `"coverageCrs"`
/// (`service.coverage`'s, `EPSG:<code>`). A `coverageCrs` the address overrules is said.
pub(crate) fn coverage_system(s: &mut Session, p: &Value, url: &str) -> Option<rustgis_data::raster::Crs> {
// Only `EPSG:<code>`: `Crs::parse` takes WKT and PROJ text too, and keeps a system for them.
let given = ps(p, "coverageCrs")
.and_then(|c| c.strip_prefix("EPSG:")?.parse::<u32>().ok())
.and_then(rustgis_data::raster::Crs::from_epsg)
.filter(|c| !c.is_geographic());
given.or_else(|| rustgis_data::ogc::coverage_request_system(url))
let Some(asked) = rustgis_data::ogc::coverage_request_system(url) else {
// An address naming another system (longitude/latitude, one RustGIS doesn't read) asked
// the server for that one: its answer isn't read in coverageCrs.
if rustgis_data::ogc::coverage_request_names_system(url) {
if let Some(given) = given {
s.notify(
format!(
"the coverage's address asks for it in another system than coverageCrs {}, so its answer isn't read in that one",
given.label()
),
false,
);
}
return None;
}
return given;
};
if let Some(given) = given.filter(|g| *g != asked) {
s.notify(
format!(
"the coverage's address asks for it in {}, so its answer is read in that system, not in coverageCrs {}",
asked.label(),
given.label()
),
false,
);
}
Some(asked)
}

/// Adds a file's contents (an upload, a download) as its name's extension says. A PDF's page is
Expand Down
108 changes: 95 additions & 13 deletions crates/engine/src/cmd/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ pub fn features_answer(s: &mut Session, name: &str, url: &str, bytes: Vec<u8>, b
if let Some(note) = rustgis_data::ogc::partial_note(&bytes) {
s.notify(format!("{name}: {note}"), false);
}
let (bytes, assumed) = rustgis_data::ogc::place_answer(bytes, url, bounds);
let (bytes, assumed, unturned) = rustgis_data::ogc::place_answer(bytes, url, bounds);
// Once per kind with a count over the command (a service group reads many answers).
if let Some(assumed) = assumed {
for assumed in [assumed, unturned].into_iter().flatten() {
s.notify_counted(assumed.loss(), assumed.template(), 1);
}
bytes
Expand Down Expand Up @@ -629,6 +629,55 @@ pub(crate) fn download_features(s: &mut Session, name: &str, url: &str, max: usi
}
}

/// Whether a fetch's error `e` is the server's refusal, an HTTP status of 400 to 599, the
Comment thread
giswqs marked this conversation as resolved.
Resolved
/// address it may be prefixed with (`<address>: http status: 400`) set aside.
#[cfg(not(target_arch = "wasm32"))]
fn server_refused(e: &str) -> bool {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
refusal_status(e).is_some()
}

/// The HTTP status of 400 to 599 a fetch's error `e` is, the address it may be prefixed with set
/// aside: what is said of a refusal, never the error's text, which may hold the address.
#[cfg(not(target_arch = "wasm32"))]
fn refusal_status(e: &str) -> Option<u16> {
std::iter::once(e)
.chain(e.match_indices(": ").filter_map(|(at, sep)| e.get(at + sep.len()..)))
.find_map(cache::http_status)
.filter(|status| (400..=599).contains(status))
}

/// Whether `bytes` are an OWS or WFS 1.0 exception report (not GML, which a server ignoring the
/// JSON output format would send): told by the name of its root element, past a byte order mark,
/// white space, the XML declaration, comments and a DOCTYPE, within its first 64 KB. A scan of the
/// prolog rather than the XML parser: the answer may be a large feature collection, which this
/// looks at without parsing it whole.
pub(crate) fn is_exception_report(bytes: &[u8]) -> bool {
Comment thread
giswqs marked this conversation as resolved.
Resolved
let head = String::from_utf8_lossy(bytes.get(..64 << 10).unwrap_or(bytes));
let mut rest = head.trim_start_matches('\u{feff}').trim_start();
loop {
let skipped = if rest.starts_with("<?") {
rest.find("?>").map(|at| at + 2)
} else if rest.starts_with("<!--") {
rest.find("-->").map(|at| at + 3)
} else if rest.starts_with("<!") {
// A DOCTYPE, past its internal subset (`[ … ]`) when it has one.
let close = match (rest.find('['), rest.find('>')) {
(Some(open), Some(end)) if open < end => rest.get(open..).and_then(|t| t.find(']')).map(|at| open + at),
_ => Some(0),
};
close.and_then(|from| rest.get(from..)?.find('>').map(|at| from + at + 1))
} else {
break;
};
let Some(at) = skipped else { return false };
rest = rest.get(at..).unwrap_or_default().trim_start();
}
let Some(tag) = rest.strip_prefix('<') else { return false };
let name = tag.split(|c: char| c.is_whitespace() || c == '>' || c == '/').next().unwrap_or_default();
let local = name.rsplit(':').next().unwrap_or_default();
matches!(local, "ExceptionReport" | "ServiceExceptionReport")
}

/// A service layer's features at `url` read whole while the command waits, as [`download_layer`]
/// reads them (in pages, as protocol buffers when an ArcGIS layer lists them), and added with
/// `p` (a GeoJSON answer under the file name `file` gives it, its axes checked against
Expand Down Expand Up @@ -659,28 +708,31 @@ pub(crate) fn add_service_layer(
// A WFS type asked in its own system that the server refuses (an error, or an exception
// report where features were expected) is asked once more in EPSG:4326, as before RustGIS
// asked types in their own system, and that is said.
// Only the server's own refusal: an HTTP error status, or an exception report. A cancel, a
// timeout, an answer past the download cap or an address refused here would fail again (or
// was asked to stop), so it isn't asked a second time.
let refused = |r: &Result<(Downloaded, Drawing), String>| match r {
Err(_) => true,
// An OWS or WFS 1.0 exception report (not GML, which a server ignoring the JSON output
// format would send).
Ok((Downloaded::Bytes(b), _)) => {
let head = String::from_utf8_lossy(&b[..b.len().min(1024)]);
head.trim_start().starts_with('<') && head.contains("ExceptionReport")
}
Err(e) => server_refused(e),
Comment thread
giswqs marked this conversation as resolved.
Resolved
Ok((Downloaded::Bytes(b), _)) => is_exception_report(b),
Ok(_) => false,
};
let fallback = rustgis_data::ogc::wfs_lonlat_fallback(url).filter(|_| refused(&first));
let (url, (downloaded, drawing)) = match fallback {
Some(lonlat) => {
// Its status only: the error's text may hold the address.
let why = match &first {
Err(e) => e.chars().take(200).collect::<String>(),
Ok(_) => "it answered with an exception report".into(),
// Only a refusal reaches here (`refused`), so it has a status.
Err(e) => format!("HTTP {}", refusal_status(e).unwrap_or_default()),
Ok(_) => "an exception report".into(),
};
// Failing too, both are said.
let second = fetch(s, &lonlat).map_err(|e| format!("{e} (asked in its own system first: {why})"))?;
let second = fetch(s, &lonlat).map_err(|e| format!("{e} (asked in its own system first, it answered with {why})"))?;
let asked = rustgis_data::ogc::asked_system(url).map(|c| c.label()).unwrap_or_default();
// The answer may refuse the system or something else: what it was is said, not why.
s.notify(
format!("{name}: the server refused its own system ({asked}: {why}); its features were asked for in EPSG:4326 instead"),
format!(
"{name}: asked in its own system ({asked}), the server answered with {why}; its features were asked for in EPSG:4326 instead"
),
false,
);
(lonlat, second)
Expand Down Expand Up @@ -2091,6 +2143,36 @@ fn fetch_records(url: &str, _: &str, _: Reach, _: bool) -> Result<(Vec<u8>, Reac
mod tests {
use super::*;

/// A WFS type is asked again in degrees only on the server's refusal (an error status, its
/// address set aside, or an exception report), never after a timeout, a cancel, an answer
/// past the cap or an address refused here.
#[test]
fn only_a_servers_refusal_asks_a_wfs_type_again() {
for (refusal, status) in [("http status: 400", 400), ("https://x.org/wfs?a=1: http status: 500", 500), ("HTTP 404", 404)] {
assert!(server_refused(refusal), "{refusal}");
assert_eq!(refusal_status(refusal), Some(status));
}
for other in [
"https://x.org/wfs?a=1: the pages took too long",
"cancelled",
"https://x.org/wfs?a=1: larger than RustGIS downloads (512 MB)",
"https://x.org/wfs?a=1: a public address can't lead to a local one",
"http status: 302",
"https://x.org/400: refused",
] {
assert!(!server_refused(other), "{other}");
}
assert!(is_exception_report(br#"<?xml version="1.0"?><ows:ExceptionReport/>"#));
assert!(is_exception_report("\u{feff}<ows:ExceptionReport/>".as_bytes()), "after a byte order mark");
assert!(!is_exception_report(br#"<wfs:FeatureCollection/>"#));
assert!(is_exception_report(br#"<?xml version="1.0"?><!-- a comment --><ServiceExceptionReport version="1.2.0"/>"#));
assert!(is_exception_report(br#"<!DOCTYPE x [ <!ENTITY a "b"> ]><ows:ExceptionReport/>"#), "past a DOCTYPE's subset");
// The words inside another document don't make it one.
assert!(!is_exception_report(br#"<wfs:FeatureCollection><name>ExceptionReport</name></wfs:FeatureCollection>"#));
assert!(!is_exception_report(br#"{"type":"FeatureCollection","features":[{"properties":{"n":"<ExceptionReport>"}}]}"#));
assert!(!is_exception_report(b""));
}

/// Every fallback to the standard tile address off the frame is said (AGENTS.md, Never silent):
/// a list leading on past two documents, a template refused, a document address refused. A
/// template read says nothing (#1319).
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30317,7 +30317,7 @@ fn a_catalogue_refusing_crs84_is_asked_for_the_area_without_it() {
assert_eq!(asked.lock().unwrap().clone(), [true]);

// Words the catalogue isn't asked for are counted.
let p = json!({"url": "https://cat.example.org/csw", "query": format!("a\tb{}", "c".repeat(250)), "text": PAGE});
let p = json!({"url": "https://cat.example.org/csw", "query": format!("a\u{7}b{}", "c".repeat(250)), "text": PAGE});
let v = s.run("catalog.search", &p).unwrap();
let said: Vec<&str> = v["notes"].as_array().into_iter().flatten().filter_map(Value::as_str).collect();
assert_eq!(said, ["control characters left out of the words searched for: 1", "the words are cut to 200 characters; left out: 52"]);
Expand Down
Loading
Loading