I am trying to import selected features from Quantum GIS to postgresql directly. I do not know how to do it.

Actually, my problem is, I have full country road network. But, I need to cut road network of a small area. If i import full country road network using Quantum GIS to postgresql, I can do it. But, I can not import small area road network after extracting that small area. Something, has been change after cutting sample area. But, I do not know what it is?? It is very strange.

If anyone have the solution. Please let me know.

  • 1
    What is the source of your data? There are a lot of tools that let you import a bounding box from some source format into postgresql.
    – mrg
    Jan 22, 2012 at 10:16
  • my raw data is in shape file format. Actually I got it from OpenStreetMap website. it is the shapefile of road network of total Sweden.
    – Shahjalal
    Jan 22, 2012 at 16:13

1 Answer 1


As you got your data from OSM i assume you can also get the data in .osm.bz2 format. I also assume you are using linux.

See: http://download.geofabrik.de/osm/europe/sweden.osm.bz2

Then find out what the bounding box is that you want to work with. If you go to www.openstreetmap.nl. Go to the map and then zoom to Sweden the lat,lon is shown in the top right of your screen. Let's say the bouding box is top=54.0, bottom=53.0, left=6.0, right=7.0 (yes i am aware this is not Sweden).

Install osmosis and bzip2 with the package manager.

Then do the following command to get a dataset that only consists out of the area you are interested in:

sudo bzcat sweden.osm.bz2 | osmosis --read-xml enableDateParsing=no file=- --bounding-box top=54.0 left=6.0 bottom=53.0 right=7.0 --write-xml file=-| sudo bzip2 > part_of_sweden_you_are_interested_in.osm.bz2

Then uncompress your file:

bzcat part_of_sweden_you_are_interested_in.osm.bz2 > part_of_sweden_you_are_interested_in.osm

I assume you want to route over your network, so you have to install pgrouting and osm2pgrouting. There are several guides on the internet how to do this as i don't know your specific OS and version.

You already have a postgresql database with postgis extension. Make sure it also has the pgrouting extension. After that do:

osm2pgrouting -file part_of_sweden_you_are_interested_in.osm -conf mapconfig.xml -dbname your_db -user your_user -clean -host localhost -passwd your_pwd

Now you not only have a database with just the area you are interested in, but also routing tools to work with this data.

  • Thanks, a lot for your details. Could you please help me little more? Actually, I am using windows 7 platform. I already installed PostgreSQL/PostGIS and pgRouting. My problem is data. I want to import a small area's road network into my database from this full country road network. Is there any plugin in qgis or any other way to do this? I tried it before. I can extract this small area such as Stockholm road network. But after extraction, i can not import it to my database. It shows some sql error. But, without this extraction i can easily import whole country road network. It is strange.
    – Shahjalal
    Jan 23, 2012 at 2:06
  • The extract that you do have i that in shapefile format too? If so then you can just use shp2pgsql to import it into postgresql.
    – mrg
    Jan 23, 2012 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.