Hi Ari,

As a follow-up, I posted an answer here:
http://stackoverflow.com/a/21922058/327026

Interior and exterior rings are structured differently. For any
polygon, there is always 1 exterior ring with zero or more interior
rings.

So looking at the structure of a geometry, `exterior` is a
`LinearRing` object, and `interiors` is a *list* of zero or more
`LinearRing` objects. Any `LinearRing` object will have `coords`,
which you can slice to see a list of the coordinates with `coords[:]`.

The following is a function that returns a dict of lists of exterior
and interior coordinates:

    def extract_poly_coords(geom):
        if geom.type == 'Polygon':
            exterior_coords = geom.exterior.coords[:]
            interior_coords = []
            for int in geom.interiors:
                interior_coords += i.coords[:]
        elif geom.type == 'MultiPolygon':
            exterior_coords = []
            interior_coords = []
            for part in geom:
                epc = extract_poly_coords(part)  # Recursive call
                exterior_coords += epc['exterior_coords']
                interior_coords += epc['interior_coords']
        else:
            raise ValueError('Unhandled geometry type: ' + repr(geom.type))
        return {'exterior_coords': exterior_coords,
                'interior_coords': interior_coords}

E.g.:

    extract_poly_coords(myShape)

-Mike
_______________________________________________
Community mailing list
Community@lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community

Reply via email to