private void output(final AtlasEntity item) { Rectangle rectangle = item.bounds(); if (this.distanceInMeters.isPresent()) { rectangle = rectangle.expand(Distance.meters(this.distanceInMeters.get())); } item.getAtlas().subAtlas(rectangle, AtlasCutType.SOFT_CUT).ifPresent(this.subAtlases::add); } }
public LocationIterableProperties asGeoJsonBigNode() { final List<Location> locations = new ArrayList<>(); nodes().stream().forEach(node -> locations .addAll(Rectangle.forLocated(node.getLocation()).expand(Distance.meters(2)))); return new LocationIterableProperties(new Polygon(locations), Maps.hashMap("BigNode", String.valueOf(getSource().getIdentifier()))); }
protected Set<Node> neighbors(final SlippyTile targetTile) { final Set<Node> neighboringNodes = new HashSet<>(); for (final Node leafNode : this.leafNodes(targetTile.bounds())) { final Rectangle expandedBoundary = leafNode.bounds() .expand(SlippyTile.calculateExpansionDistance(leafNode.bounds())); if (targetTile.bounds().overlaps(expandedBoundary) && !leafNode.bounds().equals(targetTile.bounds())) { neighboringNodes.add(leafNode); } } return neighboringNodes; }
/** * Main API for time zone query * * @param location * The location to query * @return the specified TimeZone, or the GMT zone if in the middle of the sea */ public synchronized TimeZone timeZone(final Location location) { List<TimeZoneBoundary> boundaries = this.index.get(location.bounds(), boundary -> boundary.getPolygon().fullyGeometricallyEncloses(location)); // if find polygons contain location if (boundaries.size() >= 1) { return smallest(boundaries).getTimeZone(); } // expand bounding box by 12 * 2 nautical miles and search again final Rectangle larger = location.bounds().expand(SEA_TERRITORY_ZONE_WITH_BUFFER); boundaries = this.index.get(larger); // return any found one if (boundaries.size() >= 1) { return boundaries.get(0).getTimeZone(); } // the location is in the middle of the sea, use normalized time zone (15 degree per zone) final int offset = (int) location.getLongitude().asDegrees() / DEGREES_PER_TIME_ZONE; return TimeZone.getTimeZone(ZoneOffset.of(offset > 0 ? "+" + offset : "" + offset)); }
/** * Query country boundaries which cover/partially cover given {@link PolyLine}, with an * extension square box * * @param polyLine * Any {@link PolyLine} or {@link Polygon} * @param extension * Extension {@link Distance} * @return a list of {@link CountryBoundary} */ public List<CountryBoundary> boundaries(final PolyLine polyLine, final Distance extension) { return this.boundariesHelper( () -> this.query(polyLine.bounds().expand(extension).asEnvelope()), boundary -> boundary.intersects(JTS_POLYLINE_CONVERTER.convert(polyLine))); }
/** * @return All neighbors for the current tile, including diagonal tiles that may share a single * vertex on the corner they meet. */ public Set<SlippyTile> neighbors() { return Iterables .stream(new SlippyTileSharding(this.zoom) .shards(bounds().expand(calculateExpansionDistance(bounds())))) .map(shard -> (SlippyTile) shard).filter(tile -> !this.equals(tile)).collectToSet(); }
@Test public void testIsland() { final TimeZoneMap map = new TimeZoneMap(BERMUDA_INSIDE.bounds().expand(Distance.miles(50))); Assert.assertEquals("Atlantic/Bermuda", map.timeZone(BERMUDA_INSIDE).getID()); Assert.assertEquals("Atlantic/Bermuda", map.timeZone(BERMUDA_OUTSIDE_CLOSE).getID()); // in the middle of the sea Assert.assertEquals("GMT-04:00", map.timeZone(BERMUDA_OUTSIDE_FARAWAY).getID()); } }
@Test public void testBoundary() { final TimeZoneMap map = new TimeZoneMap( LOCATION_IN_NEVADA.bounds().expand(Distance.miles(50))); Assert.assertEquals("America/Los_Angeles", map.timeZone(LOCATION_IN_NEVADA).getID()); Assert.assertEquals("America/Boise", map.timeZone(LOCATION_IN_IDAHO).getID()); Assert.assertEquals("America/Denver", map.timeZone(LOCATION_IN_UTAH).getID()); }
@Test public void testArizonaMultiPolygon() { final TimeZoneMap map = new TimeZoneMap( ARIZONA_MULTI_POLYGON_LEVEL_3.bounds().expand(Distance.miles(50))); Assert.assertEquals("America/Denver", map.timeZone(ARIZONA_MULTI_POLYGON_LEVEL_3).getID()); Assert.assertEquals("America/Phoenix", map.timeZone(ARIZONA_MULTI_POLYGON_LEVEL_2).getID()); Assert.assertEquals("America/Denver", map.timeZone(ARIZONA_MULTI_POLYGON_LEVEL_1).getID()); }
final Distance searchDistance, final Distance toleranceDistance) final Rectangle bounds = location.bounds().expand(searchDistance); buildNodeSpatialIndexIfNecessary(); final SortedSet<Node> nodes = new TreeSet<>((node1, node2) ->
initialShard.bounds().expand(SHARD_EXPANSION_DISTANCE), Rectangle.MAXIMUM) .withDeferredLoading(true).withExtendIndefinitely(false) .withAtlasEntitiesToConsiderForExpansion(
@Test public void testRawAtlasCreationWithBoundingBox() { final String path = RawAtlasGeneratorTest.class.getResource("9-433-268.osm.pbf").getPath(); final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(path), MultiPolygon.forPolygon(Location.forWkt("POINT (124.9721500 -8.9466200)").bounds() .expand(Distance.meters(100)))); final Atlas atlas = rawAtlasGenerator.build(); // Verify Atlas Entities assertBasicRawAtlasPrinciples(atlas); Assert.assertEquals(1361, atlas.numberOfPoints()); Assert.assertEquals(25, atlas.numberOfLines()); Assert.assertEquals(0, atlas.numberOfRelations()); }
final Rectangle expanded = this.rectangle1.expand(Distance.ONE_METER); Assert.assertEquals(this.rectangle1, expanded.contract(Distance.ONE_METER));