rastertodataframe.util module

rastertodataframe.util.burn_vector_mask_into_raster(raster_path, vector_path, out_path, vector_field=None)[source]

Create a new raster based on the input raster with vector features burned into the raster. To be used as a mask for pixels in the vector.

Parameters:
  • raster_path (str) –
  • vector_path (str) –
  • out_path (str) – Path for output raster. Format and Datatype are the same as ras.
  • vector_field (str or None) – Name of a field in the vector to burn values from. If None, all vector features are burned with a constant value of 1.
Returns:

Single band raster with vector geometries burned.

Return type:

gdal.Dataset

rastertodataframe.util.get_epsg(data)[source]

Get the EPSG code from an input.

Parameters:data (gdal.Dataset or ogr.DataSource or gpd.GeoDataFrame) –
Returns:
Return type:int
rastertodataframe.util.get_pixels(ras, mask, mask_val=None)[source]

Get pixels from a raster (with optional mask).

Parameters:
  • ras (np.ndarray) – Array of raster data in the form [bands][y][x].
  • mask (np.ndarray) – Array (2D) of zeroes to mask data.
  • mask_val (int) – Value of the data pixels in the mask. Default: non-zero.
Returns:

Array of non-masked data.

Return type:

np.ndarray

rastertodataframe.util.get_raster_band_names(raster)[source]

Obtain the names of bands from a raster. The raster metadata is queried first, if no names a present, a 1-index list of band_N is returned.

Parameters:raster (gdal.Dataset) –
Returns:
Return type:list[str]
rastertodataframe.util.open_raster(path, read_only=True)[source]

Open a raster using GDAL.

Parameters:
  • path (str) – Path of file to open.
  • read_only (bool) – File mode, set to False to open in “update” mode.
Returns:

Return type:

GDAL dataset

rastertodataframe.util.open_vector(path, with_geopandas=False, read_only=True)[source]

Open a vector dataset using OGR or GeoPandas.

Parameters:
  • path (str) – Path to vector file.
  • with_geopandas (bool) – Set to True to open with geopandas, else use OGR.
  • read_only (bool) – If opening with OGR, set to False to open in “update” mode.
Returns:

Return type:

GeoDataFrame if with_geopandas else OGR datsource.

rastertodataframe.util.same_epsg(data1, data2)[source]

Check sets of data have the same EPSG.

Parameters:
  • data1 (gdal.DataSet or ogr.DataSource or gpd.GeoDataFrame) –
  • data2 (gdal.DataSet or ogr.DataSource or gpd.GeoDataFrame) –
Returns:

Return type:

bool