@Override public Rectangle bounds() { return Rectangle.forLocations(this); }
/** * @param that * The other {@link Rectangle} to combine * @return The {@link Rectangle} wrapping this {@link Rectangle} and the one passed as an * argument. */ public Rectangle combine(final Rectangle that) { return Rectangle.forLocations(this.lowerLeft, this.upperRight, that.lowerLeft, that.upperRight); }
@Override public Rectangle bounds() { final List<Location> locations = Lists.newArrayList(); this.polyLineList.stream().map(PolyLine::getPoints).forEach(locations::addAll); return Rectangle.forLocations(locations); }
/** * Build a {@link Rectangle} that wraps around an array of {@link Location} objects. * * @param locations * The array of {@link Location} objects * @return The resulting {@link Rectangle} */ public static Rectangle forLocations(final Location... locations) { return Rectangle.forLocations(Iterables.iterable(locations)); }
@Override public Rectangle bounds() { if (this.bounds == null && !this.isEmpty()) { final Set<Location> locations = new HashSet<>(); forEach(polygon -> polygon.forEach(locations::add)); this.bounds = Rectangle.forLocations(locations); } return this.bounds; }
/** * Get a {@link Rectangle} around this {@link Location} * * @param extension * The height of the 1/2 {@link Rectangle}. The height of the total {@link Rectangle} * will be twice that. Same for width. * @return The {@link Rectangle} around this {@link Location} */ public Rectangle boxAround(final Distance extension) { final Location north = this.shiftAlongGreatCircle(Heading.NORTH, extension); final Location south = this.shiftAlongGreatCircle(Heading.SOUTH, extension); final Location east = this.shiftAlongGreatCircle(Heading.EAST, extension); final Location west = this.shiftAlongGreatCircle(Heading.WEST, extension); return Rectangle.forLocations(north, south, east, west); }
@Before public void init() { this.quadrant = new Polygon(Location.TEST_3, Location.TEST_4, Location.TEST_1, Location.TEST_2); this.rectangle = Rectangle .forLocations(Iterables.iterable(Location.TEST_5, Location.TEST_3)); }
return Rectangle.forLocations(intersections.iterator().next()); && !location1.getLongitude().equals(location2.getLongitude())) return Rectangle.forLocations(location1, location2); return Rectangle.forLocations(location1, location2, missing); return Rectangle.forLocations(location1, location2, missing); return Rectangle.forLocations(location1, location2, missing); return Rectangle.forLocations(location1, location2, missing);
/** * @param rectangleString * The string definition * @return The resulting {@link Rectangle} parsed from its string definition */ public static Rectangle forString(final String rectangleString) { final StringList split = StringList.split(rectangleString, ":"); if (split.size() != 2) { throw new CoreException("Invalid Rectangle String: {}", rectangleString); } return forLocations(Location.forString(split.get(0)), Location.forString(split.get(1))); }
@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)); }
public static Rectangle forBoundingBox(final BoundingBox boundingBox) { return Rectangle.forLocations( new Location(Latitude.degrees(boundingBox.getMinY()), Longitude.degrees(boundingBox.getMinX())), new Location(Latitude.degrees(boundingBox.getMaxY()), Longitude.degrees(boundingBox.getMaxX()))); }
@Test public void testCovers() { final Rectangle rwac = Rectangle .forLocations(Iterables.iterable(Location.TEST_3, Location.TEST_1)); logger.info("Polygon: " + this.quadrant); final boolean containsTest6 = this.quadrant.fullyGeometricallyEncloses(Location.TEST_6); final boolean containsTest5 = this.quadrant.fullyGeometricallyEncloses(Location.TEST_5); final boolean containsTestRectangle = this.quadrant .fullyGeometricallyEncloses(Rectangle.TEST_RECTANGLE_2); final boolean containsRWAC = this.quadrant.fullyGeometricallyEncloses(rwac); logger.info("Test 6: {} -> {}", Location.TEST_6, containsTest6); logger.info("Test 5: {} -> {}", Location.TEST_5, containsTest5); logger.info("Test Rectangle: {} -> {}", Rectangle.TEST_RECTANGLE_2, containsTestRectangle); logger.info("RWAC 2: {} -> {}", rwac, containsRWAC); Assert.assertTrue(!containsTest5); Assert.assertTrue(containsTest6); Assert.assertTrue(containsTestRectangle); Assert.assertTrue(!containsRWAC); }
@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)); }
@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)); }
final Rectangle featureBound = Rectangle.forLocations( new Location(Latitude.degrees(boundingBox.getMinY()), Longitude.degrees(boundingBox.getMinX())),
final Rectangle rectangleInMAF = Rectangle.forLocations(Location.forString("18.09, -63.06"), Location.forString("18.08, -63.04")); final Geometry geometry = reader.read(new WktPolygonConverter().convert(rectangleInMAF));
@Test public void testPartialLoad() { final Rectangle rectangleInStMartin = Rectangle.forLocations( Location.forString("18.0298609, -63.0665379"), Location.forString("18.0298052, -63.0663907")); final CountryBoundaryMap partialStMartinMap = new CountryBoundaryMap(rectangleInStMartin); partialStMartinMap.readFromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(partialStMartinMap.hasGridIndex()); Assert.assertEquals(1, partialStMartinMap.size()); Assert.assertEquals("MAF", firstCountryName(partialStMartinMap)); Assert.assertNotNull(partialStMartinMap.countryBoundary("MAF")); Assert.assertNull(partialStMartinMap.countryBoundary("AIA")); final Rectangle rectangleInAIA = Rectangle.forLocations( Location.forString("18.096068, -63.0643537"), Location.forString("18.0927713, -63.0612415")); final CountryBoundaryMap partialAIAMap = new CountryBoundaryMap(rectangleInAIA); partialAIAMap.readFromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(partialAIAMap.hasGridIndex()); Assert.assertEquals(1, partialAIAMap.size()); Assert.assertEquals("AIA", firstCountryName(partialAIAMap)); Assert.assertNotNull(partialAIAMap.countryBoundary("AIA")); Assert.assertNull(partialAIAMap.countryBoundary("MAF")); }