Repository navigation
Description
Before you start
- I searched the existing issues and the roadmap and did not find a duplicate request.
What problem does this solve?
CityJSON is the JSON encoding of the CityGML data model, used to publish 3D city models. RustGIS can't open these files, so their buildings, attributes and heights can't be mapped, queried or joined to other data.
Full 3D display depends on #726, which has no Phase 1 work yet: Coord is still {x, y}, and there is no mesh layer. But RustGIS already has a way to show 3D objects in its 2D model. Since #697, a File Geodatabase multipatch is read as its footprint, with z_min, z_max and height fields, and an extrusion can stand it up by height. CityJSON could use the same approach now, without waiting for 3D scenes.
Proposed solution
A native CityJSON reader, crates/data/src/cityjson.rs, with no new dependencies. It would work on the desktop and in the browser, in Add Data, the CLI and Python, like the other multi-layer readers.
Detection. The .city.json extension, or a .json file whose top-level type is CityJSON, as TopoJSON is recognised today.
Versions. CityJSON 1.1 and 2.0, which differ little for a reader. +GenericCityObject in a 1.1 file and GenericCityObject in a 2.0 file share one layer. Any other version is refused with an error that names it and suggests upgrading the file with cjio.
Layers. One layer per City Object type and geometry family: Building, BuildingPart, Road and so on, including extension types such as +Something. MultiPoint becomes points, MultiLineString becomes lines, and surfaces and solids become polygons.
Footprints. For each object, the first source that gives one:
- LoD 0 geometry;
- surfaces with the
GroundSurfacesemantic; - the union of the faces seen from above, as multipatches do;
- the hull of its points, as multipatches do in the browser or past the face limit.
Fields. The object's attributes, plus id, type, parent, lod, z_min, z_max and height (z_max - z_min). The names match the multipatch fields, so Style › Extrusion works the same way. measuredHeight stays an ordinary attribute.
Coordinate system. Vertices are decoded with transform and converted to longitude/latitude from metadata.referenceSystem. CityJSON often names a compound system, such as EPSG:7415, which Crs::from_epsg doesn't know. A small table would map common compound codes to their horizontal part. An unknown system with coordinates that aren't longitude/latitude is an error, not a guess.
Hostile input. Vertex and surface indexes are checked, and nesting and sizes are bounded, with no panics. Tests cover bad indexes and broken nesting.
Notices. One per kind, with a count, as the project requires:
- 3D geometry drawn as footprints, with heights kept in fields;
- objects drawn as a hull;
- objects skipped, with no usable geometry;
TINReliefobjects, not drawn in this version;GeometryInstanceobjects, drawn as a point at their reference point.
A clean 2D result gives no notice, and tests check both ways.
Out of scope, for later:
- CityJSONSeq (
.city.jsonl); - CityGML, which could produce the same output with a larger reader;
- writing CityJSON;
- real 3D geometry, which belongs to [Feature]: Full 3D scenes: heights in the data, 3D objects and point clouds, a scene camera #726 and could reuse this reader once Z and meshes exist.
Known limit. Extrusions have no base height, so a BuildingPart that starts above the ground still stands on the ground. A base height would be a separate, reusable change.
Questions for the maintainer:
- Does this bridge fit with [Feature]: Full 3D scenes: heights in the data, 3D objects and point clouds, a scene camera #726, or would you rather wait for Phase 1?
- Is one layer per object type right, or should all objects of a family share a layer with a
typefield? - A CityJSON and CityGML reader and writer are also proposed for Terrio in Read and write CityJSON and CityGML terrio#462. Should RustGIS keep this small reader in
datafor now, and revisit it if the Terrio integration goes ahead?
Estimated scope
Medium: a broader feature that is feasible in a reasonable timeframe
Alternatives considered
- Wait for Z and meshes ([Feature]: Full 3D scenes: heights in the data, 3D objects and point clouds, a scene camera #726). This gives real 3D models, but it has no date and needs the data-model decision first.
- Read through GDAL. CityJSON isn't in RustGIS's list of formats read through GDAL. It would also work only on the desktop with GDAL installed, and still produce the same flat result.
- Convert outside RustGIS first. This works today, but it adds a step and depends on another tool to keep the heights and attributes.
- Use a Terrio driver instead of a reader here. Read and write CityJSON and CityGML terrio#462 proposes CityJSON and CityGML drivers, which would serve Terrio's own users either way. But RustGIS doesn't depend on Terrio, and the roadmap lists that integration as an open question, so using them here would need the driver and a decision on the integration.
Activity
jgregoriorincon commentedon Nov 1, 2026
An update, since Terrio now has both readers: opengeos/terrio#464 (CityJSON) and opengeos/terrio#470 (CityGML).
I'd like to implement this issue, and I won't start until you confirm the approach:
z_min,z_maxandheight, as File Geodatabase multipatches are read. Either through Terrio's readers, with the footprints computed in RustGIS, or with a reader incrates/data. Which do you prefer, given that the Terrio integration is still exploratory?BuildingPartabove the ground stands at its own height.Real 3D (roofs, solids) stays with #726.
While testing the Terrio readers, I collected real files that break naive readers: 3DBAG tiles with degenerate rings, PLATEAU files whose solids link to their thematic surfaces' polygons, and 100 MB Roofer models with faces only in thematic surfaces. I'll use them to test whichever path you choose.
jgregoriorincon commentedon Nov 1, 2026
@giswqs, when you have a moment: the question above is whether RustGIS should read CityJSON and CityGML through Terrio's readers or with its own in
crates/data. I'll wait for your answer before starting.giswqs commentedon Nov 1, 2026
@jgregoriorincon thanks for checking first. Please go ahead with a reader in
crates/data, not through Terrio.Terrio's CityJSON reader returns one flat XYZ feature per surface, so RustGIS would still have to group surfaces by object, compute the footprints and
z_min/z_max, and add its notices. That is most of this issue, so the dependency would save little. Its CityGML reader (opengeos/terrio#470) also isn't merged yet.crates/data/src/filegdb.rsrather than writing a second version; it's private today and will need adapting. If you use Terrio's reader as a guide, name it in the PR.Real 3D (roofs, solids) stays with #726, as you said.
jgregoriorincon commentedon Nov 1, 2026
Thanks! Starting now, in this order:
filegdb.rsinto a shared module, with no change in behaviour (FileGDB's tests unchanged).I'll name Terrio's reader in the PR if I follow it.
feat(data): read CityJSON models as footprints with their heights
feat(data): read CityJSON models as footprints with their heights
feat(data): read CityJSON models as footprints with their heights
feat(data): read CityJSON models as footprints with their heights
feat(data): read CityJSON models as footprints with their heights (#1300
flight1973 commentedon Nov 5, 2026
Since you're testing with 3DBAG and PLATEAU: both use compound CRSs in
metadata.referenceSystem. 3DBAG is EPSG:7415 (RD New + NAP height) and PLATEAU is EPSG:6697 (JGD2011 + JGD2011 vertical height), soz_min/z_maxcome out as orthometric heights in that local datum, not above the ellipsoid. It'd be worth keeping the vertical part of the CRS on the layer rather than dropping it, so that once #726 puts these on terrain or the globe they can be converted instead of landing tens of meters off.heightitself is fine either way, since it's a difference.Small thing: CityJSON vertices are integers until you apply
transform(scale and translate), z included, so the z scale needs to go through too.jgregoriorincon commentedon Nov 7, 2026
The CityGML follow-up agreed here now has its own issue, #1536, with its scope and plan in three pull requests. This issue stays for CityJSON.
jgregoriorincon commentedon Nov 12, 2026
Thanks, and sorry for the slow answer. Both points checked against what was merged:
transform: vertices are decoded with all three scales and translations, z included (cityjson.rs, where the vertices are read).horizontal_epsgmaps EPSG:7415 to 28992 and 6697 to 6668 and drops the vertical datum, soz_minandz_maxare heights in the file's own vertical datum, and the layer doesn't record which. As you say,heightis a difference, and the extrusion uses only that. Keeping the vertical system on the layer is what [Feature]: Full 3D scenes: heights in the data, 3D objects and point clouds, a scene camera #726 will need to put these on terrain, so it belongs with that work. Until then I'll add a notice for a vertical system whose unit isn't the metre, since heights are read as metres.jgregoriorincon commentedon Nov 13, 2026
Starting the extrusion base height (point 3 of the plan above), now that CityGML 1.0–3.0 and the vertical-unit notice (#1536) are in. It touches more than the renderer, so here is the plan, and one question on the saved-file format before I write it.
What a base means: walls start at the base and rise by the height:
basetobase + height. The height keeps its meaning, so existing projects draw the same. A city model'sheightis already a thickness (z_max - z_min).Where the base comes from.
z_minis absolute (NAP, sea level), so a model of a town at 500 m would float 500 m up. The CityJSON and CityGML readers will add abase_heightfield: an object'sz_minminus thez_minof its top-level object, its ground. A building gets 0 and a balcony part 3 m. Ground-relative heights from terrain stay with #726.Three pull requests, about 450 lines in all:
base_heightin both city-model readers.Extrusiongetsbase_fieldandbase, set bylayer.extrusion(baseField,base), with the numeric check and the repair lists.Known limit: the CPU paths draw extrusions in painter's order by their place on the ground, so a raised part over a building behind it can be drawn in the wrong order. The GPU path has a depth buffer. I'll say it in the user guide rather than change the CPU ordering here.
The question: the format number.
docs/maintaining.mdsays an older RustGIS "doesn't save [a file] again without what it couldn't read". Today an older version would open a project, map, layer or style file with a base, drop the two new fields (serde ignores them), and save it without them. The options I see:write_formatwould write the lowest format the content needs instead of alwaysFORMAT. My preference.FORMATto 2 for every file. It is simpler, but older versions would refuse every new file, base or not.This would be the first time
FORMATgoes up, so I'd rather you choose before pull request 2. Pull request 1 doesn't depend on it, so I'll start there.6 remaining items
fix(render): a roof label ignores a height below the ground, and the …
fix(engine): the web scene caps an extrusion's base and height togeth…
fix(render): a raised part's hole walls cast its shadow, with no seco…
feat(render): extrusions stand on a base, from a field or a constant,…
fix(engine): Extrusion Base refuses a base outside its range, and say…
docs(data): a CityJSON part is raised by any base, a field or a const…
feat(engine): Extrusion Base sets what an extrusion stands on, a fiel…
fix(engine): Extrusion Base refuses a base outside its range, and say…
docs(data): a CityJSON part is raised by any base, a field or a const…
feat(engine): Extrusion Base sets what an extrusion stands on, a fiel…
fix(ui): the Base menu has an icon of its own, Ground covers a base b…
fix(ui): Base (m) and Factor show a saved value out of range without …
feat(ui): Style › Extrusion › Base chooses the ground, a field or a c…
jgregoriorincon commentedon Nov 15, 2026
Everything planned here is in:
z_min,z_maxandheight(feat(data): read CityJSON models as footprints with their heights #1300), on a city-model module shared with File Geodatabase multipatches (refactor(data): move the city model's shared part out of the CityJSON reader (#1536) #1537).base_heightfrom both readers (feat(data): city-model readers give each object's base_height above its topmost object (#1269) #1974); extrusions standing on a base from a field or a constant, in every view and the web scene (feat(render): extrusions stand on a base, from a field or a constant, in every view and the web scene (#1269) #2006);layer.extrusionBase(feat(engine): Extrusion Base sets what an extrusion stands on, a field or a constant (#1269) #2039); Style › Extrusion › Base (feat(ui): Style › Extrusion › Base chooses the ground, a field or a constant for what extrusions stand on (#1269) #2094).What follows lives elsewhere: keeping the vertical datum so these sit on terrain belongs to #726, and city models coming in already extruded on their base is #2161. Closing as completed.