/** * Test if this rectangle fully encloses a {@link Located} item * * @param item * The item to test * @return True if this rectangle contains a {@link Located} item */ public boolean fullyGeometricallyEncloses(final Located item) { final Rectangle bounds = item instanceof Rectangle ? (Rectangle) item : item.bounds(); return this.lowerLeft().getLatitude().isLessThanOrEqualTo(bounds.lowerLeft().getLatitude()) && this.lowerLeft().getLongitude() .isLessThanOrEqualTo(bounds.lowerLeft().getLongitude()) && this.upperRight().getLatitude() .isGreaterThanOrEqualTo(bounds.upperRight().getLatitude()) && this.upperRight().getLongitude() .isGreaterThanOrEqualTo(bounds.upperRight().getLongitude()); }
private List<Location> randomLocations(final Rectangle bound, final int numberToGenerate) { final List<Location> list = new ArrayList<>(numberToGenerate); final List<Double> doubleLatitudes = new Random() .doubles(bound.lowerLeft().getLatitude().asDegrees(), bound.upperRight().getLatitude().asDegrees()) .limit(numberToGenerate).boxed().collect(Collectors.toList()); final List<Double> doubleLongitudes = new Random() .doubles(bound.lowerLeft().getLongitude().asDegrees(), bound.upperRight().getLongitude().asDegrees()) .limit(numberToGenerate).boxed().collect(Collectors.toList()); for (int i = 0; i < doubleLongitudes.size(); i++) { list.add(new Location(Latitude.degrees(doubleLatitudes.get(i)), Longitude.degrees(doubleLongitudes.get(i)))); } return list; }
/** * @param bounds * Bounds to constrain the result * @return A random location within the bounds */ public static Location random(final Rectangle bounds) { final int latitude = RANDOM.ints((int) bounds.lowerLeft().getLatitude().asDm7(), (int) bounds.upperRight().getLatitude().asDm7()).iterator().next(); final int longitude = RANDOM.ints((int) bounds.lowerLeft().getLongitude().asDm7(), (int) bounds.upperRight().getLongitude().asDm7()).iterator().next(); return new Location(Latitude.dm7(latitude), Longitude.dm7(longitude)); }
protected Rectangle2D asAwtRectangle() { final int xAxis = (int) this.upperLeft().getLongitude().asDm7(); final int yAxis = (int) this.upperLeft().getLatitude().asDm7(); final int width = (int) (this.upperRight().getLongitude().asDm7() - this.upperLeft().getLongitude().asDm7()); final int height = (int) (this.upperLeft().getLatitude().asDm7() - this.lowerLeft().getLatitude().asDm7()); return new java.awt.Rectangle(xAxis, yAxis, width, height); } }
final SlippyTile lowerLeft = new SlippyTile(bounds.lowerLeft(), zoom); final SlippyTile upperRight = new SlippyTile(bounds.upperRight(), zoom); final int minX = lowerLeft.getX();
final Distance rectangle1CornerToCorner = this.rectangle1.lowerLeft() .distanceTo(this.rectangle1.upperRight()); final Rectangle collapsedRectangle1 = this.rectangle1.contract(rectangle1CornerToCorner); 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(Math.round(contractRectangle2Distance.asMeters()), Math.round(new Location(collapsedVertically.middle().getLatitude(), this.rectangle2.lowerLeft().getLongitude()) .distanceTo(collapsedVertically.lowerLeft()).asMeters()));
final Rectangle bounds = tile.bounds(); writer.write("(\'" + tile.getName() + "\', ST_MakeEnvelope(" + bounds.lowerLeft().getLongitude().asDegrees() + "," + bounds.lowerLeft().getLatitude().asDegrees() + "," + bounds.upperRight().getLongitude().asDegrees() + "," + bounds.upperRight().getLatitude().asDegrees() + ",4326))");
@Test public void testSurface() { final Rectangle rectangle = Rectangle.TEST_RECTANGLE; Assert.assertEquals(rectangle.surface(), new Polygon(rectangle).surface()); final Polygon tilted = new Polygon(rectangle.lowerLeft(), new Location(rectangle.upperLeft().getLatitude(), Longitude.degrees(rectangle.upperLeft().getLongitude().asDegrees() + 0.1)), new Location(rectangle.upperRight().getLatitude(), Longitude.degrees(rectangle.upperRight().getLongitude().asDegrees() + 0.1)), rectangle.lowerRight()); Assert.assertEquals(rectangle.surface(), tilted.surface()); }
@Test public void testSurface() { final Rectangle rectangle = Rectangle.TEST_RECTANGLE; Assert.assertEquals(rectangle.surface(), MultiPolygon.forPolygon(rectangle).surface()); final MultiPolygon tilted = MultiPolygon.forPolygon(new Polygon(rectangle.lowerLeft(), new Location(rectangle.upperLeft().getLatitude(), Longitude.degrees(rectangle.upperLeft().getLongitude().asDegrees() + 0.1)), new Location(rectangle.upperRight().getLatitude(), Longitude.degrees(rectangle.upperRight().getLongitude().asDegrees() + 0.1)), rectangle.lowerRight())); Assert.assertEquals(rectangle.surface(), tilted.surface()); }