asu-trans-ai-lab / grid2demand

A tool for generating zone-to-zone travel demand based on grid zones and gravity model
Apache License 2.0
71 stars 21 forks source link

Implement Point-to-Grid Mapping and Closest Zone Detection Algorithm using a simple spatial index system #30

Open asu-trans-ai-lab opened 2 weeks ago

asu-trans-ai-lab commented 2 weeks ago

For each possible activity node (where zone_id is positive in the node.csv generated by osm2gmns), we need to assign a zone_id from the TAZ system to the corresponding node in the updated node.csv. This is a feature where, for each node, we need to find the closest zone ID. Similarly, for each POI, we need to find the closest zone.

Feature Enhancement: We need to implement an algorithm that maps an activity node (x, y) to a specific grid cell based on grid size. The algorithm should retrieve the subset of zones associated with the grid cell, compute the distances between the node and the zones, and identify the closest zone. If no zone is available in the cell, the algorithm should exit and search for the closest zone in adjacent cells.

Tasks: Implement a function to map a point (x, y) to a grid cell. Retrieve the subset of zones for each grid cell. Compute the distances between the node and the zones. Identify and return the closest zone based on the computed distances.

Expected Behavior: The algorithm should correctly map a node to its grid cell using X_index and Y_index. The subset of zones for each grid cell should be efficiently retrieved. Distances between the node and the zones should be accurately computed (centroid-based or boundary-based, depending on requirements). The closest zone should be selected and its ID returned.

1. Mapping a Point (x, y) to a Grid Cell

For any continuous coordinates x and y, you can calculate the corresponding grid cell index using the following steps: