geoutils.Raster#
- class geoutils.Raster(filename_or_dataset, bands=None, is_mask=False, load_data=False, parse_sensor_metadata=False, silent=True, downsample=1, force_nodata=None)[source]#
The georeferenced raster.
- Main attributes:
- data:
np.ndarray Data array of the raster, with dimensions corresponding to (count, height, width).
- transform:
affine.Affine Geotransform of the raster.
- crs:
pyproj.crs.CRS Coordinate reference system of the raster.
- nodata:
intorfloat Nodata value of the raster.
- data:
All other attributes are derivatives of those attributes, or read from the file on disk. See the API for more details.
- __init__(filename_or_dataset, bands=None, is_mask=False, load_data=False, parse_sensor_metadata=False, silent=True, downsample=1, force_nodata=None)[source]#
Instantiate a raster from a filename or rasterio dataset.
- Parameters:
filename_or_dataset (
str|Path|TypeVar(RasterType, bound= RasterBase) |DatasetReader|MemoryFile|dict[str,Any]) – Path to file or Rasterio dataset.bands (
int|list[int] |None) – Band(s) to load into the object. Default loads all bands.load_data (
bool) – Whether to load the array during instantiation. Default is False.parse_sensor_metadata (
bool) – Whether to parse sensor metadata from filename and similarly-named metadata files.silent (
bool) – Whether to parse metadata silently or with console output.downsample (
int|float|integer[Any] |floating[Any]) – Downsample the array once loaded by a round factor. Default is no downsampling.force_nodata (
int|float|None) – Force nodata value to be used (overwrites the metadata). Default reads from metadata.
Methods
__init__(filename_or_dataset[, bands, ...])Instantiate a raster from a filename or rasterio dataset.
astype(dtype[, convert_nodata, inplace])coords([grid, shift_area_or_point, force_offset])Get coordinates (x,y) of all pixels in the raster.
copy([new_array, cast_nodata, deep])Copy the raster in-memory.
crop(bbox[, inplace])Crop the raster to a given extent.
filter(method[, size, sigma, engine, ...])Apply a filter to the array.
from_array(data, transform, crs[, nodata, ...])Create a raster from a numpy array and the georeferencing information.
from_pointcloud_regular(pointcloud[, ...])Create a raster from a point cloud with coordinates on a regular grid.
from_xarray(ds[, dtype])Create raster from a xarray.DataArray.
georeferenced_grid_equal(other)Check that raster shape, geotransform and CRS are equal.
get_bounds_projected(out_crs[, densify_points])Get raster bounds projected in a specified CRS.
get_footprint_projected(out_crs[, ...])Get raster footprint projected in a specified CRS.
get_mask()Get mask of invalid values from the raster.
get_metric_crs([local_crs_type, method])Get local metric coordinate reference system for the raster (UTM, UPS, or custom Mercator or Polar).
get_nanarray([floating_dtype, return_mask])get_stats([stats_name, inlier_mask, band, ...])icrop(bbox[, inplace])Crop raster based on pixel indices (bbox), converting them into georeferenced coordinates.
ij2xy(i, j[, shift_area_or_point, force_offset])Get coordinates (x,y) of indexes (row,column).
info([stats, verbose])interp_points(points[, method, ...])intersection(other[, match_ref])Returns the bounding box of intersection between this raster and another.
load([bands])Load the raster array from disk.
outside_image(xi, yj[, index])Check whether a given point falls outside the bounds of the raster.
plot([bands, cmap, vmin, vmax, alpha, ...])polygonize([target_values, connectivity, ...])Polygonize the raster into a vector of polygon geometries delineating target values.
proximity([vector, target_values, ...])Compute proximity distances to the raster target pixels, or to a vector geometry on the raster grid.
raster_allclose(other[, strict_masked, ...])Check if two rasters are all close.
raster_equal(other[, strict_masked, ...])Check if two rasters are equal.
reduce_points(points[, reducer_function, ...])Reduce raster values around point coordinates.
reproject([ref, crs, res, grid_size, ...])Reproject raster to a different geotransform (resolution, bounds) and/or coordinate reference system (CRS).
save(filename[, driver, dtype, nodata, ...])set_area_or_point(new_area_or_point[, ...])Set new pixel interpretation of the raster.
set_crs(new_crs)Set the coordinate reference system of the raster.
set_mask(mask)Set a mask on the raster array.
set_nodata(new_nodata[, update_array, ...])Set a new nodata value for all bands.
set_transform(new_transform)Set the geotransform of the raster.
split_bands([bands, deep])Split the bands into separate rasters.
subsample(subsample[, return_indices, band, ...])to_file(filename[, driver, dtype, nodata, ...])Write the raster to file.
to_pointcloud([data_column_name, data_band, ...])to_points(**kwargs)Export to a Rasterio in-memory dataset.
to_xarray([name])Convert a xarray.DataArray raster.
translate(xoff, yoff[, distance_unit, inplace])xy2ij(x, y[, op, precision, shift_area_or_point])Get indexes (row,column) of coordinates (x,y).
Attributes
Pixel interpretation of the raster.
Band indexes loaded in memory if they are, otherwise on disk.
Bounding coordinates of the raster.
Count of bands loaded in memory if they are, otherwise the one on disk.
Coordinate reference system of the raster.
Array of the raster.
Driver used to read a file on disk.
Data type of the raster.
footprintFootprint of the raster.
Height of the raster in pixels.
indexesBand indexes (duplicate of .bands attribute, mirroring Rasterio naming "indexes").
Whether the raster array is loaded.
Whether the raster array is a boolean data type (a mask).
Name of the file on disk, if it exists.
Nodata value of the raster.
profileBasic metadata and creation options of this dataset.
Resolution (X, Y) of the raster in georeferenced units.
Shape (i.e., height, width) of the raster in pixels.
Metadata tags of the raster.
Geotransform of the raster.
Width of the raster in pixels.