-
-
Save huwd/f550ace8de8c2a0e3ed2679c25e63cca to your computer and use it in GitHub Desktop.
A python script to take a list of Geojson features (representing building ways with ref:GB:uprn values and upload them using the API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import osmapi | |
import json | |
JSON_FILE_PATH = "../geojson_normaliser/leagrave_urpns_normalised.geojson" | |
f = open(JSON_FILE_PATH,) | |
data = json.load(f) | |
api = osmapi.OsmApi( | |
passwordfile="./.password" | |
) | |
cs = api.ChangesetCreate() | |
api.ChangesetUpdate( | |
{"comment": u"Add UPRN numbers based on single UPRN nodes being only candidate within a building area"}) | |
for feature in data["features"]: | |
if feature["properties"]["osm_type"] == "way": | |
print("Querying Way") | |
feature_id = feature["properties"]["osm_id"] | |
print(f"updating {feature_id}") | |
way = api.WayGet(feature_id) | |
if not "ref:GB:uprn" in way["tag"]: | |
way["tag"]["ref:GB:uprn"] = feature["properties"]["ref:GB:uprn"] | |
api.ChangesetUpload( | |
[ | |
{ | |
"type": "way", | |
"action": "modify", | |
"data": way | |
} | |
] | |
) | |
else: | |
print("Not a way ERROR") | |
api.ChangesetClose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment