Example of RFC 6902 GeoJSON diff
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 json | |
import jsonpatch | |
import os.path | |
import requests | |
import subprocess | |
# original | |
if not os.path.exists('hackspots-44de76ef53.json'): | |
r = requests.get('https://github.com/lyzidiamond/learn-geojson/raw/44de76ef53b20bdaf51e0cde4aa634df210cd9d4/geojson/hackspots.geojson') | |
data = r.content | |
with open('hackspots-44de76ef53.json', 'wb') as f: | |
f.write(data) | |
# next commit | |
if not os.path.exists('hackspots-e9514f5c31.json'): | |
r = requests.get('https://github.com/lyzidiamond/learn-geojson/raw/e9514f5c317ee980b94ed6580950cfd9fbde53db/geojson/hackspots.geojson') | |
data = r.content | |
with open('hackspots-e9514f5c31.json', 'wb') as f: | |
f.write(data) | |
diff_text = subprocess.check_output([ | |
'jsondiff', | |
'hackspots-44de76ef53.json', | |
'hackspots-e9514f5c31.json']) | |
diff = json.loads(diff_text) | |
print(json.dumps(diff, indent=2)) | |
# Moving coordinates of hackspots-e9514f5c31 | |
diff = '[{"path": "/features/2/geometry/coordinates/0", "value": -122.655, "op": "replace"}, {"path": "/features/2/geometry/coordinates/1", "value": 45.522, "op": "replace"}]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment