@Override public String toString() { return String.valueOf(this.asDegrees()); } }
public JsonArray asGeoJsonBbox() { final JsonArray array = new JsonArray(); array.add(new JsonPrimitive(this.lowerLeft.getLongitude().asDegrees())); array.add(new JsonPrimitive(this.lowerLeft.getLatitude().asDegrees())); array.add(new JsonPrimitive(this.upperRight.getLongitude().asDegrees())); array.add(new JsonPrimitive(this.upperRight.getLatitude().asDegrees())); return array; }
@Override public JsonArray convert(final Location location) { final JsonArray coordinates = new JsonArray(); coordinates.add(new JsonPrimitive(location.getLongitude().asDegrees())); coordinates.add(new JsonPrimitive(location.getLatitude().asDegrees())); return coordinates; }
@Override public Coordinate convert(final Location location) { return new Coordinate(location.getLongitude().asDegrees(), location.getLatitude().asDegrees()); } }
final double latitude = location.getLatitude().asDegrees(); final double longitude = location.getLongitude().asDegrees(); int xAxis = (int) Math
final JsonArray coordinates = new JsonArray(); coordinates.add(new JsonPrimitive(point.getLocation().getLongitude().asDegrees())); coordinates.add(new JsonPrimitive(point.getLocation().getLatitude().asDegrees())); geometry.add(TASK_TYPE, new JsonPrimitive(POINT)); geometry.add(TASK_FEATURE_COORDINATES, coordinates);
@Override public byte[] convert(final PolyLine polyLine) { final Geometry geometry; final List<Coordinate> cooordinates = new ArrayList<>(); for (final Location location : polyLine) { // swap latitude/longitude for JTS Coordinate format cooordinates.add(new Coordinate(location.getLongitude().asDegrees(), location.getLatitude().asDegrees())); } final Coordinate[] coordinateArray = cooordinates .toArray(new Coordinate[cooordinates.size()]); if (coordinateArray.length == 1) { geometry = new GeometryFactory().createPoint(coordinateArray[0]); } else { geometry = new GeometryFactory().createLineString(coordinateArray); } final byte[] wkb = new WKBWriter().write(geometry); return wkb; } }
/** * @return JTS object {@link Envelope}, which is an equivalent of {@link Rectangle} */ public Envelope asEnvelope() { return new Envelope(this.lowerLeft.getLongitude().asDegrees(), this.upperRight.getLongitude().asDegrees(), this.lowerLeft.getLatitude().asDegrees(), this.upperRight.getLatitude().asDegrees()); }
/** * From a location, we get a Latitude / Longitude Json Array [ latitude, longitude ] * * @param location * An atlas location * @return JsonArray [ longitude, latitude ] coordinate. */ public static JsonArray coordinate(final Location location) { return coordinate(location.getLongitude().asDegrees(), location.getLatitude().asDegrees()); }
private String compress(final PolyLine points, final int precision0) { long oldLatitude = 0; long oldLongitude = 0; String encoded = ""; final double precision = Math.pow(10, precision0); Location last = Location.CENTER; for (final Location location : points) { // Round to N decimal places final long latitude = Math.round(location.getLatitude().asDegrees() * precision); final long longitude = Math.round(location.getLongitude().asDegrees() * precision); // Encode the differences between the points encoded += encodeNumber(latitude - oldLatitude); final long deltaLongitude = longitude - oldLongitude; if (Math.abs(deltaLongitude) > MAXIMUM_DELTA_LONGITUDE) { throw new PolyLineCompressionException( "Unable to compress the polyLine, two consecutive points ({} and {}) are too far apart in longitude: {} degrees.", last, location, deltaLongitude / precision); } encoded += encodeNumber(deltaLongitude); oldLatitude = latitude; oldLongitude = longitude; last = location; } return encoded; }
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; }
final double p0Y = this.start().getLatitude().asDegrees(); final double p1X = this.end().getLongitude().asDegrees(); final double p1Y = this.end().getLatitude().asDegrees(); final double p2X = that.start().getLongitude().asDegrees(); final double p2Y = that.start().getLatitude().asDegrees(); final double p3X = that.end().getLongitude().asDegrees(); final double p3Y = that.end().getLatitude().asDegrees();
@Override public Node convert(final Location object) { return new Node(new CommonEntityData(object.asConcatenation(), 0, new Date(), new OsmUser(0, "osm"), 0), object.getLatitude().asDegrees(), object.getLongitude().asDegrees()); } }
/** * This method returns the cross product between two adjacent edges. * * @see "https://en.wikipedia.org/wiki/Cross_product" * @param edge1 * An Edge entity in the roundabout * @param edge2 * An Edge entity in the roundabout adjacent to edge1 * @return A double corresponding to the cross product between two edges */ private static Double getCrossProduct(final Edge edge1, final Edge edge2) { // Get the nodes' latitudes and longitudes to use in deriving the vectors final double node1Y = edge1.start().getLocation().getLatitude().asDegrees(); final double node1X = edge1.start().getLocation().getLongitude().asDegrees(); final double node2Y = edge1.end().getLocation().getLatitude().asDegrees(); final double node2X = edge1.end().getLocation().getLongitude().asDegrees(); final double node3Y = edge2.end().getLocation().getLatitude().asDegrees(); final double node3X = edge2.end().getLocation().getLongitude().asDegrees(); // Get the vectors from node 2 to 1, and node 2 to 3 final double vector1X = node2X - node1X; final double vector1Y = node2Y - node1Y; final double vector2X = node2X - node3X; final double vector2Y = node2Y - node3Y; // The cross product tells us the direction of the orthogonal vector, which is // Directly related to the direction of rotation/traffic return (vector1X * vector2Y) - (vector1Y * vector2X); }
@Override public Node convert(final AtlasPrimitiveLocationItem object) { return new Node( new CommonEntityData(object.getLocation().asConcatenation(), 0, new Date(), new OsmUser(0, "osm"), 0, TAG_MAP_TO_TAG_COLLECTION_CONVERTER.convert(object.getTags())), object.getLocation().getLatitude().asDegrees(), object.getLocation().getLongitude().asDegrees()); } }
@Test public void testConversionToEarthCenteredEarthFixed() { final EarthCenteredEarthFixedCoordinate earthCenteredCoordinates = new EarthCenteredEarthFixedCoordinate( -576793.17, -5376363.47, 3372298.51); final GeodeticCoordinate geodeticCoordinates = CONVERTER .backwardConvert(earthCenteredCoordinates); Assert.assertEquals(32.12345, geodeticCoordinates.getLatitude().asDegrees(), 1e-3); Assert.assertEquals(-96.12345, geodeticCoordinates.getLongitude().asDegrees(), 1e-3); Assert.assertEquals(500.0, geodeticCoordinates.getAltitude().asMeters(), 1e-2); }
@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); }
@Test public void testFullConversionCycle() { final double latitude = -39.664914; final double longitude = 176.881899; final double altitude = 300.0; final GeodeticCoordinate geodeticCoordinates = new GeodeticCoordinate( Latitude.degrees(latitude), Longitude.degrees(longitude), Altitude.meters(altitude)); final EarthCenteredEarthFixedCoordinate earthCenteredCoordinates = CONVERTER .convert(geodeticCoordinates); assertEquals(-4909490.91860, earthCenteredCoordinates.getX(), 1e-2); assertEquals(267444.11617, earthCenteredCoordinates.getY(), 1e-2); assertEquals(-4049606.55365, earthCenteredCoordinates.getZ(), 1e-2); final GeodeticCoordinate backToGeodetic = CONVERTER .backwardConvert(earthCenteredCoordinates); assertEquals(latitude, backToGeodetic.getLatitude().asDegrees(), 1e-6); assertEquals(longitude, backToGeodetic.getLongitude().asDegrees(), 1e-6); assertEquals(altitude, backToGeodetic.getAltitude().asMeters(), 1e-6); } }