gemgis.raster.save_as_tiff
gemgis.raster.save_as_tiff#
- gemgis.raster.save_as_tiff(raster: numpy.ndarray, path: str, extent: Union[List[Union[int, float]], Tuple[Union[int, float]]], crs: Union[str, pyproj.crs.crs.CRS, rasterio.crs.CRS], nodata: Union[float, int] = None, transform=None, overwrite_file: bool = False, create_directory: bool = False)#
Saving a np.array as tif file
- Parameters
array (np.ndarray) – Array containing the raster values
path (string) – Path and name of the file, e.g.
path='mesh.msh'
extent (Union[List[Union[int, float]], Tuple[Union[int, float]]]) – List containing the bounds of the raster, e.g.
extent=[0, 972, 0, 1069]
crs (Union[str, pyproj.crs.crs.CRS, rasterio.crs.CRS]) – CRS of the saved raster, e.g.
crs='EPSG:4647'
nodata (Union[float, int]) – Nodata value of the raster, e.g.
nodata=9999.0
, defaultNone
transform – Transform of the data, default is
None
overwrite_file (bool) – Variable to overwrite an already existing file. Options include:
True
orFalse
, default isFalse
create_directory (bool) – Variable to create a new directory of directory does not exist Options include:
True
orFalse
, default set toFalse
New in version 1.0.x.
Example
>>> # Loading Libraries and File >>> import gemgis as gg >>> import rasterio >>> raster = rasterio.open(fp='raster.tif')
>>> # Defining raster extent and CRS >>> extent = [0, 972, 0, 1069] >>> crs = 'EPSG:4326'
>>> # Saving raster as tiff >>> gg.raster.save_as_tiff(raster=raster.read(1), path='raster_saved.tif', extent=extent, crs=crs) Raster successfully saved