rasterstats.io module

class rasterstats.io.Raster(raster, affine=None, nodata=None, band=1)[source]

Bases: object

Raster abstraction for data access to 2/3D array-like things

Use as a context manager to ensure dataset gets closed properly:

>>> with Raster(path) as rast:
...
Parameters:

raster: 2/3D array-like data source, required

Currently supports paths to rasterio-supported rasters and numpy arrays with Affine transforms.

affine: Affine object

Maps row/col to coordinate reference system required if raster is ndarray

nodata: nodata value, optional

Overrides the datasource’s internal nodata if specified

band: integer

raster band number, optional (default: 1)

Methods

index(x, y) Given x,y in crs, return the (column, row) on the raster
read([bounds, window, masked, nan_as_nodata]) Performs a boundless read against the underlying array source
index(x, y)[source]

Given x,y in crs, return the (column, row) on the raster

read(bounds=None, window=None, masked=False, nan_as_nodata=False)[source]

Performs a boundless read against the underlying array source

Parameters:

bounds: bounding box

in w, s, e, n order, iterable, optional

window: rasterio-style window, optional

bounds OR window are required, specifying both or neither will raise exception

masked: boolean

return a masked numpy array, default: False bounds OR window are required, specifying both or neither will raise exception

nan_as_nodata: boolean

Treat NaN values as nodata, default: False

Returns:

Raster object with update affine and array info

rasterstats.io.boundless_array(arr, window, nodata, masked=False)[source]
rasterstats.io.bounds_window(bounds, affine)[source]

Create a full cover rasterio-style window

rasterstats.io.parse_feature(obj)[source]

Given a python object attemp to a GeoJSON-like Feature from it

rasterstats.io.read_featurecollection(obj, layer=0)[source]
rasterstats.io.read_features(obj, layer=0)[source]
rasterstats.io.rowcol(x, y, affine, op=<built-in function floor>)[source]

Get row/col for a x/y

rasterstats.io.window_bounds(window, affine)[source]
rasterstats.io.wrap_geom(geom)[source]

Wraps a geometry dict in an GeoJSON Feature