5

Postgis allows using ST_Polygonize() from GEOS to make polygons out of lines. I have seen the same function available in Shapely library for Python, but in Shapely, the other method named polygonize_full() is also available.

In PostgreSQL 10.1 + PostGIS 2.3.0, I would do something like this:

SELECT (ST_Dump(foofoo.polycoll)).geom AS geomtextrep
FROM (SELECT ST_Polygonize(wkb_geometry) AS polycoll
FROM (SELECT wkb_geometry FROM the_table WHERE ST_GeometryType(wkb_geometry) = 'ST_LineString') AS foo) AS foofoo;

In Python3 + Shapely, I would do something like this:

result, dangles, cuts, invalids = polygonize_full(lines)

I have seen in the GEOS library that there are two functions:

GEOSPolygonize_full - Returns polygons, dangles, cuts, invalid rings
GEOSPolygonize - Returns only polygons

Is there any way to replicate the behaviour of GEOSPolygonize_full with PostGIS? I would like to use the dangles, cuts and invalids to judge whether I have missed out on some lines in the input data, and flag these events so I can manually check the source files (AutoCAD drawings) and associated layers.

I would hope ST_Polygonize_Full() maybe existed in PostGIS, but as far as I can see, it does not.

  • Welcome to GIS SE. As a new user, please take the Tour. – Vince Jan 24 '18 at 11:26
0

Not quite an answer, but ST_Polygonize is defined in https://github.com/postgis/postgis/blob/svn-trunk/postgis/postgis.sql.in

-- Availability: 1.4.0
CREATE OR REPLACE FUNCTION ST_Polygonize (geometry[])
    RETURNS geometry
    AS 'MODULE_PATHNAME', 'polygonize_garray'
    LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL
COST 1; -- reset cost, see #3675

i.e. it calls the function polygonize_array, defined in https://github.com/postgis/postgis/blob/svn-trunk/postgis/lwgeom_geos.c, which calls GEOSPolygonize:

geos_result = GEOSPolygonize(vgeoms, nelems);

I couldn't find any reference to GEOSPolygonize_full in the PostGIS source though, so... not yet implemented?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.