hypothesis-geojson icon indicating copy to clipboard operation
hypothesis-geojson copied to clipboard

geometry validity

Open perrygeo opened this issue 7 years ago • 0 comments

It would be nice to (optionally?) assert that the geometries are valid with correct winding order, etc.

A potential implementation

def validate_ring(coords):
    from shapely.geometry import shape, mapping
    from shapely.geometry.polygon import orient
    poly = shape({'type': 'Polygon', 'coordinates': [coords]})
    poly2 = poly.buffer(0)
    if poly2.type == 'MultiPolygon':
        poly2 = poly2.geoms[0]
    ring = mapping(orient(poly2).exterior)['coordinates']
    return list(ring)

Is there any way to achieve this without a Shapely dependency?

perrygeo avatar Jun 22 '17 16:06 perrygeo