This refer to this post : Read Here

I'm in trouble when using osmosis command line to export data from planet-latest.osm.bz2 directly to osm2pgsql using some criteria to select what to transfer.

I think is more easy to export planet-latest.osm.bz2 to an XML with osmosis and then use osm2pgsql to import to Postgre, but I can't go further. So I need help in osmosis parameters to show how can I to export data using filters like

--place='city' --admin_level='2'

and import to Postgre using osm2pgsql.

Sorry about this very similar post, but the user was helping me was gived up.

1 Answer 1


Firstly, you can download OSM extracts that are already filtered by country/region/city directly from CloudMade: http://downloads.cloudmade.com/

Secondly, the reason your command isn't working is because osm2pgsql requires a filename to be passed in. On Linux you would use /dev/stdin (and this is what the osm2pgsql docs tell you to do) but it looks like you're on Windows. Try the standard filename - used by most linux-native programs (from the source code it looks like this should work):

osmosis --read-pbf-fast south-america.osm.bz2 --node-key-value keyValueList="place.city,admin_level.2" --write-xml output.xml | osm2pgsql -c -s -d OSMTest -U postgres -H -P 5432 -S ./default.style -
  • 1
    cloudmade extracts are good if you don't care too much about data currency: gis.stackexchange.com/questions/29250/…
    – tomfumb
    Commented Dec 11, 2012 at 17:50
  • I don't want to work on filtered extracts. I need to work on planet-latest.osm.bz2 and select my own extracts. Anyway, the code in your example looks the same I show in the other post. Where can I put the stdin you show? Why this don't work in planet-latest.osm.bz2 ? I can work on Ubuntu with no problems, so you can tell me linux language.
    – Magno C
    Commented Dec 12, 2012 at 10:50
  • Well, trying the first part ( only osmosis export ) I received a Java heap OutOfMemory error. I need to solve this before reward you. If the osmosis export to XML works fine, the import to osm2pgsql will be easy. I don't care about making the process in two steps.
    – Magno C
    Commented Dec 12, 2012 at 11:11
  • 1
    Solved the out of memory error by setting JAVACMD_OPTIONS = -Xmx2048m -XX:MaxPermSize=256m -XX:PermSize=64M. Now I'm getting "Unable to get next blob from PBF stream" error.
    – Magno C
    Commented Dec 12, 2012 at 12:16
  • 1
    Worked. the 2 steps process worked. After the export with osmosis --read-xml brazil.osm.bz2 --node-key-value keyValueList="place.city,admin_level.2" --write-xml output.osm I do osm2pgsql -c -s -d OSMTest -U postgres -W -H -P 5432 ./output.osm -S ./default.style and the data was imported the way I need. Next I will try put all togeter in one step and try with planet-latest.osm.bz2.
    – Magno C
    Commented Dec 12, 2012 at 12:49

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.