stems.gis.grids module¶
Create and work with geospatial data tiling schemes
A tile scheme defines the grid which many products are based on. Tiling schemes define a projection, usually a projection applicable over a wide area, the size (in pixels) of each tile, and georeferencing information that defines the upper left coordinate and pixel sizes (thus defining the posting of each pixel). Tiles are defined by the tile grid coordinate (horizontal & vertical indices) that determines the number of tiles offset from the upper left coordinate of the tiling scheme, such that one can retrieve the real-world coordinate of a pixel if the tile grid index and pixel row/column within the tile is known.
-
class
stems.gis.grids.
Tile
(index, crs, bounds, res, size)[source]¶ Bases:
object
A Tile
-
crs
¶ The tile coordinate reference system
- Type
-
bounds
¶ The bounding box of the tile
- Type
BoundingBox
-
property
bbox
¶ This tile’s bounding box geometry
- Type
shapely.geometry.Polygon
-
coords
(self, center=True)[source]¶ Return y/x pixel coordinates
- Parameters
center (bool, optional) – Return coordinates for pixel centers (default)
- Returns
np.ndarray – Y coordinates
np.ndarray – X coordinates
-
classmethod
from_dict
(d)[source]¶ Create a Tile from a dict
- Parameters
d (dict) – Tile info, including “index”, “crs” (a WKT), “bounds”, “res”, and “size”
-
geojson
(self, crs='epsg:4326')[source]¶ Return this Tile’s geometry as GeoJSON
- Parameters
crs (rasterio.crs.CRS) – Coordinate reference system of output. Defaults to EPSG:4326 per GeoJSON standard (RFC7946). If
None
, will return geometries in Tile’s CRS- Returns
This tile’s geometry and crs represented as GeoJSON
- Return type
References
-
to_dict
(self)[source]¶ Return a
dict
representing this Tile- Returns
This Tile as a dict (CRS will be a WKT for portability)
- Return type
-
property
transform
¶ The
Affine
transform for the tile- Type
affine.Affine
-
-
class
stems.gis.grids.
TileGrid
(ul, crs, res, size, limits=None, name='Grid')[source]¶ Bases:
collections.abc.Mapping
A tile grid specification for gridding data
-
crs
¶ Coordinate system information
- Type
-
limits
¶ Maximum and minimum rows (vertical) and columns (horizontal) given as ((row_start, row_stop), (col_start, col_stop)). Used to limit access to Tiles beyond domain.
-
bounds_to_tiles
(self, bounds)[source]¶ Yield Tile objects for this grid within a given bounds
- Parameters
bounds (BoundingBox) – Input bounds. Bounds must be in the same CRS as the TileGrid.
- Yields
tile (Tile) – Tiles that are within within provided bounds
-
geojson
(self, crs='epsg:4326', rows=None, cols=None, rfc7946=False, skip_invalid=False)[source]¶ Returns this grid of tiles as GeoJSON
- Parameters
crs (rasterio.crs.CRS) – Coordinate reference system of output. Defaults to EPSG:4326 per GeoJSON standard (RFC7946). If
None
, will return geometries in TileGrid’s CRSrows (Sequence[int], optional) – If this TileGrid was not given
limits
or if you want a subset of the tiles, specify the rows to mapcols (Sequence[int], optional) – If this TileGrid was not given
limits
or if you want a subset of the tiles, specify the rows to maprfc7946 (bool, optional) – Return GeoJSON compliant with RFC7946. Helps fix GeoJSON that crosses the anti-meridian/datelines by splitting polygons into multiple as needed
skip_invalid (bool, optional) – If
True
, checks for tile bounds for invalid geometries and will only include valid tile geometries.
- Returns
GeoJSON
- Return type
-
point_to_tile
(self, point)[source]¶ Return a Tile containing a given point (x, y)
- Parameters
point (tuple) – X/Y coordinates. Coordinates must be in the same CRS as the TileGrid.
- Returns
tile – The intersecting :class`Tile`
- Return type
-
roi_to_tiles
(self, roi)[source]¶ Yield tiles within a Region of Interest (ROI)
shapely
geometry- Parameters
roi (Polygon, MultiPolygon, etc.) – A shapely geometry. Must be in the same CRS as the TileGrid.
- Yields
iterable[Tile] – Yields
Tile
objects within provided Region of Interest
-
to_dict
(self)[source]¶ Return this TileGrid as a dictionary (e.g., to serialize)
- Returns
TileGrid attributes needed to re-initialize class
- Return type
-
property
transform
¶ the affine transform for this TileGrid
- Type
affine.Affine
-