py_tools_ds.geo.vector package

Submodules

py_tools_ds.geo.vector.conversion module

py_tools_ds.geo.vector.conversion.get_boxImXY_from_shapelyPoly(shapelyPoly: shapely.geometry.polygon.Polygon, im_gt: tuple) list[source]

Convert each vertex coordinate of a shapely polygon into image coordinates corresponding to the given geotransform without respect to invalid image coordinates. Those must be filtered later.

Parameters
  • shapelyPoly – <shapely.Polygon>

  • im_gt – <list> the GDAL geotransform of the target image

py_tools_ds.geo.vector.conversion.points_to_raster(points: np.ndarray, values: np.ndarray, tgt_res: float, prj: str = None, fillVal: float = None)[source]

Convert a set of point geometries with associated values into a raster array.

Parameters
  • points – list or 1D numpy.ndarray containings shapely.geometry point geometries

  • values – list or 1D numpy.ndarray containing int or float values

  • tgt_res – target resolution in projection units

  • prj – WKT projection string

  • fillVal – fill value used to fill in where no point geometry is available

py_tools_ds.geo.vector.conversion.round_shapelyPoly_coords(shapelyPoly: shapely.geometry.polygon.Polygon, precision: int = 10) shapely.geometry.polygon.Polygon[source]

Round the coordinates of the given shapely polygon.

Parameters
  • shapelyPoly – the shapely polygon

  • precision – number of decimals

Returns

py_tools_ds.geo.vector.conversion.shapelyBox2BoxYX(shapelyBox, coord_type='image')[source]
py_tools_ds.geo.vector.conversion.shapelyImPoly_to_shapelyMapPoly(shapelyBox, gt)[source]
py_tools_ds.geo.vector.conversion.shapelyImPoly_to_shapelyMapPoly_withPRJ(shapelyImPoly, gt, prj)[source]

py_tools_ds.geo.vector.geometry module

class py_tools_ds.geo.vector.geometry.boxObj(**kwargs)[source]

Bases: object

property boundsIm

Return xmin,xmax,ymin,ymax in image coordinates.

property boundsMap

Return xmin,xmax,ymin,ymax in map coordinates.

property boxImXY
property boxImYX
property boxMapXY

Return a list of XY coordinate tuples for all corners in the order UL_XY, UR_XY, LR_XY, LL_XY.

Returns

UL_XY, UR_XY, LR_XY, LL_XY

property boxMapYX

Return a list of YX coordinate tuples for all corners in the order UL_YX, UR_YX, LR_YX, LL_YX.

Returns

UL_YX, UR_YX, LR_YX, LL_YX

buffer_imXY(buffImX: float = 0, buffImY: float = 0) None[source]

Buffer the box in X- and/or Y-direction.

Parameters
  • buffImX – <float> buffer value in x-direction as IMAGE UNITS (pixels)

  • buffImY – <float> buffer value in y-direction as IMAGE UNITS (pixels)

buffer_mapXY(buffMapX: float = 0, buffMapY: float = 0) None[source]

Buffer the box in X- and/or Y-direction.

Parameters
  • buffMapX – <float> buffer value in x-direction as MAP UNITS

  • buffMapY – <float> buffer value in y-direction as MAP UNITS

get_coordArray_MapXY(prj: Optional[str] = None) Tuple[numpy.ndarray][source]

Return two coordinate arrays for X and Y coordinates in the given projection.

NOTE: If no projection is given, <boxObj>.prj is used.

Parameters

prj – GDAL projection as WKT string

Returns

property imDimsXY
property imDimsYX
property imPoly
is_larger_DimXY(boundsIm2test: tuple)[source]

Check if the boxObj is larger than a given set of bounding image coordinates (in X- and/or Y-direction).

Parameters

boundsIm2test – <tuple> (xmin,xmax,ymin,ymax) as image coordinates

property mapDimsXY
property mapDimsYX
property mapPoly
py_tools_ds.geo.vector.geometry.get_winPoly(wp_imYX: tuple, ws: tuple, gt: list, match_grid: bool = 0)[source]

Create a shapely polygon from a given set of image cordinates, window size and geotransform.

Parameters
  • wp_imYX

  • ws – <tuple> X/Y window size

  • gt

  • match_grid – <bool>

py_tools_ds.geo.vector.topology module

py_tools_ds.geo.vector.topology.fill_holes_within_poly(poly: Union[shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon]) shapely.geometry.polygon.Polygon[source]

Fill the holes within a shapely Polygon or MultiPolygon and return a Polygon with only the outer boundary.

Parameters

poly – <shapely.geometry.Polygon, shapely.geometry.MultiPolygon>, shapely.geometry.GeometryCollection>

Returns

py_tools_ds.geo.vector.topology.find_line_intersection_point(line1, line2)[source]
py_tools_ds.geo.vector.topology.get_bounds_polygon(gt, rows, cols)[source]

Get a polygon representing the outer bounds of an image.

Parameters
  • gt – GDAL geotransform

  • rows – number of rows

  • cols – number of columns

Returns

py_tools_ds.geo.vector.topology.get_footprint_polygon(CornerLonLat, fix_invalid=False)[source]

Convert a list of coordinates into a shapely polygon object.

Parameters
  • CornerLonLat – a list of coordinate tuples like [[lon,lat], [lon. lat], ..] in clockwise or counter clockwise order

  • fix_invalid – fix invalid output polygon by returning its convex hull (sometimes this can be different)

Returns

a shapely.Polygon() object

py_tools_ds.geo.vector.topology.get_largest_onGridPoly_within_poly(outerPoly, gt, rows, cols)[source]
py_tools_ds.geo.vector.topology.get_overlap_polygon(poly1, poly2, v=False)[source]

Return a dict with the overlap of two shapely.Polygon() objects, the overlap percentage and the overlap area.

Parameters
  • poly1 – first shapely.Polygon() object

  • poly2 – second shapely.Polygon() object

  • v – verbose mode

Returns

overlap polygon as shapely.Polygon() object

Returns

overlap percentage as float value [%]

Returns

area of overlap polygon

py_tools_ds.geo.vector.topology.get_smallest_boxImYX_that_contains_boxMapYX(box_mapYX, gt_im, tolerance_ndigits=5)[source]

Return image coordinates of the smallest box at the given coordinate grid that contains the given map coords box.

Parameters
  • box_mapYX – input box coordinates as YX-tuples

  • gt_im – geotransform of input box

  • 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

Returns

py_tools_ds.geo.vector.topology.get_smallest_shapelyImPolyOnGrid_that_contains_shapelyImPoly(shapelyPoly)[source]

Return the smallest box that matches the coordinate grid of the given geotransform. The returned shapely polygon contains image coordinates.

py_tools_ds.geo.vector.topology.polyVertices_outside_poly(inner_poly, outer_poly, tolerance=0)[source]

Check if a shapely polygon (inner_poly) contains vertices that are outside of another polygon (outer_poly).

Parameters
  • inner_poly – the polygon with the vertices to check

  • outer_poly – the polygon where all vertices have to be inside

  • tolerance – tolerance of the decision

Module contents