/** * @param xAxis * The tile's x index * @param zoom * The zoom level * @return The corresponding longitude */ private Longitude tile2lon(final int xAxis, final int zoom) { final double longitude = xAxis / Math.pow(ZOOM_LEVEL_POWER, zoom) * FULL_ROTATION_DEGREES - HALF_ROTATION_DEGREES; return longitude >= LONGITUDE_BOUNDARY ? Longitude.MAXIMUM : longitude < -LONGITUDE_BOUNDARY ? Longitude.MINIMUM : Longitude.degrees(longitude); } }
@Override public Location backwardConvert(final Coordinate coordinate) { return new Location(Latitude.degrees(coordinate.y), Longitude.degrees(coordinate.x)); }
public Converter<JsonArray, Location> revert() { return jsonArray -> { final double latitude = jsonArray.get(1).getAsDouble(); double longitude = jsonArray.get(0).getAsDouble(); if (longitude == DATE_LINE_LONGITUDE_EAST) { longitude = DATE_LINE_LONGITUDE_WEST; } return new Location(Latitude.degrees(latitude), Longitude.degrees(longitude)); }; } }
@Override public Location backwardConvert(final Point point) { return new Location(Latitude.degrees(point.getY()), Longitude.degrees(point.getX())); }
private boolean nodeWithinTargetBoundary(final Node node) { return this.boundingBox.fullyGeometricallyEncloses(new Location( Latitude.degrees(node.getLatitude()), Longitude.degrees(node.getLongitude()))); }
private Location convertLoc(final Loc point) { if (point.value().equalsIgnoreCase(Loc.USE_LATLON) && (point.lat() == Loc.BAD_VALUE || point.lon() == Loc.BAD_VALUE)) { throw new CoreException("Loc doesn't have a valid string value or lat/lon values"); } if (point.value().equalsIgnoreCase(Loc.USE_LATLON)) { return new Location(Latitude.degrees(point.lat()), Longitude.degrees(point.lon())); } if (point.value().equalsIgnoreCase(Loc.TEST_1)) { return Location.TEST_1; } return Location.forString(point.value()); }
@Override public Location backwardConvert(final Node object) { return new Location(Latitude.degrees(object.getLatitude()), Longitude.degrees(object.getLongitude())); }
@Test public void testGeodeticCoordinateEquality() { final GeodeticCoordinate coordinate = new GeodeticCoordinate(Latitude.degrees(32.12345), Longitude.degrees(-96.12345), Altitude.meters(500.0)); final GeodeticCoordinate identicalCoordinate = new GeodeticCoordinate( Latitude.degrees(32.12345), Longitude.degrees(-96.12345), Altitude.meters(500.0)); final GeodeticCoordinate newCoordinate = new GeodeticCoordinate(Latitude.degrees(45.24252), Longitude.degrees(-99.14141), Altitude.meters(700.0)); Assert.assertEquals(coordinate, identicalCoordinate); Assert.assertNotEquals(coordinate, newCoordinate); } }
/** * Uses the {@link Node} OSM identifier, geometry and tags to create an Atlas {@link Point}. * * @param entity * The {@link Entity} that will become an Atlas {@link Point} */ private void processNode(final Entity entity) { final Node node = (Node) entity; this.builder.addPoint(padIdentifier(node.getId()), new Location(Latitude.degrees(node.getLatitude()), Longitude.degrees(node.getLongitude())), populateEntityTags(node)); this.statistics.recordCreatedPoint(); }
@Test public void testHeadingTo() { final Location location1 = new Location(Latitude.degrees(37.336900), Longitude.degrees(-122.005414)); final Location location2 = new Location(Latitude.degrees(37.332758), Longitude.degrees(-122.005409)); Assert.assertTrue(Heading.degrees(180).difference(location1.headingTo(location2)) .isLessThan(Angle.degrees(1))); }
@Test public void testAssertCompareAntiMeridian() { final Longitude oneEighty = Longitude.degrees(180); final Longitude minusOneEighty = Longitude.degrees(-180); final Longitude ninety = Longitude.degrees(90); Assert.assertTrue(oneEighty.isGreaterThan(minusOneEighty)); Assert.assertTrue(minusOneEighty.isLessThan(oneEighty)); Assert.assertFalse(minusOneEighty.isGreaterThanOrEqualTo(oneEighty)); Assert.assertTrue(oneEighty.isGreaterThanOrEqualTo(oneEighty)); Assert.assertTrue(oneEighty.isLessThanOrEqualTo(oneEighty)); Assert.assertTrue(oneEighty.isGreaterThan(ninety)); Assert.assertTrue(ninety.isLessThanOrEqualTo(oneEighty)); } }
@Test public void testMidPoint() { final Location location1 = new Location(Latitude.degrees(52.205), Longitude.degrees(0.119)); final Location location2 = new Location(Latitude.degrees(48.857), Longitude.degrees(2.351)); final Location midpoint = location1.midPoint(location2); Assert.assertEquals(50.5363269, midpoint.getLatitude().asDegrees(), DELTA); Assert.assertEquals(1.2746141, midpoint.getLongitude().asDegrees(), DELTA); }
@Test public void testLoxodromicMidPoint() { final Location location1 = new Location(Latitude.degrees(51.127), Longitude.degrees(1.338)); final Location location2 = new Location(Latitude.degrees(50.964), Longitude.degrees(1.853)); final Location midpoint = location1.loxodromicMidPoint(location2); Assert.assertEquals(51.0455, midpoint.getLatitude().asDegrees(), DELTA); Assert.assertEquals(1.5957265, midpoint.getLongitude().asDegrees(), DELTA); }
@Override public Location middle() { return new Location( Latitude.degrees((this.start().getLatitude().asDegrees() + this.end().getLatitude().asDegrees()) / 2.0), Longitude.degrees((this.start().getLongitude().asDegrees() + this.end().getLongitude().asDegrees()) / 2.0)); }
@Test public void testConversionToGeodetic() { final GeodeticCoordinate geodeticCoordinates = new GeodeticCoordinate( Latitude.degrees(32.12345), Longitude.degrees(-96.12345), Altitude.meters(500.0)); final EarthCenteredEarthFixedCoordinate earthCenteredCoordinates = CONVERTER .convert(geodeticCoordinates); Assert.assertEquals(-576793.17, earthCenteredCoordinates.getX(), 1e-2); Assert.assertEquals(-5376363.47, earthCenteredCoordinates.getY(), 1e-2); Assert.assertEquals(3372298.51, earthCenteredCoordinates.getZ(), 1e-2); }
@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()); }
@Test public void testAtlasFileExtensionFilter() { final PackedAtlasBuilder builder = new PackedAtlasBuilder(); builder.addPoint(1, new Location(Latitude.degrees(0), Longitude.degrees(0)), Maps.hashMap()); final Atlas atlas = builder.get(); final ByteArrayResource atlasResource = new ByteArrayResource() .withName("iDoNotHaveAnAtlasExt.txt"); atlas.save(atlasResource); Assert.assertNull(new AtlasResourceLoader().load(atlasResource)); Assert.assertNotNull(new AtlasResourceLoader().withAtlasFileExtensionFilterSetTo(false) .load(atlasResource)); }
@Test public void testIntersection() { Assert.assertEquals(null, new Segment(Location.TEST_1, Location.TEST_2) .intersection(new Segment(Location.TEST_4, Location.TEST_3))); Assert.assertEquals(false, new Segment(Location.TEST_1, Location.TEST_2) .intersects(new Segment(Location.TEST_4, Location.TEST_3))); Assert.assertEquals( new Location(Latitude.degrees(37.3273389), Longitude.degrees(-122.0287109)), new Segment(Location.TEST_1, Location.TEST_3) .intersection(new Segment(Location.TEST_4, Location.TEST_2))); Assert.assertEquals(true, new Segment(Location.TEST_1, Location.TEST_3) .intersects(new Segment(Location.TEST_4, Location.TEST_2))); } }