urbanflow.RasterGrid¶
- class urbanflow.RasterGrid(coordinate_reference_system='EPSG:32633', cell_size=1)¶
Bases:
object
RasterGrid class. Stores the following information: 1. grid: an np.ndarray[np.uint8] with unsigned integer values. 2. transform an Affine transform object to transform points onto the grid 3. legend: a python dict describing the different grid values and their meaning.
- Parameters:
coordinate_reference_system (str)
cell_size (float)
- cell_size¶
Square cell width/height in CRS units
- Type:
float
- Interface¶
- __init__¶
- Type:
constructor
- .save(filepath)¶
- Type:
saving the grid, as small as possible
- .laod(filepath)¶
- Type:
load the grid, as quickly as possible
- __init__(coordinate_reference_system='EPSG:32633', cell_size=1)¶
Constructor given a grid, transform, and legend
- Parameters:
cell_size (float) – Square cell width/height in CRS units. Defaults to 1
coordinate_reference_system (str) – Name of the CRS of this grid. Defaults to EPSG:32633.
Methods
__init__
([coordinate_reference_system, ...])Constructor given a grid, transform, and legend
from_geojson_dataframes
(buildings, streets, ...)Rasterize buildings, streets, and canals of Venice into a RasterGrid.
load
(filepath)Create a RasterGrid object from a .npz compressed file.
save
(filepath)Save a RasterGrid to a .npz file.
to_image
([scale, palette])Convert a uint8 grid of states into a PIL Image.
- classmethod from_geojson_dataframes(buildings, streets, canals, *, courtyards=None, auto_courtyards=True, coordinate_reference_system='EPSG:32633', cell_size=1, legend={'building': 2, 'canal': 3, 'courtyard': 4, 'ocean': 0, 'street': 1})¶
Rasterize buildings, streets, and canals of Venice into a RasterGrid.
- Parameters:
buildings (GeoDataFrames) – All must share the same CRS.
streets (GeoDataFrames) – All must share the same CRS.
canals (GeoDataFrames) – All must share the same CRS.
cell_size (float) – Square cell width/height in CRS units.
legend (Dict[str, int]) – A python dict that contains what cell values contian what. The dict must define: “ocean” : (default 0) “street” : (default 1) “building” : default 2) “canal” : (default 3)
courtyards (GeoDataFrame)
auto_courtyards (bool)
coordinate_reference_system (str)
- Return type:
RasterGrid object with grid, transform, and legend.
- classmethod load(filepath)¶
Create a RasterGrid object from a .npz compressed file.
- save(filepath)¶
Save a RasterGrid to a .npz file.
- Parameters:
filepath (str)
- to_image(scale=1, palette=None)¶
Convert a uint8 grid of states into a PIL Image.
- Parameters:
grid (ndarray[int] shape (rows, cols)) – Cell codes: 0=ocean, 1=street, 2=building (extend as you wish).
scale (int, default 1) – How many output pixels per cell (must be ≥1). 2 doubles width/height.
palette ({state: (R, G, B)}, optional) – Custom colors. Unspecified states default to white.
- Return type:
PIL.Image.Image (mode “RGB”)
Notes
Uses pure NumPy → very fast, even for multi-million-cell grids.
Nearest-neighbour up-scaling keeps the crisp blocky CA look.