Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Last active August 29, 2015 14:10
Show Gist options
  • Save hugoledoux/0ede43fee521461a703c to your computer and use it in GitHub Desktop.
Save hugoledoux/0ede43fee521461a703c to your computer and use it in GitHub Desktop.
WKT --> simple geojson file
import json
from shapely.wkt import loads
allgeoms = []
# 0. valid square
allgeoms.append(loads('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'))
# 1. both rings same orientation
allgeoms.append(loads('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 3 1, 3 3, 1 1))'))
# 2. duplicate vertices iring
allgeoms.append(loads('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 3 1, 3 1, 3 3, 1 1))'))
# 3. valid with iring
allgeoms.append(loads('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 3 3, 3 1, 1 1))'))
# 4. invalid cw orientation
allgeoms.append(loads('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'))
# 5. duplicate vertices
allgeoms.append(loads('POLYGON((0 0, 10 0, 10 0, 10 10, 0 10, 0 0))'))
# 6. invalid: bowtie
allgeoms.append(loads('POLYGON((0 0, 0 10, 10 0, 10 10, 0 0))'))
# 7. invalid: dangling edge
allgeoms.append(loads('POLYGON((0 0, 0 10, 10 0, 10 10, 0 0))'))
print json.dumps(
dict(
type='FeatureCollection',
features=[dict(type='Feature', geometry=g.__geo_interface__) for g in allgeoms]
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment