blockparty-team / blockparty

https://blockparty.dev
MIT License
3 stars 2 forks source link

In-app map routing/directions #140

Open baffioso opened 1 year ago

baffioso commented 1 year ago

Currently user get redirected to google maps for directions. pgRouting is available as extension in Supabase and could be used to generate in-app directions on the map. A postgres function with from and to coordinates as arguments can return route as GeoJSON LineString. This function can be exposed to the app using rpc

To setup pgRouting OSM data needs to be imported and processed in postgres.

Import https://pgrouting.org/docs/tools/osm2pgrouting.html https://osm2po.de/

Getting started https://www.crunchydata.com/blog/routing-with-postgresql-and-crunchy-spatial https://mapscaping.com/getting-started-with-pgrouting/

baffioso commented 1 year ago

@jschristensen tempting to enable in-app directions

baffioso commented 1 year ago

Importing OSM data to PostgreSQL

  1. Download OSM data: https://download.geofabrik.de/europe/denmark-latest.osm.bz2
  2. Unzip
  3. Download mapconfig.xml:
    curl -o mapconfig.xml https://raw.githubusercontent.com/pgRouting/osm2pgrouting/main/mapconfig.xml
  4. Install osm2pgrouting:
    brew install osm2pgrouting
  5. Run local supabase (supabase start) and create routing schema for the data and enable pgRouting extension
    create schema routing;
    create extension pgrouting;
  6. Import data to Postgres (get pg connection string from local running supabase supabase status)
    osm2pgrouting -f denmark-latest.osm -c mapconfig.xml --schema routing -d postgres -U postgres --port 54322 -W postgres

    ✅ Done

TODO: Download smaller OSM area (Copenhagen). No need to process all Denmark

Create function for routing