Search Shortcut cmd + k | ctrl + k

Read, write, and query CityJSON, CityJSONSeq, FlatCityBuf, and CityParquet 3D city model files, with OBJ and glTF interchange.

Maintainer(s): HideBa

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.5.5 1.5.6 2.0.0 2.0.1
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

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',
  xmin => 84000, ymin => 444000, xmax => 84500, ymax => 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', 'city_package');

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 objects
  • cityjson_metadata, cityjsonseq_metadata, flatcitybuf_metadata — inspect file headers
  • COPY ... TO with formats cityjson, cityjsonseq, and flatcitybuf — write query results

Appearance:

  • cityjson_materials, cityjson_textures, cityjson_implicit_geometries — sidecar readers
  • Per-LoD material_lod* / texture_lod* reference columns, or appearance := '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 package
  • insert_cityjson, insert_cityjsonseq, insert_flatcitybuf — add a file, routed by CityGML module
  • cityparquet_validate, cityparquet_reconcile, cityparquet_orphans, cityparquet_vacuum
  • cityparquet_delete (with cascade) and cityparquet_merge
  • cityjson_geoparquet_geo — the GeoParquet geo and CityParquet city footer objects

Mesh interchange:

  • read_obj, obj_materials, obj_textures, obj_metadata — read OBJ with its .mtl and textures
  • COPY ... TO with formats obj, gltf, and glb

Additional features:

  • Automatic schema inference from CityJSON attributes
  • Wide columnar layout: one WKB geometry column per Level of Detail, plus a per-object bbox extent
  • 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, and object_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 Returns the distinct appearance ids a material_lod* or texture_lod* cell references, as an ascending list. NULL [SELECT cityjson_appearance_ids(material_lod3_0) FROM read_cityjsonseq('test/data/railway_appearance.city.jsonl', appearance := 'sidecar') WHERE material_lod3_0 IS NOT NULL LIMIT 1;]
cityjson_geoparquet_geo table Returns the GeoParquet geo and CityParquet city footer JSON for a CityJSON(Seq) source, to pass to COPY … (FORMAT PARQUET, KV_METADATA …); geo is NULL when no LoD is GeoParquet-legal. NULL [SELECT geo IS NOT NULL AS has_geo, city IS NOT NULL AS has_city FROM cityjson_geoparquet_geo('https://cityjson.open3d.city/cityjsonseq/delft.city.jsonl');]
cityjson_implicit_geometries table Returns a CityJSON(Seq) file's geometry templates as CityParquet implicit_geometries sidecar rows, one shared relative geometry per row, in local coordinates with one set of geometry_lod* columns per LoD. NULL [SELECT * FROM cityjson_implicit_geometries('test/data/railway_appearance.city.jsonl');]
cityjson_materials table Returns a CityJSON(Seq) file's materials as CityParquet materials sidecar rows, interned across the whole file under dataset-global ids. NULL [SELECT id, name, diffuseColor, transparency FROM cityjson_materials('test/data/railway_appearance.city.jsonl');]
cityjson_metadata table Returns one row of dataset-level metadata from a CityJSON document: version, transform, extent, reference system, point of contact and CityObject count. NULL [SELECT version, city_objects_count FROM cityjson_metadata('https://cityjson.open3d.city/cityjson/delft.city.json');]
cityjson_shift_appearance_ids scalar Adds a constant to every appearance id in a material_lod* or texture_lod* cell; the renumbering step that cityparquet_merge and insert_cityjson generate. NULL [SELECT cityjson_shift_appearance_ids(material_lod3_0, 10) FROM read_cityjsonseq('test/data/railway_appearance.city.jsonl', appearance := 'sidecar') WHERE material_lod3_0 IS NOT NULL LIMIT 1;]
cityjson_textures table Returns a CityJSON(Seq) file's textures as CityParquet textures sidecar rows, interned across the whole file under dataset-global ids. NULL [SELECT * FROM cityjson_textures('test/data/railway_appearance.city.jsonl');]
cityjson_wkb_extent scalar Returns the 3D extent (xmin, ymin, zmin, xmax, ymax, zmax) of a WKB geometry, including the PolyhedralSurface Z solids that DuckDB spatial rejects. NULL [SELECT cityjson_wkb_extent(geometry_lod2_2).zmax FROM read_cityjsonseq('https://cityjson.open3d.city/cityjsonseq/delft.city.jsonl') WHERE geometry_lod2_2 IS NOT NULL LIMIT 1;]
cityjson_wkb_geometry_type scalar Returns the geometry type name of a WKB blob, such as 'MultiPolygon Z' or 'PolyhedralSurface Z', without decoding its coordinates. NULL [SELECT DISTINCT cityjson_wkb_geometry_type(geometry_lod2_2) FROM read_cityjsonseq('https://cityjson.open3d.city/cityjsonseq/delft.city.jsonl') WHERE geometry_lod2_2 IS NOT NULL;]
cityjsonseq_metadata table Returns one row of dataset-level metadata from a CityJSONSeq stream, in cityjson_metadata's columns, counting both CityObjects and features. NULL [SELECT reference_system.code, city_objects_count, features_count FROM cityjsonseq_metadata('https://cityjson.open3d.city/cityjsonseq/delft.city.jsonl');]
cityparquet_city_field scalar Returns one top-level field of a CityParquet city footer JSON string as text, or NULL when the footer is not a JSON object or the field is absent or null. NULL [cityparquet_city_field('{"source_format": "CityJSONSeq"}', 'source_format')]
cityparquet_delete pragma Deletes the objects matching a SQL predicate from a CityParquet package schema, with their descendants unless cascade = false, prunes them from survivors' hierarchy and re-derives feature_id and bbox. NULL [PRAGMA cityparquet_delete('delft', 'object_type = ''Building'' AND b3_h_dak_max > 20');]
cityparquet_delete_sql scalar Returns the SQL that PRAGMA cityparquet_delete would run, without running it. NULL [cityparquet_delete_sql('delft', 'id = ''x''')]
cityparquet_hilbert scalar Returns the position of (x, y) along a 2D Hilbert curve of 2^16 cells per axis laid over the extent [xmin, xmax] x [ymin, ymax]: the row-ordering key cityparquet_write and cityparquet-rs sort features by. NULL [cityparquet_hilbert(0.75, 0.25, 0, 0, 1, 1)]
cityparquet_init pragma Registers a schema's CityParquet object and sidecar tables in its __cityparquet bookkeeping table; idempotent, and unlike cityparquet_read it recovers no Parquet footers. NULL [PRAGMA cityparquet_init('delft');]
cityparquet_init_sql scalar Returns the SQL that PRAGMA cityparquet_init would run for a schema, without running it. NULL [cityparquet_init_sql('delft')]
cityparquet_json scalar Returns its argument typed as JSON, after checking that it parses, so that a Parquet COPY annotates the column with the JSON logical type; errors on text that is not JSON. NULL [cityparquet_json('{"roofType": "1000"}')]
cityparquet_merge pragma Merges one CityParquet package schema into another, renumbering sidecar ids, and refuses the whole merge on an id collision or a CRS mismatch. NULL [PRAGMA cityparquet_merge('delft', 'utrecht');]
cityparquet_merge_extensions scalar Returns a CityParquet city footer JSON with a city.extensions object (keyed by namespace) merged into its extensions; a namespace declared differently on the two sides is an error. NULL [cityparquet_merge_extensions(NULL, '{"energy": {"name": "Energy", "url": "https://example.org/e.json"}}')]
cityparquet_merge_sql scalar Returns the SQL that PRAGMA cityparquet_merge would run, without running it. NULL [cityparquet_merge_sql('delft', 'utrecht')]
cityparquet_orphans pragma Lists the sidecar rows no object in a CityParquet package schema references, into the temp table cityparquet_orphan_rows. NULL [PRAGMA cityparquet_orphans('delft');]
cityparquet_prefix_surface_types scalar Rewrites every CityJSON Extension surface type (a + name) in a geometry_properties surfaces JSON array to its namespace-prefixed CityParquet form: +PartyWallSurface becomes energy_PartyWallSurface. NULL [cityparquet_prefix_surface_types('[{"type": "+PartyWallSurface"}]', 'energy')]
cityparquet_read pragma Loads a CityParquet package directory into a schema, creating it if needed and replacing any same-named table, one table per file, with each file's Parquet footer in __cityparquet. NULL [PRAGMA cityparquet_read('./data/delft', 'delft');]
cityparquet_reconcile pragma Re-derives a CityParquet package schema's reciprocal hierarchy, feature_id and bbox after a structural edit; checks limits it to the ones listed. NULL [PRAGMA cityparquet_reconcile('delft', checks = ['bbox']);]
cityparquet_reconcile_sql scalar Returns the SQL that PRAGMA cityparquet_reconcile would run for a schema, without running it. NULL [cityparquet_reconcile_sql('delft')]
cityparquet_set_city_field scalar Returns a CityParquet city footer JSON string with one top-level field set to the JSON text value; a NULL or unreadable footer starts as an empty object. NULL [cityparquet_set_city_field(NULL, 'crs', '{"id": {"authority": "EPSG", "code": 7415}}')]
cityparquet_to_json scalar Returns an attribute value as the JSON it stands for – a string quoted, a number or boolean as itself, a timestamp as an ISO 8601 string in UTC, a list as an array, JSON as itself – the encoding an insert or merge gives the values of an attribute column it widens to JSON. NULL [cityparquet_to_json('Asuinrakennus')]
cityparquet_vacuum pragma Deletes the sidecar rows no object in a CityParquet package schema references. NULL [PRAGMA cityparquet_vacuum('delft');]
cityparquet_vacuum_sql scalar Returns the SQL that PRAGMA cityparquet_vacuum would run for a schema, without running it. NULL [cityparquet_vacuum_sql('delft')]
cityparquet_validate pragma Checks a CityParquet package schema for null or dangling feature_id, dangling parents and children, misaligned children_roles and duplicate ids, into the temp table cityparquet_validation. NULL [PRAGMA cityparquet_validate('delft');]
cityparquet_validate_sql scalar Returns the SQL that PRAGMA cityparquet_validate would run for a schema, without running it. NULL [cityparquet_validate_sql('delft')]
cityparquet_write table Writes a CityParquet package schema out as a package directory: one Parquet file per table with regenerated city and geo footers, plus a metadata.json STAC Item; one row per file. NULL [SELECT * FROM cityparquet_write('delft', 'out/', crs => 'EPSG:7415');]
flatcitybuf_metadata table Returns one row of dataset-level metadata from a FlatCityBuf header, in cityjson_metadata's columns; features_count is set and city_objects_count is NULL. NULL [SELECT version, features_count FROM flatcitybuf_metadata('https://flatcitybuf.open3d.city/data/delft.fcb');]
insert_cityjson pragma Inserts a CityJSON file into a CityParquet package schema, routing each object to its CityGML module table and renumbering sidecar ids; refuses an id collision or a CRS mismatch. NULL [PRAGMA insert_cityjson('delft', 'tile.city.json', create_tables = true);]
insert_cityjson_sql scalar Returns the SQL that PRAGMA insert_cityjson would run, without running it. NULL [insert_cityjson_sql('delft', 'tile.city.json')]
insert_cityjsonseq pragma Inserts a CityJSONSeq file into a CityParquet package schema, routing each object to its CityGML module table and renumbering sidecar ids; refuses an id collision or a CRS mismatch. NULL [PRAGMA insert_cityjsonseq('delft', 'tile.city.jsonl', create_tables = true);]
insert_flatcitybuf pragma Inserts a FlatCityBuf file into a CityParquet package schema, routing each object to its CityGML module table and renumbering sidecar ids; refuses an id collision or a CRS mismatch. NULL [PRAGMA insert_flatcitybuf('delft', 'tile.fcb', create_tables = true);]
obj_materials table Returns the materials of an OBJ's .mtl files as CityParquet materials sidecar rows, in the same columns as cityjson_materials. NULL [SELECT id, name, diffuseColor, transparency FROM obj_materials('test/data/obj/cube.obj');]
obj_metadata table Returns one row of dataset-level metadata for an OBJ in cityjson_metadata's columns: the extent of every vertex, and the reference system given as crs. NULL [SELECT reference_system, city_objects_count FROM obj_metadata('test/data/obj/cube.obj', crs := 'EPSG:7415');]
obj_textures table Returns the map_Kd textures of an OBJ's .mtl files as CityParquet textures sidecar rows, in the same columns as cityjson_textures. NULL [SELECT id, image_uri, image_type FROM obj_textures('test/data/obj/cube.obj');]
read_cityjson table Reads a CityJSON document (.city.json) as one row per CityObject, with typed attribute columns and one WKB geometry_lod* column per level of detail. NULL [SELECT object_type, COUNT(*) FROM read_cityjson('https://cityjson.open3d.city/cityjson/delft.city.json') GROUP BY ALL;]
read_cityjsonseq table Reads a CityJSONSeq stream (.city.jsonl) as one row per CityObject, with the same columns as read_cityjson. NULL [SELECT id, b3_h_dak_max FROM read_cityjsonseq('https://cityjson.open3d.city/cityjsonseq/delft.city.jsonl') WHERE object_type = 'Building' LIMIT 3;]
read_flatcitybuf table Reads a FlatCityBuf file (.fcb) as one row per CityObject, in read_cityjson's columns; xmin, ymin, xmax and ymax together skip features outside the box via its R-tree. NULL [SELECT COUNT(*) FROM read_flatcitybuf('https://flatcitybuf.open3d.city/data/delft.fcb', xmin => 84900, ymin => 446200, xmax => 85200, ymax => 446500);]
read_obj table Reads a Wavefront OBJ as one row per o group in the CityJSON object-table columns; lod is required, and object_type (default Building) sets every object's class. NULL [SELECT id, object_type, geometry_properties_lod2_2.type FROM read_obj('test/data/obj/cube.obj', lod := '2.2');]

Overloaded Functions

This extension does not add any function overloads.

Added Types

type_name type_size logical_type type_category internal
CITYPARQUET_JSON 16 VARCHAR STRING true

Added Settings

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp
© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog