diff --git a/crates/data/src/esripbf.rs b/crates/data/src/esripbf.rs index 617dc6a18b..255dfd063a 100644 --- a/crates/data/src/esripbf.rs +++ b/crates/data/src/esripbf.rs @@ -124,7 +124,7 @@ pub struct Losses { pub no_crs: bool, /// Values that don't fit their field's type. pub unreadable: usize, - /// Values or field names that aren't valid UTF-8. + /// Values, field names or aliases that aren't valid UTF-8. pub not_utf8: usize, /// Polygon rings without area. pub flat_rings: usize, @@ -156,7 +156,7 @@ impl Losses { } if self.not_utf8 > 0 { out.push(format!( - "{} values or field names aren't valid UTF-8; the bytes that can't be read are replaced with U+FFFD", + "{} values, field names or aliases aren't valid UTF-8; the bytes that can't be read are replaced with U+FFFD", self.not_utf8 )); } @@ -276,22 +276,23 @@ pub fn read_page_within(bytes: &[u8], name: &str, limit: usize) -> Result let (mut repeated, mut not_read, mut unknown) = (0usize, 0usize, 0usize); let mut object_id_field = None; for Declared { name, number, utf8, alias } in declared { - tally.not_utf8 += usize::from(!utf8); let Some(read_as) = kind(number) else { not_read += 1; columns.push(None); continue; }; - unknown += usize::from(number > LAST_FIELD_TYPE); // Fields are found by name whatever its case, so the first of a name keeps it. if !names.insert(name.to_lowercase()) { repeated += 1; columns.push(None); continue; } + unknown += usize::from(number > LAST_FIELD_TYPE); if number == OID && object_id_field.is_none() { object_id_field = Some(fields.len()); } + // Only a field that's kept counts toward the UTF-8 notice: a left-out name isn't shown. + tally.not_utf8 += usize::from(!utf8); columns.push(Some((fields.len(), read_as))); fields.push(Field { name, ty: read_as.field_type(), alias }); } @@ -726,7 +727,7 @@ struct Tally { unreadable: usize, /// Polygon rings without area. flat_rings: usize, - /// Text values and field names that aren't valid UTF-8. + /// Text values, field names and aliases that aren't valid UTF-8. not_utf8: usize, /// Bytes left of [`MAX_GEOMETRY_BYTES`]. geometry_room: usize, diff --git a/crates/data/src/esripbf/tests.rs b/crates/data/src/esripbf/tests.rs index 3958d49d68..9e1b7afeb2 100644 --- a/crates/data/src/esripbf/tests.rs +++ b/crates/data/src/esripbf/tests.rs @@ -271,7 +271,10 @@ fn text_that_isnt_utf8_is_read_with_replacements_and_said() { assert_eq!(ds.fields[0].name, "N\u{FFFD}AME"); assert_eq!(ds.features[0].attrs, [Value::Text("a\u{FFFD}b".into())]); assert_eq!(ds.features[1].attrs, [Value::Text("ok".into())]); - assert_eq!(report.messages, ["2 values or field names aren't valid UTF-8; the bytes that can't be read are replaced with U+FFFD"]); + assert_eq!( + report.messages, + ["2 values, field names or aliases aren't valid UTF-8; the bytes that can't be read are replaced with U+FFFD"] + ); } #[test] @@ -594,6 +597,27 @@ fn a_field_type_rustgis_doesnt_know_is_read_as_text_and_said() { assert!(report.messages.is_empty(), "{:?}", report.messages); } +#[test] +fn a_repeated_field_of_an_unknown_type_is_only_said_left_out() { + // The repeat is dropped, so it isn't also said to be read as text. + let bytes = answer(&[field("NAME", 4), field("name", 17), feature(&[text("a"), uint(5)])]); + let (ds, report) = read(&bytes, "t").unwrap(); + assert_eq!(ds.fields.len(), 1); + assert_eq!(report.messages, ["1 fields repeat an earlier field's name and are left out"]); +} + +#[test] +fn a_left_out_field_whose_name_isnt_utf8_is_only_said_left_out() { + // The name isn't shown, so it isn't said to be read with replacements. + let repeat = message(13, &[message(1, b"N\xffame"), number(2, 4)].concat()); + let bytes = answer(&[field("N\u{FFFD}AME", 4), repeat, feature(&[text("a"), text("b")])]); + let (_, report) = read(&bytes, "t").unwrap(); + assert_eq!(report.messages, ["1 fields repeat an earlier field's name and are left out"]); + let geometry = message(13, &[message(1, b"G\xff"), number(2, 7)].concat()); + let (_, report) = read(&answer(&[field("NAME", 4), geometry, feature(&[text("a")])]), "t").unwrap(); + assert_eq!(report.messages, ["1 fields hold geometries, blobs or rasters, which aren't read, and are left out"]); +} + #[test] fn text_is_taken_from_the_room_at_its_size_once_read_before_it_is_made() { // Each byte that isn't UTF-8 becomes U+FFFD, three bytes. diff --git a/crates/data/src/geometry.rs b/crates/data/src/geometry.rs index 2e980d58f4..ed09623c68 100644 --- a/crates/data/src/geometry.rs +++ b/crates/data/src/geometry.rs @@ -214,7 +214,9 @@ impl Geometry { /// A point for a label or a pop-up: the point itself, the middle vertex of the longest line /// part, or the centroid of the largest valid polygon (moved inside it if the centroid falls out). /// - /// Returns `None` if the geometry is empty or if all polygon parts contain non-finite coordinates. + /// Returns `None` if the geometry is empty (no points, no line vertices), if no polygon part + /// has only finite coordinates and a non-empty outer ring (a part with a non-finite hole is + /// left out whole), or if the chosen part's centroid isn't finite. pub fn label_point(&self) -> Option { match self { Geometry::Point(c) => Some(*c), diff --git a/crates/data/src/io.rs b/crates/data/src/io.rs index 24095cbcd6..ea00e073c3 100644 --- a/crates/data/src/io.rs +++ b/crates/data/src/io.rs @@ -2022,7 +2022,8 @@ pub fn read_zip_in(file_name: &str, bytes: &[u8], crs: Option) -> Result = Vec::new(); for n in shps { if out.len() >= MAX_ZIP_LAYERS { - break; + skipped.push(format!("{n} (past the {MAX_ZIP_LAYERS}-layer limit)")); + continue; } let base = stem(&n); let name = Path::new(&n).file_stem().and_then(|s| s.to_str()).unwrap_or("layer").to_string(); @@ -2046,6 +2047,7 @@ pub fn read_zip_in(file_name: &str, bytes: &[u8], crs: Option) -> Result = entries.iter().flatten().filter(|(n, _)| ext_of(n) == "mif").map(|(n, _)| n.clone()).collect(); mifs.sort(); for n in mifs { + // The `.mif` files not taken stay in `entries`, so the loop below names them as past the limit. if out.len() >= MAX_ZIP_LAYERS { break; } @@ -2089,6 +2091,16 @@ pub fn read_zip_in(file_name: &str, bytes: &[u8], crs: Option) -> Result skipped.push(format!("{n} ({e})")), } } + // At most this many skipped members are named; the rest are counted. + const NAMED_SKIPPED: usize = 20; + let skipped = if skipped.len() > NAMED_SKIPPED { + let more = skipped.len() - NAMED_SKIPPED; + let mut named: Vec = skipped.into_iter().take(NAMED_SKIPPED).collect(); + named.push(format!("and {more} more")); + named + } else { + skipped + }; if out.is_empty() { let why = if skipped.is_empty() { String::new() } else { format!(": {}", skipped.join("; ")) }; return Err(DataError::Format(format!("{file_name}: no Shapefile or other vector data in the archive could be read{why}"))); @@ -3490,6 +3502,34 @@ mod tests { } // A .shp alone is refused with a hint to zip it. assert!(read_bytes("x.shp", &entries[0].1).is_err()); + // Shapefiles past the layer limit are named, not dropped unsaid; at the limit nothing is said. + let shapefiles = |count: usize| -> Vec<(String, Vec)> { + (0..count).flat_map(|i| entries.iter().take(4).map(move |(n, b)| (format!("s{i:02}.{}", ext(n)), b.clone()))).collect() + }; + fn ext(n: &str) -> String { + n.rsplit('.').next().unwrap_or_default().to_ascii_lowercase() + } + let layers = read_zip("x.zip", &crate::zip::write(&shapefiles(MAX_ZIP_LAYERS + 2)).unwrap()).unwrap(); + assert_eq!(layers.len(), MAX_ZIP_LAYERS); + assert_eq!(layers[0].1.messages, ["x.zip: skipped s32.shp (past the 32-layer limit); s33.shp (past the 32-layer limit)"]); + let layers = read_zip("x.zip", &crate::zip::write(&shapefiles(MAX_ZIP_LAYERS)).unwrap()).unwrap(); + assert_eq!(layers.len(), MAX_ZIP_LAYERS); + assert!(layers.iter().all(|(_, r)| r.messages.is_empty()), "{:?}", layers[0].1.messages); + // MapInfo files past the limit are named too (by the loop over the other members, which + // they're left to), once each. + let mif = b"Version 300\nColumns 1\n id Integer\nData\nPoint 1 2\n".to_vec(); + let mifs = |count: usize| -> Vec<(String, Vec)> { + (0..count).flat_map(|i| [(format!("m{i:02}.mif"), mif.clone()), (format!("m{i:02}.mid"), b"1\n".to_vec())]).collect() + }; + let layers = read_zip("x.zip", &crate::zip::write(&mifs(MAX_ZIP_LAYERS + 1)).unwrap()).unwrap(); + assert_eq!(layers.len(), MAX_ZIP_LAYERS); + assert_eq!(layers[0].1.messages, ["x.zip: skipped m32.mif (past the 32-layer limit)"]); + let layers = read_zip("x.zip", &crate::zip::write(&mifs(MAX_ZIP_LAYERS)).unwrap()).unwrap(); + assert!(layers.iter().all(|(_, r)| r.messages.is_empty()), "{:?}", layers[0].1.messages); + // A long list of skipped members names the first ones and counts the rest. + let layers = read_zip("x.zip", &crate::zip::write(&mifs(MAX_ZIP_LAYERS + 25)).unwrap()).unwrap(); + let note = &layers[0].1.messages[0]; + assert!(note.contains("m51.mif") && !note.contains("m52.mif") && note.ends_with("; and 5 more"), "{note}"); } /// A Shapefile's loose files picked or dropped together are zipped into one, which reads as a diff --git a/crates/data/src/ogc.rs b/crates/data/src/ogc.rs index 189ad0893c..4a8d098e26 100644 --- a/crates/data/src/ogc.rs +++ b/crates/data/src/ogc.rs @@ -462,9 +462,11 @@ pub struct Service { pub past_read_limit: Option, } -/// Most layers or collections `service.layers` lists from one document. The others are still read -/// ([`Service::listed`]), so that they can be added by name: which ones come first is up to the -/// server, and some change their order between answers (#1519). +/// Most layers or collections `service.layers` lists from one document. An OGC API collection +/// can make up to three layers (features, map tiles, vector tiles), so its listing can pass this +/// many layers. The others are still read ([`Service::listed`]), so that they can be added by +/// name: which ones come first is up to the server, and some change their order between answers +/// (#1519). const MAX_LISTED_LAYERS: usize = 2_000; /// Most layers or collections read from one document, which is hostile input. const MAX_READ_LAYERS: usize = if cfg!(test) { 3_000 } else { 100_000 }; diff --git a/crates/data/src/source/fgb/checked.rs b/crates/data/src/source/fgb/checked.rs index 585a31633e..39ccaa2701 100644 --- a/crates/data/src/source/fgb/checked.rs +++ b/crates/data/src/source/fgb/checked.rs @@ -126,6 +126,9 @@ impl Read for Guard { let size = <[u8; 4]>::try_from(&*buf) .map(u32::from_le_bytes) .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "an invalid feature size prefix"))?; + if size == 0 { + return Err(io::Error::new(io::ErrorKind::InvalidData, "a zero-size feature")); + } let size = u64::from(size); let remaining = self.end.map(|end| end.saturating_sub(self.pos)).unwrap_or(u64::MAX).min(super::remote::READ_BUDGET); if size > remaining || usize::try_from(size).ok().and_then(|n| n.checked_add(4)).is_none() { @@ -181,4 +184,20 @@ mod tests { assert!(error.to_string().contains("read budget")); assert!(guard.failure.borrow().is_some()); } + + #[test] + fn a_zero_size_prefix_is_named() { + let mut guard = Guard { + input: io::Cursor::new(0u32.to_le_bytes()), + pos: 0, + end: Some(4), + start: Rc::new(Cell::new(0)), + next: None, + failure: Failure::default(), + }; + let error = guard.read_exact(&mut [0; 4]).unwrap_err(); + assert_eq!(error.kind(), io::ErrorKind::InvalidData); + assert_eq!(error.to_string(), "a zero-size feature"); + assert!(guard.failure.borrow().is_some()); + } } diff --git a/crates/data/src/source/gpkg/add.rs b/crates/data/src/source/gpkg/add.rs index 1611fcc958..b324783a5f 100644 --- a/crates/data/src/source/gpkg/add.rs +++ b/crates/data/src/source/gpkg/add.rs @@ -234,12 +234,16 @@ fn related(conn: &Connection, table: &str) -> Result { } /// The views, and triggers on other tables, whose SQL mentions `table` (by a case-blind search, -/// so a longer name containing it counts too), by name. +/// so a longer name containing it counts too), by name. Another table's own spatial index +/// triggers (`rtree__…` on ``) touch only that table and its index, so they're left +/// out: replacing `parcels` doesn't name `parcels_2`'s. fn dependents(conn: &Connection, table: &str) -> Result> { let mut st = conn .prepare( "SELECT name FROM sqlite_master WHERE type IN ('view', 'trigger') AND lower(tbl_name) != lower(?1) - AND instr(lower(sql), lower(?1)) > 0 ORDER BY name", + AND instr(lower(sql), lower(?1)) > 0 + AND NOT (type = 'trigger' AND lower(substr(name, 1, length(tbl_name) + 7)) = 'rtree_' || lower(tbl_name) || '_') + ORDER BY name", ) .map_err(err)?; let names = st.query_map([table], |r| r.get::<_, String>(0)).map_err(err)?; diff --git a/crates/data/src/source/mod.rs b/crates/data/src/source/mod.rs index 82a92e2344..b05e87edc5 100644 --- a/crates/data/src/source/mod.rs +++ b/crates/data/src/source/mod.rs @@ -203,8 +203,8 @@ impl SourceInfo { self.notes.push(format!("{n} column{} {what}: {}{more}", if n == 1 { "" } else { "s" }, named.join(", "))); } - /// The source's coordinate system, when it isn't longitude/latitude and is known by its EPSG - /// code. + /// The source's coordinate system, when it isn't longitude/latitude: one known by its EPSG + /// code or a custom one without. `None` also when `crs` isn't one RustGIS can parse. pub fn coordinate_system(&self) -> Option { Crs::parse(&self.crs).ok().filter(|c| *c != Crs::LonLat) } diff --git a/crates/data/src/source/parquet.rs b/crates/data/src/source/parquet.rs index a3209c48e6..3911233083 100644 --- a/crates/data/src/source/parquet.rs +++ b/crates/data/src/source/parquet.rs @@ -43,7 +43,8 @@ pub struct ParquetSource { field_cols: Vec, /// Leaf column indices of the bbox covering's xmin, ymin, xmax, ymax. covering: Option<[usize; 4]>, - /// The metadata declares the covering, whose null boxes then imply null geometry. + /// The metadata declares the covering, whose null boxes then mean no geometry or an empty + /// one, neither of which meets an extent. declared_covering: bool, reproject: Reproject, /// The file, when it is read by its web address. @@ -343,7 +344,7 @@ impl ParquetSource { /// Whether inferred bounds may omit or count rows that only their geometry can test. /// Unknown null counts require the same fallback as known nulls; declared coverings promise - /// that a box is present if and only if geometry is present. + /// that a box is present if and only if a non-empty geometry is present. fn needs_geometry_filter(&self, md: &ParquetMetaData, g: usize) -> bool { let Some(c) = self.covering else { return true }; !self.declared_covering diff --git a/crates/data/src/source/tests.rs b/crates/data/src/source/tests.rs index 390a82ae62..b72df946b1 100644 --- a/crates/data/src/source/tests.rs +++ b/crates/data/src/source/tests.rs @@ -2754,6 +2754,10 @@ fn geopackage_export_adds_and_replaces_tables_and_keeps_the_others() { // A second table in that system reuses its entry. let more = write_path_to(&fewer, &path, Crs::WebMercator, &to(GpkgMode::AddTable, Some("permits_2027"))).unwrap(); assert_eq!(more.1, Some(GpkgWritten { table: "permits_2027".into(), replaced: false, dependents: vec![] })); + // Its spatial index triggers mention `permits` within their own table's name, but don't use + // it, so replacing `permits` again names only the view. + let again = write_path_to(&fewer, &path, Crs::WebMercator, &to(GpkgMode::ReplaceTable, Some("permits"))).unwrap(); + assert_eq!(again.1, Some(GpkgWritten { table: "permits".into(), replaced: true, dependents: vec!["recent_permits".into()] })); // Replacing a table not there (a misspelt name) is refused rather than adding one. let e = write_path_to(&fewer, &path, Crs::LonLat, &to(GpkgMode::ReplaceTable, Some("permit"))).unwrap_err().to_string(); assert!(e.contains("no table permit to replace"), "{e}"); diff --git a/crates/engine/src/cmd/workflows.rs b/crates/engine/src/cmd/workflows.rs index 5f5f0f1139..f4a0808daf 100644 --- a/crates/engine/src/cmd/workflows.rs +++ b/crates/engine/src/cmd/workflows.rs @@ -1036,12 +1036,21 @@ fn interpolate_work(s: &Session, p: &Value) -> Result { let ds = feature_ds(s, p)?; let field = ps(p, "field").ok_or("field is required")?; let fi = ds.field_index(field).ok_or_else(|| format!("no field named '{field}'"))?; - let pts: Vec<(Coord, f64)> = ds - .features - .iter() - .enumerate() - .filter_map(|(r, ft)| Some((ft.geometry.as_ref()?.label_point()?, ds.value(r, fi).as_f64().filter(|v| v.is_finite())?))) - .collect(); + // Features without a place or a number are left out, and said (by kind, with a count). + let (mut no_point, mut no_value) = (0usize, 0usize); + let mut pts: Vec<(Coord, f64)> = Vec::with_capacity(ds.features.len()); + for (r, ft) in ds.features.iter().enumerate() { + let Some(c) = ft.geometry.as_ref().and_then(|g| g.label_point()).filter(|c| c.is_finite()) else { + no_point += 1; + continue; + }; + let Some(v) = ds.value(r, fi).as_f64().filter(|v| v.is_finite()) else { + no_value += 1; + continue; + }; + pts.push((c, v)); + } + let (layer_name, field_name) = (ds.name.clone(), field.to_string()); let e = s.project.gp_env.extent.unwrap_or_else(|| { let mut e = Extent::EMPTY; pts.iter().for_each(|(c, _)| e.expand(*c)); @@ -1051,7 +1060,37 @@ fn interpolate_work(s: &Session, p: &Value) -> Result { let name = out_name(p, format!("{}_{field}_idw", ds.name)); let power = f(p, "power").unwrap_or(2.0).clamp(0.5, 10.0); let neighbors = p.get("neighbors").and_then(Value::as_u64).unwrap_or(12).max(1) as usize; - Ok(Box::new(move || made(rasterops::idw(&pts, &e, cell, power, neighbors, &name)?, None))) + Ok(Box::new(move || { + // A surface that can't be made says what was left out of it, so the input can be fixed. + let left_out = |e: String| { + let mut why = Vec::new(); + if no_point > 0 { + why.push(format!("{no_point} features with no geometry or no usable point")); + } + if no_value > 0 { + why.push(format!("{no_value} whose value isn't a number")); + } + if why.is_empty() { e } else { format!("{e} ({} left out)", why.join(", ")) } + }; + let m = made(rasterops::idw(&pts, &e, cell, power, neighbors, &name).map_err(left_out)?, None)?; + if no_point == 0 && no_value == 0 { + return Ok(m); + } + let then: Then = Box::new(move |s: &mut Session, v: &mut Value| { + let mut why = Vec::new(); + if no_point > 0 { + why.push(format!("{no_point} with no geometry or no usable point")); + } + if no_value > 0 { + why.push(format!("{no_value} whose {field_name} isn't a number")); + } + s.notify(format!("{layer_name}: features left out of the surface: {}", why.join(", ")), false); + if let Some(o) = v.as_object_mut() { + o.insert("skipped".into(), json!({"noPoint": no_point, "noValue": no_value})); + } + }); + Ok(Made { then: Some(then), ..m }) + })) } /// Creates a route layer and reports invalid source segments omitted from its network. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cd31710330..154cad0eb2 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -33085,6 +33085,47 @@ fn topology_refuses_latitudes_past_the_poles() { } } +/// `analysis.interpolate` says how many features it leaves out, and why: those with no place to +/// stand for and those whose value isn't a number. A layer it reads whole says nothing. +#[test] +fn interpolation_says_the_features_it_leaves_out() { + use rustgis_data::{Dataset, Field, FieldType, Geometry, GeometryType, Value as V}; + use rustgis_geom::Coord; + let mut s = world(); + let mut wells = Dataset::new("wells", GeometryType::Point, vec![Field::new("depth", FieldType::Double)]); + for (i, depth) in [10.0, 20.0, 30.0].into_iter().enumerate() { + wells.push(Some(Geometry::Point(Coord::new(i as f64, i as f64))), vec![V::Float(depth)]); + } + crate::cmd::layer::add_dataset(&mut s, wells.clone()); + let mark = s.notice_mark(); + let v = s.run("analysis.interpolate", &json!({"layer": "wells", "field": "depth", "cellSize": 0.5})).unwrap(); + assert!(v.get("skipped").is_none(), "{v}"); + assert!(s.notices_since(mark).iter().all(|n| !n.text.contains("left out")), "{:?}", s.notices_since(mark)); + + wells.name = "lossy wells".into(); + wells.push(None, vec![V::Float(40.0)]); + wells.push(Some(Geometry::Point(Coord::new(f64::NAN, 1.0))), vec![V::Float(50.0)]); + wells.push(Some(Geometry::Point(Coord::new(1.5, 0.5))), vec![V::Null]); + crate::cmd::layer::add_dataset(&mut s, wells); + let mark = s.notice_mark(); + let v = s.run("analysis.interpolate", &json!({"layer": "lossy wells", "field": "depth", "cellSize": 0.5})).unwrap(); + assert_eq!(v["skipped"], json!({"noPoint": 2, "noValue": 1}), "{v}"); + let said: Vec<_> = s.notices_since(mark).iter().filter(|n| n.text.contains("left out")).map(|n| n.text.clone()).collect(); + assert_eq!( + said, + ["lossy wells: features left out of the surface: 2 with no geometry or no usable point, 1 whose depth isn't a number"] + ); + + // A surface with no usable points left fails, and the error says what was left out. + let mut bad = Dataset::new("bad wells", GeometryType::Point, vec![Field::new("depth", FieldType::Double)]); + bad.push(Some(Geometry::Point(Coord::new(f64::NAN, 1.0))), vec![V::Float(1.0)]); + bad.push(None, vec![V::Float(2.0)]); + bad.push(Some(Geometry::Point(Coord::new(1.0, 1.0))), vec![V::Null]); + crate::cmd::layer::add_dataset(&mut s, bad); + let e = s.run("analysis.interpolate", &json!({"layer": "bad wells", "field": "depth", "cellSize": 0.5})).unwrap_err(); + assert!(e.contains("(2 features with no geometry or no usable point, 1 whose value isn't a number left out)"), "{e}"); +} + /// `share.exportMap` to a `.tif` writes the view placed on the ground (#1561): in the map's /// projection, each pixel where the view drew it, RGB; a turned view north up over its box, and /// says so; a tilted view, the globe and junk refused. diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md index cf41c86c1f..b330ac8c3a 100644 --- a/docs/user-guide/data-formats.md +++ b/docs/user-guide/data-formats.md @@ -310,8 +310,9 @@ Scripts use `service.import {"url":"…","name":"My OGC Layer"}` and | WCS 1.0 / 2.0 (a 1.1 service is asked in 1.0) | Coverages, with their bounds | A raster: GetCoverage of the map's view within the coverage's bounds (or its whole extent: `"bbox": "full"`), as a GeoTIFF in EPSG:4326, at most 2048 pixels on a side | | ArcGIS REST | FeatureServer and MapServer layers; a MapServer's map; an ImageServer; a VectorTileServer | Layers queried as GeoJSON, or in protocol buffers (`f=pbf`, smaller and quicker to read) when the layer's description lists them and names its record limit (the description read first, or given up on after 15 seconds; a first protocol buffer page that can't be fetched or read has the layer read in GeoJSON, with a notice saying why), page by page past the server's record limit (`resultOffset`) up to 100,000 features or more on a computer with more memory (in protocol buffers, also no more than a quarter of the computer's memory once read, from 512 MB, the web app's limit, up to 3 GB; a later page past it ends the read with a notice, and the first page is always kept, within the reader's own limits for a page) (a command such as `service.add` waits a minute at most for the features), where the layer supports paging (ArcGIS Server 10.3 and later; otherwise up to the record limit); a map as its tile cache when it is Web Mercator's pyramid, else exported images; an ImageServer as exported images; a VectorTileServer as its MapLibre style | -A long list stops at its first 2,000 layers (for OGC API, collections), and a note says how many -the service has. Which ones come first is up to the service, and some change their order between +A long list stops at its first 2,000 layers, and a note says how many the service has. An OGC +API service stops at its first 2,000 collections instead, and each can make up to three layers +(features, map tiles and vector tiles), so its list can be longer. Which ones come first is up to the service, and some change their order between answers. `service.add` still takes any of them by name, up to 100,000 in one document, fewer (but at least 2,000) when the document's request address (an OGC API's, its own), which each layer's repeats, is very long. An ArcGIS service or directory is an exception: it is read up to