rasterio.transform module

Geospatial transforms

class rasterio.transform.TransformMethodsMixin

Bases: object

Mixin providing methods for calculations related to transforming between rows and columns of the raster array and the coordinates.

These methods are wrappers for the functionality in rasterio.transform module.

A subclass with this mixin MUST provide a transform property.

index(x, y, op=<built-in function floor>, precision=None)

Returns the (row, col) index of the pixel containing (x, y) given a coordinate reference system.

Use an epsilon, magnitude determined by the precision parameter and sign determined by the op function:

positive for floor, negative for ceil.

Parameters
  • x (float) – x value in coordinate reference system

  • y (float) – y value in coordinate reference system

  • op (function, optional (default: math.floor)) – Function to convert fractional pixels to whole numbers (floor, ceiling, round)

  • precision (int, optional (default: None)) – Decimal places of precision in indexing, as in round().

Returns

(row index, col index)

Return type

tuple

xy(row, col, offset='center')

Returns the coordinates (x, y) of a pixel at row and col. The pixel’s center is returned by default, but a corner can be returned by setting offset to one of ul, ur, ll, lr.

Parameters
  • row (int) – Pixel row.

  • col (int) – Pixel column.

  • offset (str, optional) – Determines if the returned coordinates are for the center of the pixel or for a corner.

Returns

(x, y)

Return type

tuple

rasterio.transform.array_bounds(height, width, transform)

Return the bounds of an array given height, width, and a transform.

Return the west, south, east, north bounds of an array given its height, width, and an affine transform.

rasterio.transform.from_bounds(west, south, east, north, width, height)

Return an Affine transformation given bounds, width and height.

Return an Affine transformation for a georeferenced raster given its bounds west, south, east, north and its width and height in number of pixels.

rasterio.transform.from_gcps(gcps)

Make an Affine transform from ground control points.

Parameters

gcps (sequence of GroundControlPoint) – Such as the first item of a dataset’s gcps property.

Returns

Return type

Affine

rasterio.transform.from_origin(west, north, xsize, ysize)

Return an Affine transformation given upper left and pixel sizes.

Return an Affine transformation for a georeferenced raster given the coordinates of its upper left corner west, north and pixel sizes xsize, ysize.

rasterio.transform.guard_transform(transform)

Return an Affine transformation instance.

rasterio.transform.rowcol(transform, xs, ys, op=<built-in function floor>, precision=None)

Returns the rows and cols of the pixels containing (x, y) given a coordinate reference system.

Use an epsilon, magnitude determined by the precision parameter and sign determined by the op function:

positive for floor, negative for ceil.

Parameters
  • transform (Affine) – Coefficients mapping pixel coordinates to coordinate reference system.

  • xs (list or float) – x values in coordinate reference system

  • ys (list or float) – y values in coordinate reference system

  • op (function) – Function to convert fractional pixels to whole numbers (floor, ceiling, round)

  • precision (int, optional) – Decimal places of precision in indexing, as in round().

Returns

  • rows (list of ints) – list of row indices

  • cols (list of ints) – list of column indices

rasterio.transform.tastes_like_gdal(seq)

Return True if seq matches the GDAL geotransform pattern.

rasterio.transform.xy(transform, rows, cols, offset='center')

Returns the x and y coordinates of pixels at rows and cols. The pixel’s center is returned by default, but a corner can be returned by setting offset to one of ul, ur, ll, lr.

Parameters
  • transform (affine.Affine) – Transformation from pixel coordinates to coordinate reference system.

  • rows (list or int) – Pixel rows.

  • cols (list or int) – Pixel columns.

  • offset (str, optional) – Determines if the returned coordinates are for the center of the pixel or for a corner.

Returns

  • xs (list) – x coordinates in coordinate reference system

  • ys (list) – y coordinates in coordinate reference system