Commit e61d0a3a authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Merge branch 'bugfix/fix_bound_crs' into 'master'

Fixed issue #16 (WKT2EPSG() returns None in case of bound CRS.).

Closes #16

See merge request !28
parents 25921648 a537d5b8
Pipeline #17000 passed with stages
in 4 minutes and 53 seconds
......@@ -2,6 +2,12 @@
History
=======
0.16.7 (2020-12-15)
-------------------
* Fixed issue #16 (WKT2EPSG() returns None in case of bound CRS.).
0.16.6 (2020-12-10)
-------------------
......
......@@ -22,6 +22,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
import re
import warnings
from pyproj import CRS
from typing import Union # noqa F401 # flake8 issue
from osgeo import osr
......@@ -153,7 +154,17 @@ def WKT2EPSG(wkt):
if not wkt:
return None
return CRS.from_wkt(wkt.replace('\n', '').replace('\r', '').replace(' ', '')).to_epsg()
ccrs = CRS.from_wkt(wkt.replace('\n', '').replace('\r', '').replace(' ', ''))\
if not ccrs.is_bound:
epsg = ccrs.to_epsg()
else:
epsg = ccrs.source_crs.to_epsg()
if epsg is None:
warnings.warn('Could not find a suitable EPSG code for the input WKT string.', RuntimeWarning)
else:
return epsg
def get_UTMzone(prj):
......
......@@ -61,6 +61,75 @@ wkt_utm = \
AUTHORITY["EPSG", "32633"]]
"""
wkt_bound_crs = \
"""
BOUNDCRS[
SOURCECRS[
PROJCRS["ETRS89-extended / LAEA Europe",
BASEGEOGCRS["ETRS89",
DATUM["European Terrestrial Reference System 1989",
ELLIPSOID["GRS 1980",6378137,298.257222101,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4258]],
CONVERSION["unnamed",
METHOD["Lambert Azimuthal Equal Area",
ID["EPSG",9820]],
PARAMETER["Latitude of natural origin",52,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",10,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["False easting",4321000,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",3210000,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["northing",north,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["easting",east,
ORDER[2],
LENGTHUNIT["metre",1]],
ID["EPSG",3035]]],
TARGETCRS[
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]]],
ABRIDGEDTRANSFORMATION["Transformation from ETRS89 to WGS84",
METHOD["Position Vector transformation (geog2D domain)",
ID["EPSG",9606]],
PARAMETER["X-axis translation",0,
ID["EPSG",8605]],
PARAMETER["Y-axis translation",0,
ID["EPSG",8606]],
PARAMETER["Z-axis translation",0,
ID["EPSG",8607]],
PARAMETER["X-axis rotation",0,
ID["EPSG",8608]],
PARAMETER["Y-axis rotation",0,
ID["EPSG",8609]],
PARAMETER["Z-axis rotation",0,
ID["EPSG",8610]],
PARAMETER["Scale difference",1,
ID["EPSG",8611]]]]
"""
class Test_WKT2EPSG(unittest.TestCase):
......@@ -71,6 +140,11 @@ class Test_WKT2EPSG(unittest.TestCase):
epsg = WKT2EPSG(self.wkt_utm)
self.assertTrue(isinstance(epsg, int))
def test_bound_CRS(self):
epsg = WKT2EPSG(wkt_bound_crs)
self.assertTrue(isinstance(epsg, int))
self.assertEqual(epsg, 3035)
class Test_EPSG2WKT(unittest.TestCase):
......@@ -82,6 +156,11 @@ class Test_EPSG2WKT(unittest.TestCase):
self.assertTrue(isinstance(wkt, str), "EPSG2WKT returned a %s object instead of a string!" % type(wkt))
self.assertNotEqual(wkt, "", msg="EPSG2WKT returned an empty WKT string!")
def test_bound_CRS(self):
wkt = EPSG2WKT(3035)
self.assertTrue(isinstance(wkt, str), "EPSG2WKT returned a %s object instead of a string!" % type(wkt))
self.assertNotEqual(wkt, "", msg="EPSG2WKT returned an empty WKT string!")
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment