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
earth_observation_public
PySegCNN
Commits
2e76ebb2
Commit
2e76ebb2
authored
Sep 29, 2021
by
Frisinghelli Daniel
Browse files
Catch error when coordinates are inverted.
parent
85aaabed
Changes
1
Hide whitespace changes
Inline
Side-by-side
pysegcnn/core/utils.py
View file @
2e76ebb2
...
...
@@ -2834,18 +2834,38 @@ def clip_raster(src_ds, mask_ds, trg_ds, buffer=None, fmt=None,
extent
=
[
extent
[
0
]
-
buffer
,
extent
[
1
]
-
buffer
,
extent
[
2
]
+
buffer
,
extent
[
3
]
+
buffer
]
# clip raster
try
:
ds
=
gdal
.
Warp
(
str
(
tmp_path
),
str
(
src_path
),
outputBounds
=
extent
,
outputBoundsSRS
=
src_sr
,
xRes
=
src_ds
.
GetGeoTransform
()[
1
],
yRes
=
src_ds
.
GetGeoTransform
()[
-
1
],
srcNodata
=
src_no_data
,
dstNodata
=
trg_no_data
,
format
=
fmt
)
ds
.
FlushCache
()
# REQUIRED: writes dataset to disk!
# catch AttirbuteError when TransformPoint inverts outputs from (x, y)
# to (y, x) which results in ds=None
except
AttributeError
:
# invert extent: from: (y_tl, x_br, y_br, x_tl)
# to : (x_tl, y_br, x_br, y_tl)
extent
=
extent
[::
-
1
]
ds
=
gdal
.
Warp
(
str
(
tmp_path
),
str
(
src_path
),
outputBounds
=
extent
,
outputBoundsSRS
=
src_sr
,
xRes
=
src_ds
.
GetGeoTransform
()[
1
],
yRes
=
src_ds
.
GetGeoTransform
()[
-
1
],
srcNodata
=
src_no_data
,
dstNodata
=
trg_no_data
,
format
=
fmt
)
ds
.
FlushCache
()
# REQUIRED: writes dataset to disk!
# clip raster extent
LOGGER
.
info
(
'Clipping: {}, Extent: (x_tl={:.2f}, y_br={:.2f}, x_br={:.2f},'
' y_tl={:.2f})'
.
format
(
src_path
.
name
,
*
extent
))
ds
=
gdal
.
Warp
(
str
(
tmp_path
),
str
(
src_path
),
outputBounds
=
extent
,
outputBoundsSRS
=
src_sr
,
xRes
=
src_ds
.
GetGeoTransform
()[
1
],
yRes
=
src_ds
.
GetGeoTransform
()[
-
1
],
srcNodata
=
src_no_data
,
dstNodata
=
trg_no_data
,
format
=
fmt
)
ds
.
FlushCache
()
# REQUIRED: writes dataset to disk!
# compress raster dataset
compress_raster
(
tmp_path
,
trg_path
,
compress
=
compress
)
...
...
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