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

Fix for incompatibility of round_shapelyPoly_coords() with shapely>1.6.4.


Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent 59a23589
Pipeline #7763 passed with stage
in 53 seconds
...@@ -26,6 +26,7 @@ import numpy as np ...@@ -26,6 +26,7 @@ import numpy as np
# custom # custom
from shapely.geometry import shape, mapping, box from shapely.geometry import shape, mapping, box
from shapely.geometry import Polygon # noqa F401 # flake8 issue from shapely.geometry import Polygon # noqa F401 # flake8 issue
from shapely import wkt
try: try:
from osgeo import ogr from osgeo import ogr
...@@ -81,12 +82,15 @@ def get_boxImXY_from_shapelyPoly(shapelyPoly, im_gt): ...@@ -81,12 +82,15 @@ def get_boxImXY_from_shapelyPoly(shapelyPoly, im_gt):
return boxImXY return boxImXY
def round_shapelyPoly_coords(shapelyPoly, precision=10, out_dtype=None): def round_shapelyPoly_coords(shapelyPoly, precision=10):
geojson = mapping(shapelyPoly) # type: (Polygon, int) -> Polygon
geojson['coordinates'] = np.round(np.array(geojson['coordinates']), precision) """Round the coordinates of the given shapely polygon.
if out_dtype:
geojson['coordinates'] = geojson['coordinates'].astype(out_dtype) :param shapelyPoly: the shapely polygone
return shape(geojson) :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): def points_to_raster(points, values, tgt_res, prj=None, fillVal=None):
......
...@@ -126,7 +126,7 @@ class boxObj(object): ...@@ -126,7 +126,7 @@ class boxObj(object):
@property @property
def boxImYX(self): 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') floatImBoxYX = shapelyBox2BoxYX(temp_imPoly, coord_type='image')
return [[int(i[0]), int(i[1])] for i in floatImBoxYX] return [[int(i[0]), int(i[1])] for i in floatImBoxYX]
......
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