Skip to content

Instantly share code, notes, and snippets.

@sgillies
Last active December 30, 2015 07:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgillies/7797688 to your computer and use it in GitHub Desktop.
Save sgillies/7797688 to your computer and use it in GitHub Desktop.
Example of RFC 6902 GeoJSON diff
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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