rasterio package
Subpackages
- rasterio.rio package
- Submodules
- rasterio.rio.blocks module
- rasterio.rio.bounds module
- rasterio.rio.calc module
- rasterio.rio.clip module
- rasterio.rio.convert module
- rasterio.rio.edit_info module
- rasterio.rio.env module
- rasterio.rio.gcps module
- rasterio.rio.helpers module
- rasterio.rio.info module
- rasterio.rio.insp module
- rasterio.rio.main module
- rasterio.rio.mask module
- rasterio.rio.merge module
- rasterio.rio.options module
- rasterio.rio.overview module
- rasterio.rio.rasterize module
- rasterio.rio.rm module
- rasterio.rio.sample module
- rasterio.rio.shapes module
- rasterio.rio.stack module
- rasterio.rio.transform module
- rasterio.rio.warp module
- Module contents
- Submodules
Submodules
- rasterio.control module
- rasterio.coords module
- rasterio.crs module
CRS
CRS.data
CRS.from_authority()
CRS.from_dict()
CRS.from_epsg()
CRS.from_proj4()
CRS.from_string()
CRS.from_user_input()
CRS.from_wkt()
CRS.get()
CRS.is_epsg_code
CRS.is_geographic
CRS.is_projected
CRS.is_valid
CRS.items()
CRS.linear_units
CRS.linear_units_factor
CRS.to_authority()
CRS.to_dict()
CRS.to_epsg()
CRS.to_proj4()
CRS.to_string()
CRS.to_wkt()
CRS.units_factor
CRS.wkt
epsg_treats_as_latlong()
epsg_treats_as_northingeasting()
- rasterio.drivers module
- rasterio.dtypes module
- rasterio.enums module
ColorInterp
ColorInterp.Cb
ColorInterp.Cr
ColorInterp.Y
ColorInterp.alpha
ColorInterp.black
ColorInterp.blue
ColorInterp.cyan
ColorInterp.gray
ColorInterp.green
ColorInterp.grey
ColorInterp.hue
ColorInterp.lightness
ColorInterp.magenta
ColorInterp.palette
ColorInterp.red
ColorInterp.saturation
ColorInterp.undefined
ColorInterp.yellow
Compression
Interleaving
MaskFlags
MergeAlg
PhotometricInterp
Resampling
Resampling.nearest
Resampling.bilinear
Resampling.cubic
Resampling.cubic_spline
Resampling.lanczos
Resampling.average
Resampling.mode
Resampling.gauss
Resampling.max
Resampling.min
Resampling.med
Resampling.q1
Resampling.q3
Resampling.sum
Resampling.rms
Resampling.average
Resampling.bilinear
Resampling.cubic
Resampling.cubic_spline
Resampling.gauss
Resampling.lanczos
Resampling.max
Resampling.med
Resampling.min
Resampling.mode
Resampling.nearest
Resampling.q1
Resampling.q3
Resampling.rms
Resampling.sum
TransformDirection
TransformMethod
WktVersion
- rasterio.env module
- rasterio.errors module
BandOverviewError
CRSError
DatasetAttributeError
DatasetIOShapeError
DriverCapabilityError
DriverRegistrationError
EnvError
FileOverwriteError
GDALBehaviorChangeException
GDALOptionNotImplementedError
GDALVersionError
InvalidArrayError
NodataShadowWarning
NotGeoreferencedWarning
OverviewCreationError
PathError
RPCError
RasterBlockError
RasterioDeprecationWarning
RasterioError
RasterioIOError
ResamplingAlgorithmError
ShapeSkipWarning
StatisticsError
TransformError
TransformWarning
UnsupportedOperation
WarpOperationError
WarpOptionsError
WarpedVRTError
WindowError
WindowEvaluationError
- rasterio.features module
- rasterio.fill module
- rasterio.io module
BufferedDatasetWriter
BufferedDatasetWriter.block_shapes
BufferedDatasetWriter.block_size()
BufferedDatasetWriter.block_window()
BufferedDatasetWriter.block_windows()
BufferedDatasetWriter.bounds
BufferedDatasetWriter.build_overviews()
BufferedDatasetWriter.checksum()
BufferedDatasetWriter.close()
BufferedDatasetWriter.closed
BufferedDatasetWriter.colorinterp
BufferedDatasetWriter.colormap()
BufferedDatasetWriter.compression
BufferedDatasetWriter.count
BufferedDatasetWriter.crs
BufferedDatasetWriter.dataset_mask()
BufferedDatasetWriter.descriptions
BufferedDatasetWriter.driver
BufferedDatasetWriter.dtypes
BufferedDatasetWriter.files
BufferedDatasetWriter.gcps
BufferedDatasetWriter.get_gcps()
BufferedDatasetWriter.get_nodatavals()
BufferedDatasetWriter.get_tag_item()
BufferedDatasetWriter.get_transform()
BufferedDatasetWriter.height
BufferedDatasetWriter.index()
BufferedDatasetWriter.indexes
BufferedDatasetWriter.interleaving
BufferedDatasetWriter.is_tiled
BufferedDatasetWriter.lnglat()
BufferedDatasetWriter.mask_flag_enums
BufferedDatasetWriter.meta
BufferedDatasetWriter.mode
BufferedDatasetWriter.name
BufferedDatasetWriter.nodata
BufferedDatasetWriter.nodatavals
BufferedDatasetWriter.offsets
BufferedDatasetWriter.options
BufferedDatasetWriter.overviews()
BufferedDatasetWriter.photometric
BufferedDatasetWriter.profile
BufferedDatasetWriter.read()
BufferedDatasetWriter.read_crs()
BufferedDatasetWriter.read_masks()
BufferedDatasetWriter.read_transform()
BufferedDatasetWriter.res
BufferedDatasetWriter.rpcs
BufferedDatasetWriter.sample()
BufferedDatasetWriter.scales
BufferedDatasetWriter.set_band_description()
BufferedDatasetWriter.set_band_unit()
BufferedDatasetWriter.shape
BufferedDatasetWriter.start()
BufferedDatasetWriter.statistics()
BufferedDatasetWriter.stop()
BufferedDatasetWriter.subdatasets
BufferedDatasetWriter.tag_namespaces()
BufferedDatasetWriter.tags()
BufferedDatasetWriter.transform
BufferedDatasetWriter.units
BufferedDatasetWriter.update_tags()
BufferedDatasetWriter.width
BufferedDatasetWriter.window()
BufferedDatasetWriter.window_bounds()
BufferedDatasetWriter.window_transform()
BufferedDatasetWriter.write()
BufferedDatasetWriter.write_band()
BufferedDatasetWriter.write_colormap()
BufferedDatasetWriter.write_mask()
BufferedDatasetWriter.write_transform()
BufferedDatasetWriter.xy()
DatasetReader
DatasetReader.block_shapes
DatasetReader.block_size()
DatasetReader.block_window()
DatasetReader.block_windows()
DatasetReader.bounds
DatasetReader.checksum()
DatasetReader.close()
DatasetReader.closed
DatasetReader.colorinterp
DatasetReader.colormap()
DatasetReader.compression
DatasetReader.count
DatasetReader.crs
DatasetReader.dataset_mask()
DatasetReader.descriptions
DatasetReader.driver
DatasetReader.dtypes
DatasetReader.files
DatasetReader.gcps
DatasetReader.get_gcps()
DatasetReader.get_nodatavals()
DatasetReader.get_tag_item()
DatasetReader.get_transform()
DatasetReader.height
DatasetReader.index()
DatasetReader.indexes
DatasetReader.interleaving
DatasetReader.is_tiled
DatasetReader.lnglat()
DatasetReader.mask_flag_enums
DatasetReader.meta
DatasetReader.mode
DatasetReader.name
DatasetReader.nodata
DatasetReader.nodatavals
DatasetReader.offsets
DatasetReader.options
DatasetReader.overviews()
DatasetReader.photometric
DatasetReader.profile
DatasetReader.read()
DatasetReader.read_crs()
DatasetReader.read_masks()
DatasetReader.read_transform()
DatasetReader.res
DatasetReader.rpcs
DatasetReader.sample()
DatasetReader.scales
DatasetReader.shape
DatasetReader.start()
DatasetReader.statistics()
DatasetReader.stop()
DatasetReader.subdatasets
DatasetReader.tag_namespaces()
DatasetReader.tags()
DatasetReader.transform
DatasetReader.units
DatasetReader.width
DatasetReader.window()
DatasetReader.window_bounds()
DatasetReader.window_transform()
DatasetReader.write_transform()
DatasetReader.xy()
DatasetWriter
DatasetWriter.block_shapes
DatasetWriter.block_size()
DatasetWriter.block_window()
DatasetWriter.block_windows()
DatasetWriter.bounds
DatasetWriter.build_overviews()
DatasetWriter.checksum()
DatasetWriter.close()
DatasetWriter.closed
DatasetWriter.colorinterp
DatasetWriter.colormap()
DatasetWriter.compression
DatasetWriter.count
DatasetWriter.crs
DatasetWriter.dataset_mask()
DatasetWriter.descriptions
DatasetWriter.driver
DatasetWriter.dtypes
DatasetWriter.files
DatasetWriter.gcps
DatasetWriter.get_gcps()
DatasetWriter.get_nodatavals()
DatasetWriter.get_tag_item()
DatasetWriter.get_transform()
DatasetWriter.height
DatasetWriter.index()
DatasetWriter.indexes
DatasetWriter.interleaving
DatasetWriter.is_tiled
DatasetWriter.lnglat()
DatasetWriter.mask_flag_enums
DatasetWriter.meta
DatasetWriter.mode
DatasetWriter.name
DatasetWriter.nodata
DatasetWriter.nodatavals
DatasetWriter.offsets
DatasetWriter.options
DatasetWriter.overviews()
DatasetWriter.photometric
DatasetWriter.profile
DatasetWriter.read()
DatasetWriter.read_crs()
DatasetWriter.read_masks()
DatasetWriter.read_transform()
DatasetWriter.res
DatasetWriter.rpcs
DatasetWriter.sample()
DatasetWriter.scales
DatasetWriter.set_band_description()
DatasetWriter.set_band_unit()
DatasetWriter.shape
DatasetWriter.start()
DatasetWriter.statistics()
DatasetWriter.stop()
DatasetWriter.subdatasets
DatasetWriter.tag_namespaces()
DatasetWriter.tags()
DatasetWriter.transform
DatasetWriter.units
DatasetWriter.update_tags()
DatasetWriter.width
DatasetWriter.window()
DatasetWriter.window_bounds()
DatasetWriter.window_transform()
DatasetWriter.write()
DatasetWriter.write_band()
DatasetWriter.write_colormap()
DatasetWriter.write_mask()
DatasetWriter.write_transform()
DatasetWriter.xy()
FilePath
MemoryFile
ZipMemoryFile
get_writer_for_driver()
get_writer_for_path()
- rasterio.mask module
- rasterio.merge module
- rasterio.path module
- rasterio.plot module
- rasterio.profiles module
- rasterio.rpc module
- rasterio.sample module
- rasterio.session module
- rasterio.shutil module
- rasterio.tools module
- rasterio.transform module
- rasterio.vrt module
WarpedVRT
WarpedVRT.src_dataset
WarpedVRT.resampling
WarpedVRT.tolerance
WarpedVRT.src_nodata
WarpedVRT.dst_nodata
WarpedVRT.working_dtype
WarpedVRT.warp_extras
WarpedVRT.block_shapes
WarpedVRT.block_size()
WarpedVRT.block_window()
WarpedVRT.block_windows()
WarpedVRT.bounds
WarpedVRT.checksum()
WarpedVRT.close()
WarpedVRT.closed
WarpedVRT.colorinterp
WarpedVRT.colormap()
WarpedVRT.compression
WarpedVRT.count
WarpedVRT.crs
WarpedVRT.dataset_mask()
WarpedVRT.descriptions
WarpedVRT.driver
WarpedVRT.dtypes
WarpedVRT.files
WarpedVRT.gcps
WarpedVRT.get_gcps()
WarpedVRT.get_nodatavals()
WarpedVRT.get_tag_item()
WarpedVRT.get_transform()
WarpedVRT.height
WarpedVRT.index()
WarpedVRT.indexes
WarpedVRT.interleaving
WarpedVRT.is_tiled
WarpedVRT.lnglat()
WarpedVRT.mask_flag_enums
WarpedVRT.meta
WarpedVRT.mode
WarpedVRT.name
WarpedVRT.nodata
WarpedVRT.nodatavals
WarpedVRT.offsets
WarpedVRT.options
WarpedVRT.overviews()
WarpedVRT.photometric
WarpedVRT.profile
WarpedVRT.read()
WarpedVRT.read_crs()
WarpedVRT.read_masks()
WarpedVRT.read_transform()
WarpedVRT.res
WarpedVRT.rpcs
WarpedVRT.sample()
WarpedVRT.scales
WarpedVRT.shape
WarpedVRT.start()
WarpedVRT.statistics()
WarpedVRT.stop()
WarpedVRT.subdatasets
WarpedVRT.tag_namespaces()
WarpedVRT.tags()
WarpedVRT.transform
WarpedVRT.units
WarpedVRT.width
WarpedVRT.window()
WarpedVRT.window_bounds()
WarpedVRT.window_transform()
WarpedVRT.write_transform()
WarpedVRT.xy()
- rasterio.warp module
- rasterio.windows module
Module contents
Rasterio
- class rasterio.CRS(initialdata=None, **kwargs)
Bases:
object
A geographic or projected coordinate reference system.
CRS objects may be created by passing PROJ parameters as keyword arguments to the standard constructor or by passing EPSG codes, PROJ mappings, PROJ strings, or WKT strings to the from_epsg, from_dict, from_string, or from_wkt static methods.
Examples
The from_dict method takes PROJ parameters as keyword arguments.
>>> crs = CRS.from_dict(proj="aea")
EPSG codes may be used with the from_epsg method.
>>> crs = CRS.from_epsg(3005)
The from_string method takes a variety of input.
>>> crs = CRS.from_string("EPSG:3005")
- data
A PROJ4 dict representation of the CRS.
- static from_authority(auth_name, code)
Make a CRS from an authority name and code.
New in version 1.1.7.
- static from_dict(initialdata=None, **kwargs)
Make a CRS from a dict of PROJ parameters or PROJ JSON.
- static from_epsg(code)
Make a CRS from an EPSG code.
Notes
The input code is not validated against an EPSG database.
- static from_proj4(proj)
Make a CRS from a PROJ4 string.
- static from_string(value, morph_from_esri_dialect=False)
Make a CRS from an EPSG, PROJ, or WKT string
- static from_user_input(value, morph_from_esri_dialect=False)
Make a CRS from a variety of inputs.
- static from_wkt(wkt, morph_from_esri_dialect=False)
Make a CRS from a WKT string.
- get(self, item)
- is_geographic
Test if the CRS is a geographic coordinate reference system.
- is_projected
Test if the CRS is a projected coordinate reference system.
- items(self)
- linear_units
Get a short name for the linear units of the CRS.
- linear_units_factor
Get linear units and the conversion factor to meters of the CRS.
- Returns
units (str) – “m”, “ft”, etc.
factor (float) – Ratio of one unit to one meter.
- Raises
CRSError –
- to_authority(self, confidence_threshold=70)
Convert to the best match authority name and code.
For a CRS created using an EPSG code, that same value is returned. For other CRS, including custom CRS, an attempt is made to match it to definitions in authority files. Matches with a confidence below the threshold are discarded.
- Parameters
confidence_threshold (int) – Percent match confidence threshold (0-100).
- Returns
name (str) – Authority name.
code (str) – Code from the authority file.
or None
- to_dict(self, projjson=False)
Convert CRS to a PROJ dict.
Note
If there is a corresponding EPSG code, it will be used when returning PROJ parameter dict.
New in version 1.3.0.
- to_epsg(self, confidence_threshold=70)
Convert to the best match EPSG code.
For a CRS created using an EPSG code, that same value is returned. For other CRS, including custom CRS, an attempt is made to match it to definitions in the EPSG authority file. Matches with a confidence below the threshold are discarded.
- to_string(self)
Convert to a PROJ4 or WKT string.
The output will be reduced as much as possible by attempting a match to CRS defined in authority files.
Notes
Mapping keys are tested against the
all_proj_keys
list. Values ofTrue
are omitted, leaving the key bare: {‘no_defs’: True} -> “+no_defs” and items where the value is otherwise not a str, int, or float are omitted.
- to_wkt(self, morph_to_esri_dialect=False, version=None)
Convert to a OGC WKT representation.
New in version 1.3.0: version
- Parameters
morph_to_esri_dialect (bool, optional) – Whether or not to morph to the Esri dialect of WKT Only applies to GDAL versions < 3. This parameter will be removed in a future version of rasterio.
version (WktVersion or str, optional) – The version of the WKT output. Only works with GDAL 3+. Default is WKT1_GDAL.
- Return type
- Raises
CRSError –
- class rasterio.Env(session=None, aws_unsigned=False, profile_name=None, session_class=<function Session.aws_or_dummy>, **options)
Bases:
object
Abstraction for GDAL and AWS configuration
The GDAL library is stateful: it has a registry of format drivers, an error stack, and dozens of configuration options.
Rasterio’s approach to working with GDAL is to wrap all the state up using a Python context manager (see PEP 343, https://www.python.org/dev/peps/pep-0343/). When the context is entered GDAL drivers are registered, error handlers are configured, and configuration options are set. When the context is exited, drivers are removed from the registry and other configurations are removed.
Example
with rasterio.Env(GDAL_CACHEMAX=128000000) as env: # All drivers are registered, GDAL's raster block cache # size is set to 128 MB. # Commence processing... ... # End of processing. # At this point, configuration options are set to their # previous (possible unset) values.
A boto3 session or boto3 session constructor arguments aws_access_key_id, aws_secret_access_key, aws_session_token may be passed to Env’s constructor. In the latter case, a session will be created as soon as needed. AWS credentials are configured for GDAL as needed.
- credentialize()
Get credentials and configure GDAL
Note well: this method is a no-op if the GDAL environment already has credentials, unless session is not None.
- Return type
None
- drivers()
Return a mapping of registered drivers.
- rasterio.band(ds, bidx)
A dataset and one or more of its bands
- Parameters
ds (dataset object) – An opened rasterio dataset object.
bidx (int or sequence of ints) – Band number(s), index starting at 1.
- Return type
rasterio.Band
- rasterio.open(fp, mode='r', driver=None, width=None, height=None, count=None, crs=None, transform=None, dtype=None, nodata=None, sharing=False, **kwargs)
Open a dataset for reading or writing.
The dataset may be located in a local file, in a resource located by a URL, or contained within a stream of bytes.
In read (‘r’) or read/write (‘r+’) mode, no keyword arguments are required: these attributes are supplied by the opened dataset.
In write (‘w’ or ‘w+’) mode, the driver, width, height, count, and dtype keywords are strictly required.
- Parameters
fp (str, file object, PathLike object, FilePath, or MemoryFile) – A filename or URL, a file object opened in binary (‘rb’) mode, a Path object, or one of the rasterio classes that provides the dataset-opening interface (has an open method that returns a dataset).
mode (str, optional) – ‘r’ (read, the default), ‘r+’ (read/write), ‘w’ (write), or ‘w+’ (write/read).
driver (str, optional) – A short format driver name (e.g. “GTiff” or “JPEG”) or a list of such names (see GDAL docs at https://gdal.org/drivers/raster/index.html). In ‘w’ or ‘w+’ modes a single name is required. In ‘r’ or ‘r+’ modes the driver can usually be omitted. Registered drivers will be tried sequentially until a match is found. When multiple drivers are available for a format such as JPEG2000, one of them can be selected by using this keyword argument.
width (int, optional) – The number of columns of the raster dataset. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.
height (int, optional) – The number of rows of the raster dataset. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.
count (int, optional) – The count of dataset bands. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.
crs (str, dict, or CRS; optional) – The coordinate reference system. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.
transform (Affine instance, optional) – Affine transformation mapping the pixel space to geographic space. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.
dtype (str or numpy dtype) – The data type for bands. For example: ‘uint8’ or
rasterio.uint16
. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.nodata (int, float, or nan; optional) – Defines the pixel value to be interpreted as not valid data. Required in ‘w’ or ‘w+’ modes, it is ignored in ‘r’ or ‘r+’ modes.
sharing (bool; optional) – To reduce overhead and prevent programs from running out of file descriptors, rasterio maintains a pool of shared low level dataset handles. When True this function will use a shared handle if one is available. Multithreaded programs must avoid sharing and should set sharing to False.
kwargs (optional) – These are passed to format drivers as directives for creating or interpreting datasets. For example: in ‘w’ or ‘w+’ modes a tiled=True keyword argument will direct the GeoTIFF format driver to create a tiled, rather than striped, TIFF.
- Return type
A
DatasetReader
orDatasetWriter
object.
Examples
To open a GeoTIFF for reading using standard driver discovery and no directives:
>>> import rasterio >>> with rasterio.open('example.tif') as dataset: ... print(dataset.profile)
To open a JPEG2000 using only the JP2OpenJPEG driver:
>>> with rasterio.open( ... 'example.jp2', driver='JP2OpenJPEG') as dataset: ... print(dataset.profile)
To create a new 8-band, 16-bit unsigned, tiled, and LZW-compressed GeoTIFF with a global extent and 0.5 degree resolution:
>>> from rasterio.transform import from_origin >>> with rasterio.open( ... 'example.tif', 'w', driver='GTiff', dtype='uint16', ... width=720, height=360, count=8, crs='EPSG:4326', ... transform=from_origin(-180.0, 90.0, 0.5, 0.5), ... nodata=0, tiled=True, compress='lzw') as dataset: ... dataset.write(...)
- rasterio.pad(array, transform, pad_width, mode=None, **kwargs)
pad array and adjust affine transform matrix.
- Parameters
- Returns
(array, transform) – Tuple of new array and affine transform
- Return type
Notes
See numpy docs for details on mode and other kwargs: http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.pad.html