Skip to content

Instantly share code, notes, and snippets.

@diyclassics
Last active October 31, 2017 07: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 diyclassics/7374db1560ca1427a82ae81f927a502b to your computer and use it in GitHub Desktop.
Save diyclassics/7374db1560ca1427a82ae81f927a502b to your computer and use it in GitHub Desktop.
Get coordinates by Pleiades ID
import json
import urllib.request
def get_pleiades_json(pleiades_id):
# pleiades_id: STR
pleiades_url = "https://raw.githubusercontent.com/ryanfb/pleiades-geojson/gh-pages/geojson/%s.geojson" % pleiades_id
try:
with urllib.request.urlopen(pleiades_url) as url:
pleiades_geojson = json.loads(url.read().decode())
return pleiades_geojson
except:
return None
def get_pleiades_coordinates(pleiades_geojson):
# pleiades_geojson: DICT
try:
geometry = pleiades_geojson['features'][0]['geometry']
if geometry['type'] == 'Point':
coordinates = geometry['coordinates']
else:
coordinates = pleiades_geojson['reprPoint']
return tuple(coordinates)
except:
return (None, None)
pleiades_test = 697622 # Abila
print(get_pleiades_coordinates(get_pleiades_json(pleiades_test)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment