ropenstreetmaposmosis

How to extract an area from osm?


using osmosis I want to extract all natural areas from an xml osm map

osmosis --read-xml map.osm --way-key-value keyValueList="natural" --write-xml out.osm

When reading the output map out.osm (using R and readOGR), this map contains only points, while I expected multiplepolygons.

natural <- readOGR('out.osm')

Am I doing something wrong?


Solution

  • Try this using --tag-filter instead:

    export INFILE=map.osm
    
    osmosis \
       --read-xml $INFILE \
       --tag-filter accept-relations natural=* \
       --used-way \
       --used-node \
       \
       --read-xml $INFILE \
       --tag-filter reject-relations \
       --tag-filter accept-ways natural=* \
       --used-node \
       \
       --read-xml $INFILE \
       --tag-filter reject-relations \
       --tag-filter accept-nodes natural=* \
       --tag-filter reject-ways \
       \
       --merge \
       --merge \
       --write-xml out.osm
    

    This gives you relations, ways, and also nodes (three separate streams which get merged)

    If you're only interested in natural areas, then you don't want the individual nodes (e.g. individual natural=tree nodes) so you would do this:

    export INFILE=map.osm
    
    osmosis \
       --read-xml $INFILE \
       --tag-filter accept-relations natural=* \
       --used-way \
       --used-node \
       \
       --read-xml $INFILE \
       --tag-filter reject-relations \
       --tag-filter accept-ways natural=* \
       --used-node \
       \
       --merge \
       --write-xml out.osm
    

    Not exactly sure what nodes you were seeing with your first attempt, but the docs for --way-key-value say that it's deprecated, and also "Note that this filter only operates on ways"