Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to select what to import from planet-latest.osm.bz2 to database?

I want to do something like :

osm2pgsql ...  --place='city' --admin_level='2'

My goal is to use only cities and countries im my project ( maybe towns ). I can download many databases with cities and countries shapes from the world, but I think OSM is more complete and if I decide to use other things is just import again.

I just try import all full planet data and then SELECT and INSERT in other database using SQL filters, but its too time-consuming ( and non-professional ).


share|improve this question
up vote 1 down vote accepted

You should use osmosis to filter OSM file to another OSM file and then osm2pgsql to import it. You can do it with single command using pipe as following

osmosis --read-pbf-fast planet-latest.osm.bz2 --node-key-value keyValueList=",admin_level.2"  --write-xml - |osm2pgsql --append [my customized arguments] -
share|improve this answer
I got an "Usage Error" since ommited the filename from osm2pgsql ( I thing its correct ) : D:\osm2pgsql>osmosis --read-pbf-fast south-america.osm.bz2 --node-key-value keyValueList=",admin_level.2" --write-xml - | osm2pgsql -c -s -d OSMTest -U postgres -H -P 5432 -S ./ – Magno C Nov 26 '12 at 14:59
@underdark : Thanks for correcting my text, teacher! – Magno C Nov 26 '12 at 15:09
can you explain your answer to me? Still not work because I don't know how to mix you example with my arguments. Thanks. – Magno C Nov 27 '12 at 18:50
The answer is here : link – Magno C Dec 14 '12 at 14:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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