Skip to content

Instantly share code, notes, and snippets.

@huwd
Last active April 29, 2022 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huwd/f550ace8de8c2a0e3ed2679c25e63cca to your computer and use it in GitHub Desktop.
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.
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