/** * @param radians * A Longitude value in Radians * @return The built {@link Longitude} object using the Radians value */ public static Longitude radians(final double radians) { return dm7(Math.round(radians * DM7_PER_RADIAN)); }
/** * @param degrees * A Longitude value in degrees * @return The built {@link Longitude} object using the degrees value */ public static Longitude degrees(final double degrees) { return dm7(Math.round(degrees * DM7_PER_DEGREE)); }
/** * If the given radian exceeds the longitude boundary, will return the boundary value. * * @param radians * The radian of longitude * @return The adjusted longitude if exceeds the boundary, otherwise the normal longitude */ public static Longitude radiansBounded(final double radians) { long dm7 = Math.round(radians * DM7_PER_RADIAN); if (dm7 < MINIMUM_DM7) { dm7 = MINIMUM_DM7; } if (dm7 >= MAXIMUM_DM7) { dm7 = MAXIMUM_DM7 - 1; } return dm7(dm7); }
/** * Create a location from a dm7 latitude and dm7 longitude concatenated in a long * * @param concatenation * The first 32 bits are for the dm7 latitude, and the last 32 bits are for the dm7 * longitude. */ public Location(final long concatenation) { final int lon = (int) concatenation; final int lat = (int) (concatenation >>> INT_SIZE) & INT_FULL_MASK; this.longitude = Longitude.dm7(lon); this.latitude = Latitude.dm7(lat); }
@Override public Location convert(final ProtoLocation protoLocation) { final Longitude longitude = Longitude.dm7(protoLocation.getLongitude()); final Latitude latitude = Latitude.dm7(protoLocation.getLatitude()); return new Location(latitude, longitude); } }
/** * @return An expanded {@link PolyLine} */ public PolyLine asPolyLine() { boolean lat = true; int latitude = 0; int longitude = 0; final List<Location> locations = new ArrayList<>(); for (int index = 0; index < this.positions.length; index++) { final byte[] result = this.positions[index]; if (lat) { latitude += expand(result, index); lat = false; } else { longitude += expand(result, index); locations.add(new Location(Latitude.dm7(latitude), Longitude.dm7(longitude))); lat = true; } } return new PolyLine(locations); }
private void parseNodes(final PackedAtlasBuilder builder, final List<ProtoNode> nodes) { nodes.forEach(protoNode -> { final long identifier = protoNode.getId(); final Longitude longitude = Longitude.dm7(protoNode.getLocation().getLongitude()); final Latitude latitude = Latitude.dm7(protoNode.getLocation().getLatitude()); final Location geometry = new Location(latitude, longitude); final Map<String, String> tags = ProtoAtlasBuilder.PROTOTAG_LIST_CONVERTER .convert(protoNode.getTagsList()); builder.addNode(identifier, geometry, tags); }); }
private void parsePoints(final PackedAtlasBuilder builder, final List<ProtoPoint> points) { points.forEach(protoPoint -> { final long identifier = protoPoint.getId(); final Longitude longitude = Longitude.dm7(protoPoint.getLocation().getLongitude()); final Latitude latitude = Latitude.dm7(protoPoint.getLocation().getLatitude()); final Location geometry = new Location(latitude, longitude); final Map<String, String> tags = ProtoAtlasBuilder.PROTOTAG_LIST_CONVERTER .convert(protoPoint.getTagsList()); builder.addPoint(identifier, geometry, tags); }); }
@Test public void testLocationToProtoLocation() { final ProtoLocationConverter converter = new ProtoLocationConverter(); final Location location = new Location(Latitude.dm7(1), Longitude.dm7(1)); final ProtoLocation protoLocation = ProtoLocation.newBuilder().setLatitude(1) .setLongitude(1).build(); final ProtoLocation convertedFromLocation = converter.backwardConvert(location); logger.info("{}", protoLocation); logger.info("{}", convertedFromLocation); Assert.assertEquals(protoLocation, convertedFromLocation); }
protected Long nodeIdentifierForLocation(final Location location) { buildNodeSpatialIndexIfNecessary(); final Iterator<Node> nodes; final Rectangle bounds = location.bounds(); // Handle the anti-meridian case. +180 and -180 are identical in the Atlas, if this happens // to be the Longitude of the passed in Location, make sure to also check the equivalent // Location across the anti-meridian. if (location.getLongitude().equals(Longitude.ANTIMERIDIAN_EAST) || location.getLongitude().equals(Longitude.ANTIMERIDIAN_WEST)) { final Location locationAcrossAntiMeridian = new Location(location.getLatitude(), Longitude.dm7(-location.getLongitude().asDm7())); final Rectangle boundsAcrossAntiMeridian = locationAcrossAntiMeridian.bounds(); nodes = new MultiIterable<>(this.getNodeSpatialIndex().get(bounds), this.getNodeSpatialIndex().get(boundsAcrossAntiMeridian)).iterator(); } else { nodes = this.getNodeSpatialIndex().get(bounds).iterator(); } if (nodes.hasNext()) { return nodes.next().getIdentifier(); } return null; }
@Test public void testProtoLocationToLocation() { final ProtoLocationConverter converter = new ProtoLocationConverter(); final ProtoLocation protoLocation = ProtoLocation.newBuilder().setLatitude(1) .setLongitude(1).build(); final Location location = new Location(Latitude.dm7(1), Longitude.dm7(1)); final Location convertedFromProtoLocation = converter.convert(protoLocation); logger.info("{}", location); logger.info("{}", convertedFromProtoLocation); Assert.assertEquals(location, convertedFromProtoLocation); } }
+ offsetDistance / shape.dotProductLength() * shape.longitudeSpan(); final Location snapped = new Location(Latitude.dm7(Math.round(latitudeAsDm7)), Longitude.dm7(Math.round(longitudeAsDm7))); return new SnappedLocation(origin, snapped, shape);
/** * @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)); }