Read, write, and query CityJSON, CityJSONSeq, FlatCityBuf, and CityParquet 3D city model files.
Installing and Loading
INSTALL cityjson FROM community;
LOAD cityjson;
Example
-- Read a CityJSON file
SELECT * FROM read_cityjson('buildings.city.json');
-- Read a CityJSONSeq (line-delimited) file
SELECT * FROM read_cityjsonseq('buildings.city.jsonl');
-- Read a FlatCityBuf file, pushing a bounding box into its spatial index
SELECT * FROM read_flatcitybuf('buildings.fcb',
min_x => 84000, min_y => 444000, max_x => 84500, max_y => 444500);
-- Extract geometries as WKB at a specific Level of Detail
SELECT * FROM read_cityjson('buildings.city.json', lod=>'1.2');
-- Write query results to CityJSONSeq; the source CRS and metadata travel too
COPY (SELECT * FROM read_cityjson('buildings.city.json'))
TO 'output.city.jsonl' (FORMAT cityjsonseq);
-- Inspect file metadata
SELECT * FROM cityjson_metadata('buildings.city.json');
-- Read material and texture definitions
SELECT * FROM cityjson_materials('buildings.city.jsonl');
-- Build a CityParquet package: a schema you can validate, mutate and write out
CREATE SCHEMA city;
CREATE TABLE city.building AS SELECT * FROM read_cityjson('buildings.city.json');
PRAGMA cityparquet_init('city');
PRAGMA cityparquet_validate('city');
SELECT * FROM cityparquet_write('city', 'out/city');
About cityjson
The CityJSON extension provides table functions for reading and writing 3D city model files in CityJSON (.city.json), CityJSONSeq (.city.jsonl), and FlatCityBuf (.fcb) formats, and for building CityParquet packages. CityJSON is a JSON-based encoding for 3D city models (buildings, terrain, vegetation, etc.) based on the CityGML data model.
Reading and writing:
read_cityjson,read_cityjsonseq,read_flatcitybuf— table functions for querying city objectscityjson_metadata,cityjsonseq_metadata,flatcitybuf_metadata— inspect file headersCOPY ... TOwith formatscityjson,cityjsonseq, andflatcitybuf— write query results
Appearance:
cityjson_materials,cityjson_textures,cityjson_geometry_templates— sidecar readers- Per-LoD
material_lod*/texture_lod*reference columns, orappearance := 'sidecar'to normalise appearance into sidecar tables with global ids and inlined UV coordinates
CityParquet packages — a package is a DuckDB schema, so it is queryable while you build it:
cityparquet_init,cityparquet_read,cityparquet_write— create, load and write a packageinsert_cityjson,insert_cityjsonseq,insert_flatcitybuf— add a file, routed by CityGML modulecityparquet_validate,cityparquet_reconcile,cityparquet_orphans,cityparquet_vacuumcityparquet_delete(with cascade) andcityparquet_mergecityjson_geoparquet_geo— the GeoParquetgeoand CityParquetcityfooter objects
Additional features:
- Automatic schema inference from CityJSON attributes
- Wide columnar layout: one WKB geometry column per Level of Detail, plus a per-object
bboxextent geometry_properties_lod*as a native STRUCT, so semantic surfaces and shells are columns- Spatial and attribute-query pushdown on FlatCityBuf, using the file's R-tree and B+tree indexes
- Selective deserialisation: a query projecting no geometry never decodes it
- Filter pushdown on
id,feature_id, andobject_type - Streaming reads of large CityJSONSeq files and remote files over HTTP/S3/GCS
- CRS handling follows GeoParquet's tri-state convention, so a georeferenced file never silently claims OGC:CRS84
- Support for CityJSON v2.0 and CityJSONSeq formats
Full documentation — every function, its parameters and its output schema — is at cityjson.github.io/duckdb-cityjson. For more information on the CityJSON format, see https://www.cityjson.org/.
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| cityjson_appearance_ids | scalar | NULL | NULL | |
| cityjson_geometry_templates | table | NULL | NULL | |
| cityjson_geoparquet_geo | table | NULL | NULL | |
| cityjson_materials | table | NULL | NULL | |
| cityjson_metadata | table | NULL | NULL | |
| cityjson_shift_appearance_ids | scalar | NULL | NULL | |
| cityjson_textures | table | NULL | NULL | |
| cityjson_wkb_extent | scalar | NULL | NULL | |
| cityjson_wkb_geometry_type | scalar | NULL | NULL | |
| cityjsonseq_metadata | table | NULL | NULL | |
| cityparquet_city_field | scalar | NULL | NULL | |
| cityparquet_delete | pragma | NULL | NULL | |
| cityparquet_delete_sql | scalar | NULL | NULL | |
| cityparquet_init | pragma | NULL | NULL | |
| cityparquet_init_sql | scalar | NULL | NULL | |
| cityparquet_merge | pragma | NULL | NULL | |
| cityparquet_merge_sql | scalar | NULL | NULL | |
| cityparquet_orphans | pragma | NULL | NULL | |
| cityparquet_read | pragma | NULL | NULL | |
| cityparquet_reconcile | pragma | NULL | NULL | |
| cityparquet_reconcile_sql | scalar | NULL | NULL | |
| cityparquet_vacuum | pragma | NULL | NULL | |
| cityparquet_vacuum_sql | scalar | NULL | NULL | |
| cityparquet_validate | pragma | NULL | NULL | |
| cityparquet_validate_sql | scalar | NULL | NULL | |
| cityparquet_write | table | NULL | NULL | |
| flatcitybuf_metadata | table | NULL | NULL | |
| insert_cityjson | pragma | NULL | NULL | |
| insert_cityjson_sql | scalar | NULL | NULL | |
| insert_cityjsonseq | pragma | NULL | NULL | |
| insert_flatcitybuf | pragma | NULL | NULL | |
| read_cityjson | table | NULL | NULL | |
| read_cityjsonseq | table | NULL | NULL | |
| read_flatcitybuf | table | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
This extension does not add any types.
Added Settings
This extension does not add any settings.