Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/chapters/osm2pgrouting.rst @ 63

Revision 63, 5.8 KB checked in by djay, 8 years ago (diff)

Initial import of pgROuting workshop for translation. Section 1 to 3 translated, pleae review.

RevLine 
[63]1==============================================================================================================
2osm2pgrouting Import Tool
3==============================================================================================================
4
5**osm2pgrouting** is a command line tool that makes it very easy to import OpenStreetMap data into a pgRouting database. It builds the routing network topology automatically and creates tables for feature types and road classes. osm2pgrouting was primarily written by Daniel Wendt and is currently hosted on the pgRouting project site: http://www.pgrouting.org/docs/tools/osm2pgrouting.html
6
7.. note::
8
9        There are some limitations, especially regarding the network size. The current version of osm2pgrouting needs to load all data into memory, which makes it fast but also requires a lot or memory for large datasets. An alternative tool to osm2pgrouting without the network size limitation is **osm2po** (http://osm2po.de). It's available under "Freeware License".
10       
11
12Raw OpenStreetMap data contains much more features and information than need for routing. Also the format is not suitable for pgRouting out-of-the-box. An ``.osm`` XML file consists of three major feature types:
13
14* nodes
15* ways
16* relations
17
18The data of sampledata.osm for example looks like this:
19
20.. literalinclude:: code/osm_sample.osm
21        :language: xml
22
23Detailed description of all possible OpenStretMap types and classes can be found here:  http://wiki.openstreetmap.org/index.php/Map_features.
24
25When using osm2pgrouting, we take only nodes and ways of types and classes specified in ``mapconfig.xml`` file that will be imported into the routing database:
26
27.. literalinclude:: code/mapconfig_sample.xml
28        :language: xml
29
30The default ``mapconfig.xml`` is installed in ``/usr/share/osm2pgrouting/``.
31
32
33-------------------------------------------------------------------------------------------------------------
34Create routing database
35-------------------------------------------------------------------------------------------------------------
36
37Before we can run osm2pgrouting we have to create a database and load PostGIS and pgRouting functions into this database.
38If you have installed the template databases as described in the previous chapter, creating a pgRouting-ready database is done with a single command. Open a terminal window and run:
39
40.. code-block:: bash
41
42        createdb -U postgres -T template_routing routing
43       
44... and you're done.
45
46Alternativly you can use **PgAdmin III** and SQL commands. Start PgAdmin III (available on the LiveDVD), connect to any database and open the SQL Editor and then run the following SQL command:
47
48.. code-block:: sql
49
50        -- create routing database
51        CREATE DATABASE "routing" TEMPLATE "template_routing";
52
53
54Otherwise you need to manually load several files into your database. See :ref:`previous chapter <installation_load_functions>`.
55
56       
57-------------------------------------------------------------------------------------------------------------
58Run osm2pgrouting
59-------------------------------------------------------------------------------------------------------------
60
61The next step is to run ``osm2pgrouting`` converter, which is a command line tool, so you need to open a terminal window.
62
63We take the default ``mapconfig.xml`` configuration file and the ``routing`` database we created before. Furthermore we take ``~/Desktop/pgrouting-workshop/data/sampledata.osm`` as raw data. This file contains only OSM data from downtown Denver to speed up  data processing time.
64
65The workshop data is available as compressed file, which needs to be extracted first either using file manager or with this command:
66
67.. code-block:: bash
68
69        cd ~/Desktop/pgrouting-workshop/
70        tar -xvzf data.tar.gz
71
72Then run the converter:
73       
74.. code-block:: bash
75
76        osm2pgrouting -file "data/sampledata.osm" \
77                                  -conf "/usr/share/osm2pgrouting/mapconfig.xml" \
78                                  -dbname routing \
79                                  -user postgres \
80                                  -clean
81                                       
82List of all possible parameters:
83
84.. list-table::
85   :widths: 15 15 60 10
86
87   * - **Parameter**
88     - **Value**
89     - **Description**
90     - **Required**
91   * - -file
92     - <file>
93     - name of your osm xml file
94     - yes
95   * - -dbname
96     - <dbname>
97     - name of your database
98     - yes
99   * - -user
100     - <user>
101     - name of the user, which have write access to the database
102     - yes
103   * - -conf
104     - <file>
105     - name of your configuration xml file
106     - yes
107   * - -host
108     - <host>
109     - host of your postgresql database (default: 127.0.0.1)
110     - no
111   * - -port
112     - <port>
113     - port of your database (default: 5432)
114     - no
115   * - -passwd
116     - <passwd>
117     - password for database access
118     - no
119   * - -clean
120     -
121     - drop peviously created tables
122     - no
123
124.. note::
125
126        If you get permission denied error for postgres users you can set connection method to ``trust`` in ``/etc/postgresql/8.4/main/pg_hba.conf`` and restart PostgreSQL server with ``sudo service postgresql-8.4 restart``.
127
128
129Depending on the size of your network the calculation and import may take a while. After it's finished connect to your database and check the tables that should have been created:
130
131.. rubric:: Run: ``psql -U postgres -d routing -c "\d"``       
132
133If everything went well the result should look like this:
134       
135.. code-block:: sql
136
137                             List of relations
138         Schema |        Name         |   Type   |  Owner   
139        --------+---------------------+----------+----------
140         public | classes             | table    | postgres
141         public | geometry_columns    | table    | postgres
142         public | nodes               | table    | postgres
143         public | spatial_ref_sys     | table    | postgres
144         public | types               | table    | postgres
145         public | vertices_tmp        | table    | postgres
146         public | vertices_tmp_id_seq | sequence | postgres
147         public | ways                | table    | postgres
148        (8 rows)
149
150       
151
Note: See TracBrowser for help on using the repository browser.