-
-
Notifications
You must be signed in to change notification settings - Fork 367
How to: v1.x
pgRouting v1.x
- Is no longer supported
- This page is Historical
Here you can find the "How to" for that version.
- Author: Kai Behncke (edited by Daniel Kastl)
- License: Creative Commons
In that case as an example from Osnabrück ... (in lower Saxony(Germany))
Getting your own OpenStreetMap-Routing-data is not the easiest step in the world. Do you know that you need data with a real topology?
In general, Shapefiles should have one, but be very careful with OSM-Shapefiles. For most thing they work very nice, you get them e.g. from here: http://download.geofabrik.de/osm/
But please don`t use these Shapefiles (and shp2pgsql) for a routing and have a look at that discussion:
http://lists.postlbs.org/pipermail/pgrouting-users/2009-April/000096.html
Many thanks to Daniel KASTL who brought the needed information:
... shp2pgsql imports the geometry correctly, but the topology function will not work with how OSM represents their ways, because ways consist (can consist) of more than one edge often.
osm2pgrouting cares about this and splits a way into more edges if they cross each other. It then automatically does the assign_vertex topology script and adds a few more tables to keep information about road types and classes.
To get your own data you need to work with .osm (XML) files.
Please download the .osm-data from lower Saxony (Niedersachsen.osm.bz2), e.g. from here:
http://download.geofabrik.de/osm/europe/germany/
And then install osmosis, a very nice tool to work with osm-data, The wiki-site for osmosis you find here:
http://wiki.openstreetmap.org/wiki/Osmosis
You need to extract the data from Osnabrück out of Lower Saxony, it works like that:
osmosis --read-xml niedersachsen.osm --bb left=7.917 right=8.1694 \
top=52.3537 bottom=52.3537 --write-xml osnabrueck.osm
Now, you have the "real"-OSM-XML-Data from Osnabrück but without a topology.
For that, you need the tool "osm2pgrouting". After you have loaded the .osm-File in the database via osm2pgrouting, the table-structure should look like:
.. image:: img/database.png :scale: 100% :align: center
- Author: Kai Behncke (edited by Daniel Kastl)
- License: Creative Commons
Nearly a standard are the well-known ESRI-Shapefiles that consist of -at least - a .dbf-File, a .shp-File and a .shx-File.
These files mostly have already a topology.
If you have installed postgresql a tool called "shp2pgsql" will exist on your computer. You can transform your data into the sql-format doing:
shp2pgsql /home/mydata/roads.shp newtable >/home/mydata/roads.sql“
For test-purposes you can take data from British Columbia (nrn_rrn_bc_shp_en.zip).
You get it from the GeoBase <http://geobase.ca/geobase/en/data/nrn/index.html>
_
"National Road Network" dataset.
Please be aware: Don`t use OpenStreetMap-Shapefiles, as thew will create some problems because of their structure.
That sql-file that was created by shp2pgsql you need to bring in your routing-database.
- Author: Daniel Kastl
- License: Creative Commons
SELECT
count(gid) AS links,
sum(a.cost) AS cost,
sum(length) AS length
FROM shortest_path(
'SELECT gid AS id,
source::integer,
target::integer,
length::double precision AS cost
FROM <TABLE A>
WHERE <...>,
false,
false
) AS a LEFT JOIN <TABLE B> ON (a.gid = gid)
Note:
If you have some SQL commands to share, that are useful for pgRouting,send an email to project@pgrouting.org for further information.
- Author: Kaib Behncke (edited by Daniel Kastl)
- License: Creative Commons
An important thing is to test if your data work properly for routing. If you are more or less fit to UMN MapServer you can easily do some tests. First of all many thank to Stephen WOODBRIDGE for that idea.
You need to type the following commands on your vertices_tmp-table
alter table vertices_tmp add column cnt integer;
update vertices_tmp set cnt=0;
update vertices_tmp set cnt=cnt+1 from ways where ways.source=vertices_tmp.id;
update vertices_tmp set cnt=cnt+1 from ways where ways.target=vertices_tmp.id;
This will display red dots at dead ends and green dots as good connections be segments.
You can visualize it with the UMN MapServer, just take a mapfile like:
MAP
NAME 'mymap'
STATUS ON
#EXTENT 3427065.200000 5788323.530000 3443999.370000 5800691.660000
#EXTENT 7.9189 52.2102 8.1716 52.3467
EXTENT 880000 6840000 915000 6860000
IMAGECOLOR 255 255 255
SIZE 700 700
SYMBOLSET '/your_path/symbols/symbols.sym'
FONTSET '/your_path/fonts/fonts.list'
WEB
TEMPLATE 'template.html'
IMAGEPATH '/your_path/tmp/'
IMAGEURL '/tmp/'
METADATA
'WMS_TITLE' 'Gastronomap_routing'
'WMS_FEATURE_INFO_MIME_TYPE' 'text/html'
'WMS_ONLINERESOURCE' 'http://localhost/cgi-bin/mapserv?map=/your_path/routing.map'
'WMS_SRS' "EPSG:900913"
END
END
PROJECTION
'init=epsg:900913'
END
LAYER
OFFSITE 255 255 255
#LABELITEM 'name'
TOLERANCE 20
NAME 'streets'
TYPE LINE
STATUS DEFAULT
CONNECTIONTYPE postgis
CONNECTION 'user=postgres password=postgres dbname=routing host=localhost port=5432'
DATA 'the_geom from ways as foo using unique gid using SRID=900913'
CLASSITEM 'gid'
TEMPLATE 'ausgabe.phtml'
METADATA
'WMS_TITLE' 'streets'
'WMS_SRS' "EPSG:900913"
'WMS_INCLUDE_ITEMS' 'all'
END
CLASS
TEXT ([gid],[source],[target])
EXPRESSION /./
STYLE
WIDTH 1
COLOR 0 0 0
END
LABEL
TYPE TRUETYPE
ANTIALIAS TRUE
FONT 'arial'
COLOR 0 0 0
BACKGROUNDCOLOR 240 240 240
POSITION cc
MINSIZE 8
MAXSIZE 12
BUFFER 2
END
END
END
LAYER
OFFSITE 255 255 255
#LABELITEM 'name'
TOLERANCE 20
NAME 'dead_ends'
TYPE POINT
STATUS DEFAULT
CONNECTIONTYPE postgis
CONNECTION 'user=postgres password=postgres dbname=routing host=localhost port=5432'
DATA 'the_geom from vertices_tmp as foo using unique id using SRID=900913'
CLASSITEM 'cnt'
TEMPLATE 'ausgabe.phtml'
METADATA
'WMS_TITLE' 'dead_ends'
'WMS_SRS' "EPSG:900913"
'WMS_INCLUDE_ITEMS' 'all'
END
CLASS
Text ([id])
EXPRESSION /1/
STYLE
SYMBOL 'tent'
SIZE 11
COLOR 255 0 0
END
LABEL
TYPE TRUETYPE
ANTIALIAS TRUE
FONT 'arial'
COLOR 255 0 0
BACKGROUNDCOLOR 240 240 240
POSITION cr
MINSIZE 8
MAXSIZE 12
BUFFER 2
END
END
CLASS
TEXT ([id])
EXPRESSION /./
STYLE
SYMBOL 'tent'
SIZE 11
COLOR 0 0 255
END
LABEL
TYPE TRUETYPE
ANTIALIAS TRUE
FONT 'arial'
COLOR 0 0 255
BACKGROUNDCOLOR 240 240 240
POSITION cr
MINSIZE 8
MAXSIZE 12
BUFFER 2
END
END
END
END
If you open your MapServer-testing-apllication via: http://localhost/cgi-bin/mapserv?map=/var/www/gastronomap_wms/gastronomap_routing.map
and you zoom in you get something like:
Everything fine with the data ! :-)
But if it looks like:
Definitely something went wrong........