Utilities for working with raster grids defined by affine transforms
Project description
griffine
Utilities for working with grids that have affine transforms, typically for working with rasters or other gridded data.
Installation
This package is distributed on pypi and can be pip-installed:
pip install griffine
Usage
This library is composed of several major classes:
GridTiledGridAffineGridTiledAffineGridPointCellandAffineCellTileandAffineTile
Grid represents a two-dimensional grid of Cells, with a size defined by its
cols and rows. A TiledGrid is, effectively, a grid of grids. Each cell in
a TiledGrid is a Tile. Tiles are both Cells and Grids, where the tile
grid is a subset of the larger Grid that has been tiled.
AffineGrid is a Grid with the addition of an affine transformation to allow
transformations between grid/image space and model space (in the case of
geospatial data, model space would be the raster's coordinate reference
system). AffineGrids allow looking up the Point represented by a Cell
(using its origin, centroid, or antiorigin), or the Cell containing a
Point.
A TiledAffineGrid is to an AffineGrid as a TiledGrid is to a Grid: each
AffileTile in a TiledAffineGrid is an AffineGrid representing some subset
of the larger AffineGrid that was tiled. TiledAffineGrids allow finding the
AffineTile containingaCellor aPoint`.
griffine does not handle coordinate systems and thus does not do any
reprojection. It is expected that users ensure they are using a consistent CRS
between the affine transforms of their grid and any points.
The Python __geo_interface__
protocol is supported by all
operations accepting a Point and on the Point class itself, to easily allow
using or casting to point geometries from other Python libraries (shapely,
odc-geo, etc.).
affine_grid = grid.add_transform(transform)affine_cell.antiorigin
Examples
# Affine re-exported from the affine package
# Point is re-exported from the pygeoif package
from griffine import Affine, Grid, Point
# 10m pixel grid in UTM coordinates
transform = Affine(10, 0, 200000, 0, -10, 5100000)
# First we create a grid!
grid = Grid(10000, 5000)
# We can grab a cell from the grid using index notation.
cell = grid[424, 2343]
cell.row # 424
cell.col # 2343
# We can tile the grid using another grid.
# In this example we'd get a 10x5 tile grid
# where each tile is a grid of 1000x1000.
tile = grid.tile_into(Grid(10, 5))[0, 0]
tile.size # (1000, 1000)
# We can also add an affine transform to our grid.
# A transform allows converting between grid space and
# model space (i.e., cell coords and spatial coords).
affine_grid = grid.add_transform(transform)
affine_grid.origin # Point(200000.0, 5100000.0)
affine_grid.centroid # Point(225000.0, 5050000.0)
affine_grid.antiorigin # Point(250000.0, 5000000.0)
# Affine grids also support grabbing a cell via
# index notation. Affine grids will provide affine
# cells, which support transform-based operations too.
affine_cell = affine_grid[0, 0]
affine_cell.origin # Point(200000.0, 5100000.0)
affine_cell.centroid # Point(200005.0, 5099995.0)
affine_cell.antiorigin # Point(200010.0, 5099990.0)
# Transform operations can go the other way too.
# Let's make a point and find its enclosing cell!
point = Point(223433.2934, 5095752.8931)
affine_cell = affine_grid.point_to_cell(point)
affine_cell.row # 424
affine_cell.col # 2343
# Grids can also be tiled via a tile size expressed
# as a grid. Here we'll get a 10x5 tile grid, but the
# left and bottom edge tiles will not be full size.
tiled_affine_grid = affine_grid.tile_via(Grid(1024, 1024))
# Affine-enabled tiles and tile grids also support
# transform-based operations:
affine_tile = tiled_affine_grid.point_to_tile(point)
affine_tile.row # 0
affine_tile.col # 2
affine_tile_cell = affine_tile.point_to_cell(point)
affine_tile_cell.row # 424
affine_tile_cell.col # 2343
affine_tile_cell.tile_row # 0
affine_tile_cell.tile_col # 2
# We can work our way back up to the original grid
# from cells and tiles as needed:
#
# cell tile tile grid grid
affine_tile_cell.parent_grid.parent_grid.base_grid is affine_grid # True
How to say "griffine"
The name of this library is pronounced "grif-fine", as in the words "grift", and "fine". It's also okay to say it "grif-feen", as rhymes with "mean".
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file griffine-0.1.0.tar.gz.
File metadata
- Download URL: griffine-0.1.0.tar.gz
- Upload date:
- Size: 63.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1597308d127e79b1337e0e032d2441b764345c4c00f4307024764ddcdc465d35
|
|
| MD5 |
021824b04d6c0919078daa171bdae343
|
|
| BLAKE2b-256 |
73a00382c2d06daaf39abb23e1fd88f1ae197f2955404af6da35a8f1e8fcf10a
|
Provenance
The following attestation bundles were made for griffine-0.1.0.tar.gz:
Publisher:
release.yml on jkeifer/griffine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
griffine-0.1.0.tar.gz -
Subject digest:
1597308d127e79b1337e0e032d2441b764345c4c00f4307024764ddcdc465d35 - Sigstore transparency entry: 201890102
- Sigstore integration time:
-
Permalink:
jkeifer/griffine@7e9926e34e05f7221720febf52437f8bdcc71983 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jkeifer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e9926e34e05f7221720febf52437f8bdcc71983 -
Trigger Event:
release
-
Statement type:
File details
Details for the file griffine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: griffine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c47015b1852ef1eb7000e4fdc0ac8ae426c4a72e802149f8571184a7094ed6
|
|
| MD5 |
8481fa53a334b44a9465909bd6d1ef8a
|
|
| BLAKE2b-256 |
b6f5761924ba642d976786f6f2d886f052434abe99b5708e889f0013682bb155
|
Provenance
The following attestation bundles were made for griffine-0.1.0-py3-none-any.whl:
Publisher:
release.yml on jkeifer/griffine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
griffine-0.1.0-py3-none-any.whl -
Subject digest:
76c47015b1852ef1eb7000e4fdc0ac8ae426c4a72e802149f8571184a7094ed6 - Sigstore transparency entry: 201890105
- Sigstore integration time:
-
Permalink:
jkeifer/griffine@7e9926e34e05f7221720febf52437f8bdcc71983 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jkeifer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7e9926e34e05f7221720febf52437f8bdcc71983 -
Trigger Event:
release
-
Statement type: