Removing all but highways with osmosis


I’m currently trying to remove all elements except highways (relations, buildings, railways, rivers, etc.) from a pbf file of size germany. I want to do that with osmosis 0.39. But it fails even for a single task like removing all relations. I’m doing this with this command:

./osmosis --read-pbf file="file1" --tf reject-relations idTrackerType=BitSet --un --write-pbf file="file2"

edit: I forgot the output of osmosis :confused: :

SCHWERWIEGEND: Thread for task 1-read-pbf failed
java.lang.OutOfMemoryError: Java heap space
    at java.util.ArrayList.<init>(
    at org.openstreetmap.osmosis.core.filter.common.ListIdTracker.ensureListIsSorted(
    at org.openstreetmap.osmosis.core.filter.common.ListIdTracker.get(
    at org.openstreetmap.osmosis.tagfilter.v0_6.UsedNodeFilter.complete(
    at org.openstreetmap.osmosis.tagfilter.v0_6.TagFilter.complete(
    at crosby.binary.osmosis.OsmosisBinaryParser.complete(
    at crosby.binary.file.BlockInputStream.process(
04.06.2011 14:25:56 org.openstreetmap.osmosis.core.Osmosis main
SCHWERWIEGEND: Execution aborted.
org.openstreetmap.osmosis.core.OsmosisRuntimeException: One or more tasks failed.
    at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.waitForCompletion(
    at org.openstreetmap.osmosis.core.Osmosis.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(
    at org.codehaus.classworlds.Launcher.main(

I also tried to set

export JAVACMD_OPTIONS=-Xmx1024M

but it seems not to be working or enough memory.

I learned that “–un” is the problem here but I need the not used nodes to be removed.

Any hints?


Hello & welcome!

Unfortunately I cannot help you with Osmosis but there are other users who certainly can. I just lack experience with Osmosis, sorry.

In case you do not succeed using Osmosis for this task, there is an alternative. But - and that’s a real disadvantage - you cannot write PBF as output. Nevertheless, if you want to try, here is an example:

o5mfilter bremen.osm --keep"highway=" >streets.osm

You can save a lot of time for filtering if you take .o5m for input instead of .osm format:

osmconvert bremen.osm.pbf --out-o5m >bremen.o5m
o5mfilter bremen.o5m --keep"highway=" >streets.osm

If you want to get just major streets, try this:

o5mfilter bremen.o5m --keep"highway=primary =secondary" >streets.osm

If you need just names and nothing else, take this command:

o5mfilter bremen.o5m --keep"highway=primary =secondary" --keep-tags="highway= name=" >streets.osm

and so on…

That works just fine, thank you. :slight_smile:

I have one more problem now. My source files contain nodes from clipped ways so they don’t belong to anything useful. I know they result from my bounding-box operations (“completeWays=no”).

I would like to remove them as well. My approach with osmosis should handle this with the --un parameter. Anyone has a hint to just remove such nodes from an osm-file?

I’m not sure I got that right. There are nodes from outside of your original bounding box? You could exclude these nodes from the file with Osmosis (–bb option). Or you could use osmconvert for this purpose. For example:

osmconvert europe.osm.pbf -b=10,50,11,51 --drop-brokenrefs --out-o5m >my_region.o5m

I’m doing a bounding-box command with osmosis with


The ways with nodes inside and outside of the bbox are dropped but the nodes of these ways that are inside the bbox stay. These are the nodes I want to remove.

I hope this is understandable :confused:

Ok, I think I got you now. Unfortunately, I don’t know haw to do this with Osmosis. Maybe anyone else could help?

Why do you want to exclude these ways completely? Wouldn’t it be better to accept the ways and remove every node of them which lies outside the bounding box?