-
-
Save rg3915/d790be6680d9a3c4cf46e022f1bd5a39 to your computer and use it in GitHub Desktop.
How to union a list of geometries in GeoDjango
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.contrib.gis.geos import GEOSGeometry | |
| # sample data | |
| geom_1 = GEOSGeometry('POLYGON((-71.8 42.1,-70.6 42.1,-70.5 41.2,-71.8 41.2,-71.8 42.1))') | |
| geom_2 = GEOSGeometry('POLYGON((-71.12 42.23,-71.48 42.34,-71.52 42.55,-71.12 42.23))') | |
| geom_3 = GEOSGeometry('POLYGON((-73.12 42.23,-71.48 42.34,-71.52 42.55,-73.12 42.23))') | |
| polygons = [geom_1, geom_2, geom_3] | |
| # get first polygon | |
| polygon_union = polygons[0] | |
| # update list | |
| polygons = polygons[1:] | |
| # loop through list of polygons | |
| for poly in polygons: | |
| polygon_union = polygon_union.union(poly) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment