Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize profile calculation #67

Open
schroedtert opened this issue Jul 19, 2022 · 2 comments
Open

Optimize profile calculation #67

schroedtert opened this issue Jul 19, 2022 · 2 comments
Labels
optimization Anything related to enhance the execution time profiles Anything related to computing profiles

Comments

@schroedtert
Copy link
Collaborator

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

@schroedtert schroedtert added profiles Anything related to computing profiles optimization Anything related to enhance the execution time labels Jul 19, 2022
@chraibi
Copy link
Collaborator

chraibi commented Mar 17, 2024

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

@chraibi
Copy link
Collaborator

chraibi commented Apr 4, 2024

@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
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Anything related to enhance the execution time profiles Anything related to computing profiles
Projects
None yet
Development

No branches or pull requests

2 participants