Skip to content

[Feature]: Read CityJSON city models as footprints with their heights #1269

Closed

Description

@jgregoriorincon

Before you start

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:

  1. LoD 0 geometry;
  2. surfaces with the GroundSurface semantic;
  3. the union of the faces seen from above, as multipatches do;
  4. 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;
  • TINRelief objects, not drawn in this version;
  • GeometryInstance objects, 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:

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:

  1. 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?
  2. Is one layer per object type right, or should all objects of a family share a layer with a type field?
  3. 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 data for 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

  1. added
    enhancement
    on Nov 1, 2026
  2. jgregoriorincon commented on Nov 1, 2026

    @jgregoriorincon
    ContributorAuthor

    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:

    1. Reader. RustGIS reads CityJSON and CityGML as footprints with z_min, z_max and height, as File Geodatabase multipatches are read. Either through Terrio's readers, with the footprints computed in RustGIS, or with a reader in crates/data. Which do you prefer, given that the Terrio integration is still exploratory?
    2. Extrusion base height, as a separate small PR, so that a BuildingPart above 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.

  3. jgregoriorincon commented on Nov 1, 2026

    @jgregoriorincon
    ContributorAuthor

    @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.

  4. giswqs commented on Nov 1, 2026

    @giswqs
    Member

    @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.

    1. Reader: CityJSON first, with CityGML as a follow-up PR. Please reuse the footprint logic in crates/data/src/filegdb.rs rather 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.
    2. Test files: please use the 3DBAG, PLATEAU and Roofer files you collected. They're valuable here, and the "never crash" rules apply to all of them.
    3. Extrusion base height: go ahead with it as a separate PR.
    4. Later: the reader can move to Terrio if that integration goes ahead, since the footprint step stays in RustGIS either way. The wider integration is a separate decision and doesn't block this work.

    Real 3D (roofs, solids) stays with #726, as you said.

  5. jgregoriorincon commented on Nov 1, 2026

    @jgregoriorincon
    ContributorAuthor

    Thanks! Starting now, in this order:

    1. Move the footprint step out of filegdb.rs into a shared module, with no change in behaviour (FileGDB's tests unchanged).
    2. The CityJSON reader on top of it, tested with the 3DBAG, PLATEAU and Roofer files.
    3. The extrusion base height.
    4. The CityGML reader as a follow-up.

    I'll name Terrio's reader in the PR if I follow it.

  6. flight1973 commented on Nov 5, 2026

    @flight1973
    Contributor

    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), so z_min/z_max come 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. height itself 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.

  7. jgregoriorincon commented on Nov 7, 2026

    @jgregoriorincon
    ContributorAuthor

    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.

  8. jgregoriorincon commented on Nov 12, 2026

    @jgregoriorincon
    ContributorAuthor

    Thanks, and sorry for the slow answer. Both points checked against what was merged:

    • The transform: vertices are decoded with all three scales and translations, z included (cityjson.rs, where the vertices are read).
    • The vertical part: not kept today. horizontal_epsg maps EPSG:7415 to 28992 and 6697 to 6668 and drops the vertical datum, so z_min and z_max are heights in the file's own vertical datum, and the layer doesn't record which. As you say, height is 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.
  9. jgregoriorincon commented on Nov 13, 2026

    @jgregoriorincon
    ContributorAuthor

    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: base to base + height. The height keeps its meaning, so existing projects draw the same. A city model's height is already a thickness (z_max - z_min).

    Where the base comes from. z_min is 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 a base_height field: an object's z_min minus the z_min of 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:

    1. Data: base_height in both city-model readers.
    2. Model and renderers:
      • Extrusion gets base_field and base, set by layer.extrusion (baseField, base), with the numeric check and the repair lists.
      • The base is drawn by the CPU (flat and tilted), GPU, tilted-drape and glTF paths, with CPU/GPU parity tests.
      • The shader needs no change: only vertex values move.
    3. Style › Extrusion › Base menu: with the user guide and screenshots.

    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.md says 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:

    • (a) Write format 2 only when a layer uses a base, so files without one stay at 1 and still open in older versions. write_format would write the lowest format the content needs instead of always FORMAT. My preference.
    • (b) Raise FORMAT to 2 for every file. It is simpler, but older versions would refuse every new file, base or not.
    • (c) Leave it at 1. An older version would drop the base on save, which the rule doesn't allow.

    This would be the first time FORMAT goes up, so I'd rather you choose before pull request 2. Pull request 1 doesn't depend on it, so I'll start there.

  10. 6 remaining items

  11. jgregoriorincon commented on Nov 15, 2026

    @jgregoriorincon
    ContributorAuthor

    Everything planned here is in:

    1. Reader: CityJSON read as footprints with z_min, z_max and height (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).
    2. CityGML: moved to its own issue, [Feature]: Read CityGML city models as footprints with their heights #1536, done (CityGML 1.0–3.0, with the notice for a vertical unit that isn't the metre).
    3. Extrusion base: each object's base_height from 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions