How can I store road maps in postGIS?

604 Views Asked by At

How do I export a OSM road map into a postGIS database? Also if I have the the coordinates of the intersections can I get the section of the road that I need?

Any help would be appreciated. Thanks!

1

There are 1 best solutions below

3
On BEST ANSWER

You can use the osm2pgsql tool, which supports osm xml (*.osm).

Basic usage:

osm2pgsql -d your_geo_database your-osm-data.osm.bz2

This command imports the your-osm-data.osm.bz2 file in the your_geo_database database.

The database must exist and must have the postgis extension loaded.

Yes, you can import only a part of you osm data by specifying the bounding box you want to import using the --bbox option and comma separated coordinates as minlon,minlat,maxlon,maxlat, i.e:

osm2pgsql -l -d your_geo_database --boxx -0.5,51.25,0.5,51.75 you-osm-data.osm.bz2

You can not specify the section of roads you need using a point, but you can construct a bounding box around this point, i.e. a square 100m X 100m

Type

osm2pgsql --help

to see all options.

Same important options are:

-l : Store data in degrees of latitude & longitude (srid 4326)

-a : Add the OSM file into the database without removing existing data.

-d -H -U -W -P: database connection options: database name, host, username, password, port.

If your osm file is too big, you will probably need to use some options which optimize the memory usage, i.e.: --cache-strategy, --slim or --unlogged