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:
Inputs:
x: the x-coordinate of the point.
y: the y-coordinate of the point.
grid_width: the width of each grid cell.
grid_height: the height of each grid cell.
Steps:
Compute the x and y indices:
To calculate the grid cell index in the x-direction (x_index) and y-direction (y_index):
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
andy
, you can calculate the corresponding grid cell index using the following steps:Inputs:
x
: the x-coordinate of the point.y
: the y-coordinate of the point.grid_width
: the width of each grid cell.grid_height
: the height of each grid cell.Steps:
Compute the x and y indices: To calculate the grid cell index in the x-direction (
x_index
) and y-direction (y_index
):This equation divides the x-coordinate of the point by the grid width and takes the floor (integer part) to determine the x-index of the grid cell.
Similarly, divide the y-coordinate by the grid height and take the floor to find the y-index of the grid cell.
Map the 2D index to a 1D index: After finding the x and y indices, you can convert these indices into a 1D index using:
This equation multiplies the y-index by the number of columns in the grid and adds the x-index to get a unique 1D cell ID.