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
cf473165
Commit
cf473165
authored
Mar 24, 2020
by
Daniel Scheffler
Browse files
Fix for incompatibility of round_shapelyPoly_coords() with shapely>1.6.4.
Signed-off-by:
Daniel Scheffler
<
danschef@gfz-potsdam.de
>
parent
59a23589
Pipeline
#7763
passed with stage
in 53 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
py_tools_ds/geo/vector/conversion.py
View file @
cf473165
...
...
@@ -26,6 +26,7 @@ import numpy as np
# custom
from
shapely.geometry
import
shape
,
mapping
,
box
from
shapely.geometry
import
Polygon
# noqa F401 # flake8 issue
from
shapely
import
wkt
try
:
from
osgeo
import
ogr
...
...
@@ -81,12 +82,15 @@ def get_boxImXY_from_shapelyPoly(shapelyPoly, im_gt):
return
boxImXY
def
round_shapelyPoly_coords
(
shapelyPoly
,
precision
=
10
,
out_dtype
=
None
):
geojson
=
mapping
(
shapelyPoly
)
geojson
[
'coordinates'
]
=
np
.
round
(
np
.
array
(
geojson
[
'coordinates'
]),
precision
)
if
out_dtype
:
geojson
[
'coordinates'
]
=
geojson
[
'coordinates'
].
astype
(
out_dtype
)
return
shape
(
geojson
)
def
round_shapelyPoly_coords
(
shapelyPoly
,
precision
=
10
):
# type: (Polygon, int) -> Polygon
"""Round the coordinates of the given shapely polygon.
:param shapelyPoly: the shapely polygone
:param precision: number of decimals
:return:
"""
return
wkt
.
loads
(
wkt
.
dumps
(
shapelyPoly
,
rounding_precision
=
precision
))
def
points_to_raster
(
points
,
values
,
tgt_res
,
prj
=
None
,
fillVal
=
None
):
...
...
py_tools_ds/geo/vector/geometry.py
View file @
cf473165
...
...
@@ -126,7 +126,7 @@ class boxObj(object):
@
property
def
boxImYX
(
self
):
temp_imPoly
=
round_shapelyPoly_coords
(
self
.
imPoly
,
precision
=
0
,
out_dtype
=
int
)
temp_imPoly
=
round_shapelyPoly_coords
(
self
.
imPoly
,
precision
=
0
)
floatImBoxYX
=
shapelyBox2BoxYX
(
temp_imPoly
,
coord_type
=
'image'
)
return
[[
int
(
i
[
0
]),
int
(
i
[
1
])]
for
i
in
floatImBoxYX
]
...
...
Write
Preview
Markdown
is supported
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