Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Scheffler
py_tools_ds
Commits
a537d5b8
Commit
a537d5b8
authored
Dec 15, 2020
by
Daniel Scheffler
Browse files
Fixed issue
#16
(WKT2EPSG() returns None in case of bound CRS.).
Signed-off-by:
Daniel Scheffler
<
danschef@gfz-potsdam.de
>
parent
25921648
Pipeline
#16982
passed with stage
in 1 minute and 3 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
HISTORY.rst
View file @
a537d5b8
...
@@ -2,6 +2,12 @@
...
@@ -2,6 +2,12 @@
History
History
=======
=======
0.16.7 (2020-12-15)
-------------------
* Fixed issue #16 (WKT2EPSG() returns None in case of bound CRS.).
0.16.6 (2020-12-10)
0.16.6 (2020-12-10)
-------------------
-------------------
...
...
py_tools_ds/geo/projection.py
View file @
a537d5b8
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
# with this program. If not, see <http://www.gnu.org/licenses/>.
import
re
import
re
import
warnings
from
pyproj
import
CRS
from
pyproj
import
CRS
from
typing
import
Union
# noqa F401 # flake8 issue
from
typing
import
Union
# noqa F401 # flake8 issue
from
osgeo
import
osr
from
osgeo
import
osr
...
@@ -153,7 +154,17 @@ def WKT2EPSG(wkt):
...
@@ -153,7 +154,17 @@ def WKT2EPSG(wkt):
if
not
wkt
:
if
not
wkt
:
return
None
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
):
def
get_UTMzone
(
prj
):
...
...
tests/test_geo/test_projection.py
View file @
a537d5b8
...
@@ -61,6 +61,75 @@ wkt_utm = \
...
@@ -61,6 +61,75 @@ wkt_utm = \
AUTHORITY["EPSG", "32633"]]
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
):
class
Test_WKT2EPSG
(
unittest
.
TestCase
):
...
@@ -71,6 +140,11 @@ class Test_WKT2EPSG(unittest.TestCase):
...
@@ -71,6 +140,11 @@ class Test_WKT2EPSG(unittest.TestCase):
epsg
=
WKT2EPSG
(
self
.
wkt_utm
)
epsg
=
WKT2EPSG
(
self
.
wkt_utm
)
self
.
assertTrue
(
isinstance
(
epsg
,
int
))
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
):
class
Test_EPSG2WKT
(
unittest
.
TestCase
):
...
@@ -82,6 +156,11 @@ 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
.
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!"
)
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__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment