/** * Query country boundaries which cover given {@link Location}, with an extension square box * * @param location * Any {@link Location} * @param extension * Extension {@link Distance} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final Location location, final Distance extension) { return this.boundaries(location.boxAround(extension)); }
@Override public SortedSet<SnappedEdge> snaps(final Location point, final Distance threshold) { final SortedSet<SnappedEdge> snaps = new TreeSet<>(); for (final Edge edge : this.edgesIntersecting(point.boxAround(threshold))) { final SnappedEdge candidate = new SnappedEdge(point.snapTo(edge.asPolyLine()), edge); snaps.add(candidate); } return snaps; }
/** * @return Rectangle list which expand 1 km bounding box for each location */ private List<Rectangle> locationToRectangle(final List<Location> loactions) { return loactions.stream().map(location -> location.boxAround(Distance.kilometers(1))) .collect(Collectors.toList()); }
@Override public SnappedEdge snapped(final Location point, final Distance threshold) { SnappedEdge result = null; for (final Edge edge : this.edgesIntersecting(point.boxAround(threshold))) { final SnappedEdge candidate = new SnappedEdge(point.snapTo(edge.asPolyLine()), edge); if (result == null || candidate.getDistance().isLessThan(result.getDistance())) { result = candidate; } } return result; }
private Atlas createSource() { final Rectangle bounds = Location.TEST_1.boxAround(Distance.TEN_MILES); final AtlasSize estimates = new AtlasSize(8, 10, 4, 7, 9, 2); final long startIdentifier = 100; final AtlasStartIdentifiers startIdentifiers = new AtlasStartIdentifiers( startIdentifier + 100, startIdentifier + 200, startIdentifier + 300, startIdentifier + 400, startIdentifier + 500, startIdentifier + 600); return new RandomPackedAtlasBuilder().generate(estimates, startIdentifiers, bounds); } }
@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()); }
public static PackedAtlas generate(final long size, final long startIdentifier) { final Rectangle bounds = Location.TEST_5.boxAround(Distance.miles(100)); final AtlasSize estimates = new AtlasSize(size, size, size, size, size, size); final AtlasStartIdentifiers startIdentifiers = new AtlasStartIdentifiers(startIdentifier, startIdentifier, startIdentifier + size, startIdentifier + 2 * size, startIdentifier + size, startIdentifier); return new RandomPackedAtlasBuilder().generate(estimates, startIdentifiers, bounds); }
@Test public void testDeserializedSpatialIndex() { final Atlas deserialized = deserialized(); Assert.assertEquals(2, Iterables.size( deserialized.areasIntersecting(Location.TEST_8.boxAround(Distance.ONE_METER)))); }
final Rectangle box = point.getLocation().boxAround(boundsSize);
@Test public void testPoint() { final Point point1 = this.atlas.point(1); final Point point2 = this.atlas.point(2); final Point point3 = this.atlas.point(3); final Point point4 = this.atlas.point(4); final Point point5 = this.atlas.point(5); final Point point6 = this.atlas.point(6); final Point point7 = this.atlas.point(7); logger.trace(point1.toString()); logger.trace(point2.toString()); logger.trace(point3.toString()); logger.trace(point4.toString()); logger.trace(point5.toString()); logger.trace(point6.toString()); logger.trace(point7.toString()); Assert.assertTrue(Location.TEST_3.boxAround(Distance.ONE_METER) .fullyGeometricallyEncloses(point1.getLocation())); Assert.assertTrue(Location.TEST_3.boxAround(Distance.kilometers(2)) .fullyGeometricallyEncloses(point3.getLocation())); Assert.assertEquals(1, Iterables .size(this.atlas.pointsWithin(Location.TEST_3.boxAround(Distance.ONE_METER)))); Assert.assertEquals(3, Iterables .size(this.atlas.pointsWithin(Location.TEST_3.boxAround(Distance.kilometers(2))))); final Rectangle box = Location.TEST_3.boxAround(Distance.ONE_METER); Assert.assertEquals(1, Iterables.size( this.atlas.points(point -> box.fullyGeometricallyEncloses(point.getLocation())))); }
@Test public void testIndex() { final Rectangle testBox = Location.TEST_6.boxAround(Distance.ONE_METER); Assert.assertEquals(1, Iterables.size(this.atlas.nodesWithin(testBox))); Assert.assertEquals(Location.TEST_6, this.atlas.nodesWithin(testBox).iterator().next().getLocation()); Assert.assertEquals(3, Iterables.size(this.atlas.edgesIntersecting(testBox))); Assert.assertTrue( Iterables.contains(this.atlas.edgesIntersecting(testBox), this.atlas.edge(9))); Assert.assertTrue( Iterables.contains(this.atlas.edgesIntersecting(testBox), this.atlas.edge(-9))); Assert.assertTrue( Iterables.contains(this.atlas.edgesIntersecting(testBox), this.atlas.edge(987))); }