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
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Name":"Albina Press","Address":"4637 N Albina Ave Portland, OR 97217","Notes":"usually busy, outlets on side wall only"},"geometry":{"type":"Point","coordinates":[-122.67516911029816,45.55673233031101]}},{"type":"Feature","properties":{"Name":"Arbor Lodge","Address":"1507 N Rosa Parks Way Portland, OR 97217","Notes":""},"geometry":{"type":"Point","coordinates":[-122.68242716789246,45.56997505986905]}},{"type":"Feature","properties":{"Name":"Three Friends Coffeehouse","Address":"201 SE 12th Ave, Portland, OR 97214"},"geometry":{"type":"Point","coordinates":[-122.655,45.522]}}]}
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