Skip to content

Commit

Permalink
bug fix; CRS identification was failing as the old implementation rel…
Browse files Browse the repository at this point in the history
…ied on proj parameters being in a specific order.

implementation was changed to account for the fact that different dependency versions give the proj params in different orders
  • Loading branch information
lachlanhurst committed Sep 4, 2023
1 parent e3f6773 commit deae693
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion arc/toolbox/tenement-tools-toolbox.pyt
Original file line number Diff line number Diff line change
Expand Up @@ -6600,7 +6600,7 @@ class Nicher_SDM(object):
elif not hasattr(ds, 'crs'):
arcpy.AddError('GeoTiff CRS attribute not found. CRS required.')
return
elif '3577' not in ds.crs:
elif tools.get_xr_crs(ds) != 3577:
arcpy.AddError('GeoTiff CRS is not EPSG:3577. EPSG:3577 required.')
return
elif not hasattr(ds, 'nodatavals'):
Expand Down
16 changes: 11 additions & 5 deletions shared/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,11 @@ def get_xr_crs(ds):
"""

# raw arcgis albers proj info
albers_proj = ('+proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +' +
'lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 ' +
'+towgs84=0,0,0,0,0,0,0 +units=m +no_defs=True')
albers_proj = set((
'+proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +'
'lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 '
'+towgs84=0,0,0,0,0,0,0 +units=m +no_defs=True'
).split())

# when crs attribute is a string
if isinstance(ds.crs, str):
Expand All @@ -782,9 +784,13 @@ def get_xr_crs(ds):
return int(ds.geobox.crs.epsg)

# approach 3
if ds.crs == albers_proj:
# use set logic to check if all the tokens in theh ds.crs are within what we
# defined above for the albers_proj. Here we support the albers_proj definition
# gaving some redundant info (eg; +towgs84=0,0,0,0,0,0,0) by using `issubset`
ds_crs = set(ds.crs.split())
if ds_crs.issubset(albers_proj):
return 3577

# approach 4
if '+init=epsg:' in ds.crs:
return int(ds.crs.split(':')[-1])
Expand Down

0 comments on commit deae693

Please sign in to comment.