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

Merge branch 'bugfix/fix_issue10' into 'master'

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

See merge request !17
parents 59a23589 cf473165
Pipeline #7797 passed with stages
in 6 minutes and 54 seconds
......@@ -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
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 wkt.loads(wkt.dumps(shapelyPoly, rounding_precision=precision))
def points_to_raster(points, values, tgt_res, prj=None, fillVal=None):
......@@ -126,7 +126,7 @@ class boxObj(object):
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]
Supports Markdown
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