diff --git a/crates/data/src/citygml.rs b/crates/data/src/citygml.rs
index 9efd173123..27d04e0f52 100644
--- a/crates/data/src/citygml.rs
+++ b/crates/data/src/citygml.rs
@@ -1906,6 +1906,7 @@ impl Reading {
ty: ty.to_string(),
parent_ids: parent.map(str::to_string).into_iter().collect(),
z: made.z,
+ ground: None,
solid: made.solid,
attributes: attributes.into_iter().collect(),
});
diff --git a/crates/data/src/citygml/tests.rs b/crates/data/src/citygml/tests.rs
index 78b1978d3d..b462738617 100644
--- a/crates/data/src/citygml/tests.rs
+++ b/crates/data/src/citygml/tests.rs
@@ -241,11 +241,16 @@ fn a_vertical_system_that_isnt_metres_upward_is_said() {
assert_eq!(
notes(&compound("25832", "6360"), &["EPSG:25832"], None),
[
- "a vertical system the file names (crs:EPSG::6360) measures heights in US survey feet: z_min, z_max and height are kept as the file has them, and Style › Extrusion reads metres, so objects may stand at the wrong height"
+ "a vertical system the file names (crs:EPSG::6360) measures heights in US survey feet: z_min, z_max, height and base_height are kept as the file has them, and Style › Extrusion reads metres, so objects may stand at the wrong height"
]
);
let depth = notes(&compound("25832", "5715"), &["EPSG:25832"], None);
- assert!(depth.len() == 1 && depth[0].contains("(crs:EPSG::5715) measures depth, downward, in metres"), "{depth:?}");
+ assert!(
+ depth.len() == 1
+ && depth[0].contains("(crs:EPSG::5715) measures depth, downward, in metres")
+ && depth[0].contains("base_height is how far an object's top is below its topmost object's top"),
+ "{depth:?}"
+ );
let unknown = notes(&compound("25832", "9999"), &["EPSG:25832"], None);
assert!(unknown.len() == 1 && unknown[0].contains("(crs:EPSG::9999) is one RustGIS doesn't know"), "{unknown:?}");
// A geometry whose vertical part differs from the root's is said too; one system is said once,
@@ -275,6 +280,43 @@ fn a_vertical_system_that_isnt_metres_upward_is_said() {
assert!(said[VERTICALS].starts_with("2 geometries or envelopes name a vertical system, past the first 8 said"), "{said:?}");
}
+/// A part starts at its lowest point's height above its building's lowest point, written in it or
+/// linked to it; a group's member starts at 0, whatever the group's other members.
+#[test]
+fn a_part_above_its_building_starts_there() {
+ let raised = |id: &str, z: f64| {
+ [
+ surface("GroundSurface", &[polygon(&format!("{id}-g"), &square(0.0, 0.0, 4.0, z))]),
+ surface("RoofSurface", &[polygon(&format!("{id}-r"), &square(0.0, 0.0, 4.0, z + 1.0))]),
+ ]
+ .concat()
+ };
+ let inner = format!(
+ r##"{}
+ "##,
+ box_surfaces("p1")
+ );
+ let linked = format!(
+ r#"{}"#,
+ raised("p2", 7.0)
+ );
+ let far = building("c1", &raised("c1", 40.0));
+ let group = r##"
+ "##;
+ let out = read("model.gml", &lonlat(&[building("b1", &inner), linked, far, group.to_string()].concat()), None).unwrap();
+ let base = |id: &str| {
+ out.iter()
+ .find_map(|(ds, _)| {
+ (0..ds.features.len()).find(|&r| value(ds, r, "id") == Value::Text(id.into())).map(|r| value(ds, r, "base_height"))
+ })
+ .unwrap()
+ };
+ assert_eq!(base("p1"), Value::Float(0.0));
+ assert_eq!(base("p2"), Value::Float(7.0), "a linked part starts 7 m above its building's lowest point");
+ assert_eq!(base("b1"), Value::Float(0.0));
+ assert_eq!(base("c1"), Value::Float(0.0), "not 40 m above the group's lowest member");
+}
+
/// A part is an object of its own, with its parent's id, and lends its parent its heights.
#[test]
fn a_building_part_names_its_parent_and_raises_it() {
diff --git a/crates/data/src/cityjson.rs b/crates/data/src/cityjson.rs
index 1ba9489953..834f1facd7 100644
--- a/crates/data/src/cityjson.rs
+++ b/crates/data/src/cityjson.rs
@@ -363,6 +363,7 @@ fn read_with(file_name: &str, bytes: &[u8], given: Option, keep_named: bool
id: id.clone(),
ty: type_name(&object.ty),
parent_ids: object.parents,
+ ground: None,
z: made.z,
solid: made.solid,
attributes,
diff --git a/crates/data/src/cityjson/tests.rs b/crates/data/src/cityjson/tests.rs
index a5f2e951ab..4c3534f202 100644
--- a/crates/data/src/cityjson/tests.rs
+++ b/crates/data/src/cityjson/tests.rs
@@ -82,7 +82,7 @@ fn a_solid_is_its_footprint_with_its_heights() {
assert_eq!(ds.name, "model", "the only layer takes the file's name");
assert_eq!(ds.geometry_type, GeometryType::Polygon);
let names: Vec<&str> = ds.fields.iter().map(|f| f.name.as_str()).collect();
- assert_eq!(names, ["id", "type", "parent", "lod", "floors", "name", "z_min", "z_max", "height"]);
+ assert_eq!(names, ["id", "type", "parent", "lod", "floors", "name", "z_min", "z_max", "height", "base_height"]);
assert_eq!(value(ds, 0, "id"), crate::Value::Text("b1".into()));
assert_eq!(value(ds, 0, "lod"), crate::Value::Text("2".into()));
assert_eq!(value(ds, 0, "floors"), crate::Value::Int(2));
@@ -92,6 +92,8 @@ fn a_solid_is_its_footprint_with_its_heights() {
let said = messages_of(&out);
assert_eq!(said.len(), 1, "a clean solid says only that: {said:?}");
assert!(said[0].starts_with("1 3D city objects are drawn as their footprints"), "{said:?}");
+ assert!(said[0].ends_with("the lowest point of the topmost object they are part of (0 for that object)"), "{said:?}");
+ assert_eq!(value(ds, 0, "base_height"), crate::Value::Float(0.0), "a building alone starts where it stands");
}
/// A clean 2D model says nothing.
@@ -273,7 +275,7 @@ fn an_instance_kept_without_geometry_isnt_said_to_be_drawn() {
fn an_attribute_named_as_a_field_is_renamed_and_said() {
let bytes = doc(
box_vertices(),
- json!({"b": {"type": "Building", "attributes": {"height": 99, "Type": "x"},
+ json!({"b": {"type": "Building", "attributes": {"height": 99, "Type": "x", "base_height": 7},
"geometry": [{"type": "Solid", "lod": "2", "boundaries": box_shell()}]}}),
);
let out = read("m.city.json", &bytes, None).unwrap();
@@ -281,7 +283,12 @@ fn an_attribute_named_as_a_field_is_renamed_and_said() {
assert_eq!(value(ds, 0, "height_1"), crate::Value::Int(99));
assert_eq!(value(ds, 0, "height"), crate::Value::Float(5.0));
assert_eq!(value(ds, 0, "Type_1"), crate::Value::Text("x".into()));
- assert!(says(&out, "attributes renamed with a number, as these fields are the reader's own: Type, height"), "{:?}", messages_of(&out));
+ assert_eq!(value(ds, 0, "base_height_1"), crate::Value::Int(7));
+ assert!(
+ says(&out, "attributes renamed with a number, as these fields are the reader's own: Type, base_height, height"),
+ "{:?}",
+ messages_of(&out)
+ );
// Renamed, it keeps clear of the object's other attributes.
let bytes = doc(
box_vertices(),
@@ -825,11 +832,43 @@ fn built(id: &str, parent: Option<&str>, z: Option<(f64, f64)>) -> Built {
ty: "Building".into(),
parent_ids: parent.into_iter().map(String::from).collect(),
z,
+ ground: None,
solid: false,
attributes: Vec::new(),
}
}
+/// Taking grounds from the topmost objects stops past what the visits allow, and says after how many
+/// rounds; a cycle settles to its lowest.
+#[test]
+fn setting_grounds_is_bounded() {
+ let chain = || -> Vec {
+ (0..20)
+ .map(|i| {
+ let parent = (i < 19).then(|| format!("o{}", i + 1));
+ built(&format!("o{i}"), parent.as_deref(), Some((f64::from(19 - i), 30.0)))
+ })
+ .collect()
+ };
+ let mut objects = chain();
+ assert_eq!(set_grounds(&mut objects, 0), Some(MIN_PARENT_ROUNDS));
+ assert!(objects[0].ground > Some(0.0), "the top's ground isn't reached: {:?}", objects[0].ground);
+ let mut objects = chain();
+ assert_eq!(set_grounds(&mut objects, MAX_PARENT_VISITS), None, "with room, it settles");
+ assert_eq!(objects[0].ground, Some(0.0));
+ let mut cycle = vec![built("a", Some("b"), Some((1.0, 2.0))), built("b", Some("a"), Some((0.0, 1.0)))];
+ assert_eq!(set_grounds(&mut cycle, MAX_PARENT_VISITS), None);
+ assert_eq!((cycle[0].ground, cycle[1].ground), (Some(0.0), Some(0.0)));
+ let said = |c: &Counts| messages(c).into_iter().filter(|m| m.contains("base_height is measured")).collect::>();
+ assert_eq!(
+ said(&Counts { ground_rounds: 3, ..Counts::default() }),
+ [
+ "parent chains go deeper than 3 levels: some parts' base_height is measured from a parent, not from the topmost object they are part of"
+ ]
+ );
+ assert!(said(&Counts::default()).is_empty(), "grounds that settled say nothing");
+}
+
/// Past what the visits allow it stops and says after how many rounds; a cycle settles.
#[test]
fn raising_parents_is_bounded() {
@@ -857,6 +896,70 @@ fn raising_parents_is_bounded() {
assert_eq!((cycle[0].z, cycle[1].z), (Some((0.0, 2.0)), Some((0.0, 2.0))));
}
+/// `base_height` is how far above the lowest point of the topmost object it is part of an object
+/// starts: 0 for a building, its own height for a part over the building's roof, and a basement's
+/// depth for a part over a basement. A group's members aren't parts of the group.
+#[test]
+fn a_part_starts_at_its_height_above_its_building() {
+ let points = |lo: f64, hi: f64| [[0.0, 0.0, lo], [0.0001, 0.0001, hi]];
+ let z = [(10.0, 20.0), (13.0, 14.0), (50.0, 60.0), (0.0, 10.0), (-3.0, 0.0), (0.0, 10.0), (-3.0, 0.0), (5.0, 6.0)];
+ let vertices: Vec<[f64; 3]> = z.iter().flat_map(|&(lo, hi)| points(lo, hi)).collect();
+ let at = |k: usize| json!([{"type": "MultiPoint", "boundaries": [2 * k, 2 * k + 1]}]);
+ let objects = json!({
+ "g": {"type": "CityObjectGroup", "children": ["b", "c"]},
+ "b": {"type": "Building", "parents": ["g"], "children": ["b0", "b1"]},
+ "b0": {"type": "BuildingPart", "parents": ["b"], "geometry": at(0)},
+ "b1": {"type": "BuildingPart", "parents": ["b"], "geometry": at(1)},
+ "c": {"type": "Building", "parents": ["g"], "geometry": at(2)},
+ "d": {"type": "Building", "children": ["d0", "d1"]},
+ "d0": {"type": "BuildingPart", "parents": ["d"], "geometry": at(3)},
+ "d1": {"type": "BuildingPart", "parents": ["d"], "geometry": at(4)},
+ // Three levels, listed child first (by their ids): the ground comes from the top, through the
+ // middle, in more than one round.
+ "z": {"type": "Building", "children": ["y0", "y1"]},
+ "y0": {"type": "BuildingPart", "parents": ["z"], "children": ["x"], "geometry": at(5)},
+ "y1": {"type": "BuildingPart", "parents": ["z"], "geometry": at(6)},
+ "x": {"type": "BuildingPart", "parents": ["y0"], "geometry": at(7)},
+ });
+ let out = read("m.city.json", &doc(json!(vertices), objects), None).unwrap();
+ let base = |id: &str| {
+ out.iter()
+ .find_map(|(ds, _)| {
+ (0..ds.features.len()).find(|&r| value(ds, r, "id") == crate::Value::Text(id.into())).map(|r| value(ds, r, "base_height"))
+ })
+ .unwrap()
+ };
+ let float = crate::Value::Float;
+ assert_eq!(base("b0"), float(0.0));
+ assert_eq!(base("b1"), float(3.0), "the balcony starts 3 m above its building's lowest point");
+ assert_eq!(base("b"), float(0.0));
+ assert_eq!(base("c"), float(0.0), "not 40 m above the group's lowest member");
+ assert_eq!(base("g"), float(0.0));
+ assert_eq!(base("d1"), float(0.0));
+ assert_eq!(base("d0"), float(3.0), "over a basement, it starts at the basement's depth");
+ assert_eq!(base("x"), float(8.0), "from its topmost object's lowest point, not its parent's");
+ assert!(!says(&out, "name a parent"), "{:?}", messages_of(&out));
+}
+
+/// A part whose parent isn't in the file, or couldn't be read, is measured from itself, and said.
+#[test]
+fn a_part_whose_parent_is_missing_is_said() {
+ let vertices = json!([[0.0, 0.0, 10.0], [0.0001, 0.0001, 20.0]]);
+ let at = json!([{"type": "MultiPoint", "boundaries": [0, 1]}]);
+ let objects = json!({
+ "p": {"type": "BuildingPart", "parents": ["nowhere"], "geometry": at},
+ "q": {"type": "BuildingPart", "parents": ["broken"], "geometry": at},
+ "broken": {"type": 7},
+ });
+ let out = read("m.city.json", &doc(vertices, objects), None).unwrap();
+ assert_eq!(value(&out[0].0, 0, "base_height"), crate::Value::Float(0.0));
+ assert!(
+ says(&out, "2 city objects name a parent that isn't in the file or couldn't be read: their base_height leaves it out"),
+ "{:?}",
+ messages_of(&out)
+ );
+}
+
/// A compound URN is read by its horizontal part, not by its last code, and its vertical part gives
/// the heights' unit: said when it isn't metres upward, in place of the horizontal system's.
#[test]
@@ -977,11 +1080,22 @@ fn lines_and_points_keep_their_highest_lod() {
fn a_height_too_large_to_be_a_number_is_said() {
let objects = json!({"a": {"type": "Road", "geometry": [{"type": "MultiPoint", "boundaries": [0, 1]}]}});
let out = read("m.city.json", &doc(json!([[0, 0, -1e308], [1, 1, 1e308]]), objects.clone()), None).unwrap();
- assert!(says(&out, "1 city objects have a lowest and highest Z too far apart"), "{:?}", messages_of(&out));
+ assert!(says(&out, "1 city objects have Z values too far apart for their difference to be a number"), "{:?}", messages_of(&out));
assert_eq!(value(&out[0].0, 0, "height"), crate::Value::Null);
assert_eq!(value(&out[0].0, 0, "z_max"), crate::Value::Float(1e308));
- let out = read("m.city.json", &doc(json!([[0, 0, -10], [1, 1, 20]]), objects), None).unwrap();
+ let out = read("m.city.json", &doc(json!([[0, 0, -10], [1, 1, 20]]), objects.clone()), None).unwrap();
assert!(!says(&out, "too far apart"), "{:?}", messages_of(&out));
+ // A part too far above its building's lowest point: its base_height is left empty, and said.
+ let parts = json!({
+ "b": {"type": "Building", "children": ["p", "q"]},
+ "p": {"type": "BuildingPart", "parents": ["b"], "geometry": [{"type": "MultiPoint", "boundaries": [0]}]},
+ "q": {"type": "BuildingPart", "parents": ["b"], "geometry": [{"type": "MultiPoint", "boundaries": [1]}]},
+ });
+ let out = read("m.city.json", &doc(json!([[0, 0, -1e308], [1, 1, 1e308]]), parts), None).unwrap();
+ let ds = out.iter().map(|(ds, _)| ds).find(|ds| ds.features.len() == 2).unwrap();
+ let q = (0..2).find(|&r| value(ds, r, "id") == crate::Value::Text("q".into())).unwrap();
+ assert_eq!(value(ds, q, "base_height"), crate::Value::Null);
+ assert!(says(&out, "2 city objects have Z values too far apart"), "the building and its part: {:?}", messages_of(&out));
}
/// A line of one point at a higher level doesn't take the place of a line drawn at a lower one, and
@@ -1353,7 +1467,24 @@ fn attributes_are_typed_by_every_value_in_their_layer() {
let names: Vec<&str> = ds.fields.iter().map(|f| f.name.as_str()).collect();
assert_eq!(
names,
- ["id", "type", "parent", "lod", "big", "count", "exact", "flag", "mixed", "nested", "none", "share", "z_min", "z_max", "height"]
+ [
+ "id",
+ "type",
+ "parent",
+ "lod",
+ "big",
+ "count",
+ "exact",
+ "flag",
+ "mixed",
+ "nested",
+ "none",
+ "share",
+ "z_min",
+ "z_max",
+ "height",
+ "base_height"
+ ]
);
}
diff --git a/crates/data/src/citymodel.rs b/crates/data/src/citymodel.rs
index 4f251a5eea..36e341e0b9 100644
--- a/crates/data/src/citymodel.rs
+++ b/crates/data/src/citymodel.rs
@@ -27,8 +27,8 @@ pub(crate) const MAX_FACES: usize = 200_000;
pub(crate) const MAX_FILE_FACES: usize = if cfg!(target_arch = "wasm32") { 500_000 } else { 4_000_000 };
/// The rounds of passing heights up to parents always allowed. The specification has two levels.
pub(crate) const MIN_PARENT_ROUNDS: usize = 8;
-/// Most objects and parent links visited passing heights up: past it, a crafted chain stops, with a
-/// notice, rather than costing the square of its length. [`MIN_PARENT_ROUNDS`] are run whatever it
+/// Most objects and parent links visited passing heights up, and again taking grounds from the
+/// topmost objects: past it, a crafted chain stops, with a notice, rather than costing the square of its length. [`MIN_PARENT_ROUNDS`] are run whatever it
/// says, so a file with more links than it pays for eight rounds of costs those eight.
pub(crate) const MAX_PARENT_VISITS: usize = if cfg!(target_arch = "wasm32") { 50_000_000 } else { 200_000_000 };
/// Most characters of an object type shown in a layer's name.
@@ -36,7 +36,7 @@ pub(crate) const MAX_TYPE_IN_NAME: usize = 64;
/// The fields every row starts with.
const LEAD: [&str; 4] = ["id", "type", "parent", "lod"];
/// The fields every row ends with.
-const HEIGHTS: [&str; 3] = ["z_min", "z_max", "height"];
+const HEIGHTS: [&str; 4] = ["z_min", "z_max", "height", "base_height"];
/// Most names listed in one notice.
const MAX_LISTED: usize = 16;
@@ -82,6 +82,9 @@ pub(crate) struct Built {
pub(crate) ty: String,
pub(crate) parent_ids: Vec,
pub(crate) z: Option<(f64, f64)>,
+ /// The lowest Z of the topmost object it is part of, its own when it is part of none ([`set_grounds`]):
+ /// its `base_height` is how far above it it starts.
+ pub(crate) ground: Option,
/// It has solids, so it is 3D however flat its heights.
pub(crate) solid: bool,
pub(crate) attributes: Vec<(String, Json)>,
@@ -106,10 +109,15 @@ pub(crate) struct Counts {
pub(crate) tin_reliefs: usize,
pub(crate) unconverted: usize,
pub(crate) bad_heights: usize,
- /// Objects whose lowest and highest Z are too far apart for their difference to be a number.
+ /// Objects whose lowest and highest Z, or lowest Z and ground, are too far apart for their
+ /// difference to be a number.
pub(crate) height_overflows: usize,
/// The rounds after which passing heights up to parents stopped, when it did.
pub(crate) parent_rounds: usize,
+ /// The rounds after which taking parts' grounds from their topmost objects stopped, when it did.
+ pub(crate) ground_rounds: usize,
+ /// Objects naming a parent that isn't among those read: their grounds leave it out.
+ pub(crate) unknown_parents: usize,
pub(crate) unknown: BTreeSet,
pub(crate) renamed: BTreeSet,
/// Objects drawn from another geometry or level of detail than one whose X or Y can't be drawn.
@@ -355,13 +363,13 @@ pub(crate) fn vertical_note(system: &str) -> Option {
let shown: String = system.chars().take(80).collect();
Some(match OTHER_VERTICALS.iter().find(|(c, _, _)| Some(*c) == code) {
Some((_, unit, false)) => format!(
- "a vertical system the file names ({shown}) measures heights in {unit}: z_min, z_max and height are kept as the file has them, and Style › Extrusion reads metres, so objects may stand at the wrong height"
+ "a vertical system the file names ({shown}) measures heights in {unit}: z_min, z_max, height and base_height are kept as the file has them, and Style › Extrusion reads metres, so objects may stand at the wrong height"
),
Some((_, unit, true)) => format!(
- "a vertical system the file names ({shown}) measures depth, downward, in {unit}: z_min and z_max are kept as the file has them, so the lower value is the higher point, and Style › Extrusion reads heights in metres"
+ "a vertical system the file names ({shown}) measures depth, downward, in {unit}: z_min and z_max are kept as the file has them, so the lower value is the higher point, and base_height is how far an object's top is below its topmost object's top; Style › Extrusion reads heights in metres"
),
None => format!(
- "a vertical system the file names ({shown}) is one RustGIS doesn't know the unit or direction of: z_min, z_max and height are kept as the file has them, and Style › Extrusion reads heights in metres"
+ "a vertical system the file names ({shown}) is one RustGIS doesn't know the unit or direction of: z_min, z_max, height and base_height are kept as the file has them, and Style › Extrusion reads heights in metres"
),
})
}
@@ -452,7 +460,7 @@ pub(crate) fn coordinate_system(
}
if let Some(unit) = crs.height_unit_not_metre().filter(|_| !vertical_named) {
notes.push(format!(
- "{} measures in {unit}: z_min, z_max and height are kept as the file has them, and Style › Extrusion reads metres, so objects may stand at the wrong height",
+ "{} measures in {unit}: z_min, z_max, height and base_height are kept as the file has them, and Style › Extrusion reads metres, so objects may stand at the wrong height",
crs.label()
));
}
@@ -530,7 +538,13 @@ pub(crate) fn finish(
counts.unconverted += objects.len();
}
counts.parent_rounds = raise_parents(&mut built, MAX_PARENT_VISITS).unwrap_or(0);
- counts.height_overflows = built.iter().filter(|b| b.z.is_some_and(|(lo, hi)| !(hi - lo).is_finite())).count();
+ counts.ground_rounds = set_grounds(&mut built, MAX_PARENT_VISITS).unwrap_or(0);
+ counts.unknown_parents = {
+ let ids: HashSet<&str> = built.iter().map(|b| b.id.as_str()).collect();
+ built.iter().filter(|b| b.parent_ids.iter().any(|p| !ids.contains(p.as_str()))).count()
+ };
+ let overflows = |b: &Built| b.z.is_some_and(|(lo, hi)| !(hi - lo).is_finite() || b.ground.is_some_and(|g| !(lo - g).is_finite()));
+ counts.height_overflows = built.iter().filter(|b| overflows(b)).count();
let is_3d = |b: &Built| b.solid || b.z.is_some_and(|(lo, hi)| hi > lo);
counts.footprints = rows
.iter()
@@ -811,6 +825,44 @@ pub(crate) fn raise_parents(built: &mut [Built], visits: usize) -> Option
Some(rounds)
}
+/// Each object's ground: the lowest Z of the topmost object it is part of (of the lowest, when it is
+/// part of several), so a part over a building's roof starts at its lowest point's height above the
+/// building's lowest point (its basement's, when it has one), and a building at 0. A group's
+/// members aren't parts of the group: their ground is their own. Heights are passed up first
+/// ([`raise_parents`]), so each object's lowest Z is at most its parts', and the ground is the
+/// least of its own and its parents'. Run in as many rounds as passing heights up, and bounded the
+/// same way; gives the rounds it stopped after, when grounds were still moving. Not looking at
+/// Cancel: like passing heights up, a pass over objects already read.
+pub(crate) fn set_grounds(built: &mut [Built], visits: usize) -> Option {
+ let links: Vec> = {
+ let index: HashMap<&str, usize> = built.iter().enumerate().map(|(i, b)| (b.id.as_str(), i)).collect();
+ let group = |p: &usize| built.get(*p).is_some_and(|b| b.ty == "CityObjectGroup");
+ built.iter().map(|b| b.parent_ids.iter().filter_map(|p| index.get(p.as_str()).copied()).filter(|p| !group(p)).collect()).collect()
+ };
+ for b in built.iter_mut() {
+ b.ground = b.z.map(|(lo, _)| lo);
+ }
+ let per_round = links.iter().map(|l| l.len() + 1).sum::().max(1);
+ let rounds = built.len().min(visits / per_round).max(MIN_PARENT_ROUNDS);
+ for _ in 0..rounds {
+ let mut changed = false;
+ for (i, parents) in links.iter().enumerate() {
+ let lowest = parents.iter().filter_map(|&p| built.get(p).and_then(|b| b.ground)).fold(f64::INFINITY, f64::min);
+ if let Some(b) = built.get_mut(i)
+ && let Some(ground) = b.ground
+ && lowest < ground
+ {
+ b.ground = Some(lowest);
+ changed = true;
+ }
+ }
+ if !changed {
+ return None;
+ }
+ }
+ Some(rounds)
+}
+
/// A row's properties, its attributes under their layer's `names` (unique, as [`attribute_names`]
/// makes them), sorted by name as a GeoJSON feature's are. Attributes are borrowed, not copied.
fn properties<'a>(b: &'a Built, lod: Option<&'a str>, names: &'a HashMap) -> BTreeMap<&'a str, Cow<'a, Json>> {
@@ -822,7 +874,12 @@ fn properties<'a>(b: &'a Built, lod: Option<&'a str>, names: &'a HashMap) -> String {
}
/// One notice per kind, with a count.
-fn messages(c: &Counts) -> Vec {
+pub(crate) fn messages(c: &Counts) -> Vec {
let mut out = Vec::new();
let mut say = |n: usize, text: String| {
if n > 0 {
@@ -976,7 +1033,7 @@ fn messages(c: &Counts) -> Vec {
say(
c.footprints,
format!(
- "{} 3D city objects are drawn as their footprints, with their lowest and highest Z in z_min and z_max, and the difference in height",
+ "{} 3D city objects are drawn as their footprints, with their lowest and highest Z in z_min and z_max, the difference in height, and in base_height how far their lowest point is above the lowest point of the topmost object they are part of (0 for that object)",
c.footprints
),
);
@@ -1044,7 +1101,7 @@ fn messages(c: &Counts) -> Vec {
say(
c.height_overflows,
format!(
- "{} city objects have a lowest and highest Z too far apart for their difference to be a number: their height is left empty",
+ "{} city objects have Z values too far apart for their difference to be a number: their height or base_height is left empty",
c.height_overflows
),
);
@@ -1055,6 +1112,20 @@ fn messages(c: &Counts) -> Vec {
c.parent_rounds
),
);
+ say(
+ c.ground_rounds,
+ format!(
+ "parent chains go deeper than {} levels: some parts' base_height is measured from a parent, not from the topmost object they are part of",
+ c.ground_rounds
+ ),
+ );
+ say(
+ c.unknown_parents,
+ format!(
+ "{} city objects name a parent that isn't in the file or couldn't be read: their base_height leaves it out",
+ c.unknown_parents
+ ),
+ );
if !c.unknown.is_empty() {
out.push(format!("geometries of unknown types are left out: {}", listed(&c.unknown)));
}
diff --git a/docs/user-guide/data-formats.md b/docs/user-guide/data-formats.md
index 098a6ee7e1..0a6d2216b1 100644
--- a/docs/user-guide/data-formats.md
+++ b/docs/user-guide/data-formats.md
@@ -29,7 +29,7 @@ not every EPSG code; azimuthal equidistant systems such as Equi7 need the deskto
| OpenStreetMap PBF | `.osm.pbf`, or `.pbf` containing OSM data | Add Data, drop the file, or upload | Points (tagged nodes), lines and multipolygons (closed ways that are areas, and multipolygon and boundary relations), with common tags as fields and the rest in `other_tags`, as GDAL gives them. Up to 40 million nodes (4 million in the web app); on the desktop, extracts over 256 MiB open through GDAL when it is installed. Vector-tile `.pbf` files use Add Tile Layer instead. |
| ArcGIS feature-service answers (protocol buffer) | `.pbf` holding an answer to an ArcGIS query with `f=pbf`, or the query's address | Add Data, drop the file, upload, or From URL… with the query's address (`…/FeatureServer/0/query?…&f=pbf`) | One page of the layer: the fields and values the same query gives as GeoJSON, with the fields' aliases as their display names (dates as milliseconds since 1970, date-only and time values as text), points, lines or polygons converted to longitude/latitude from the answer's coordinate system. Z and M values, geometry, blob and raster fields are left out, with a notice. A page that stopped at the service's record limit keeps its features, with a notice that the rest aren't in it. A query the service refuses (an empty answer), a count, ids or an extent, curves, multipatches and envelopes give an error. Told from OpenStreetMap data by its content. |
| TopoJSON | `.topojson`, or `.json` | Add Data, drop the file, or upload | Shared arcs (quantized or not) are rebuilt into geometries. A `.topojson` adds a layer per object, up to 64; a topology named `.json` adds its first object and names the others in a notice. Use `.topojson` to add them all. |
-| CityJSON | `.city.json`, or `.json` | Add Data, drop the file, upload, or From URL… | CityJSON 1.1 and 2.0, read in 2D: a layer per City Object type and geometry family (a name two layers would share, such as two long types cut to their first 64 characters, or two that differ only in ASCII case, gets ` (2)`, ` (3)`… on the later ones: the first number no other layer's name uses). Surfaces and solids become footprints (LoD 0, else the `GroundSurface` surfaces, else the union of the faces of the highest LoD, each tried when the one before gives no area, else the outline of the points; lines and points come from their highest level of detail that draws; a level passed over because its X or Y isn't a finite number, or is too large, is named in a notice; a geometry of more than 200,000 faces is the outline of its points (of its ground's, for a footprint from the ground), with a notice, unless its footprint is its ground and all of its ground faces are within the cap), with `z_min`, `z_max` and `height` fields, from every level of detail and the children's heights included, so Style › Extrusion stands them up. Also `id`, `type`, `parent`, `lod` and the object's attributes; one named as one of these fields, or as another attribute of its layer but for case, takes a number (`height_1`), the same in every row, and a notice lists them. A `.city.json`, or a model from an address, adds every layer, up to 64; a file named `.json` adds its first layer with something to draw and names the others in a notice. A file that names no coordinate system and isn't longitude/latitude is refused: for now the way to add it is the `"crs"` parameter of `layer.addData`, from the command line, Python or the AI Assistant. Geometry instances are their template placed by their matrix at their reference point, with its heights, and rings the matrix flattens are left out and said for each instance; one whose template is missing, can't be read or draws nothing, or whose matrix is missing or isn't 16 numbers ending in `0 0 0 1`, is drawn as a point at its reference point, with no height, as are those past what placing may cost (as many points, all instances together, as the file could write out), and a notice says how many. `TINRelief` objects aren't drawn; a notice says so, as it does for addresses. Appearance (materials and textures) isn't read, and a notice says how much is left out. Heights are kept in the file's unit: in a coordinate system that doesn't measure in metres, a notice says so, as Style › Extrusion reads metres. A compound URN (`urn:ogc:def:crs,crs:EPSG::25832,crs:EPSG::5783`) is read by its horizontal part, and its vertical part gives the heights' unit, said as in CityGML when it isn't a height in metres. In a zip, a `"crs"` applies only to a model that names no coordinate system RustGIS knows. In the browser a footprint that needs a union is the outline of the object's points; a notice says so. Extrusions have no base height yet, so a part above the ground stands on the ground. |
+| CityJSON | `.city.json`, or `.json` | Add Data, drop the file, upload, or From URL… | CityJSON 1.1 and 2.0, read in 2D: a layer per City Object type and geometry family (a name two layers would share, such as two long types cut to their first 64 characters, or two that differ only in ASCII case, gets ` (2)`, ` (3)`… on the later ones: the first number no other layer's name uses). Surfaces and solids become footprints (LoD 0, else the `GroundSurface` surfaces, else the union of the faces of the highest LoD, each tried when the one before gives no area, else the outline of the points; lines and points come from their highest level of detail that draws; a level passed over because its X or Y isn't a finite number, or is too large, is named in a notice; a geometry of more than 200,000 faces is the outline of its points (of its ground's, for a footprint from the ground), with a notice, unless its footprint is its ground and all of its ground faces are within the cap), with `z_min`, `z_max` and `height` fields, from every level of detail and the children's heights included, so Style › Extrusion stands them up, and `base_height`, how far an object's lowest point is above the lowest point of the topmost object it is part of (0 for a building; for a balcony part, its lowest point's height above the building's; a building's lowest point is its basement's when it has one, and a group's members aren't parts of the group). Also `id`, `type`, `parent`, `lod` and the object's attributes; one named as one of these fields, or as another attribute of its layer but for case, takes a number (`height_1`), the same in every row, and a notice lists them. A `.city.json`, or a model from an address, adds every layer, up to 64; a file named `.json` adds its first layer with something to draw and names the others in a notice. A file that names no coordinate system and isn't longitude/latitude is refused: for now the way to add it is the `"crs"` parameter of `layer.addData`, from the command line, Python or the AI Assistant. Geometry instances are their template placed by their matrix at their reference point, with its heights, and rings the matrix flattens are left out and said for each instance; one whose template is missing, can't be read or draws nothing, or whose matrix is missing or isn't 16 numbers ending in `0 0 0 1`, is drawn as a point at its reference point, with no height, as are those past what placing may cost (as many points, all instances together, as the file could write out), and a notice says how many. `TINRelief` objects aren't drawn; a notice says so, as it does for addresses. Appearance (materials and textures) isn't read, and a notice says how much is left out. Heights are kept in the file's unit: in a coordinate system that doesn't measure in metres, a notice says so, as Style › Extrusion reads metres. A compound URN (`urn:ogc:def:crs,crs:EPSG::25832,crs:EPSG::5783`) is read by its horizontal part, and its vertical part gives the heights' unit, said as in CityGML when it isn't a height in metres. In a zip, a `"crs"` applies only to a model that names no coordinate system RustGIS knows. In the browser a footprint that needs a union is the outline of the object's points; a notice says so. Extrusions have no base height yet, so a part above the ground stands on the ground; `base_height` holds where it starts. |
| CityGML | `.gml`, or `.xml` | Add Data, drop the file, upload, or From URL… | CityGML 1.0, 2.0 and 3.0, read in 2D as CityJSON is (the same layers, fields, footprints, heights and notices). 3.0 is read by the names it keeps and by its own where they change (thematic surfaces in `boundary`, openings in `fillingSurface`, generic attributes named by `gen:name`, a group's member inside its `Role`), read only in 3.0's namespaces, so an extension of a 1.0 or 2.0 model that uses one of those names keeps its own meaning; its spaces (a `BuildingRoom`, a `Storey`) are objects like any other. The objects are the features of the model's members and those nested in them with a `gml:id` or a geometry (a `BuildingPart`, a `Room`), each with its parent's id in `parent`; thematic surfaces and their openings are their object's faces, and a `GroundSurface` its ground. A geometry's level of detail is the one its property names (`lod2Solid` is 2); one in another property (a group's) has none. Converted from the `srsName`, by its horizontal part for a compound system (the URN and URL forms of geographic systems are latitude first, CRS84 longitude first; heights are kept as they come, and a vertical part that isn't a height in metres, such as one in feet, a depth, or one RustGIS doesn't know, is said; when a vertical part is named, its unit is the heights', not the horizontal system's), or from the coordinate system given (`crs`), which takes the place of the one the file names; a file naming different systems (on its geometries or envelopes) is refused unless a system is given, which reads them all and says how many named another, and one system with its axes in different orders is refused either way. Picked by name (`layer`), a layer keeps the notices the file as a whole gives; zipped, a model keeps the system it names, and the one given applies only when it names none RustGIS knows. Generic attributes are typed by their element, `measuredHeight`, the storey counts, years and any property with a unit in metres are numbers (a measure in another unit than the metre is text with its unit), other simple properties are text (the code list a code names, `codeSpace`, a value's other attributes, such as its language, `xml:lang`, and a generic attribute set's members with no name and its own code list aren't kept, and notices say how many, generic attributes included), a property given twice is a list and a structured one its JSON. Each member of the model is parsed on its own, with the objects nested in it (each object of a `featureMembers` on its own), so no tree of the whole model is built; the file's text and the rows read stay in memory. On the desktop, Add Data reads a file added by its path in the background, with its progress counted a member at a time and Cancel (in a zip, from text, or listed, it is read as the command runs). A member nested too deep or too large to parse is left out whole, with a notice. A geometry given by a link (`xlink:href`) to one written in the file, in the same member or another, as a solid's faces are to its walls' and roof's polygons, is read where the link stands, once its object's own geometries are read, a ground surface's links first: one its object holds already at that level of detail isn't read again (a ground face stays its ground, and a face read as a wall that a ground surface links to is read as the ground too), through links each is read at most once per object and level, so links in a cycle end, and what a member's links read is bounded by the member's size, and what links copy and read from other members by four times the file's, past which the links left are said; a solid whose exterior is a link that is followed and reads something keeps its cavities; a link to a `gml:id` that several elements have reads the one in its member, else the first in the file, and a notice says how many geometries repeat one; a geometry whose coordinates can't be read is said once, whichever object or link reads it first. An implicit geometry is its prototype (`relativeGMLGeometry`, `relativeGeometry` in 3.0, written in place or given by a link, in its member or another) placed by its matrix at its reference point, in the file's axis order (latitude first where the system is), with its heights: the prototype is read once and placed for each instance, and rings its matrix flattens are left out and said for each instance; one whose prototype is in another file (`libraryObject`), can't be read or holds nothing to place, or whose matrix isn't 16 numbers ending in `0 0 0 1`, is drawn as a point at its reference point, with no height, as are those past what placing may cost (as many points, all instances together, as the file could write out), and a notice says how many. A part, a group's member or a group's parent given by a link (`consistsOfBuildingPart`, `buildingPart`, `bridgePart` and `tunnelPart` in 3.0, `groupMember`, a `CityObjectGroup`'s `parent`) makes the object it names a child of the other, as if written in it, so its heights go to it, wherever it is in the file (an object written in a group's `parent` is the group's parent too, not its child); the link stays an attribute too, a link naming no other object of the file is said, and a member's role in its group isn't kept, and is said. Not read, and said in a notice: geometries given by a link to another file, nothing or a member that can't be parsed, to what isn't a geometry, or to one where nothing is drawn (an appearance's, a terrain intersection's), a prototype's geometry linked from outside its implicit geometry, and links inside a prototype; thematic surfaces and openings given only by a link; rings given by one (a hole so given is left out, its face kept), lines and rings with a point or curve given by one, and an oriented curve whose base curve is, terrain intersection curves, appearances, addresses, and the properties of thematic surfaces and openings (a name, generic attributes: their faces are kept as their object's); arcs and splines are read as straight lines through their points (a curve given backwards, `orientation="-"`, in its direction, and one held in a ring counted like a standalone one); an arc given by its centre (`ArcByCenterPoint`, `CircleByCenterPoint`) isn't read as the curve's points, its centre is never a vertex, and an arc that is its curve's only segment leaves the geometry with nothing to read; a `gml:Point` written with more than one position keeps the first one, and is said; a solid with no exterior shell is left out, as is a solid whose exterior has nothing read (a link that isn't followed, an empty shell, or a shell whose surfaces are all links that lead nowhere), its cavities with it (read alone they would be drawn as a footprint), and one whose cavity can't be read is left out whole; a file cut short, even inside a tag, keeps the objects before the cut; `TINRelief` objects aren't drawn; 3.0's relations between objects (`CityObjectRelation`) and the model's versions (`versionMember`, `versionTransitionMember`) aren't read. |
| AutoCAD DXF | `.dxf` (ASCII) | Add Data, drop the file, or upload | Points, lines and polygons layers from the drawing's entities: POINT, LINE, LWPOLYLINE and POLYLINE (bulges drawn as arcs; closed ones stay lines; polyface meshes become polygons), CIRCLE, ARC, ELLIPSE, SPLINE, HELIX, LEADER, MLINE (its centre line), TEXT, MTEXT, ATTRIB and constant ATTDEF (points with their text, at the alignment point of justified text), HATCH boundaries (holes found by nesting), SOLID, TRACE and 3DFACE (polygons). Blocks (named in any case) are drawn where INSERTs place them (scaled, rotated, in arrays, nested up to 8 deep), and so are DIMENSIONs' blocks (a linear dimension without one draws its lines and measured text). Entities in an object's own coordinate system are turned into the drawing's. Fields: `layer`, `entity`, `color` (ACI, BYLAYER and BYBLOCK resolved), `linetype`, `text`, `height`, `rotation`, `block`, `elevation` and `paperspace`. The drawing's layouts (paper space: title blocks, viewport frames) are left out, with a notice, unless `"paperSpace": true`. A drawing never says its coordinate system: give `"crs"` (such as `EPSG:2263`), or its coordinates are kept as they are, with a notice. `"layer"` picks one of the drawing's own layers, and `info.fileLayers` lists them. Up to 2 million features (500,000 in the web app). Not read: binary DXF, MULTILEADER, WIPEOUT, IMAGE and ACIS solids (3DSOLID, REGION), named in a notice. |
| Geotagged photos | `.jpg`, `.jpeg` | Add Data (several at once in the web app), drop them, upload, or `layer.addPhotos` with `"paths"` or a `"folder"` | JPEGs with a GPS position in their EXIF become points in the **Photos** layer (photos added one at a time join it): each with its `name`, `file`, `time` (when it was taken), `altitude`, `direction` (where the camera faced), `camera` and a `thumbnail` of at most 160 pixels, kept with the feature so the project needs no other file. Identify shows the thumbnail. Photos without a position are named in a notice and left out; a layer holds up to 2,000 photos. A JPEG is always read as a photo unless `layer.addData` or `layer.addDataBytes` is given `"as": "scan"` (a phone photo of a paper map, say: see [Scans with no coordinates](#rasters)). |