Search in sources :

Example 71 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class MissingMultiEntityRelationTest method testRelationsForMissingRelation.

@Test
public void testRelationsForMissingRelation() {
    final PackedAtlasBuilder builderWithRelation = new PackedAtlasBuilder();
    builderWithRelation.addPoint(1L, Location.forString("1,1"), Maps.hashMap("somePoint", "inTwoAtlases"));
    final RelationBean bean = new RelationBean();
    bean.addItem(1L, "some member point", ItemType.POINT);
    builderWithRelation.addRelation(1, 1, bean, Maps.hashMap());
    final RelationBean bean2 = new RelationBean();
    bean2.addItem(1L, "parent relation of subrelation", ItemType.RELATION);
    builderWithRelation.addRelation(2, 2, bean2, Maps.hashMap());
    final PackedAtlasBuilder builderNoRelation = new PackedAtlasBuilder();
    builderNoRelation.addPoint(1L, Location.forString("1,1"), Maps.hashMap("somePoint", "inTwoAtlases"));
    final RelationBean bean3 = new RelationBean();
    bean3.addItem(1L, "some member point", ItemType.POINT);
    builderNoRelation.addRelation(1, 1, bean3, Maps.hashMap());
    final PackedAtlas atlasWithRelation = (PackedAtlas) builderWithRelation.get();
    final PackedAtlas atlasNoRelation = (PackedAtlas) builderNoRelation.get();
    // 1 MiB resources
    final ByteArrayResource resourceWithRelation = new ByteArrayResource(1024 * 1024);
    final ByteArrayResource resourceNoRelation = new ByteArrayResource(1024 * 1024);
    atlasWithRelation.save(resourceWithRelation);
    atlasNoRelation.save(resourceNoRelation);
    /*
         * Here, we want to add the atlas without the relation first, since the MultiAtlas appends
         * identical relations into the MultiRelation list. It then will always choose the first
         * subRelation to get the parent relations. See the MultiAtlas.populateReferences() and
         * MultiRelation.relations() to see what's happening.
         */
    final Atlas multiAtlas = new AtlasResourceLoader().load(resourceNoRelation, resourceWithRelation);
    Assert.assertFalse(multiAtlas.relation(1L).relations().isEmpty());
    final Atlas multiAtlas2 = new AtlasResourceLoader().load(resourceWithRelation, resourceNoRelation);
    Assert.assertFalse(multiAtlas2.relation(1L).relations().isEmpty());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) PackedAtlas(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas) AtlasResourceLoader(org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader) PackedAtlasBuilder(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder) RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) PackedAtlas(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas) ByteArrayResource(org.openstreetmap.atlas.streaming.resource.ByteArrayResource) Test(org.junit.Test)

Example 72 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class PackedAtlasTest method testRelationMembersWithSameIdentifiersButDifferentTypes.

@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());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) Test(org.junit.Test)

Example 73 with RelationBean

use of org.openstreetmap.atlas.geography.atlas.builder.RelationBean in project atlas by osmlab.

the class RelationToMultiPolygonMemberConverterTest method init.

@Before
public void init() {
    final PackedAtlasBuilder builder = new PackedAtlasBuilder();
    builder.addLine(0, new PolyLine(ONE, TWO), Maps.hashMap());
    builder.addLine(1, new PolyLine(TWO, THR), Maps.hashMap());
    builder.addLine(2, new PolyLine(THR, FOR), Maps.hashMap());
    builder.addLine(3, new PolyLine(FOR, FVE), Maps.hashMap());
    builder.addLine(4, new PolyLine(FVE, ONE), Maps.hashMap());
    builder.addLine(5, new PolyLine(SIX, SVN), Maps.hashMap());
    builder.addLine(6, new PolyLine(SVN, EIT), Maps.hashMap());
    builder.addLine(7, new PolyLine(EIT, SIX), Maps.hashMap());
    builder.addArea(0, INNER_LOOP, Maps.hashMap());
    final RelationBean bean = new RelationBean();
    bean.addItem(0L, RelationTypeTag.MULTIPOLYGON_ROLE_OUTER, ItemType.AREA);
    bean.addItem(0L, RelationTypeTag.MULTIPOLYGON_ROLE_OUTER, ItemType.LINE);
    bean.addItem(1L, RelationTypeTag.MULTIPOLYGON_ROLE_OUTER, ItemType.LINE);
    bean.addItem(2L, RelationTypeTag.MULTIPOLYGON_ROLE_OUTER, ItemType.LINE);
    bean.addItem(3L, RelationTypeTag.MULTIPOLYGON_ROLE_OUTER, ItemType.LINE);
    bean.addItem(4L, RelationTypeTag.MULTIPOLYGON_ROLE_OUTER, ItemType.LINE);
    bean.addItem(5L, RelationTypeTag.MULTIPOLYGON_ROLE_INNER, ItemType.LINE);
    bean.addItem(6L, RelationTypeTag.MULTIPOLYGON_ROLE_INNER, ItemType.LINE);
    bean.addItem(7L, RelationTypeTag.MULTIPOLYGON_ROLE_INNER, ItemType.LINE);
    builder.addRelation(0, 0, bean, Maps.hashMap(RelationTypeTag.KEY, RelationTypeTag.MULTIPOLYGON_TYPE));
    this.atlas = builder.get();
}
Also used : PackedAtlasBuilder(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder) RelationBean(org.openstreetmap.atlas.geography.atlas.builder.RelationBean) PolyLine(org.openstreetmap.atlas.geography.PolyLine) Before(org.junit.Before)

Aggregations

RelationBean (org.openstreetmap.atlas.geography.atlas.builder.RelationBean)73 Test (org.junit.Test)40 PackedAtlasBuilder (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder)21 CompleteRelation (org.openstreetmap.atlas.geography.atlas.complete.CompleteRelation)20 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)17 RelationBeanItem (org.openstreetmap.atlas.geography.atlas.builder.RelationBean.RelationBeanItem)17 PolyLine (org.openstreetmap.atlas.geography.PolyLine)12 Relation (org.openstreetmap.atlas.geography.atlas.items.Relation)9 ArrayList (java.util.ArrayList)8 Location (org.openstreetmap.atlas.geography.Location)8 PackedAtlas (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas)8 Polygon (org.openstreetmap.atlas.geography.Polygon)7 ItemType (org.openstreetmap.atlas.geography.atlas.items.ItemType)7 AtlasResourceLoader (org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader)6 FeatureChange (org.openstreetmap.atlas.geography.atlas.change.FeatureChange)6 ByteArrayResource (org.openstreetmap.atlas.streaming.resource.ByteArrayResource)6 CoreException (org.openstreetmap.atlas.exception.CoreException)5 CompleteNode (org.openstreetmap.atlas.geography.atlas.complete.CompleteNode)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4