Skip to content

Instantly share code, notes, and snippets.

@djq
Created November 22, 2014 21:23

Revisions

  1. David Quinn created this gist Nov 22, 2014.
    17 changes: 17 additions & 0 deletions unions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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)