Skip to content

Commit

Permalink
Merge branch '108_srs_standard_strings' into 'dev'
Browse files Browse the repository at this point in the history
#108 allow str formatted srs definitions in srs.loadSRS()

See merge request iek-3/shared-code/geokit!47
  • Loading branch information
shitabishmam committed Oct 19, 2023
2 parents 2444c0e + 50244d2 commit bd04a52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion geokit/core/srs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def loadSRS(source):
Example of acceptable objects are...
* osr.SpatialReference object
* An EPSG integer ID
* A standardized srs str definition such as 'EPSG:4326' or 'ESRI:53003'
* a string corresponding to one of the systems found in geokit.srs.SRSCOMMON
* a WKT string
Expand All @@ -51,7 +52,13 @@ def loadSRS(source):
# assume a name for one of the common SRS's was given
srs = SRSCOMMON[source]
else:
srs.ImportFromWkt(source) # assume a Wkt string was input
try:
# try handling as a standardized epsg or esri etc. code
srs = osr.SpatialReference()
_val = srs.SetFromUserInput(source)
assert _val==0
except:
srs.ImportFromWkt(source) # assume a Wkt string was input
elif(isinstance(source, int)):
srs.ImportFromEPSG(source)
else:
Expand Down
3 changes: 3 additions & 0 deletions geokit/test/test_02_srs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def test_loadSRS():
s1 = srs.loadSRS(srs.EPSG4326)
# Test an EPSG identifier
s2 = srs.loadSRS(4326)
# Test an EPSG code
s3 = srs.loadSRS("epsg:4326")
# Are they the same?
assert s1.IsSame(s2)
assert s1.IsSame(s3)

# test an invalid srs, must raise error
with pytest.raises(AssertionError):
Expand Down

0 comments on commit bd04a52

Please sign in to comment.