/** * This function will validate if the supplied atlas object is valid for the check. * * @param object * the atlas object supplied by the Atlas-Checks framework for evaluation * @return {@code true} if this object should be checked */ @Override public boolean validCheckForObject(final AtlasObject object) { // Object must be either a MultiPolygon Relation with at least one member, or an Area with // a place=islet, place=island, place=archipelago, or natural=water tag return (object instanceof Relation && IS_MULTIPOLYGON_WATER_RELATION.test(object) && ((Relation) object).members().size() >= 2) || (object instanceof Area && (TagPredicates.IS_WATER_BODY.test(object) || IS_ISLET.test(object) || IS_ISLAND.test(object)) && !this.isFlagged(object.getIdentifier())); }
/** * @param relation * The {@link Relation} for which to create seeds for * @return an array of identifiers corresponding to the first unused identifier for each * relation member in the given Relation */ private long[] createIdentifierSeeds(final Relation relation) { // Assume any member can be split, so create a seed for each one final long[] seeds = new long[relation.members().size()]; for (int seedIndex = 0; seedIndex < seeds.length; seedIndex++) { long identifier = relation.members().get(seedIndex).getEntity().getIdentifier(); final long originalAtlasIdentifier = new ReverseIdentifierFactory() .getFirstAtlasIdentifier(identifier); final Set<Long> createdWaysForIdentifier = this.slicedPointAndLineChanges .getDeletedToCreatedLineMapping().get(originalAtlasIdentifier); if (createdWaysForIdentifier != null) { // Grab the first Atlas identifier for this entity and increment at offset identifier = identifier + createdWaysForIdentifier.size() * CountrySlicingIdentifierFactory.IDENTIFIER_SCALE; } seeds[seedIndex] = identifier; } return seeds; }
@Test public void testLoadRelationByIdentifier() { // Already loaded: 12-1350-1870 final Relation relation1 = this.dynamicAtlas.relation(1); Assert.assertEquals(1, relation1.members().size()); final Relation relation2 = this.dynamicAtlas.relation(2); Assert.assertEquals(1, relation2.members().size()); // Prompts load of 12-1350-1869 this.dynamicAtlas.edge(2000000); Assert.assertEquals(2, relation1.members().size()); Assert.assertEquals(1, relation2.members().size()); // Prompts load of 12-1349-1870 this.dynamicAtlas.edge(8000000); Assert.assertEquals(2, relation1.members().size()); Assert.assertEquals(2, relation2.members().size()); }
@Override protected Optional<CheckFlag> flag(final AtlasObject object) { final Relation relation = (Relation) object; final RelationMemberList members = relation.members(); // If the number of members in the relation is 1 if (members.size() == 1) { if (members.get(0).getEntity().getType().equals(ItemType.RELATION)) { return Optional.of(createFlag(getRelationMembers((Relation) object), this.getLocalizedInstruction(2, relation.getOsmIdentifier(), members.get(0).getEntity().getOsmIdentifier()))); } // If the relation is a multi-polygon, if (relation.isMultiPolygon()) { return Optional.of(createFlag(getRelationMembers((Relation) object), this.getLocalizedInstruction(1, relation.getOsmIdentifier()))); } return Optional.of(createFlag(getRelationMembers((Relation) object), this.getLocalizedInstruction(0, relation.getOsmIdentifier()))); } return Optional.empty(); }
@Test public void testWaterWayAsRelationOfWaterWays() { final Atlas canalAsRelationOfCanalEntities = this.rule .getCanalAsRelationOfCanalEntitiesAtlas(); final Iterable<ComplexWaterEntity> waterEntities = new ComplexWaterEntityFinder() .find(canalAsRelationOfCanalEntities, Finder::ignore); Assert.assertEquals( "The number of water entities should be equal to the number of relation members", canalAsRelationOfCanalEntities.relation(6006326000000L).members().size(), Iterables.size(waterEntities)); }
@Test public void testRelationMemberLocationItemInclusion() { // Based on https://www.openstreetmap.org/relation/578254 - the Node in the Relation gets // created as both an Atlas point and node. Let's verify that the Relation consists of both. final Atlas slicedRawAtlas = this.setup.getNodeAndPointAsRelationMemberAtlas(); final CountryBoundaryMap boundaryMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(() -> WaySectionProcessorTest.class .getResourceAsStream("nodeAndPointRelationMemberBoundaryMap.txt"))); final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run(); final RelationMemberList members = finalAtlas.relation(578254000000L).members(); Assert.assertEquals("Six members - 2 pairs of reverse edges, 1 node and 1 point", 6, members.size()); Assert.assertEquals("Single point", 1, members.stream() .filter(member -> member.getEntity().getType() == ItemType.POINT).count()); Assert.assertEquals("Single node", 1, members.stream() .filter(member -> member.getEntity().getType() == ItemType.NODE).count()); }
@Test public void testLoadRelationWithOverlappingMembersByIdentifier() { // Already loaded: 12-1350-1870 Assert.assertEquals(4, this.dynamicAtlas.numberOfEdges()); Assert.assertEquals(1, this.dynamicAtlas.relation(3).members().size()); // Prompts load of 12-1349-1870 this.dynamicAtlas.edge(8000000); Assert.assertEquals(6, this.dynamicAtlas.numberOfEdges()); // Prompts load of 12-1349-1869 final Relation relation3 = this.dynamicAtlas.relation(3); Assert.assertEquals(3, relation3.members().size()); Assert.assertEquals(8, this.dynamicAtlas.numberOfEdges()); }
@Test public void testSlicedRelation() { final Relation relation1 = this.multi.relation(1L); final RelationMemberList members = relation1.members(); Assert.assertEquals(4, members.size()); for (int i = 0; i < members.size(); i++) { Assert.assertTrue(members.get(i) != null); } // Members are ordered by entity type and ascending member identifier Assert.assertEquals(4, members.get(0).getEntity().getIdentifier()); Assert.assertEquals(1234, members.get(1).getEntity().getIdentifier()); Assert.assertEquals(-9, members.get(2).getEntity().getIdentifier()); Assert.assertEquals(9, members.get(3).getEntity().getIdentifier()); final Relation relation2 = this.multi.relation(2L); final RelationMemberList allMembers2 = relation2.allKnownOsmMembers(); final Relation relation3 = this.multi.relation(3L); final RelationMemberList allMembers3 = relation3.allKnownOsmMembers(); Assert.assertEquals(8, allMembers2.size()); Assert.assertEquals(8, allMembers3.size()); }
@Test public void testOneWaySubAtlasWithRelations() { final Atlas subAtlas1 = this.setup.oneWaySubAtlas1From1To3WithRelations(); final Atlas subAtlas2 = this.setup.oneWaySubAtlas2From1To3WithRelations(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); // Verify first edge verifyEdge(multiAtlas.edge(123456789120001L), MultiAtlasBorderFixerTestRule.POINT_1_LOCATION, MultiAtlasBorderFixerTestRule.POINT_2_LOCATION); // Verify second edge verifyEdge(multiAtlas.edge(123456789120002L), MultiAtlasBorderFixerTestRule.POINT_2_LOCATION, MultiAtlasBorderFixerTestRule.POINT_3_LOCATION); // Verify relations Assert.assertEquals(multiAtlas.edge(123456789120001L).relations().size(), 2); Assert.assertEquals(multiAtlas.edge(123456789120002L).relations().size(), 2); // Verify that relation has members Assert.assertEquals(multiAtlas.relation(987654321L).members().size(), 2); Assert.assertEquals(multiAtlas.relation(887654321L).members().size(), 2); }
@Test public void testSameRelationMemberWithDifferentRole() { final Atlas atlas = this.rule.getAtlas(); final RelationMemberList relationMembers = atlas .relation(PackedRelationTestCaseRule.RELATION_IDENTIFIER).members(); Assert.assertEquals(3, relationMembers.size()); Assert.assertTrue(listContains(relationMembers, RelationTypeTag.RESTRICTION_ROLE_FROM)); Assert.assertTrue(listContains(relationMembers, RelationTypeTag.RESTRICTION_ROLE_VIA)); Assert.assertTrue(listContains(relationMembers, RelationTypeTag.RESTRICTION_ROLE_TO)); }
@Test public void testEmptyRelations() throws IOException { try (OsmosisReaderMock osmosis = new OsmosisReaderMock(this.store)) { final AtlasLoadingOption loadingOption = AtlasLoadingOption .createOptionWithAllEnabled(this.countryBoundariesAll) .setAdditionalCountryCodes(COUNTRY_1_NAME); Atlas atlas = new RawAtlasGenerator(() -> osmosis, loadingOption, MultiPolygon.MAXIMUM) .build(); atlas = new RawAtlasCountrySlicer(COUNTRY_1_NAME, loadingOption.getCountryBoundaryMap()) .slice(atlas); atlas = new WaySectionProcessor(atlas, AtlasLoadingOption.createOptionWithNoSlicing()) .run(); logger.info("{}", atlas); Assert.assertEquals(2, atlas.numberOfLines()); Assert.assertEquals(1, atlas.numberOfRelations()); final Relation relation = atlas.relations().iterator().next(); Assert.assertEquals(2, relation.members().size()); Assert.assertEquals(2, atlas.numberOfEdges()); } }
@Test public void testOneWaySubAtlasWithInconsistentRoadsAndARelation() { final Atlas subAtlas1 = this.setup.oneWaySubAtlas1WithInconsistentRoadsAndARelation(); final Atlas subAtlas2 = this.setup.oneWaySubAtlas2WithInconsistentRoadsAndARelation(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); // Verify edges are NOT gone even though they were forming an inconsistent road Assert.assertNotNull(multiAtlas.edge(123456789120000L)); Assert.assertNotNull(multiAtlas.edge(123456789120001L)); Assert.assertNotNull(multiAtlas.edge(123456789120002L)); // Verify that relation has members Assert.assertEquals(multiAtlas.relation(987654321L).members().size(), 2); Assert.assertEquals(multiAtlas.relation(887654321L).members().size(), 1); // Verify fixed edges verifyEdge(multiAtlas.edge(223456789120001L), MultiAtlasBorderFixerTestRule.POINT_5_LOCATION, MultiAtlasBorderFixerTestRule.POINT_6_LOCATION); verifyEdge(multiAtlas.edge(223456789120002L), MultiAtlasBorderFixerTestRule.POINT_6_LOCATION, MultiAtlasBorderFixerTestRule.POINT_7_LOCATION); }
@Test public void testRelationMembersWithSameIdentifiersButDifferentTypes() { final PackedAtlasBuilder builder = new PackedAtlasBuilder(); builder.addArea(0, Polygon.SILICON_VALLEY, Maps.hashMap()); builder.addLine(0, PolyLine.TEST_POLYLINE, Maps.hashMap()); final RelationBean bean = new RelationBean(); bean.addItem(0L, "Role of the Area", ItemType.AREA); bean.addItem(0L, "Role of the Line", ItemType.LINE); builder.addRelation(0, 0, bean, Maps.hashMap()); final Atlas result = builder.get(); Assert.assertEquals(2, result.relation(0).members().size()); }
@Test public void testSubAtlasWithNodeNestedWithinRelationCase() { final Atlas source = this.rule.getNodeNestedWithinRelationAtlas(); final Predicate<AtlasEntity> entitiesWithIdentifierZero = entity -> entity .getIdentifier() == 0; final Atlas subAtlasWithZeroBasedIdentifiers = source .subAtlas(entitiesWithIdentifierZero, AtlasCutType.SOFT_CUT) .orElseThrow(() -> new CoreException("SubAtlas was not present.")); // Nodes Assert.assertNotNull(source.node(1)); Assert.assertNotNull(subAtlasWithZeroBasedIdentifiers.node(1)); Assert.assertNotNull(source.node(2)); Assert.assertNotNull(subAtlasWithZeroBasedIdentifiers.node(2)); Assert.assertNotNull(source.node(3)); Assert.assertNull(subAtlasWithZeroBasedIdentifiers.node(3)); Assert.assertNotNull(source.node(4)); Assert.assertNotNull(subAtlasWithZeroBasedIdentifiers.node(4)); // Edges Assert.assertNotNull(source.edge(0)); Assert.assertNotNull(subAtlasWithZeroBasedIdentifiers.edge(0)); Assert.assertNotNull(source.edge(1)); Assert.assertNull(subAtlasWithZeroBasedIdentifiers.edge(1)); // Relations Assert.assertNotNull(source.relation(0)); Assert.assertEquals(2, source.relation(0).members().size()); Assert.assertNotNull(subAtlasWithZeroBasedIdentifiers.relation(0)); Assert.assertEquals(2, subAtlasWithZeroBasedIdentifiers.relation(0).members().size()); }
Assert.assertNotNull(sub.relation(1)); Assert.assertNotNull(source.relation(2)); Assert.assertEquals(2, source.relation(2).members().size()); Assert.assertNotNull(sub.relation(2)); Assert.assertEquals(1, sub.relation(2).members().size()); Assert.assertNotNull(source.relation(3)); Assert.assertNull(sub.relation(3)); Assert.assertNotNull(source.relation(4)); Assert.assertEquals(2, source.relation(4).members().size()); Assert.assertNotNull(sub.relation(4)); Assert.assertEquals(1, sub.relation(4).members().size()); Assert.assertNotNull(source.relation(5)); Assert.assertEquals(1, source.relation(5).members().size()); Assert.assertNotNull(sub.relation(5)); Assert.assertEquals(1, sub.relation(5).members().size());
Assert.assertNull(sub.relation(5)); Assert.assertNotNull(source.relation(6)); Assert.assertEquals(2, source.relation(6).members().size()); Assert.assertNotNull(sub.relation(6)); Assert.assertEquals(2, sub.relation(6).members().size()); Assert.assertNotNull(source.relation(7)); Assert.assertEquals(2, source.relation(7).members().size()); Assert.assertNotNull(sub.relation(7)); Assert.assertEquals(1, sub.relation(7).members().size());
Assert.assertNull(sub.relation(5)); Assert.assertNotNull(source.relation(6)); Assert.assertEquals(2, source.relation(6).members().size()); Assert.assertNotNull(sub.relation(6)); Assert.assertEquals(2, sub.relation(6).members().size()); Assert.assertNotNull(source.relation(7)); Assert.assertEquals(2, source.relation(7).members().size()); Assert.assertNotNull(sub.relation(7)); Assert.assertEquals(1, sub.relation(7).members().size());