Import OSM into Postgres on Wind

2017-01-08  本文已影响0人  CCXJTU_NTU
extra imagination

This image comes from Dribbble.

In order to import OSM data into postgres, some softwares are required.

  1. PostgreSQL, the geo-spacial database, for Windows OS.
  2. PostGIS, a spatial database extender for PostgreSQL object-relational database.

When all the above mentioned softwares are installed, you can start to import OSM data following the details below.

  1. pbf file of targeted region. You can download from multiple websites. Commonly, we use GEOFABRIK.
  2. Osmconvert can be used to convert and process OpenStreetMap files. It can transfer .pbf files into .osm files.
  3. osm2pgsql. It is a tool used to transfer OSM data format to postGIS-enabled PostgreSQL databases.
  4. Osmfilter can extract OSM data with specified tags.

Then you need to open command line to do all the processing and tranformation.

  1. Convert pbf file to osm file:
    osmconvert ./path/to/your/pbf/file/targeted region.pbf > ./path/to/your/expected/osm/file/targeted region.osm
  2. For my application, I need all the road networks:
    osmfilter ./path/to/your/expected/osm/file/targeted region.osm --keep="highway=" -o=./path/to/your/expected/osm/file/with/only/highway/targeted region.osm
  3. Create a PostGIS database and remember the name, password and port number.
    You need to open the PostGIS 2.0 shapefile and DBF Loader and Exporter by clicking the icon after installing PostGIS.
    Then fill all the information into the blank box after clicking View connection detials... button.
    The results can be found in the figure below.
PostGIS 2.0 shapefile and DBF Loader and Exporter
  1. Enable PostGIS on the database:
    Connect to database:
    psql databasename
    In the databased prompt:
    create extension potgis
  2. Import osm file into postgres database:
    osm2pgsql.exe -s -U username -W -d database name -P port number ./path/to/the/osm/file/road.osm
    An example is like:
    osm2pgsql.exe -s -U postgres -W -d sgosm -P 5434 F:\road_network.osm
  3. Input the password of your data base
  4. The success of importing shows "Osm2pgsql took 27s overall".

Then we need to open PostgreSQL to check the results. You need to open the pgAdmin 4 and check whether they are successfully imported. The items are not empty. You can find a successful screen shot below. The brackets have numbers inside, which means the OSM data are imported successfully.

success screenshot

This is a summary when I import OSM files into PostgreSQL database. This database can be easily conneted with Python.

上一篇下一篇

猜你喜欢

热点阅读