4

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

Thanks.

underdark
  • 84,148
  • 21
  • 231
  • 413
Magno C
  • 2,140
  • 3
  • 24
  • 63

1 Answers1

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] -
JaakL
  • 2,156
  • 2
  • 13
  • 20
  • 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 10.5.112.210 -P 5432 -S ./default.style – 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