Skip to content

Instantly share code, notes, and snippets.

@companje
Last active November 29, 2024 13:36
Show Gist options
  • Save companje/0f392e944d1f7faeeeaec62ae1526717 to your computer and use it in GitHub Desktop.
Save companje/0f392e944d1f7faeeeaec62ae1526717 to your computer and use it in GitHub Desktop.
wktLiteral to GeoJSON met shapely
import json
from shapely import wkt
from shapely.geometry import mapping
with open('OSG.json', 'r') as infile:
data = json.load(infile)
geojson_features = []
for item in data:
geometry = wkt.loads(item['x'])
geojson_features.append({
"type": "Feature",
"geometry": mapping(geometry),
"properties": {
"label": item.get("xLabel")
}
})
geojson_collection = {
"type": "FeatureCollection",
"features": geojson_features
}
with open('OSG_GeoJSON.json', 'w') as outfile:
json.dump(geojson_collection, outfile, indent=2)
[
{
"x": "POLYGON((5.1899522828057 52.072762705454,5.1895443427964 52.072613723583,5.1892033916532 52.07248873861,5.1907981441628 52.069344104925,5.1925058778054 52.065811515274,5.1927738395413 52.065899505003,5.1933177596231 52.066080483264,5.191612024855 52.069540080344,5.1899522828057 52.072762705454))",
"xLabel": "1536: Adriaan van Nijeveld (OSG)"
},
{
"x": "POLYGON((5.1899522828057 52.072762705454,5.1895443427964 52.072613723583,5.1892033916532 52.07248873861,5.1907981441628 52.069344104925,5.1925058778054 52.065811515274,5.1927738395413 52.065899505003,5.1933177596231 52.066080483264,5.191612024855 52.069540080344,5.1899522828057 52.072762705454))",
"xLabel": "1599: 5 M onbekend (OSG),"
},
{
"x": "POLYGON((5.1899522828057 52.072762705454,5.1895443427964 52.072613723583,5.1892033916532 52.07248873861,5.1907981441628 52.069344104925,5.1925058778054 52.065811515274,5.1927738395413 52.065899505003,5.1933177596231 52.066080483264,5.191612024855 52.069540080344,5.1899522828057 52.072762705454))",
"xLabel": "1716: 5 M onbekend (OSG)"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment