py_tools_ds.geo.raster package¶
Submodules¶
py_tools_ds.geo.raster.conversion module¶
- py_tools_ds.geo.raster.conversion.raster2polygon(array: numpy.ndarray, gt: Union[list, tuple], prj: Union[str, int], DN2extract: int = 1, exact: bool = True, maxfeatCount: Optional[int] = None, min_npx: int = 1, timeout: Optional[float] = None, progress: bool = True, q: bool = False) Union[shapely.geometry.polygon.Polygon, shapely.geometry.multipolygon.MultiPolygon] [source]¶
Calculate a footprint polygon for the given array.
- Parameters
array – 2D numpy array
gt – GDAL GeoTransform
prj – projection as WKT string, ‘EPSG:1234’ or <EPSG_int>
DN2extract – <int, float> pixel value to create polygons for
exact – whether to compute the exact footprint polygon or a simplified one for speed (exact=False downsamples large input datasets before polygonizing)
maxfeatCount – the maximum expected number of polygons. If more polygons are found, every further processing is cancelled and a RunTimeError is raised.
min_npx – minmal polygon area to be included in the result (in numbers of pixels; default: 1)
timeout – breaks the process after a given time in seconds
progress – show progress bars (default: True)
q – quiet mode (default: False)
- Returns
py_tools_ds.geo.raster.reproject module¶
- py_tools_ds.geo.raster.reproject.warp_ndarray(ndarray, in_gt, in_prj=None, out_prj=None, out_dtype=None, out_gsd=(None, None), out_bounds=None, out_bounds_prj=None, out_XYdims=(None, None), rspAlg='near', in_nodata=None, out_nodata=None, in_alpha=False, out_alpha=False, targetAlignedPixels=False, gcpList=None, polynomialOrder=None, options=None, transformerOptions=None, warpOptions=None, CPUs=1, warpMemoryLimit=0, progress=True, q=False)[source]¶
- Parameters
ndarray – numpy array to be warped (or a list of numpy arrays (requires lists for in_gt/in_prj))
in_gt – input GDAL geotransform (or a list of GDAL geotransforms)
in_prj – input GDAL projection or list of projections (WKT string, ‘EPSG:1234’, <EPSG_int>), default: “LOCAL_CS["MAP"]”
out_prj – output GDAL projection (WKT string, ‘EPSG:1234’, <EPSG_int>), default: “LOCAL_CS["MAP"]”
out_dtype – gdal.DataType
out_gsd –
out_bounds – [xmin,ymin,xmax,ymax] set georeferenced extents of output file to be created, e.g. [440720, 3750120, 441920, 3751320]) (in target SRS by default, or in the SRS specified with -te_srs)
out_bounds_prj –
out_XYdims –
rspAlg – <str> Resampling method to use. Available methods are: near, bilinear, cubic, cubicspline, lanczos, average, mode, max, min, med, q1, q2
in_nodata –
out_nodata –
in_alpha – <bool> Force the last band of a source image to be considered as a source alpha band.
out_alpha – <bool> Create an output alpha band to identify nodata (unset/transparent) pixels
targetAlignedPixels – (GDAL >= 1.8.0) (target aligned pixels) align the coordinates of the extent of the output file to the values of the -tr, such that the aligned extent includes the minimum extent.
gcpList – <list> list of ground control points in the output coordinate system to be used for warping, e.g. [gdal.GCP(mapX,mapY,mapZ,column,row),…]
polynomialOrder – <int> order of polynomial GCP interpolation
options – <str> additional GDAL options as string, e.g. ‘-nosrcalpha’ or ‘-order’
transformerOptions – <list> list of transformer options, e.g. [‘SRC_SRS=invalid’]
warpOptions – <list> list of warp options, e.g. [‘CUTLINE_ALL_TOUCHED=TRUE’], find available options here: http://www.gdal.org/doxygen/structGDALWarpOptions.html
CPUs – <int> number of CPUs to use (default: None, which means ‘all CPUs available’)
warpMemoryLimit – <int> size of working buffer in bytes (default: 0)
progress – <bool> show progress bar (default: True)
q – <bool> quiet mode (default: False)
- Returns
- py_tools_ds.geo.raster.reproject.warp_ndarray_rasterio(ndarray, in_gt, in_prj, out_prj, out_gt=None, outRowsCols=None, outUL=None, out_res=None, out_extent=None, out_dtype=None, rsp_alg=0, in_nodata=None, out_nodata=None, outExtent_within=True)[source]¶
Reproject / warp a numpy array with given geo information to target coordinate system.
- Parameters
ndarray – numpy.ndarray [rows,cols,bands]
in_gt – input gdal GeoTransform
in_prj – input projection as WKT string
out_prj – output projection as WKT string
out_gt – output gdal GeoTransform as float tuple in the source coordinate system (optional)
outUL – [X,Y] output upper left coordinates as floats in the source coordinate system (requires outRowsCols)
outRowsCols – [rows, cols] (optional)
out_res – output resolution as tuple of floats (x,y) in the TARGET coordinate system
out_extent – [left, bottom, right, top] as floats in the source coordinate system
out_dtype – output data type as numpy data type
rsp_alg – Resampling method to use. One of the following (int, default is 0): 0 = nearest neighbour, 1 = bilinear, 2 = cubic, 3 = cubic spline, 4 = lanczos, 5 = average, 6 = mode
in_nodata – no data value of the input image
out_nodata – no data value of the output image
outExtent_within – Ensures that the output extent is within the input extent. Otherwise an exception is raised.
- Return out_arr
warped numpy array
- Return out_gt
warped gdal GeoTransform
- Return out_prj
warped projection as WKT string