Commit 9bf1431b by Daniel Scheffler

### Added a tolerance to get_smallest_boxImYX_that_contains_boxMapYX() to avoid...

Added a tolerance to get_smallest_boxImYX_that_contains_boxMapYX() to avoid float coordinate rounding issues.
parent 19e57d7d
Pipeline #3322 passed with stages
in 19 minutes and 38 seconds
 ... ... @@ -68,11 +68,23 @@ def get_footprint_polygon(CornerLonLat, fix_invalid=False): return outpoly def get_smallest_boxImYX_that_contains_boxMapYX(box_mapYX, gt_im): def get_smallest_boxImYX_that_contains_boxMapYX(box_mapYX, gt_im, tolerance_ndigits=5): """Returns 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 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) -> tolerance is given as number of decimal digits of an image coordinate :return: """ xmin, ymin, xmax, ymax = Polygon([(i[1], i[0]) for i in box_mapYX]).bounds # map-bounds box_mapYX (ymin, xmin), (ymax, xmax) = mapYX2imYX([ymin, xmin], gt_im), mapYX2imYX([ymax, xmax], gt_im) # image coord bounds xmin, ymin, xmax, ymax = int(xmin), math.ceil(ymin), math.ceil(xmax), int( ymax) # round min coords off and max coords on # 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) return (ymax, xmin), (ymax, xmax), (ymin, xmax), (ymin, xmin) # UL_YX,UR_YX,LR_YX,LL_YX ... ...
 __version__ = '0.13.6' __versionalias__ = '20181203_05' __version__ = '0.13.7' __versionalias__ = '20181204_01'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!