/** * @param yAxis * The tile's y index * @param zoom * The zoom level * @return The corresponding latitude */ private Latitude tile2lat(final int yAxis, final int zoom) { final double pivot = Math.PI - CIRCULAR_MULTIPLIER * Math.PI * yAxis / Math.pow(ZOOM_LEVEL_POWER, zoom); return Latitude.degrees(Math.toDegrees(Math.atan(Math.sinh(pivot)))); }
@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())); }
/** * @param locationString * The {@link Location} as a {@link String} in "longitude(degrees),latitude(degrees)" * format * @return The corresponding {@link Location} */ public static Location forStringLongitudeLatitude(final String locationString) { final StringList split = StringList.split(locationString, ","); if (split.size() != 2) { throw new CoreException("Invalid Location String: {}", locationString); } final double latitude = Double.parseDouble(split.get(1)); final double longitude = Double.parseDouble(split.get(0)); return new Location(Latitude.degrees(latitude), Longitude.degrees(longitude)); }
/** * @param locationString * The {@link Location} as a {@link String} in "latitude(degrees),longitude(degrees)" * format * @return The corresponding {@link Location} */ public static Location forString(final String locationString) { final StringList split = StringList.split(locationString, ","); if (split.size() != 2) { throw new CoreException("Invalid Location String: {}", locationString); } final double latitude = Double.parseDouble(split.get(0)); final double longitude = Double.parseDouble(split.get(1)); return new Location(Latitude.degrees(latitude), Longitude.degrees(longitude)); }
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(); }
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; }
@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 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 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))); } }