-
Notifications
You must be signed in to change notification settings - Fork 10
Importing Data Using Osm2Po
Below are the steps that can be used to import OSM road networks and create topologies that can be used for pgrServer services using Osm2Po. Osm2Po is a Java application that converts OSM XML data files into a SQL file output that can be imported into PostgreSQL to create a table that contains the attributes and geometric data of the OSM file, and creates a topology on that data.
For this example, the latest U.K. road network will be imported. This example also presupposes that PostgreSQL and PostGIS have already been successfully installed.
-
download Osm2Po
-
apply fix in order for osm2po to create SQL files by uncommenting out the following lines in osm2po.config
postp.0.class = de.cm.osm2po.plugins.postp.PgRoutingWriter
postp.0.writeMultiLineStrings = true
postp.1.class = de.cm.osm2po.plugins.postp.PgVertexWriter
postp.2.class = de.cm.osm2po.plugins.postp.PgPolyWayWriter
postp.3.class = de.cm.osm2po.plugins.postp.PgPolyRelWriter
postp.4.class = de.cm.osm2po.postp.SndExtensionBuilder
postp.5.class = de.cm.osm2po.postp.BndExtensionBuilder
postp.6.class = de.cm.osm2po.postp.MlgExtensionBuilder
postp.6.id = 0
postp.6.maxLevel = 3, 1.0
postp.7.class = de.cm.osm2po.sd.postp.SdGraphBuilder
# Pg*Writer usually create sql files. Enable the following
# parameter to redirect them to stdout (console) e.g.:
postp.1.pipeOut = true
-
download great-britain-latest.osm.pbf from GeoFabrik
-
create the topology for great-britain
java -Xmx2g -jar osm2po-core-5.3.2-signed.jar cmd=c prefix=great_britain great-britain-latest.osm.pbf
- Create a PostgreSQL database named
pgr
.
createdb pgr
- Add the PostGIS extension into the database
pgr
CREATE EXTENSION postgis;
- import the SQL file into PostgreSQL database
pgr
.
psql -f great_britain_2po_4pgr.sql pgr
- create a spatial index on the Geographic Field
create index ukndx on great_britain_2po_4pgr using gist( geom_way );
- do a vacuum full on the table to update the table stats.
VACUUM FULL;
- and finally, create the pgrserver VIEW table that will be used by the pgrServer service.
create view pgrserver as select id,source,target,cost,reverse_cost,km * 1000 as length,
geom_way as geom from great_britain_2po_4pgr ;
NOTE:
- The length has to be in Meters (m) Units.This is the reason why
km
is multiplied by 1000. - The reverse_cost value has to be greater than the cost in order for the edge to be considered as a one-way street.