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
e78dc623
Commit
e78dc623
authored
Sep 20, 2017
by
Daniel Scheffler
Browse files
Fix mapinfo2geotransform for asserting wrong length of map info in case of geographic coordinates.
parent
1a518582
Changes
1
Hide whitespace changes
Inline
Side-by-side
py_tools_ds/geo/map_info.py
View file @
e78dc623
...
...
@@ -27,6 +27,7 @@ def geotransform2mapinfo(gt, prj):
if
gt
[
2
]
!=
0
or
gt
[
4
]
!=
0
:
# TODO
raise
NotImplementedError
(
'Currently rotated datasets are not supported.'
)
srs
=
osr
.
SpatialReference
()
srs
.
ImportFromWkt
(
prj
)
Proj4
=
[
i
[
1
:]
for
i
in
srs
.
ExportToProj4
().
split
()]
...
...
@@ -49,20 +50,23 @@ def geotransform2mapinfo(gt, prj):
def
mapinfo2geotransform
(
map_info
):
# type: (list) -> _T_mapinfo_out
"""Builds GDAL GeoTransform tuple from an ENVI geo info.
:param map_info: ENVI geo info (list), e.g. ['UTM', 1, 1, 192585.0, 5379315.0, 30.0, 30.0, 41, 'North', 'WGS-84']
:param map_info: ENVI geo info (list), e.g., ['UTM', 1, 1, 192585.0, 5379315.0, 30.0, 30.0, 41, 'North', 'WGS-84']
:returns: GDAL GeoTransform, e.g. [249885.0, 30.0, 0.0, 4578615.0, 0.0, -30.0]
:rtype: list
"""
if
map_info
:
# FIXME rotated datasets are currently not supported -> function must return rotation at gt[2] and gt[4]
# validate input map info
exp_len
=
10
if
map_info
[
0
]
==
'UTM'
else
8
assert
isinstance
(
map_info
,
list
)
and
len
(
map_info
)
==
exp_len
,
\
"The map info argument has to be a list of length %s. Got %s."
%
(
map_info
,
exp_len
)
if
map_info
[
1
]
==
1
and
map_info
[
2
]
==
1
:
ULmapX
,
ULmapY
=
float
(
map_info
[
3
]),
float
(
map_info
[
4
])
else
:
ULmapX
=
float
(
map_info
[
3
])
-
(
float
(
map_info
[
1
])
*
float
(
map_info
[
5
])
-
float
(
map_info
[
5
]))
ULmapY
=
float
(
map_info
[
4
])
+
(
float
(
map_info
[
2
])
*
float
(
map_info
[
6
])
-
float
(
map_info
[
6
]))
assert
isinstance
(
map_info
,
list
)
and
len
(
map_info
)
==
10
,
\
"The geo info argument has to be a list of length 10. Got %s."
%
map_info
return
[
ULmapX
,
float
(
map_info
[
5
]),
0.
,
ULmapY
,
0.
,
-
float
(
map_info
[
6
])]
...
...
@@ -70,10 +74,12 @@ def get_corner_coordinates(gdal_ds=None, gt=None, cols=None, rows=None):
"""Returns (ULxy, LLxy, LRxy, URxy) in the same coordinate units like the given geotransform."""
assert
gdal_ds
or
(
gt
and
cols
and
rows
),
\
"GEOP.get_corner_coordinates: Missing argument! Please provide either 'gdal_ds' or 'gt', 'cols' AND 'rows'."
gdal_ds_GT
=
gdal_ds
.
GetGeoTransform
()
if
gdal_ds
else
gt
ext
=
[]
xarr
=
[
0
,
gdal_ds
.
RasterXSize
if
gdal_ds
else
cols
]
yarr
=
[
0
,
gdal_ds
.
RasterYSize
if
gdal_ds
else
rows
]
for
px
in
xarr
:
for
py
in
yarr
:
x
=
gdal_ds_GT
[
0
]
+
(
px
*
gdal_ds_GT
[
1
])
+
(
py
*
gdal_ds_GT
[
2
])
...
...
@@ -81,4 +87,5 @@ def get_corner_coordinates(gdal_ds=None, gt=None, cols=None, rows=None):
ext
.
append
([
x
,
y
])
yarr
.
reverse
()
del
gdal_ds_GT
return
ext
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