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

Bugfix for not rounding off negative coordinates in...


Bugfix for not rounding off negative coordinates in get_smallest_boxImYX_that_contains_boxMapYX() and get_smallest_shapelyImPolyOnGrid_that_contains_shapelyImPoly().
Signed-off-by: Daniel Scheffler's avatarDaniel Scheffler <danschef@gfz-potsdam.de>
parent e8f7330c
......@@ -71,7 +71,7 @@ def get_footprint_polygon(CornerLonLat, fix_invalid=False):
:param CornerLonLat: a list of coordinate tuples like [[lon,lat], [lon. lat], ..]
in clockwise or counter clockwise order
:param fix_invalid: fix invalid output polygon by returning its convex hull (somtimes this can be different)
:param fix_invalid: fix invalid output polygon by returning its convex hull (sometimes this can be different)
:return: a shapely.Polygon() object
"""
......@@ -93,7 +93,7 @@ def get_footprint_polygon(CornerLonLat, fix_invalid=False):
def get_smallest_boxImYX_that_contains_boxMapYX(box_mapYX, gt_im, tolerance_ndigits=5):
"""Return image coordinates of the smallest box at the given coordinate grid that contains the given map coords box.
:param box_mapYX: input box ccordinates as YX-tuples
:param box_mapYX: input box coordinates as YX-tuples
:param gt_im: geotransform of input box
:param tolerance_ndigits: tolerance to avoid that output image coordinates are rounded to next integer although
they have been very close to an integer before (this avoids float rounding issues)
......@@ -105,7 +105,7 @@ def get_smallest_boxImYX_that_contains_boxMapYX(box_mapYX, gt_im, tolerance_ndig
# round min coords off and max coords on but tolerate differences below n decimal digits as the integer itself
xmin, ymin, xmax, ymax = np.round([xmin, ymin, xmax, ymax], tolerance_ndigits)
xmin, ymin, xmax, ymax = int(xmin), math.ceil(ymin), math.ceil(xmax), int(ymax)
xmin, ymin, xmax, ymax = math.floor(xmin), math.ceil(ymin), math.ceil(xmax), math.floor(ymax)
return (ymax, xmin), (ymax, xmax), (ymin, xmax), (ymin, xmin) # UL_YX,UR_YX,LR_YX,LL_YX
......@@ -114,6 +114,7 @@ def get_largest_onGridPoly_within_poly(outerPoly, gt, rows, cols):
oP_xmin, oP_ymin, oP_xmax, oP_ymax = outerPoly.bounds
xmin, ymax = find_nearest_grid_coord((oP_xmin, oP_ymax), gt, rows, cols, direction='SE')
xmax, ymin = find_nearest_grid_coord((oP_xmax, oP_ymin), gt, rows, cols, direction='NW')
return box(xmin, ymin, xmax, ymax)
......@@ -122,7 +123,10 @@ def get_smallest_shapelyImPolyOnGrid_that_contains_shapelyImPoly(shapelyPoly):
The returned shapely polygon contains image coordinates."""
xmin, ymin, xmax, ymax = shapelyPoly.bounds # image_coords-bounds
return box(int(xmin), int(ymin), math.ceil(xmax), math.ceil(ymax)) # round min coords off and max coords on
# round min coords off and max coords on
out_poly = box(math.floor(xmin), math.floor(ymin), math.ceil(xmax), math.ceil(ymax))
return out_poly
def find_line_intersection_point(line1, line2):
......@@ -136,11 +140,12 @@ def find_line_intersection_point(line1, line2):
d = (det(*line1), det(*line2))
x = det(d, xdiff) / div
y = det(d, ydiff) / div
return x, y
def polyVertices_outside_poly(inner_poly, outer_poly, tolerance=0):
"""Check if a shapely polygon (inner_poly) contains vertices that do not intersect another polygon (outer_poly)
"""Check if a shapely polygon (inner_poly) contains vertices that do not intersect another polygon (outer_poly).
:param inner_poly: the polygon with the vertices to check
:param outer_poly: the polygon where all vertices have to be inside
......
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