Last active
October 31, 2017 07:59
-
-
Save diyclassics/7374db1560ca1427a82ae81f927a502b to your computer and use it in GitHub Desktop.
Get coordinates by Pleiades ID
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 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