To use the PostGIS Data Reader for GraphHopper described in the previous post, please do the following:
Download the package in https://github.com/mbasa/graphhopper. As of this writing, the most stable can be found
postgis-0.11 branch. So change the branch from
master and download the package as a ZIP file.
Un-zip the downloaded file. Ensure the Java is installed in the system.
Build the source code by issuing a
./graphhopper.sh build in the command line. This will download Maven if it is not installed in the system, and compile all the source files.
Uncomment the PostGIS parameters in the
config.yml and set the appropriate values. The PostGIS reader will only be used if all the PostGIS parameters are set.
Prepare the road network data in PostgreSQL. The following columns have to be part of the table or view that will be used for conversion:
osm_id, maxspeed, oneway, fclass, name, geom
For example, to create a View:
CREATE VIEW myroad_view
(osm_id, maxspeed, oneway, fclass, name, geom)
AS SELECT id, 0, oneway, 'tertiary'::text, name, geom FROM custom_road_network;
Start the GraphHopper server by adding the parameter
/<path where graph will reside>/<table or view name>. The example below will create a graph
/Users/mbasa/t for the
myroad_view view of PostgreSQL:
./graphhopper.sh web /Users/mbasa/t/myroad_view
If the data in PostgreSQL changes and the graph has to be updated, just delete the created graph directory and restart GraphHopper using the above method.