Skip to content

Commit

Permalink
added fallback epsg wkt source when prj2epsg.org doesn't have an epsg (
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdot authored May 6, 2020
1 parent 7b50a7a commit dbec9e3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions usgs_lidar_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,24 @@ def proj_from_epsg(epsg, printf=print):
# Try to get WKT for these epsg codes from webservices, need this to get a definite value for unit
try:
epsg_response = requests.get('http://prj2epsg.org/epsg/' + str(epsg) + '.json', allow_redirects=False, timeout=5.0)
if epsg_response.ok:
wkt = epsg_response.json()['wkt']
elif epsg_response.status_code == 404:
# try to get from spatialreference.org instead
printf("epsg not found at prj2epsg.org, trying spatialreference.org instead.")
sr_response = requests.get('https://www.spatialreference.org/ref/esri/' + str(epsg) + '/prj/')
if sr_response.ok:
wkt = sr_response.text
else:
sr_response.raise_for_status()
else:
epsg_response.raise_for_status()

except:
printf("Problem looking up epsg with prj2epsg.org, try running the tool later.")
printf("Problem looking up epsg with prj2epsg.org and/or spatialreference.org, try running the tool later.")
raise
epsg_json = epsg_response.json()
return get_proj_and_unit_from_wkt(epsg_json['wkt'], printf=printf)

return get_proj_and_unit_from_wkt(wkt, printf=printf)


def convert_latlon_to_utm_espg(lat, lon):
Expand Down

0 comments on commit dbec9e3

Please sign in to comment.