Closed yaseenelzawahry closed 3 years ago
Sure you can do that. You have to read the file at least twice then, check all ways for the tag you are interested in, remember the node ids you need, then re-read the file, this time only calling the NodeLocationsForWays
handler for the nodes you have remembered. It depends very much on your exact use case whether that makes sense or whether it is faster to just remember all nodes. (But that, as you mention, will need more memory.)
It might be easier in your case to just use osmium-tool to filter out all coastlines (osmium tags-filter input.osm.pbf w/natural=coastline -o out.osm.pbf
) and then work with that filtered file, no need to write something special for that.
I am aware of using the
NodeLocationsForWays
handler to cache node locations so that I can later access the location information from theNodeRef
objects. If I understand correctly, it seems to me that this will cache ALL the node locations, which of course results in rather (unnecessarily) large files. My question is, is there a way to only cache node locations, for example, that are part of a way that hasTag:natural=coastline
instead of all the nodes in the .pbf file?