Skip to content

Optimize profile calculation #67

Open

Description

@schroedtert

Currently the profiles are computed for all grid cells in the bounding box of the geometry, see:
image

But as one can see a lot these cells may lie outside of the geometry, and do not need to be computed, see:
image

Activity

  1. added
    profiles
    optimization
    on Jul 19, 2022
  2. chraibi commented on Mar 17, 2024

    @chraibi
    Collaborator

    Is this still an issue with WalkableAreas? Can you upload an example?

  3. chraibi commented on Apr 4, 2024

    @chraibi
    Collaborator

    @schroedtert

    What if we check cells within the walkable area?

    def get_grid_cells(
        *, walkable_area: shapely.geometry.Polygon, grid_size: float
    ) -> Tuple[npt.NDArray[shapely.geometry.Polygon], int, int]:
        """Creates a list of square grid cells covering the geometry, considering only those cells whose centroids are within the walkable area."""
        bounds = walkable_area.bounds
        min_x, min_y, max_x, max_y = bounds
    
        x_coords = np.arange(min_x, max_x + grid_size, grid_size)
        y_coords = np.arange(max_y, min_y - grid_size, -grid_size)
    
        grid_cells = []
        for j in range(len(y_coords) - 1):
            for i in range(len(x_coords) - 1):
                grid_cell = shapely.geometry.box(x_coords[i], y_coords[j], x_coords[i + 1], y_coords[j + 1])
                if walkable_area.contains(grid_cell.centroid):
                    grid_cells.append(grid_cell)
    
        return np.array(grid_cells), len(y_coords) - 1, len(x_coords) - 1
        
    
  4. M-Colley commented on Nov 21, 2026

    @M-Colley

    Opened #599 addressing this optimization.

    Note on preserving (rows, cols) shape: compute_profiles, compute_density_profile, compute_speed_profile, and plot_profiles (imshow) expect each frame's profile array to reshape cleanly into (rows, cols) over the bounding box. By pre-filtering active grid cells whose interiors overlap walkable_area.polygon (shapely.intersects & ~shapely.touches) once and indexing only those active cells in a shapely.STRtree, all grid cells outside the walkable geometry (as well as non-overlapping cell-polygon pairs inside it) are completely skipped during polygon intersection while keeping exact (rows, cols) output arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    optimizationprofiles

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions