Skip to content

Instantly share code, notes, and snippets.

@cm3
Last active February 13, 2022 15:23
Show Gist options
  • Save cm3/ff0ae072f0d2dae45fa49b28cb0d6313 to your computer and use it in GitHub Desktop.
Save cm3/ff0ae072f0d2dae45fa49b28cb0d6313 to your computer and use it in GitHub Desktop.
stroly-json from https://stroly.com/ to GeoJSON
import json
with open("landmark1 (1).json", "r", encoding="utf8") as fr:
landmarks = json.load(fr)["landmarks"]
with open("landmark.geojson", "w", encoding="utf8") as fw:
fw.write("""{
"type": "FeatureCollection",
"name": "points",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [""")
id_num = 0
for item in landmarks:
fw.write("{ \"type\": \"Feature\", \"properties\": { \"id\": "+str(id_num)+", \"name\": \""+(item["langs"][0]["name"] if len(item["langs"]) >= 1 else "")+"\" }, \"geometry\": { \"type\": \"Point\", \"coordinates\": ["+str(item["lng"])+", "+str(item["lat"])+"]}}")
id_num += 1
if id_num == len(landmarks):
fw.write("\n")
else:
fw.write(",\n")
fw.write("]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment