From 496e9117c5f75bfd153c544fc674d0da740eb1b4 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Sun, 25 Oct 2026 23:34:14 -0300 Subject: [PATCH 1/3] Services: ask a WFS, OGC API or ArcGIS feature layer for an area only (#819) service.add takes "bbox" ([west, south, east, north] or "view") for feature layers too, and the From Service dialog gets "Only the map's area" (off by default). The whole layer stays the default. The box goes into each service's request: WFS 1.1/2.0 BBOX (CRS84, else urn EPSG::4326 latitude first), OGC API bbox, ArcGIS envelope. WFS 1.0 and areas across the antimeridian are asked whole, with a note. A whole layer past the 60 s wait suggests "bbox". Co-Authored-By: Claude Opus 5.5 --- crates/data/src/ogc.rs | 96 ++++++++++++++++++++++++++++ crates/engine/src/cmd/service.rs | 51 +++++++++++++-- crates/engine/src/tests.rs | 56 ++++++++++++++++ crates/ui-egui/src/connectiontree.rs | 2 +- crates/ui-egui/src/dialogs.rs | 8 ++- crates/ui-egui/src/lib.rs | 3 + crates/ui-egui/src/serviceui.rs | 28 ++++++-- docs/user-guide/data-formats.md | 24 +++++++ 8 files changed, 256 insertions(+), 12 deletions(-) diff --git a/crates/data/src/ogc.rs b/crates/data/src/ogc.rs index ad8ca84a04..5c3d0ee6fe 100644 --- a/crates/data/src/ogc.rs +++ b/crates/data/src/ogc.rs @@ -702,6 +702,55 @@ fn wfs(url: &str, root: &Node) -> Service { service } +// --------------------------------------------------------------------------------------------- +// Features over an area + +/// Query parameters that already filter a request by place or by feature: an address carrying +/// one is left as it is. +const SPATIAL_KEYS: [&str; 6] = ["bbox", "filter", "cql_filter", "featureid", "resourceid", "geometry"]; + +/// An [`Offer::Features`] address that asks only for the features crossing a longitude/latitude +/// `area` (west, south, east, north), in each service's own terms: +/// - a WFS 1.1 or 2.0 GetFeature: `BBOX` in CRS84 (longitude first) when its `SRSNAME` is +/// CRS84, else in `urn:ogc:def:crs:EPSG::4326`, latitude first as that URN fixes (a bare +/// `EPSG:4326` is read either way by different servers); +/// - an ArcGIS layer's query: an envelope in EPSG:4326 that the features intersect; +/// - an OGC API collection's items: `bbox`, longitude first by the standard (its `next` links +/// keep it). +/// +/// `None` when the request can't carry the box: a WFS 1.0 GetFeature (its `BBOX` is in the +/// type's own coordinate system, which its capabilities may not give as longitude/latitude), an +/// address that already filters, or an area across the antimeridian or off the globe. +pub fn features_in_area(url: &str, area: [f64; 4]) -> Option { + let [w, s, e, n] = area; + let lon = |x: f64| (-180.0..=180.0).contains(&x); + let lat = |y: f64| (-90.0..=90.0).contains(&y); + if !(lon(w) && lon(e) && lat(s) && lat(n) && w <= e && s <= n) { + return None; + } + if SPATIAL_KEYS.iter().any(|k| query_value(url, k).is_some()) { + return None; + } + let is = |key: &str, value: &str| query_value(url, key).is_some_and(|v| v.eq_ignore_ascii_case(value)); + let q = if is("service", "wfs") && is("request", "getfeature") { + if query_value(url, "version").is_none_or(|v| v.starts_with("1.0")) { + return None; + } + if query_value(url, "srsname").is_some_and(is_crs84) { + format!("BBOX={w},{s},{e},{n},urn:ogc:def:crs:OGC:1.3:CRS84") + } else { + format!("BBOX={s},{w},{n},{e},urn:ogc:def:crs:EPSG::4326") + } + } else if is_arcgis_query(url) { + format!("geometry={w},{s},{e},{n}&geometryType=esriGeometryEnvelope&inSR=4326&spatialRel=esriSpatialRelIntersects") + } else if base(url).trim_end_matches('/').ends_with("/items") { + format!("bbox={w},{s},{e},{n}") + } else { + return None; + }; + Some(with_query(url, &q)) +} + // --------------------------------------------------------------------------------------------- // WCS @@ -2321,6 +2370,53 @@ mod tests { assert!(s.notes.iter().any(|n| n.contains("1 collections"))); } + #[test] + fn features_asked_for_over_an_area() { + let piaui = [-45.99, -10.93, -40.37, -2.74]; + let offered = |caps: &str, body: &str| { + let s = parse(caps, body.as_bytes()).unwrap(); + let Offer::Features { url } = &s.layers[0].offer else { panic!("{:?}", s.layers[0].offer) }; + url.clone() + }; + // WFS 2.0 offering CRS84: the box in CRS84, longitude first. + let v20 = r#"CGMAT:municurn:ogc:def:crs:EPSG::4674urn:ogc:def:crs:OGC:1.3:CRS84"#; + let url = offered("https://x.org/geoserver/wfs", v20); + assert_eq!(features_in_area(&url, piaui).unwrap(), format!("{url}&BBOX=-45.99,-10.93,-40.37,-2.74,urn:ogc:def:crs:OGC:1.3:CRS84")); + // WFS 1.1 without CRS84: latitude first, as urn:ogc:def:crs:EPSG::4326 fixes. + let v11 = r#"aurn:ogc:def:crs:EPSG::4326"#; + let url = offered("https://x.org/wfs", v11); + assert_eq!(features_in_area(&url, piaui).unwrap(), format!("{url}&BBOX=-10.93,-45.99,-2.74,-40.37,urn:ogc:def:crs:EPSG::4326")); + // WFS 1.0 reads its box in the type's own coordinate system: not asked. + let v10 = r#"roadsEPSG:4326"#; + assert_eq!(features_in_area(&offered("https://old.example.org/wfs", v10), piaui), None); + // ArcGIS: an envelope in EPSG:4326, kept by the pages that follow (they add to the query). + let arcgis = r#"{"currentVersion": 11.1, "layers": [{"id": 0, "name": "Parcels"}]}"#; + let url = offered("https://x.org/arcgis/rest/services/A/FeatureServer", arcgis); + let asked = features_in_area(&url, piaui).unwrap(); + assert_eq!( + asked, + format!( + "{url}&geometry=-45.99,-10.93,-40.37,-2.74&geometryType=esriGeometryEnvelope&inSR=4326&spatialRel=esriSpatialRelIntersects" + ) + ); + assert!(arcgis_page_url(&asked, 2, 2, Some("FID")).contains("&geometry=-45.99,-10.93,-40.37,-2.74&")); + // OGC API Features: bbox, longitude first, before a fragment. + assert_eq!( + features_in_area("https://api.example.org/collections/a/items?limit=10000&f=json#x", piaui).unwrap(), + "https://api.example.org/collections/a/items?limit=10000&f=json&bbox=-45.99,-10.93,-40.37,-2.74#x" + ); + assert_eq!( + features_in_area("https://api.example.org/collections/a/items", [-1.5, 0.0, 2.0, 1e-7]).unwrap(), + "https://api.example.org/collections/a/items?bbox=-1.5,0,2,0.0000001" + ); + // Across the antimeridian, off the globe, already filtered, or not a feature request. + assert_eq!(features_in_area("https://api.example.org/collections/a/items", [170.0, -20.0, -170.0, -10.0]), None); + assert_eq!(features_in_area("https://api.example.org/collections/a/items", [-200.0, -20.0, 10.0, 95.0]), None); + assert_eq!(features_in_area("https://api.example.org/collections/a/items?bbox=1,2,3,4", piaui), None); + assert_eq!(features_in_area(&format!("{}&CQL_FILTER=uf%3D'PI'", offered("https://x.org/wfs", v11)), piaui), None); + assert_eq!(features_in_area("https://x.org/data.geojson", piaui), None); + } + #[test] fn wfs_versions_and_axes() { // WFS 1.0: onlineResource, TYPENAME and MAXFEATURES. diff --git a/crates/engine/src/cmd/service.rs b/crates/engine/src/cmd/service.rs index e5cf44204d..ba947a8e5e 100644 --- a/crates/engine/src/cmd/service.rs +++ b/crates/engine/src/cmd/service.rs @@ -1,6 +1,7 @@ //! Web map and feature services: connect to a WMS, WMTS, WFS, WCS, OGC API Features or ArcGIS //! REST service, list what it offers (from its capabilities), and add a layer — map layers as -//! tile layers, feature types and collections as data downloaded as GeoJSON, coverages as rasters +//! tile layers, feature types and collections as data downloaded as GeoJSON (the whole layer, or +//! the features crossing an area), coverages as rasters //! (a GeoTIFF of the view from GetCoverage). And search a catalogue (CSW) for records and the //! services and files they link to. //! @@ -26,7 +27,7 @@ pub fn commands() -> Vec { r#"{"url": "a WMS, WMTS or WFS address (GetCapabilities is added), an OGC API collections address or landing page (its map tiles and linked collections), or an ArcGIS FeatureServer, MapServer, ImageServer or VectorTileServer, or an ArcGIS services directory or folder (its folders and services, each listed by its own url)", "type"?: "wms"|"wmts"|"wfs"|"ogcapi"|"arcgis" (guessed from the address), "text"?: "the capabilities document, when already fetched", "documents"?: [{"url": "a discovered document address", "text": "its fetched JSON"}]} → layers with source_url, and next when supplied documents need another fetch"#, ), C::new("service.add", "Add Service Layer", "Home › Add", add).params( - r#"{"url": "as service.layers", "type"?, "layer": "the layer's name (service.layers lists them)", "name"?: text, "time"?: "a time-enabled WMTS layer's date (2024-06-01; its default otherwise)", "text"?: "the capabilities document, when already fetched", "documents"?: "additional fetched documents, as service.layers", "source_url"?: "the listed layer's source_url", "describe"?: "a WCS coverage's DescribeCoverage document, when already fetched", "tiles"?: "an OGC API layer's tile template, when already read from its tileset (the app's)", "bbox"?: [west, south, east, north] | "view" (the default) | "full" (a WCS coverage's area)}"#, + r#"{"url": "as service.layers", "type"?, "layer": "the layer's name (service.layers lists them)", "name"?: text, "time"?: "a time-enabled WMTS layer's date (2024-06-01; its default otherwise)", "text"?: "the capabilities document, when already fetched", "documents"?: "additional fetched documents, as service.layers", "source_url"?: "the listed layer's source_url", "describe"?: "a WCS coverage's DescribeCoverage document, when already fetched", "tiles"?: "an OGC API layer's tile template, when already read from its tileset (the app's)", "bbox"?: [west, south, east, north] | "view" | "full": a WCS coverage's area (the view by default); for a WFS, OGC API or ArcGIS feature layer, only the features that cross it (the whole layer, "full", by default)}"#, ), C::new("service.coverage", "WCS Coverage Request", "Home › Add", coverage).view().params( r#"{"url": "a WCS address", "type"?: "wcs", "layer": "the coverage's name", "text"?: "the capabilities document, when already fetched", "documents"?: "additional fetched documents, as service.layers", "source_url"?: "the listed coverage's source_url", "describe"?: "its DescribeCoverage answer, when already fetched", "bbox"?: [west, south, east, north] | "view" (the default) | "full"} → the GetCoverage address of a GeoTIFF (layer.addUrl adds it)"#, @@ -417,24 +418,62 @@ pub(crate) fn add(s: &mut Session, p: &Value) -> CmdResult { } } Offer::Features { url: items } => { + let area = features_area(s, p)?; + let asked = area.and_then(|a| rustgis_data::ogc::features_in_area(items, a)); #[cfg(target_arch = "wasm32")] { - let _ = items; + let _ = (items, asked); Err(format!("{url}: in the web app, Home › Add Data › From Service downloads the features")) } #[cfg(not(target_arch = "wasm32"))] { + if p.get("bbox").is_some_and(|b| !b.is_null() && *b != "full") && asked.is_none() { + let why = if area.is_none() { "an area across the antimeridian" } else { "the service can't be asked for an area" }; + s.notify(format!("{name}: {why}, so the whole layer is asked for"), false); + } let max = crate::render::rustgis_tiles::cache::MAX_DOWNLOAD; - let bytes = download_features(s, &name, items, max)?; + let bytes = download_features(s, &name, asked.as_deref().unwrap_or(items), max) + .map_err(|e| slow_whole_layer(e, asked.is_some()))?; let bytes = features_answer(s, &name, bytes); - let r = super::raster::add_named_bytes(s, &json!({"name": name}), format!("{name}.geojson"), bytes)?; - zoom(s); + let mut r = super::raster::add_named_bytes(s, &json!({"name": name}), format!("{name}.geojson"), bytes)?; + // Over an area, the features crossing it: the view stays, or goes to a box given + // (the whole layer's bounds would show a country to fill one state). + match (asked.is_some(), area, p.get("bbox")) { + (true, Some([w, so, e, n]), Some(Value::Array(_))) => s.zoom_to(&rustgis_geom::Extent::new(w, so, e, n)), + (true, ..) => {} + _ => zoom(s), + } + if let (Some(_), Some(out)) = (&asked, r.as_object_mut()) { + out.insert("area".into(), json!(area)); + } Ok(r) } } } } +/// The area a service's features are asked for over: a `bbox` given (`[west, south, east, +/// north]`, or `"view"`, the map's), else none, for the whole layer (`"full"` says so). A box +/// across the antimeridian asks for the whole layer too, as `catalog.search` does. +fn features_area(s: &Session, p: &Value) -> Result, String> { + match p.get("bbox") { + None | Some(Value::Null) => Ok(None), + Some(Value::String(f)) if f == "full" => Ok(None), + Some(_) => Ok(Some(super::catalogs::area(s, p)?).filter(|a| a[0] <= a[2])), + } +} + +/// A whole layer too slow to download while a command waits: the error says an area can be asked +/// for instead. +#[cfg(not(target_arch = "wasm32"))] +fn slow_whole_layer(e: String, over_area: bool) -> String { + if !over_area && (e.contains("timeout") || e.contains("timed out")) { + format!("{e}; or ask for the features in an area only, with \"bbox\": [west, south, east, north] or \"view\"") + } else { + e + } +} + /// The area a coverage is asked for over: `bbox` given, `"full"` (its bounds), or the map's view /// (the default); within its bounds when they are known. fn coverage_area(s: &Session, p: &Value, info: &rustgis_data::ogc::CoverageInfo, id: &str) -> Result<[f64; 4], String> { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index def24f2b70..8407980e00 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -8591,6 +8591,62 @@ fn arcgis_features_read_past_the_record_limit() { ); } +/// A feature layer comes whole unless an area is asked for (#819): then only the features that +/// cross it, a WFS 1.1 or 2.0 asked with `BBOX` latitude first in urn:ogc:def:crs:EPSG::4326. A +/// WFS 1.0, or an area across the antimeridian, is asked whole, and says so. +#[test] +fn service_features_asked_for_over_an_area() { + use ogc_server::{Route, Server}; + let features = r#"{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"n": 1}, "geometry": {"type": "Point", "coordinates": [-42.8, -5.1]}}]}"#; + let server = Server::new(vec![Route::new("/wfs", features)]); + let caps = |version: &str| { + format!( + r#" +CGMAT:municMunicipalitiesEPSG:4674"#, + server.base + ) + }; + let url = format!("{}/wfs", server.base); + let piaui = json!([-45.99, -10.93, -40.37, -2.74]); + let mut s = Session::new(Project::default()); + let add = |s: &mut Session, version: &str, bbox: Option| { + let mut p = json!({"url": url, "layer": "CGMAT:munic", "text": caps(version), "name": format!("M{}", s.map().layers.len())}); + if let Some(b) = bbox { + p["bbox"] = b; + } + s.run("service.add", &p).unwrap() + }; + let r = add(&mut s, "1.1.0", Some(piaui.clone())); + assert_eq!(r["features"], 1); + assert_eq!(r["area"], piaui); + let r = add(&mut s, "2.0.0", Some(json!("view"))); + assert!(r["area"].is_array(), "{r}"); + let r = add(&mut s, "2.0.0", None); + assert!(r.get("area").is_none(), "{r}"); + add(&mut s, "2.0.0", Some(json!("full"))); + add(&mut s, "2.0.0", Some(json!([170.0, -20.0, -170.0, -10.0]))); + add(&mut s, "1.0.0", Some(piaui.clone())); + let boxes: Vec> = + server.requests().iter().map(|r| r.query.iter().find(|(k, _)| k == "BBOX").map(|(_, v)| v.clone())).collect(); + assert_eq!(boxes.len(), 6); + assert_eq!(boxes[0].as_deref(), Some("-10.93,-45.99,-2.74,-40.37,urn:ogc:def:crs:EPSG::4326")); + assert!(boxes[1].as_deref().is_some_and(|b| b.ends_with(",urn:ogc:def:crs:EPSG::4326")), "{boxes:?}"); + assert_eq!(&boxes[2..], [None, None, None, None]); + let notes: Vec<&str> = s.notices.iter().map(|n| n.text.as_str()).collect(); + assert!(notes.iter().any(|n| n.starts_with("M4: an area across the antimeridian")), "{notes:?}"); + assert!(notes.iter().any(|n| n.starts_with("M5: the service can't be asked for an area")), "{notes:?}"); + // Asked for the box given, the map goes to it, not to the whole layer's bounds. + s.run("service.add", &json!({"url": url, "layer": "CGMAT:munic", "text": caps("2.0.0"), "name": "Piauí", "bbox": piaui})).unwrap(); + let v = view_lonlat(&s); + assert!(v[0] < -45.0 && v[2] > -41.0 && v[1] < -10.0 && v[3] > -3.0 && v[2] - v[0] < 20.0, "{v:?}"); +} + +/// The map's view in longitude/latitude, as `bbox: "view"` reads it. +fn view_lonlat(s: &Session) -> [f64; 4] { + let e = crate::cmd::workspace::view_extent(s); + [e.min_x, e.min_y, e.max_x, e.max_y] +} + /// A WCS coverage (from a local server) becomes a raster of the view, asked for in EPSG:4326 within /// its bounds; an error answer is refused. A catalogue's records come with the links RustGIS can /// follow, those pointing inward left out. diff --git a/crates/ui-egui/src/connectiontree.rs b/crates/ui-egui/src/connectiontree.rs index ec8e6b8068..67570a822e 100644 --- a/crates/ui-egui/src/connectiontree.rs +++ b/crates/ui-egui/src/connectiontree.rs @@ -258,7 +258,7 @@ fn add_from(app: &mut RustGisApp, child: &Value, source: Option<&ServiceSource>, let params = add["params"].clone(); match (source, child.get("layer").filter(|l| l.is_object())) { (Some(source), Some(layer)) => { - serviceui::add_layer_from(app, source, layer, "", false, origin)?; + serviceui::add_layer_from(app, source, layer, "", None, false, origin)?; } _ => match command { "layer.addUrl" => { diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index dc9e568a6c..b78649dfef 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -828,6 +828,11 @@ fn add_service(app: &mut RustGisApp, ui: &mut egui::Ui) -> bool { ui.label(egui::RichText::new(tl!("YYYY-MM-DD, for the layers that change with time")).small().weak()); }); } + // Feature layers come whole, or only the features crossing the map's view. + if !grouped && layers.iter().any(|l| l["offer"]["type"] == "features") { + ui.checkbox(&mut browse.area, tl!("Only the map's area")) + .on_hover_text(tl!("Feature layers: ask the service only for the features that cross the map's view")); + } if grouped && layers.iter().any(|l| l["offer"]["type"] == "features") { ui.horizontal(|ui| { ui.label(tl!("Name")); @@ -929,7 +934,8 @@ fn add_service(app: &mut RustGisApp, ui: &mut egui::Ui) -> bool { let title = l.get("title").and_then(Value::as_str).unwrap_or(name).to_string(); // Features are downloaded in the background, as From URL… does; map layers are added now. let time = app.ui.service_browse.time.trim().to_string(); - match crate::serviceui::add_layer(app, &src, &l, &time, true) { + let area = app.ui.service_browse.area.then(|| rustgis_engine::cmd::catalogs::area(&app.session, &Value::Null)).transpose(); + match area.and_then(|area| crate::serviceui::add_layer(app, &src, &l, &time, area, true)) { Ok(m) => app.dialogs.info = Some(format!("{m} {title}")), Err(e) => app.dialogs.error = Some(e), } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 16c664263c..42d4e795a5 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -320,6 +320,9 @@ pub struct ServiceBrowse { pub filter: String, /// The date time-enabled layers are added at (their default when empty). pub time: String, + /// Feature layers are asked only for the features crossing the map's view (Only the map's + /// area), not whole. + pub area: bool, /// The directories (and their types) opened before the one shown, the last most recent. pub back: Vec<(String, &'static str)>, } diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index e63b138a5e..f088935a61 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -46,9 +46,18 @@ pub(crate) fn kind_of(t: &str) -> &'static str { /// Adds one of a service's layers (as `service.layers` lists it): features are downloaded in the /// background as From URL… does, map layers are added now, and an OGC API layer or a WCS coverage -/// waits on a document (a step the app moves along). `dialog` tells where the result is reported. -pub(crate) fn add_layer(app: &mut RustGisApp, src: &ServiceSource, l: &Value, time: &str, dialog: bool) -> Result<&'static str, String> { - add_layer_from(app, src, l, time, dialog, None) +/// waits on a document (a step the app moves along). A feature layer is asked only for the +/// features crossing `area` (longitude/latitude) when given, whole otherwise. `dialog` tells where +/// the result is reported. +pub(crate) fn add_layer( + app: &mut RustGisApp, + src: &ServiceSource, + l: &Value, + time: &str, + area: Option<[f64; 4]>, + dialog: bool, +) -> Result<&'static str, String> { + add_layer_from(app, src, l, time, area, dialog, None) } /// [`add_layer`] for a layer of the connection named `origin` (the Connections tree): once the @@ -59,6 +68,7 @@ pub(crate) fn add_layer_from( src: &ServiceSource, l: &Value, time: &str, + area: Option<[f64; 4]>, dialog: bool, origin: Option<&str>, ) -> Result<&'static str, String> { @@ -66,7 +76,17 @@ pub(crate) fn add_layer_from( let title = l.get("title").and_then(Value::as_str).unwrap_or(&name).to_string(); let offer = l.get("offer").cloned().unwrap_or_default(); if offer.get("type").and_then(Value::as_str) == Some("features") { - let items = offer.get("url").and_then(Value::as_str).unwrap_or("").to_string(); + let items = offer.get("url").and_then(Value::as_str).unwrap_or(""); + // Over an area when its request can carry one (not a WFS 1.0's, nor across the + // antimeridian): whole otherwise, as `service.add` does. + let asked = area.and_then(|a| ogc::features_in_area(items, a)); + if area.is_some() && asked.is_none() { + app.session.notify( + crate::i18n::fmt("{name}: the service can't be asked for an area, so the whole layer is asked for", &[("name", &title)]), + false, + ); + } + let items = asked.as_deref().unwrap_or(items); return crate::connectiontree::run_add_url(app, json!({"url": items, "name": title, "service": true}), origin) .map(|_| tl!("Downloading…")); } diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index a7ee78ff49..25e4d43f83 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -190,6 +190,30 @@ format and bounds; `service.coverage` gives the GetCoverage address alone). Movi ask for it again: add it again for another area. The server reprojects it to EPSG:4326 (WCS 2.0 through its CRS extension); one that can't answers with an error, which is shown. +A WFS, OGC API Features or ArcGIS feature layer comes whole, as in other GIS programs. A large +one (a country's municipalities, hundreds of megabytes) can be asked for over an area instead: +tick **Only the map's area** in the dialog, or give `service.add` a `"bbox"` +(`[west, south, east, north]` in longitude/latitude, or `"view"`). The service then sends only +the features that cross the area, whole, not clipped. `service.add` then zooms to the box given +(not to the whole layer's bounds), and leaves the view as it is for `"view"`. The box is asked in +each service's own terms: + +- **WFS 1.1 and 2.0:** `BBOX`, in CRS84 when the feature type offers it, else in + `urn:ogc:def:crs:EPSG::4326`, latitude first as that name fixes. +- **OGC API Features:** `bbox`, longitude first; the `next` pages keep it. +- **ArcGIS:** an envelope in EPSG:4326 the features intersect; the pages past the record limit + keep it. + +A WFS 1.0 service reads its box in the feature type's own coordinate system, so it is asked for +the whole layer, as is an area across the antimeridian; a note says so. When a whole layer takes +longer than `service.add` waits (a minute), the error suggests `"bbox"`: + +```sh +rustgis-cli run --cmd 'service.add={"url":"https://geoservicos.ibge.gov.br/geoserver/wfs","layer":"CGMAT:qg_2024_030_munic","bbox":[-45.99,-10.93,-40.37,-2.74]}' +``` + +The layer holds the features of the area it was added for: moving the map doesn't ask for more. + For callers that fetch documents themselves (including the web app), `service.layers` accepts `text` for the initial document and `documents: [{"url": "…", "text": "…"}]` for subsequent responses. It returns `next` while another collections document is needed; supplied documents From 98937cb4c58caf8d6de891f54fd69c631dd8f5f5 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 26 Oct 2026 02:25:19 -0300 Subject: [PATCH 2/3] Services: an OGC API address with bbox-crs is left as it is (#819) A box asked in another coordinate system (OGC API Part 2's bbox-crs) would have the lon/lat box read in that system: such an address keeps its own request, as one that already filters does. Co-Authored-By: Claude Opus 5.5 --- crates/data/src/ogc.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/data/src/ogc.rs b/crates/data/src/ogc.rs index 5c3d0ee6fe..962dddcee1 100644 --- a/crates/data/src/ogc.rs +++ b/crates/data/src/ogc.rs @@ -705,9 +705,9 @@ fn wfs(url: &str, root: &Node) -> Service { // --------------------------------------------------------------------------------------------- // Features over an area -/// Query parameters that already filter a request by place or by feature: an address carrying -/// one is left as it is. -const SPATIAL_KEYS: [&str; 6] = ["bbox", "filter", "cql_filter", "featureid", "resourceid", "geometry"]; +/// Query parameters that already filter a request by place or by feature, or that name another +/// coordinate system for a box (OGC API's `bbox-crs`): an address carrying one is left as it is. +const SPATIAL_KEYS: [&str; 7] = ["bbox", "bbox-crs", "filter", "cql_filter", "featureid", "resourceid", "geometry"]; /// An [`Offer::Features`] address that asks only for the features crossing a longitude/latitude /// `area` (west, south, east, north), in each service's own terms: @@ -2413,6 +2413,8 @@ mod tests { assert_eq!(features_in_area("https://api.example.org/collections/a/items", [170.0, -20.0, -170.0, -10.0]), None); assert_eq!(features_in_area("https://api.example.org/collections/a/items", [-200.0, -20.0, 10.0, 95.0]), None); assert_eq!(features_in_area("https://api.example.org/collections/a/items?bbox=1,2,3,4", piaui), None); + let other_crs = "https://api.example.org/collections/a/items?bbox-crs=http://www.opengis.net/def/crs/EPSG/0/31983"; + assert_eq!(features_in_area(other_crs, piaui), None); assert_eq!(features_in_area(&format!("{}&CQL_FILTER=uf%3D'PI'", offered("https://x.org/wfs", v11)), piaui), None); assert_eq!(features_in_area("https://x.org/data.geojson", piaui), None); } From edfe57b33bc6270369cac241472d2e603bc3852b Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 26 Oct 2026 02:28:40 -0300 Subject: [PATCH 3/3] Services: the dialog asks for the view's area for a feature layer only (#819) With Only the map's area ticked, an unknown view stopped a map layer (WMS, WMTS) from being added too, though it never uses the area. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index b78649dfef..ad1842dcea 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -934,7 +934,11 @@ fn add_service(app: &mut RustGisApp, ui: &mut egui::Ui) -> bool { let title = l.get("title").and_then(Value::as_str).unwrap_or(name).to_string(); // Features are downloaded in the background, as From URL… does; map layers are added now. let time = app.ui.service_browse.time.trim().to_string(); - let area = app.ui.service_browse.area.then(|| rustgis_engine::cmd::catalogs::area(&app.session, &Value::Null)).transpose(); + // The view's area, for a feature layer only: a map layer never asks for one, so an + // unknown view can't stop it. + let features = l["offer"]["type"] == "features"; + let area = + (features && app.ui.service_browse.area).then(|| rustgis_engine::cmd::catalogs::area(&app.session, &Value::Null)).transpose(); match area.and_then(|area| crate::serviceui::add_layer(app, &src, &l, &time, area, true)) { Ok(m) => app.dialogs.info = Some(format!("{m} {title}")), Err(e) => app.dialogs.error = Some(e),