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!
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!
Copyright © 2021 Jogjafile Inc.
You can use the osm2pgsql tool, which supports osm xml (*.osm).
Basic usage:
This command imports the
your-osm-data.osm.bz2
file in theyour_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: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
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