Retour : page principale > sommaire eFlore v5 > sommaire intégration > sommaire projets

OSM


Ressources

FR : communes

Vérifier que org2ogr support le format OSM et Mysql : ogrinfo --formats|grep "OSM\|MySQL"
Sinon, compiler GDAL avec les formats nécessaires pour utiliser l'utilitaire ogr2ogr.
Extraire les données que vous souhaitez importer dans Mysql à l'aide d'Osmosis.

Configurer Mysql en ajoutant/modifiant dans le fichier my.cnf (/opt/lampp/etc/my.cnf) :
[mysqld]
max_allowed_packet = 32M
wait_timeout = 28800
interactive_timeout = 28800
#skip-networking # à commenter

Créer une base de données (si elle n'existe pas) avec un encodage UTF-8 (de cette façon les tables créer par org2ogr seront dans cet encodage. Passer par une base de données temporaire si nécessaire avant l'intégration dans tb_eflore.
Puis exécuter la commande ci-dessous :
ogr2ogr --config OSM_CONFIG_FILE osmconf.ini \
    --config OSM_MAX_TMPFILE_SIZE 8000 \
    --config MYSQL_UNIX_PORT /opt/lampp/var/mysql/mysql.sock \
    -overwrite \
    -progress \
    -f "MySQL" MYSQL:osm,user=root,password=mot_de_passe,host=localhost,port=3306  \
    -lco engine=MYISAM \
    -lco spatial_index=no \
    fr_communes.osm multipolygons points  \
    > home/jpm/web/eflore/eflore-projets/donnees/osm/log-osm.txt 2>&1

Vérifier les logs, en cas de problème, dans home/jpm/web/eflore/eflore-projets/donnees/osm/.

Exemple de fichier osmconf.ini :
#
# Configuration file for OSM import
#

# put here the name of keys for ways that are assumed to be polygons if they are closed
# see http://wiki.openstreetmap.org/wiki/Map_Features
closed_ways_are_polygons=aeroway,amenity,boundary,building,craft,geological,historic,landuse,leisure,military,natural,office,place,shop,sport,tourism

# comment to avoid laundering of keys ( ':' turned into '_' )
attribute_name_laundering=yes

# uncomment to report all nodes, including the ones without any (significant) tag
#report_all_nodes=yes

# uncomment to report all ways, including the ones without any (significant) tag
#report_all_ways=yes

[points]
# common attributes
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no

# keys to report as OGR fields
attributes=name,place,addr:postcode,ref:SIREN,population,source:population,wikipedia
# keys that, alone, are not significant enough to report a node as a OGR point
unsignificant=created_by,converted_by,source,time,ele
# keys that should NOT be reported in the "other_tags" field
ignore=created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
#other_tags=no

[lines]
# common attributes
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no

# keys to report as OGR fields
attributes=name,highway,waterway,aerialway,barrier,man_made
# keys that should NOT be reported in the "other_tags" field
ignore=created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
#other_tags=no

[multipolygons]
# common attributes
# note: for multipolygons, osm_id=yes instanciates a osm_id field for the id of relations
# and a osm_way_id field for the id of closed ways. Both fields are exclusively set.
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no

# keys to report as OGR fields
attributes=name,type,admin_level,boundary,ref:INSEE,addr:postcode,population,source:population,wikipedia,
# keys that should NOT be reported in the "other_tags" field
ignore=area,created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
#other_tags=no

[multilinestrings]
# common attributes
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no

# keys to report as OGR fields
attributes=name,type
# keys that should NOT be reported in the "other_tags" field
ignore=area,created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
#other_tags=no

[other_relations]
# common attributes
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no

# keys to report as OGR fields
attributes=name,type
# keys that should NOT be reported in the "other_tags" field
ignore=area,created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
#other_tags=no


Convertion, statistiques

Notes
  • il est nécessaire d'utiliser des tables myisam car ce sont les seules à supporter les index spatiaux de type rtree.
  • pour accélérer l'importation, on ne créé par d'index spatiaux (il peut être créé par la suite directement dans Mysql)
  • Si une relation ne forme pas un polygone complet, elle sera ignorée.