voxcity.geoprocessor.raster.core¶
Functions¶
|
Applies a sequence of operations to an array based on a mesh size to normalize and discretize values. |
|
Translate values in an array using a dictionary mapping (vectorized). |
|
Convert non-zero numbers in a 2D numpy array to sequential IDs starting from 1. |
|
Optimized version that computes per-building averages without allocating huge arrays |
|
Safe version that tries optimization first, then falls back to original method. |
|
Calculate grid size and adjusted mesh size based on input parameters. |
|
Create a coordinate mesh based on input parameters. |
|
Create a polygon representing a grid cell. |
Compute full grid geometry from rectangle vertices and mesh size. |
|
|
Compute (lon, lat) coordinates for each grid cell center. |
|
Compute the grid dimensions (rows, cols) for a given rectangle and mesh size. |
|
Return gdf re-projected to assume_epsg. |
|
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.
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
GridGeomdict 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 latitudesReturns 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.