The code of GeoDjango-1.9.2 contains reference to the function ST_Polygonize at: https://github.com/django/django/blob/master/django/contrib/gis/db/backends/postgis/operations.py#L132

But is it seems like not documented anywhere. Is the function available for use somehow?

1 Answer 1


This function is in the list of candidates, but not really implemented yet. As an alternative, you could use a raw sql query to get what you want:

qs = MyData.objects.raw(
    'SELECT *, ST_Polygonize(geom) AS polygonized FROM myapp_mydata'

The you data objects should have a polygonized property, the following should return a polygon:

  • in fact, with openstreetmap database, I had to use following sql: UPDATE relations as r set geometry=( SELECT st_multi(st_union(geom)) FROM ( SELECT (st_dump(ST_Polygonize(w.linestring))).geom FROM ways as w JOIN relation_members as m ON m.member_id = w.id WHERE m.member_type='W' and m.relation_id = r.id ) as nest ) WHERE r.id=%(id)s and execute it as raw sql, using cursor.execute
    – QwiglyDee
    Mar 31, 2016 at 6:37

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.