List of usage examples for com.google.common.geometry S2LatLng fromDegrees
public static S2LatLng fromDegrees(double latDegrees, double lngDegrees)
From source file:com.bc.inventory.utils.S2Integer.java
public static void main(String[] args) { S2LatLng s2LatLng = S2LatLng.fromDegrees(42, 10); System.out.println("s2LatLng = " + s2LatLng); S2CellId s2CellId = S2CellId.fromLatLng(s2LatLng); System.out.println("s2CellId = " + s2CellId); S2CellId s2CellId13 = s2CellId.parent(13); System.out.println("s2CellId13 = " + s2CellId13); System.out.println("s2cellId = " + Long.toBinaryString(s2CellId.id())); System.out.println("s2cellId13 = " + Long.toBinaryString(s2CellId13.id())); System.out.println("s2cellIdInt = " + Long.toBinaryString(asInt(s2CellId))); }
From source file:com.grublr.geo.s2.internal.S2Util.java
/** * An utility method to get a bounding box of latitude and longitude from a given GeoQueryRequest. * //from w w w. ja v a 2 s.co m * @param geoQueryRequest * It contains all of the necessary information to form a latitude and longitude box. * * */ public static S2LatLngRect getBoundingLatLngRect(GeoQueryRequest geoQueryRequest) { if (geoQueryRequest instanceof QueryRectangleRequest) { QueryRectangleRequest queryRectangleRequest = (QueryRectangleRequest) geoQueryRequest; GeoPoint minPoint = queryRectangleRequest.getMinPoint(); GeoPoint maxPoint = queryRectangleRequest.getMaxPoint(); S2LatLngRect latLngRect = null; if (minPoint != null && maxPoint != null) { S2LatLng minLatLng = S2LatLng.fromDegrees(minPoint.getLatitude(), minPoint.getLongitude()); S2LatLng maxLatLng = S2LatLng.fromDegrees(maxPoint.getLatitude(), maxPoint.getLongitude()); latLngRect = new S2LatLngRect(minLatLng, maxLatLng); } return latLngRect; } else if (geoQueryRequest instanceof QueryRadiusRequest) { QueryRadiusRequest queryRadiusRequest = (QueryRadiusRequest) geoQueryRequest; GeoPoint centerPoint = queryRadiusRequest.getCenterPoint(); double radiusInMeter = queryRadiusRequest.getRadiusInMeter(); S2LatLng centerLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude(), centerPoint.getLongitude()); double latReferenceUnit = centerPoint.getLatitude() > 0.0 ? -1.0 : 1.0; S2LatLng latReferenceLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude() + latReferenceUnit, centerPoint.getLongitude()); double lngReferenceUnit = centerPoint.getLongitude() > 0.0 ? -1.0 : 1.0; S2LatLng lngReferenceLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude(), centerPoint.getLongitude() + lngReferenceUnit); double latForRadius = radiusInMeter / centerLatLng.getEarthDistance(latReferenceLatLng); double lngForRadius = radiusInMeter / centerLatLng.getEarthDistance(lngReferenceLatLng); S2LatLng minLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude() - latForRadius, centerPoint.getLongitude() - lngForRadius); S2LatLng maxLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude() + latForRadius, centerPoint.getLongitude() + lngForRadius); return new S2LatLngRect(minLatLng, maxLatLng); } return null; }
From source file:com.bc.fiduceo.geometry.s2.BcS2Point.java
@Override public void setLon(double lon) { s2LatLng = S2LatLng.fromDegrees(s2LatLng.latDegrees(), lon); }
From source file:com.bc.inventory.utils.SimpleRecord.java
public S2Point getAsPoint() { final double lon = location.getX(); final double lat = location.getY(); S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lon); return s2LatLng.toPoint(); }
From source file:com.bc.fiduceo.geometry.s2.BcS2Point.java
@Override public void setLat(double lat) { s2LatLng = S2LatLng.fromDegrees(lat, s2LatLng.lngDegrees()); }
From source file:com.norman0406.slimgress.API.Common.Location.java
public Location(double latDeg, double lngDeg) { S2LatLng pos = S2LatLng.fromDegrees(latDeg, lngDeg); latitude = pos.lat().e6(); longitude = pos.lng().e6(); }
From source file:org.esa.beam.occci.S2EoProduct.java
@Override public boolean contains(double lon, double lat) { S2Polygon poly = getPolygon(); if (poly != null) { S2Point s2Point = S2LatLng.fromDegrees(lat, lon).toPoint(); return poly.contains(s2Point); }/*from w ww . j a v a2 s . c om*/ return false; }
From source file:com.bc.fiduceo.geometry.s2.BcS2GeometryFactory.java
@Override public Point createPoint(double lon, double lat) { final S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lon); return new BcS2Point(s2LatLng); }
From source file:com.amazonaws.geo.s2.internal.S2Manager.java
public static long generateGeohash(GeoPoint geoPoint) { S2LatLng latLng = S2LatLng.fromDegrees(geoPoint.getLatitude(), geoPoint.getLongitude()); S2Cell cell = new S2Cell(latLng); S2CellId cellId = cell.id();/*from w w w . j a va 2 s . c om*/ return cellId.id(); }
From source file:org.esa.beam.occci.ReverseMatcher.java
public Set<Integer> matchInsitu(List<SimpleRecord> insituRecords, long maxTimeDifference) { Map<Integer, List<S2Point>> candidatesMap = new HashMap<>(); try (StopWatch sw = new StopWatch(" >>test for time and cell")) { for (SimpleRecord insituRecord : insituRecords) { final long referenceTime = insituRecord.getTime(); final long windowStartTime; final long windowEndTime; if (referenceTime == -1) { windowStartTime = globalStartTime; windowEndTime = globalEndTime; } else { windowStartTime = referenceTime - maxTimeDifference; windowEndTime = referenceTime + maxTimeDifference; }/*from www . j a va 2 s. c o m*/ Point2D.Float location = insituRecord.getLocation(); final double lon = location.getX(); final double lat = location.getY(); S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lon); S2Point s2Point = s2LatLng.toPoint(); S2CellId s2CellId = S2CellId.fromPoint(s2Point); final int cellInt = S2CellIdInteger.asInt(s2CellId.parent(3)); List<Integer> productIndices = reverseProductDB.findInsitu(cellInt, windowStartTime, windowEndTime); for (Integer productIndex : productIndices) { List<S2Point> candidateProducts = candidatesMap.get(productIndex); if (candidateProducts == null) { candidateProducts = new ArrayList<>(); candidatesMap.put(productIndex, candidateProducts); } candidateProducts.add(s2Point); } } System.out.println("candidatesMap = " + candidatesMap.size()); } List<Integer> uniqueProductList = new ArrayList<>(candidatesMap.size()); uniqueProductList.addAll(candidatesMap.keySet()); Set<Integer> matches = new HashSet<>(); try (StopWatch sw = new StopWatch(" >>load and test polygons")) { Collections.sort(uniqueProductList); try (DataInputStream dis = new DataInputStream( new BufferedInputStream(new FileInputStream(polygonFile)))) { int streamPID = 0; for (Integer productID : uniqueProductList) { while (streamPID < productID) { int numLoopPoints = dis.readInt(); dis.skipBytes(numLoopPoints * 3 * 8); streamPID++; } final int numLoopPoints = dis.readInt(); final double[] pointData = new double[numLoopPoints * 3]; for (int i = 0; i < pointData.length; i++) { pointData[i] = dis.readDouble(); } streamPID++; S2Polygon s2Polygon = S2IEoProduct.createS2Polygon(pointData); List<S2Point> s2Points = candidatesMap.get(productID); for (S2Point s2Point : s2Points) { if (s2Polygon.contains(s2Point)) { matches.add(productID); break; } } } } catch (IOException e) { e.printStackTrace(); return null; } } return matches; }