static Taggable with(final String... tags) { return with(Maps.hashMap(tags)); }
static Taggable with(final Collection<Tag> tagCollection) { final Map<String, String> tags = new HashMap<>(); tagCollection.forEach(tag -> tags.put(tag.getKey(), tag.getValue())); return with(tags); }
@Test public void testAllValidSimple() { final String definition = ""; final TaggableFilter filter = TaggableFilter.forDefinition(definition); Assert.assertTrue(filter.test(Taggable.with())); Assert.assertTrue(filter.test(Taggable.with("highway", "primary"))); Assert.assertTrue(filter.test(Taggable.with("bus", "lane"))); }
@Test public void testAllValidComplex() { // In this case the OR(|) is ignored here. final String definition = "bus->*|"; final TaggableFilter filter = TaggableFilter.forDefinition(definition); Assert.assertFalse(filter.test(Taggable.with())); Assert.assertFalse(filter.test(Taggable.with("highway", "primary"))); Assert.assertTrue(filter.test(Taggable.with("bus", "lane"))); }
@Test public void testBackwardsCompatibility() { final String definition = "bus->*|water->*&bus->*^water->!canal"; final TaggableFilter filter = TaggableFilter.forDefinition(definition); Assert.assertTrue(filter.test(Taggable.with("water", "pond"))); Assert.assertFalse(filter.test(Taggable.with("water", "canal"))); Assert.assertTrue(filter.test(Taggable.with("water", "canal", "bus", "stop"))); Assert.assertEquals(definition.replace("^", "||"), filter.toString()); }
@Test public void testDefaultOsmosisRelationConfiguration() { final Resource relationResource = new InputStreamResource( getClass().getClassLoader().getResourceAsStream( "org/openstreetmap/atlas/geography/atlas/pbf/osm-pbf-relation.json")); final Configuration relationConfiguration = new StandardConfiguration(relationResource); final ConfiguredTaggableFilter relationFilter = new ConfiguredTaggableFilter( relationConfiguration); final Taggable nonBoundaryRelationTags = Taggable.with("type", "restriction"); final Taggable boundaryRelationTags = Taggable.with("boundary", "administrative"); Assert.assertTrue(relationFilter.test(nonBoundaryRelationTags)); Assert.assertFalse(relationFilter.test(boundaryRelationTags)); }
@Test public void testConfigured() { final Taggable valid1 = Taggable.with("barrier", "yes"); final Taggable valid2 = Taggable.with("highway", "motorway_junction"); final Taggable valid3 = Taggable.with("railway", "level_crossing", "public_transport", "platform"); final Taggable valid4 = Taggable.with("barrier", "yes", "oneway", "yes"); final Taggable invalid1 = Taggable.with("barrier", "yes", "noexit", "yes"); final Taggable invalid2 = Taggable.with("highway", "motorway_junction", "noexit", "yes"); final Taggable invalid3 = Taggable.with("highway", "pedestrian"); final Taggable invalid4 = Taggable.with(); final Taggable invalid5 = Taggable.with("barrier", "yes", "oneway", "reversed"); Assert.assertTrue(this.filter.test(valid1)); Assert.assertTrue(this.filter.test(valid2)); Assert.assertTrue(this.filter.test(valid3)); Assert.assertTrue(this.filter.test(valid4)); Assert.assertFalse(this.filter.test(invalid1)); Assert.assertFalse(this.filter.test(invalid2)); Assert.assertFalse(this.filter.test(invalid3)); Assert.assertFalse(this.filter.test(invalid4)); Assert.assertFalse(this.filter.test(invalid5)); }
@Test public void testDefaultOsmosisWayConfiguration() { final Resource wayResource = new InputStreamResource( getClass().getClassLoader().getResourceAsStream( "org/openstreetmap/atlas/geography/atlas/pbf/osm-pbf-way.json")); final Configuration wayConfiguration = new StandardConfiguration(wayResource); final ConfiguredTaggableFilter wayFilter = new ConfiguredTaggableFilter(wayConfiguration); final Taggable boundary = Taggable.with("boundary", "administrative"); final Taggable highwayBoundary = Taggable.with("boundary", "administrative", "highway", "primary"); final Taggable railwayBoundary = Taggable.with("boundary", "administrative", "railway", "rail"); final Taggable waterwayBoundary = Taggable.with("boundary", "administrative", "waterway", "river"); Assert.assertTrue(wayFilter.test(highwayBoundary)); Assert.assertTrue(wayFilter.test(railwayBoundary)); Assert.assertTrue(wayFilter.test(waterwayBoundary)); Assert.assertFalse(wayFilter.test(boundary)); } }
@Test public void testDepth() { final String definition = "bus->*|water->*&bus->*||water->!canal&&bus->!|||water->pond,canal&&&bus->*"; final TaggableFilter filter = TaggableFilter.forDefinition(definition); Assert.assertTrue(filter.test(Taggable.with("water", "pond"))); Assert.assertFalse(filter.test(Taggable.with("water", "canal"))); Assert.assertTrue(filter.test(Taggable.with("water", "canal", "bus", "stop"))); Assert.assertEquals(definition, filter.toString()); }
final TaggableFilter filter = TaggableFilter.forDefinition(definition); final Taggable valid1 = Taggable.with("amenity", "bus_station"); final Taggable valid2 = Taggable.with("highway", "bus_stop"); final Taggable valid3 = Taggable.with("trolleybus", "yes", "public_transport", "platform"); final Taggable valid4 = Taggable.with("bus", "hello", "public_transport", "station"); final Taggable valid5 = Taggable.with("trolleybus", "bye", "public_transport", "stop_position"); final Taggable valid6 = Taggable.with("amenity", "bus_stop", "trolleybus", "bye", "public_transport", "stop_position"); final Taggable invalid1 = Taggable.with("amenity", "bus_stop"); final Taggable invalid2 = Taggable.with("highway", "bus_station"); final Taggable invalid3 = Taggable.with("trolleybus", "yes"); final Taggable invalid4 = Taggable.with("bus", "hello", "public_transport", "terminal"); final Taggable invalid5 = Taggable.with();
@Test public void testForceSlicing() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final Set<String> countries = new HashSet<>(); countries.add("HTI"); countries.add("DOM"); map.initializeGridIndex(countries); // Crosses HTI only and falls in the international waters on both sides final LineString lineString = (LineString) TestUtility.createJtsGeometryFromWKT( "LINESTRING(-72.62310537054378 16.33562831580734,-73.54595693304378 18.890373956748753)"); final List<Geometry> sliced1 = map.slice(123, lineString); map.setShouldAlwaysSlicePredicate( taggable -> taggable.getTag("IShouldBeSliced").isPresent()); final List<Geometry> sliced2 = map.slice(123, lineString); final List<Geometry> sliced3 = map.slice(123, lineString, Taggable.with("IShouldBeSliced", "yes")); final List<Geometry> sliced4 = map.slice(123, lineString, Taggable.with("ShouldIBeSliced", "no")); Assert.assertEquals(1, sliced1.size()); Assert.assertEquals(1, sliced2.size()); Assert.assertEquals(3, sliced3.size()); Assert.assertEquals(1, sliced4.size()); }
final Taggable primary = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase()); final Taggable primaryAccessNoMotorVehicleYes = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase(), AccessTag.KEY, AccessTag.NO.name().toLowerCase(), MotorVehicleTag.KEY, MotorVehicleTag.YES.name().toLowerCase()); final Taggable primaryAccessNoMotorCarYes = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase(), AccessTag.KEY, AccessTag.NO.name().toLowerCase(), MotorcarTag.KEY, MotorcarTag.YES.name().toLowerCase()); final Taggable primaryAccessNoVehicleYes = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase(), AccessTag.KEY, AccessTag.NO.name().toLowerCase(), VehicleTag.KEY, VehicleTag.YES.name().toLowerCase()); final Taggable primaryAccessNoMotorVehicleYesOneWayTrue = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase(), AccessTag.KEY, AccessTag.NO.name().toLowerCase(), MotorVehicleTag.KEY, MotorVehicleTag.YES.name().toLowerCase(), OneWayTag.KEY, OneWayTag.TRUE.name().toLowerCase()); final Taggable primaryAccessNoMotorCarYesOneWayTrue = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase(), AccessTag.KEY, AccessTag.NO.name().toLowerCase(), MotorcarTag.KEY, MotorcarTag.YES.name().toLowerCase(), OneWayTag.KEY, OneWayTag.TRUE.name().toLowerCase()); final Taggable primaryAccessNoVehicleYesOneWayTrue = Taggable.with(HighwayTag.KEY, HighwayTag.PRIMARY.name().toLowerCase(), AccessTag.KEY, AccessTag.NO.name().toLowerCase(), VehicleTag.KEY, VehicleTag.YES.name().toLowerCase(), OneWayTag.KEY, OneWayTag.TRUE.name().toLowerCase());
@Test public void testNearestNeighborCountryCodeOnMultiLineStringOutsideBoundary() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("DMA_boundary.txt"))); map.setShouldAlwaysSlicePredicate(taggable -> true); final PolyLine polyLine = PolyLine.wkt(new InputStreamResource( () -> CountryBoundaryMapTest.class.getResourceAsStream("DMA_snake_polyline.wkt")) .firstLine()); final List<Geometry> sliced = map.slice(123000000L, new JtsPolyLineConverter().convert(polyLine), Taggable.with("force-slice", "please")); int withNearestNeighborTag = 0; for (final Geometry slicedGeometry : sliced) { if (SyntheticNearestNeighborCountryCodeTag.YES.name() .equals(CountryBoundaryMap.getGeometryProperty(slicedGeometry, SyntheticNearestNeighborCountryCodeTag.KEY))) { withNearestNeighborTag++; } } Assert.assertEquals(3, withNearestNeighborTag); }