javaopenstreetmaposm.pbf

How to use tag filtering in Atlas


New to the Atlas project (and also to Java), I am trying some things out. I am looking for the preferred way to combine the instructions given here and here to apply tag filtering on an Atlas.

Would the below be a good approach or is there a better alternative?

String definition = "highway->residential";
final TaggableFilter filter = TaggableFilter.forDefinition(definition);
final Optional<Atlas> predicateAtlas = atlas.subAtlas(filter::test, AtlasCutType.SOFT_CUT);

Solution

  • Your code would work and produce an other Atlas that contains all elements with highway=residential. It is important to note that Atlas has to follow feature integrity (i.e. an Edge cannot exist without its end Nodes) which mean some features without the tag you specified here might still be pulled in (connected Nodes, or parent Relations for example).

    Another way to only get the features that are tagged highway=residential would be to not force them to be fed back to an Atlas, but just printed, or handled with a custom function of your choice:

    String definition = "highway->residential";
    final TaggableFilter filter = TaggableFilter.forDefinition(definition);
    atlas.entities(filter).forEach(entity -> ...);