final Atlas atlas = new MultiAtlas(this.subAtlases); try new MultiAtlas(ImmutableList.copyOf(this.subAtlases.iterator())) .saveAsText(new File(this.outputTextPath.toFile())); LoggerFactory.getLogger(getClass()).info("Text atlas saved to {}", this.outputTextPath);
@Override public Iterable<Edge> edges() { return Iterables.translate(this.edgeIdentifierToAtlasIndex, identifier -> edge(identifier)); }
/** * Load a {@link MultiAtlas} from an {@link Iterable} of {@link PackedAtlas} serialized * resources * * @param resources * The {@link Resource}s to read from (which each contain a serialized * {@link PackedAtlas}). * @return The deserialized {@link MultiAtlas} */ public static MultiAtlas loadFromPackedAtlas(final Iterable<? extends Resource> resources) { return loadFromPackedAtlas(resources, false); }
/** * This is to build maps of nodes that are at the same location, and to build their master to * slave relationship. The master to slave relationship is purely arbitrary, the first node at a * location to be found becoming the master. */ protected void aggregateSameLocationNodes() { this.parent.getNodeIdentifierToAtlasIndices().forEach(identifier -> { final Node master = this.parent.node(identifier); final Set<Node> slaves = nodesOverlapping(master); slaves.remove(master); if (!slaves.isEmpty()) { if (!this.overlappingNodeIdentifierToMasterNodeIdentifier.containsKey(identifier)) { // if our master is not already a slave slaves.forEach(node -> { final long slaveIdentifier = node.getIdentifier(); this.overlappingNodeIdentifierToMasterNodeIdentifier.put(slaveIdentifier, identifier); this.masterNodeIdentifierToOverlappingNodeIdentifier.add(identifier, slaveIdentifier); }); warnIfNodesHaveDifferentTags(master, slaves); } } }); }
? MultiAtlas.loadFromPackedAtlas(resources) : MultiAtlas.loadFromPackedAtlas(resources, this.atlasEntityFilter); if (this.multiAtlasName != null) result.setName(this.multiAtlasName);
this.atlasSpatialIndex = newPackedAtlasSpatialIndex(); long numberOfNodes; long numberOfEdges; populateReferences(atlas, atlasIndex); atlasIndex++; "MultiAtlas - edgeIdentifierToAtlasIndexCandidate", this.getMaximumSize(), this.getEdgeHashSize(), this.getEdgeMemoryBlockSize(), this.getSubArraySize(), this.getEdgeMemoryBlockSize(), this.getSubArraySize()); this.getEdgeIdentifierToAtlasIndex().forEach(identifier -> this.getEdgeIdentifierToAtlasIndex().get(identifier)); this.setEdgeIdentifierToAtlasIndex(edgeIdentifierToAtlasIndexCandidate); this.populateReferences(this.borderFixer.getFixAtlas(), -1); this.getAsNewNodeSpatialIndex(); this.getAsNewEdgeSpatialIndex(); this.getAsNewAreaSpatialIndex(); this.getAsNewLineSpatialIndex(); this.getAsNewPointSpatialIndex(); this.getAsNewRelationSpatialIndex(); this.nodeIdentifierToAtlasIndices .forEach(identifier -> this.getNodeSpatialIndex().add(node(identifier))); this.edgeIdentifierToAtlasIndex .forEach(identifier -> this.getEdgeSpatialIndex().add(edge(identifier))); this.areaIdentifierToAtlasIndices
final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); verifyEdge(multiAtlas.edge(123456789120001L), MultiAtlasBorderFixerTestRule.POINT_1_LOCATION, MultiAtlasBorderFixerTestRule.POINT_2_LOCATION); verifyEdge(multiAtlas.edge(123456789120002L), MultiAtlasBorderFixerTestRule.POINT_2_LOCATION, MultiAtlasBorderFixerTestRule.POINT_3_LOCATION); multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_1_ID_LONG).inEdges().isEmpty()); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_1_ID_LONG).outEdges() .contains(multiAtlas.edge(123456789120001L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_2_ID_LONG).inEdges() .contains(multiAtlas.edge(123456789120001L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_2_ID_LONG).outEdges() .contains(multiAtlas.edge(123456789120002L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_3_ID_LONG).inEdges() .contains(multiAtlas.edge(123456789120002L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_3_ID_LONG).outEdges() .isEmpty());
@Test public void testThreeWaySubAtlas() { // In this test, fix couldn't be applied and edges from first atlas will be used final Atlas subAtlas1 = this.setup.threeWaySubAtlas1(); final Atlas subAtlas2 = this.setup.threeWaySubAtlas2(); final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); // Verify these edges exist Assert.assertNotNull(multiAtlas.edge(123456789120001L)); Assert.assertNotNull(multiAtlas.edge(123456789120002L)); Assert.assertNotNull(multiAtlas.edge(123456789120004L)); Assert.assertNotNull(multiAtlas.edge(123456789120005L)); // Verify this edge does NOT exist Assert.assertNull(multiAtlas.edge(123456789120003L)); }
final boolean hasFixEdges = subRelations.hasFixRelation(); final MultiMapWithSet<Long, Long> relationIdentifiersToRemovedEdgeMembers = multiAtlas() .getRelationIdentifiersToRemovedEdgeMembers(); for (final Relation subRelation : subRelations.getSubRelations()) if (nonMulti instanceof Node) multiEntity = multiAtlas().node(identifier); multiEntity = multiAtlas().edge(identifier); multiEntity = multiAtlas().area(identifier); multiEntity = multiAtlas().line(identifier); multiEntity = multiAtlas().point(identifier); multiEntity = multiAtlas().relation(identifier); if (nonMulti instanceof Edge) multiEntity = multiAtlas().edge(identifier);
@Override protected int finish(final CommandMap command) { final Atlas atlas = new MultiAtlas(this.atlases); try { final PackedAtlas saveMe = new PackedAtlasCloner().cloneFrom(atlas); final Path path = (Path) command.get(OUTPUT_PARAMETER); Files.createDirectories(path.getParent()); saveMe.save(new File(path.toString())); return 0; } catch (final IOException oops) { throw new CoreException("Error when saving packed atlas", oops); } }
@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); }
final MultiMapWithSet<Long, Long> removedEdges) final Set<Long> slaveNodes = multiAtlas().overlappingNodes(getIdentifier()); final Optional<Long> masterNode = multiAtlas().masterNode(this.identifier); if (!slaveNodes.isEmpty()) .addAll(((MultiNode) multiAtlas().node(slaveIdentifier)) .attachedEdges(getConnectedEdges, removedEdges))); return result;
@Override public Iterable<Relation> relations() { return Iterables.translate(this.relationIdentifierToAtlasIndices, identifier -> relation(identifier)); }
@Test public void connectivityTest() { this.multi.forEach(atlasItem -> logger.trace(atlasItem.toString())); // Out edges of CC2: 987 Assert.assertEquals(1, this.multi.edge(6).end().outEdges().size()); Assert.assertEquals(987, this.multi.edge(6).end().outEdges().iterator().next().getIdentifier()); Assert.assertEquals(2, this.multi.edge(-9).end().outEdges().size()); Assert.assertEquals(2, this.multi.edge(-9).end().inEdges().size()); Assert.assertEquals(2, this.multi.edge(987).start().inEdges().size()); }
@Test public void totalTest() { final Iterator<Edge> edges = this.multi.edges().iterator(); int numberEdges = 0; while (edges.hasNext()) { numberEdges++; edges.next(); } Assert.assertEquals(6, numberEdges); // Assert.assertEquals(6, Iterables.size(this.multi.edges())); // Assert.assertEquals(4, Iterables.size(this.multi.nodes())); Assert.assertEquals(6, Iterables.size(this.multi.edges())); Assert.assertEquals(4, Iterables.size(this.multi.nodes())); Assert.assertEquals(3, Iterables.size(this.multi.relations())); } }
@Test public void spatialIndexTest() { final Rectangle ac2Box = Location.TEST_1.boxAround(Distance.ONE_METER); Assert.assertEquals(1, Iterables.size(this.multi.nodesWithin(ac2Box))); Assert.assertEquals(4L, this.multi.nodesWithin(ac2Box).iterator().next().getIdentifier()); Assert.assertEquals(2, Iterables.size(this.multi.edgesIntersecting(ac2Box))); final Iterator<Edge> edgeIterator = this.multi.edgesIntersecting(ac2Box).iterator(); Assert.assertEquals(6, edgeIterator.next().getIdentifier()); Assert.assertEquals(5, edgeIterator.next().getIdentifier()); Assert.assertFalse(edgeIterator.hasNext()); }
for (final Long subEdgeIdentifier : subResult) final Edge multiEdge = multiAtlas().edge(subEdgeIdentifier); if (multiEdge == null) final List<Atlas> atlases = ((MultiAtlas) getAtlas()).getAtlases(); for (int index = 0; index < atlases.size(); index++)
@Override public Iterable<Node> nodes() { // Use the identifier here to avoid listing duplicated nodes twice. return Iterables.translate(this.nodeIdentifierToAtlasIndices, identifier -> node(identifier)); }
for (final Rectangle bound : bounds) others.addAll(Iterables.asSet(this.parent.nodesWithin(bound)));
final MultiAtlas multiAtlas = new MultiAtlas(subAtlas1, subAtlas2); verifyEdge(multiAtlas.edge(123456789120001L), MultiAtlasBorderFixerTestRule.POINT_1_LOCATION, MultiAtlasBorderFixerTestRule.POINT_2_LOCATION); verifyEdge(multiAtlas.edge(123456789120002L), MultiAtlasBorderFixerTestRule.POINT_2_LOCATION, MultiAtlasBorderFixerTestRule.POINT_3_LOCATION); multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_1_ID_LONG).inEdges().isEmpty()); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_1_ID_LONG).outEdges() .contains(multiAtlas.edge(123456789120001L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_2_ID_LONG).inEdges() .contains(multiAtlas.edge(123456789120001L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_2_ID_LONG).outEdges() .contains(multiAtlas.edge(123456789120002L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_3_ID_LONG).inEdges() .contains(multiAtlas.edge(123456789120002L))); Assert.assertTrue(multiAtlas.node(MultiAtlasBorderFixerTestRule.POINT_3_ID_LONG).outEdges() .isEmpty());