ST_BuildArea
What is ST_BuildArea?
ST_BuildArea is a PostGIS function that assembles an areal geometry (polygon or multipolygon) from the constituent linework of its input. Unlike ST_Polygonize, which returns every face it can find, ST_BuildArea treats closed rings topologically — nested rings become holes rather than separate polygons.
ST_BuildArea(geometry geom) → geometryThe input is typically a MultiLineString or a collection of lines representing a closed, noded network. The output is a Polygon or MultiPolygon, or NULL if no areas can be formed.
When would you use ST_BuildArea?
Use ST_BuildArea when you have linework — parcel boundaries digitised as lines, a road network forming blocks, or cadastral edges — and need to derive the enclosed polygons. It is the standard tool for reconstructing polygons from OpenStreetMap way data or for rebuilding faces after topology editing.
1SELECT ST_BuildArea(ST_Collect(geom)) AS block_polygon
2FROM road_edges
3WHERE ST_Intersects(geom, ST_MakeEnvelope(-73.99, 40.72, -73.98, 40.73, 4326));FAQs
How is ST_BuildArea different from ST_Polygonize?
ST_Polygonize returns every polygonal face it can construct, including rings that topologically represent holes. ST_BuildArea is smarter — it recognises nested rings and produces polygons with holes, matching how GIS users normally think about areas. If you want holes, use ST_BuildArea; if you want every face individually, use ST_Polygonize.
Why am I getting NULL output?
ST_BuildArea only produces output when the input lines form closed rings. If the linework has dangles, gaps, or is not properly noded, no area can be built. Run ST_Node(ST_Union(geom)) first to ensure lines are split at intersections, and inspect the result with ST_IsValid or visually.
Does input order matter?
No. ST_BuildArea works on the geometric configuration of the input, not the order in which rings or lines are supplied. Internally it nodes and polygonises the input, so whether you pass a MultiLineString or a GeometryCollection of lines the result is identical.
Does ST_BuildArea respect CRS?
Yes — the output carries the same SRID as the input, and all computation happens in the input's native coordinate system. It performs no reprojection, so if you need areas in metres make sure the input is already in a projected CRS.