Search Shortcut cmd + k | ctrl + k
three_d

3D solid processing for city models — enclosed volume, validation, distance, and measurement of polyhedral solids.

Maintainer(s): HideBa

Installing and Loading

INSTALL three_d FROM community;
LOAD three_d;

Example

-- Build a 3D solid from WKB (e.g. produced by the cityjson extension) and measure it.
-- ST_3DFromWKB accepts optional CityJSON geometry_properties to recover shell structure.
SELECT
    ST_3DVolume(solid)                  AS volume_m3,
    ST_3DSurfaceArea(solid)             AS surface_m2,
    ST_Area(solid)                      AS footprint_m2,
    ST_ZMax(solid) - ST_ZMin(solid)     AS height_m,
    ST_3DIsClosed(solid)                AS closed
FROM (SELECT ST_3DFromWKB(geometry, geometry_properties) AS solid FROM buildings);

-- Validate a solid before measuring it (ST_3DVolume requires a valid solid).
SELECT ST_3DValidationReport(solid) AS report FROM buildings;

-- 3D distance between two geometries (GEOM_3D, built from WKB with ST_Geom3DFromWKB).
SELECT ST_3DDistance(ST_Geom3DFromWKB(a.wkb), ST_Geom3DFromWKB(b.wkb)) AS gap_m
FROM a, b;

About three_d

three_d (repository duckdb-3d) makes the polyhedral solids in 3D city models — buildings from CityJSON / 3DBAG, CityParquet, and similar sources — first-class, queryable values in DuckDB. DuckDB's built-in geometry surface is 2D / simple-features centric; this extension adds the solid-aware types and functions that 3D workflows need, on a self-contained C++ kernel (no CGAL/SFCGAL dependency).

Two BLOB-backed logical types:

  • SOLID_3D — closed polyhedral solids, backed by a versioned binary payload that preserves shell/face topology.
  • GEOM_3D — general 3D geometry (points, lines, polygons, multis, polyhedral surfaces) for the class-generic accessor, distance, and serialization functions.

Function families (PostGIS-style ST_* / ST_3D* names, a curated 3D subset):

  • Import / export: ST_3DFromWKB, ST_3DTryFromWKB, ST_3DAsWKB, ST_Geom3DFromWKB, ST_AsText, ST_AsGeoJSON, ST_AsBinary
  • Introspection: ST_3DBounds, ST_3DNumSolids, ST_3DNumShells, ST_3DNumFaces, ST_GeometryType, ST_NDims, ST_HasZ, ST_X, ST_Y, ST_Z, ST_ZMin, ST_ZMax, ST_CoordDim, ST_Dimension, ST_NumGeometries
  • Validation: ST_3DIsClosed, ST_3DIsManifold, ST_3DIsOriented, ST_3DValidationReport, ST_IsPlanar
  • Measurement: ST_3DVolume, ST_3DSurfaceArea / ST_3DArea, ST_Area (footprint), ST_3DPerimeter, ST_3DLength
  • Distance: ST_3DDistance, ST_3DDWithin, ST_3DMaxDistance, ST_3DDFullyWithin, ST_3DIntersects, ST_3DClosestPoint, ST_3DShortestLine
  • Transform / construct: ST_Translate, ST_Scale, ST_RotateX/Y/Z, ST_Force3D, ST_ConvexHull, ST_3DCentroid, ST_3DExtrude, ST_MakeSolid

It composes with the cityjson extension: read CityJSON / CityJSONSeq with read_cityjson(..., lod => '...') to get geometry (WKB) plus geometry_properties (JSON), then pipe both into ST_3DFromWKB. The extension is experimental and under active development; APIs and payload formats may change.

Added Functions

function_name function_type description comment examples
st_3darea scalar NULL NULL  
st_3daswkb scalar NULL NULL  
st_3dbounds scalar NULL NULL  
st_3dcentroid scalar NULL NULL  
st_3dclosestpoint scalar NULL NULL  
st_3ddfullywithin scalar NULL NULL  
st_3ddistance scalar NULL NULL  
st_3ddwithin scalar NULL NULL  
st_3dextrude scalar NULL NULL  
st_3dfromwkb scalar NULL NULL  
st_3dintersects scalar NULL NULL  
st_3disclosed scalar NULL NULL  
st_3dismanifold scalar NULL NULL  
st_3disoriented scalar NULL NULL  
st_3dlength scalar NULL NULL  
st_3dmaxdistance scalar NULL NULL  
st_3dnumfaces scalar NULL NULL  
st_3dnumshells scalar NULL NULL  
st_3dnumsolids scalar NULL NULL  
st_3dperimeter scalar NULL NULL  
st_3dshortestline scalar NULL NULL  
st_3dsurfacearea scalar NULL NULL  
st_3dtryfromwkb scalar NULL NULL  
st_3dvalidationreport scalar NULL NULL  
st_3dvolume scalar NULL NULL  
st_area scalar NULL NULL  
st_asgeojson scalar NULL NULL  
st_aswkblinez scalar NULL NULL  
st_aswkbmultilinez scalar NULL NULL  
st_aswkbmultipointz scalar NULL NULL  
st_aswkbmultipolygonz scalar NULL NULL  
st_aswkbopentetra scalar NULL NULL  
st_aswkbpointz scalar NULL NULL  
st_aswkbpolygonz scalar NULL NULL  
st_aswkbpolyhedraltetra scalar NULL NULL  
st_aswkbwarpedpolygonz scalar NULL NULL  
st_convexhull scalar NULL NULL  
st_coorddim scalar NULL NULL  
st_dimension scalar NULL NULL  
st_force3d scalar NULL NULL  
st_geom3dfromwkb scalar NULL NULL  
st_geometrytype scalar NULL NULL  
st_hasz scalar NULL NULL  
st_isplanar scalar NULL NULL  
st_makesolid scalar NULL NULL  
st_ndims scalar NULL NULL  
st_numgeometries scalar NULL NULL  
st_rotatex scalar NULL NULL  
st_rotatey scalar NULL NULL  
st_rotatez scalar NULL NULL  
st_scale scalar NULL NULL  
st_translate scalar NULL NULL  
st_x scalar NULL NULL  
st_y scalar NULL NULL  
st_z scalar NULL NULL  
st_zmax scalar NULL NULL  
st_zmin scalar NULL NULL  

Overloaded Functions

function_name function_type description comment examples
st_asbinary scalar Returns the Well-Known Binary (WKB) representation of the geometry NULL [st_asbinary(ST_GeomFromWKB(X'01010000000000000000000000000000000000000000000000000'))]
st_astext scalar Returns the Well-Known Text (WKT) representation of the geometry NULL [ST_AsText(ST_GeomFromWKB(X'01010000000000000000000000000000000000000000000000'))]

Added Types

type_name type_size logical_type type_category internal
GEOM_3D 16 BLOB NULL true
SOLID_3D 16 BLOB NULL true

Added Settings

This extension does not add any settings.