@Override public Rectangle bounds() { return Rectangle.forLocated(this.atlases); }
@Override public JsonElement serialize(final Change source, final Type typeOfSource, final JsonSerializationContext context) { final JsonObject result = new JsonObject(); result.addProperty("type", "FeatureCollection"); final Rectangle bounds = source.bounds(); result.add("bbox", bounds.asGeoJsonBbox()); final JsonArray features = new JsonArray(); source.changes().map(featureChangeTypeHierarchyAdapter::serialize) .forEach(features::add); result.add("features", features); final JsonObject properties = new JsonObject(); properties.addProperty("bboxWKT", source.bounds().toWkt()); result.add("properties", properties); return result; } }
@Override public void add(final Rectangle bound, final T item) { this.tree.insert(bound.asEnvelope(), item); if (this.bound != null) { this.bound = this.bound.combine(bound); } else { this.bound = bound; } }
if (this.equals(other)) if (this.fullyGeometricallyEncloses(other)) if (other.fullyGeometricallyEncloses(this)) final Set<Location> intersections = this.intersections(other); if (intersections.size() == 0) return Rectangle.forLocations(intersections.iterator().next()); return Rectangle.forLocations(location1, location2); if (this.width().isLessThanOrEqualTo(other.width())) if (other.fullyGeometricallyEncloses(missing)) return Rectangle.forLocations(location1, location2, missing); if (this.fullyGeometricallyEncloses(missing)) return Rectangle.forLocations(location1, location2, missing); if (this.height().isLessThanOrEqualTo(other.height())) if (other.fullyGeometricallyEncloses(missing)) return Rectangle.forLocations(location1, location2, missing);
final Distance rectangle1CornerToCorner = this.rectangle1.lowerLeft() .distanceTo(this.rectangle1.upperRight()); final Rectangle collapsedRectangle1 = this.rectangle1.contract(rectangle1CornerToCorner); Assert.assertEquals(collapsedRectangle1.center().bounds(), collapsedRectangle1); Assert.assertEquals(Surface.forDm7Squared(0), collapsedRectangle1.surface()); final Rectangle expanded = this.rectangle1.expand(Distance.ONE_METER); Assert.assertEquals(this.rectangle1, expanded.contract(Distance.ONE_METER)); .distanceTo(this.rectangle1.upperRight()).scaleBy(.51); final Rectangle collapsedHorizontally = this.rectangle1 .contract(contractRectangle1Distance); Assert.assertEquals(Surface.forDm7Squared(0), collapsedHorizontally.surface()); Assert.assertEquals(collapsedHorizontally.surface(), this.rectangle1.contract(contractRectangle1Distance.scaleBy(10)).surface()); Assert.assertEquals(Math.round(contractRectangle1Distance.asMeters()), Math.round(new Location(this.rectangle1.lowerLeft().getLatitude(), collapsedHorizontally.middle().getLongitude()) .distanceTo(collapsedHorizontally.lowerLeft()).asMeters())); .distanceTo(this.rectangle2.lowerLeft()).scaleBy(.51); final Rectangle collapsedVertically = this.rectangle2.contract(contractRectangle2Distance); Assert.assertEquals(Surface.forDm7Squared(0), collapsedVertically.surface()); Assert.assertEquals(collapsedVertically.surface(), this.rectangle2.contract(contractRectangle2Distance.scaleBy(10)).surface()); Assert.assertEquals(Math.round(contractRectangle2Distance.asMeters()), Math.round(new Location(collapsedVertically.middle().getLatitude(), this.rectangle2.lowerLeft().getLongitude()) .distanceTo(collapsedVertically.lowerLeft()).asMeters()));
bounds = bounds.combine(nextBounds); if (bounds.width().onEarth().isLessThan(TEN_METERS)) bounds = bounds.expandHorizontally(TEN_METERS); if (bounds.height().onEarth().isLessThan(TEN_METERS)) bounds = bounds.expandVertically(TEN_METERS);
if (tooShortHeight && tooShortWidth) return this.center().bounds(); final Location lowerRight = new Location(this.lowerLeft().getLatitude(), this.upperRight().getLongitude()); if (tooShortHeight) final Latitude sharedLatitude = lowerRight.midPoint(this.upperRight()) .getLatitude(); return forCorners(new Location(sharedLatitude, newLowerLeft.getLongitude()), new Location(sharedLatitude, newUpperRight.getLongitude())); final Longitude sharedLongitude = lowerRight.midPoint(this.lowerLeft()) .getLongitude(); return forCorners(new Location(newLowerLeft.getLatitude(), sharedLongitude), new Location(newUpperRight.getLatitude(), sharedLongitude)); return forCorners(newLowerLeft, newUpperRight);
@Override public Rectangle bounds() { return Rectangle.forCorners(this, this); }
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; }
@Test public void testAntiMeridianEastRectangle() { final Location antiMeridian = new Location(Latitude.ZERO, Longitude.degrees(180)); final Location lowerLeftAntiMeridianRectangle = new Location(Latitude.degrees(-10), Longitude.degrees(170)); final Location lowerLeftTestRectangle = new Location(Latitude.degrees(-10), Longitude.degrees(150)); final Location upperRightTestRectangle1 = new Location(Latitude.ZERO, Longitude.degrees(160)); final Location upperRightTestRectangle2 = new Location(Latitude.ZERO, Longitude.degrees(175)); // List construction final Rectangle antiMeridianRectangle1 = Rectangle .forLocations(Arrays.asList(antiMeridian, lowerLeftAntiMeridianRectangle)); final Rectangle testRectangle1 = Rectangle .forLocations(Arrays.asList(upperRightTestRectangle1, lowerLeftTestRectangle)); Assert.assertFalse(testRectangle1.overlaps(antiMeridianRectangle1)); Assert.assertFalse(antiMeridianRectangle1.overlaps(testRectangle1)); // Corners construction final Rectangle antiMeridianRectangle2 = Rectangle .forCorners(lowerLeftAntiMeridianRectangle, antiMeridian); final Rectangle testRectangle2 = Rectangle.forCorners(lowerLeftTestRectangle, upperRightTestRectangle2); Assert.assertTrue(testRectangle2.overlaps(antiMeridianRectangle2)); Assert.assertTrue(antiMeridianRectangle2.overlaps(testRectangle2)); }
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()))); }
@Override public Rectangle bounds() { return Rectangle.forLocations(this); }
@Override public boolean fullyGeometricallyEncloses(final Rectangle item) { return this.fullyGeometricallyEncloses((Located) item); }
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 Set<Node> leafNodesIntersecting(final PolyLine polyLine) { final Set<Node> result = new HashSet<>(); final Rectangle polyLineBounds = polyLine.bounds(); if (polyLineBounds.overlaps(bounds())) { if (isFinal() && (polyLine.intersects(bounds()) || bounds().fullyGeometricallyEncloses(polyLine))) { result.add(this); } else { for (final Node child : this.children) { result.addAll(child.leafNodesIntersecting(polyLine)); } } } return result; }
@Test public void testBounds() { final String wkt = "MULTILINESTRING ((113.9980787038803 7.3216002915048872, 113.99803847074506 7.3215225281339456), " + "(113.99799555540086 7.3218335816030984, 113.99808806341453 7.3217805876994444))"; final MultiPolyLine multiPolyLine = MultiPolyLine.wkt(wkt); final Rectangle bound = multiPolyLine.bounds(); final List<Location> locations = Lists.newArrayList(); locations.add(Location.forString("7.3216002915048872, 113.9980787038803")); locations.add(Location.forString("7.3215225281339456, 113.99803847074506")); locations.add(Location.forString("7.3218335816030984, 113.99799555540086")); locations.add(Location.forString("7.3217805876994444, 113.99808806341453")); final Rectangle rectangle = Rectangle.forLocations(locations); Assert.assertTrue(rectangle.equals(bound)); }
final Rectangle featureBound = Rectangle.forLocations( new Location(Latitude.degrees(boundingBox.getMinY()), Longitude.degrees(boundingBox.getMinX())), Longitude.degrees(boundingBox.getMaxX()))); if (this.bound.overlaps(featureBound))
/** * 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))); }
@Test public void testIntersection() { Assert.assertEquals(Rectangle.forLocations(this.location2), this.rectangle1.intersection(this.rectangle2)); Assert.assertEquals(this.rectangle1, this.rectangle1.intersection(this.rectangle3)); Assert.assertEquals( Rectangle.forLocations(Location.TEST_4, new Location(Location.TEST_6.getLatitude(), Location.TEST_2.getLongitude())), this.rectangle3.intersection(this.rectangle4)); }