Search code examples
osmosis

Osmosis - get all Nodes/Ways/Relations with the same tags


I want to get all nodes, ways and relations containing certain tags and the output file must also contain the dependent ways and nodes.

So for example I want to search for all relations with amenities and get not only the relations itself but also the dependent ways and nodes. Same for all ways with the same tags and their related nodes and finally all nodes.

Currently I found a working solution but this script takes a long time to process because it effectively reads the world map file 3 times and merges the data afterwards. I hope someone could point me to a more "straightforward" solution to increase speed.

btw. I have set the java options to "-Xmx14G -server" but the script only uses 8G of memory (the machine has 32G RAM) according to the task manager (Windows - sorry folks ;-) )

So this is the script:

set readfile=--read-pbf-fast file=planet-latest.osm.pbf workers=4
set logprogress=--log-progress interval=10

set acceptlorestags=^
place=country,state,region,province,district,county,municipality,island,islet ^
natural=sea,water,wetland,beach,coastline,marsh ^
admin_level=1,2,3,4 ^
water=* ^
wetland=*

call bin\osmosis.bat ^
%readfile% ^
--tf accept-relations ^
%acceptlorestags% ^
--used-way ^
--used-node ^
%logprogress% label="lores_rel" ^
 ^
%readfile% ^
--tf reject-relations ^
--tf accept-ways ^
%acceptlorestags% ^
--used-node ^
%logprogress% label="lores_way" ^
 ^
%readfile% ^
--tf reject-relations ^
--tf reject-ways ^
--tf accept-nodes ^
%acceptlorestags% ^
%logprogress% label="lores_node" ^
 ^
--merge ^
--merge ^
%logprogress% label="map_lores" ^
--mapfile-writer file=map_lores.map type=ram

Solution

  • One should not use a hammer for a screw. I switched to osmfilter and it works much faster now.

    The full process:

    convert the pbf to o5m (approx. 30 mins):

    osmconvert.exe planet-latest.osm.pbf -o=planet-latest.o5m
    

    create a filtered xml file (approx. 30 mins):

    set source=planet-latest.o5m
    set drop2= --drop-tags="source= fixme= created_by="
    osmfilter.exe %source% --keep="natural=sea =coastline admin_level=1 =2 =3 =4 place=ocean =sea" %drop2% > map_lowres.osm
    

    convert to mapsforge:

    set osmosis=tag-conf-file=tagmapping.xml zoom-interval-conf=8,5,11,15,12,20
    call bin\osmosis.bat --read-xml file=map_lowres.osm --mapfile-writer file=map_lowres.map %osmosis%
    

    Take care that the mapfile-writer still needs days or weeks. Consider using bounding boxes and create multiple map files which is much faster than processing the whole world at once.