NREL / routee-compass

An energy-aware routing engine
https://nrel.github.io/routee-compass/
BSD 3-Clause "New" or "Revised" License
10 stars 5 forks source link

route_to_geopandas function #210

Closed nreinicke closed 4 months ago

nreinicke commented 4 months ago

To support #200, we should create a new function route_to_geopandas that converts the "route" key of the result (python dictionary) into a geopandas dataframe with the following information:

Summary row data

Any row in a route GeoDataFrame should have all traversal and cost columns that may be relevant to post-processing:

column mapping
_index (user-defined index_col path, or, by default, the top-level index value in the Compass output)
distance traversal_summary.distance
time traversal_summary.time
...  
distance_cost cost.distance
time_cost cost.time
total_cost cost.total_cost

Summary row data

Any row in a route GeoDataFrame should have all traversal and cost columns that may be relevant to post-processing: column mapping _index (user-defined index_col path, or, by default, the top-level index value in the Compass output) distance traversal_summary.distance time traversal_summary.time ...
distance_cost cost.distance time_cost cost.time total_cost cost.total_cost

All of these should be set only if they exist (optional semantics). Geo row identifiers

The route geometries are parsed as geometry objects. A _path column is added to the dataframe in the case that there is more than one path. The value is the route.path index. run() result description route column? one route {} route.path has one entry no n routes [] route.path has i entries append _path column with value i

As a result, a row is uniquely indexed by the _index column when there is one route per row, and a combination of _index and _path when route.path has more than one entry. Put another way: we end up with k * q rows for q queries and k paths. Geometry data

We need to cover the possible geometry output types. We can know in advance what the geometry type is by inspecting the configuration of the CompassApp (via https://github.com/NREL/routee-compass/issues/201). We can then switch our geometry parsing method accordingly: Compass traversal.route config value parse method for string s json (no geometry) wkt shapely.wkt.loads(s) geojson shapely.ops.shape(s)