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 ).


1 Answer 1


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 planet-latest.osm.bz2 --node-key-value keyValueList="place.city,admin_level.2"  --write-xml - |osm2pgsql --append [my customized arguments] -
  • 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="place.city,admin_level.2" --write-xml - | osm2pgsql -c -s -d OSMTest -U postgres -H -P 5432 -S ./default.style
    – Magno C
    Nov 26, 2012 at 14:59
  • @underdark : Thanks for correcting my text, teacher!
    – Magno C
    Nov 26, 2012 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, 2012 at 18:50
  • The answer is here : link
    – Magno C
    Dec 14, 2012 at 14:14

Your Answer

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

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