voxcity.geoprocessor.raster.core

Functions

apply_operation(→ numpy.ndarray)

Applies a sequence of operations to an array based on a mesh size to normalize and discretize values.

translate_array(→ numpy.ndarray)

Translate values in an array using a dictionary mapping (vectorized).

group_and_label_cells(→ numpy.ndarray)

Convert non-zero numbers in a 2D numpy array to sequential IDs starting from 1.

process_grid_optimized(→ numpy.ndarray)

Optimized version that computes per-building averages without allocating huge arrays

process_grid(→ numpy.ndarray)

Safe version that tries optimization first, then falls back to original method.

calculate_grid_size(→ Tuple[Tuple[int, int], ...)

Calculate grid size and adjusted mesh size based on input parameters.

create_coordinate_mesh(→ numpy.ndarray)

Create a coordinate mesh based on input parameters.

create_cell_polygon(origin, i, j, adjusted_meshsize, ...)

Create a polygon representing a grid cell.

compute_grid_geometry(...)

Compute full grid geometry from rectangle vertices and mesh size.

compute_cell_center_coords(→ dict)

Compute (lon, lat) coordinates for each grid cell center.

compute_grid_shape(→ Tuple[int, int])

Compute the grid dimensions (rows, cols) for a given rectangle and mesh size.

normalize_gdf_crs(gdf[, assume_epsg])

Return gdf re-projected to assume_epsg.

bbox_from_vertices(→ shapely.geometry.box)

Return a shapely box covering rectangle_vertices (lon, lat) pairs.

Module Contents

voxcity.geoprocessor.raster.core.apply_operation(arr: numpy.ndarray, meshsize: float) numpy.ndarray[source]

Applies a sequence of operations to an array based on a mesh size to normalize and discretize values.

  1. Divide by meshsize, 2) +0.5, 3) floor, 4) rescale by meshsize

voxcity.geoprocessor.raster.core.translate_array(input_array: numpy.ndarray, translation_dict: Dict[Any, Any]) numpy.ndarray[source]

Translate values in an array using a dictionary mapping (vectorized).

Any value not found in the mapping is replaced with an empty string. Returns an object-dtype ndarray preserving the input shape.

voxcity.geoprocessor.raster.core.group_and_label_cells(array: numpy.ndarray) numpy.ndarray[source]

Convert non-zero numbers in a 2D numpy array to sequential IDs starting from 1.

voxcity.geoprocessor.raster.core.process_grid_optimized(grid_bi: numpy.ndarray, dem_grid: numpy.ndarray) numpy.ndarray[source]

Optimized version that computes per-building averages without allocating huge arrays when building IDs are large and sparse.

voxcity.geoprocessor.raster.core.process_grid(grid_bi: numpy.ndarray, dem_grid: numpy.ndarray) numpy.ndarray[source]

Safe version that tries optimization first, then falls back to original method.

voxcity.geoprocessor.raster.core.calculate_grid_size(side_1: numpy.ndarray, side_2: numpy.ndarray, u_vec: numpy.ndarray, v_vec: numpy.ndarray, meshsize: float) Tuple[Tuple[int, int], Tuple[float, float]][source]

Calculate grid size and adjusted mesh size based on input parameters. Returns ((nx, ny), (dx, dy))

voxcity.geoprocessor.raster.core.create_coordinate_mesh(origin: numpy.ndarray, grid_size: Tuple[int, int], adjusted_meshsize: Tuple[float, float], u_vec: numpy.ndarray, v_vec: numpy.ndarray) numpy.ndarray[source]

Create a coordinate mesh based on input parameters. Returns array of shape (coord_dim, ny, nx)

voxcity.geoprocessor.raster.core.create_cell_polygon(origin: numpy.ndarray, i: int, j: int, adjusted_meshsize: Tuple[float, float], u_vec: numpy.ndarray, v_vec: numpy.ndarray)[source]

Create a polygon representing a grid cell.

voxcity.geoprocessor.raster.core.compute_grid_geometry(rectangle_vertices, meshsize: float) voxcity.utils.projector.GridGeom | None[source]

Compute full grid geometry from rectangle vertices and mesh size.

Returns a GridGeom dict with keys: origin, side_1, side_2, u_vec, v_vec, grid_size, adj_mesh, meshsize_m — or None if inputs are insufficient.

voxcity.geoprocessor.raster.core.compute_cell_center_coords(rectangle_vertices, meshsize: float) dict[source]

Compute (lon, lat) coordinates for each grid cell center.

Works correctly for both axis-aligned and rotated rectangles. Cell (i, j) centre = origin + (i+0.5)*dx*u_vec + (j+0.5)*dy*v_vec.

Returns a dict with all keys from compute_grid_geometry() plus: - lons : ndarray of shape grid_size with cell-centre longitudes - lats : ndarray of shape grid_size with cell-centre latitudes

Returns None when rectangle_vertices is insufficient.

voxcity.geoprocessor.raster.core.compute_grid_shape(rectangle_vertices, meshsize: float) Tuple[int, int][source]

Compute the grid dimensions (rows, cols) for a given rectangle and mesh size.

This is useful when you need to know the output grid shape without actually creating the grid (e.g., for pre-allocating arrays or fallback shapes).

Parameters:
  • rectangle_vertices – List of 4 vertices [(lon, lat), …] defining the rectangle.

  • meshsize – Grid cell size in meters.

Returns:

Tuple of (grid_size_0, grid_size_1) representing grid dimensions.

voxcity.geoprocessor.raster.core.normalize_gdf_crs(gdf, assume_epsg: int = 4326)[source]

Return gdf re-projected to assume_epsg.

If the GeoDataFrame has no CRS, EPSG:4326 is assumed with a warning.

voxcity.geoprocessor.raster.core.bbox_from_vertices(rectangle_vertices: List[Tuple[float, float]]) shapely.geometry.box[source]

Return a shapely box covering rectangle_vertices (lon, lat) pairs.