Example usage for com.google.common.geometry S2LatLng fromDegrees

List of usage examples for com.google.common.geometry S2LatLng fromDegrees

Introduction

In this page you can find the example usage for com.google.common.geometry S2LatLng fromDegrees.

Prototype

public static S2LatLng fromDegrees(double latDegrees, double lngDegrees) 

Source Link

Usage

From source file:org.geosde.cassandra.GeometryTestCase.java

static void parseVertices(String str, List<S2Point> vertices) {
    if (str == null) {
        return;/*ww  w  .j a v a  2  s . co  m*/
    }

    for (String token : Splitter.on(',').split(str)) {
        int colon = token.indexOf(':');
        if (colon == -1) {
            throw new IllegalArgumentException("Illegal string:" + token + ". Should look like '35:20'");
        }
        double lat = Double.parseDouble(token.substring(0, colon));
        double lng = Double.parseDouble(token.substring(colon + 1));
        vertices.add(S2LatLng.fromDegrees(lat, lng).toPoint());
    }
}

From source file:org.esa.beam.occci.MultiPassMatcher.java

@Override
public Set<EoProduct> matchInsitu(List<SimpleRecord> insituRecords, long maxTimeDifference) {
    Map<S2IEoProduct, List<S2Point>> candidatesMap = new HashMap<>();

    long globalStartTime;
    long globalEndTime;
    try {/*w  w w  . j a v a2s  .co m*/
        globalStartTime = AbstractEoProduct.DATE_FORMAT
                .parse(DateUtils.getNoFractionString("2014-01-01T00:00:00")).getTime();
        globalEndTime = AbstractEoProduct.DATE_FORMAT
                .parse(DateUtils.getNoFractionString("2015-01-01T00:00:00")).getTime();
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }

    try (StopWatch sw = new StopWatch("  >>test for time and cell")) {
        for (SimpleRecord insituRecord : insituRecords) {
            S2CellId s2CellId = null;
            S2Point s2Point = null;
            int level1Mask = 0;
            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;
            }

            int productIndex = productDB.getIndexForTime(windowStartTime);
            if (productIndex == -1) {
                continue;
            }

            boolean finishedWithInsitu = false;
            while (!finishedWithInsitu) {
                S2IEoProduct eoProduct = (S2IEoProduct) productDB.getRecord(productIndex);
                productIndex++;

                if (eoProduct == null) {
                    finishedWithInsitu = true;
                } else if (eoProduct.getStartTime() > windowEndTime) {
                    finishedWithInsitu = true;
                } else if (eoProduct.getEndTime() < windowStartTime) {
                    //test next product;
                } else {
                    // time match
                    if (s2CellId == null) {
                        Point2D.Float location = insituRecord.getLocation();
                        double lon = location.getX();
                        double lat = location.getY();
                        S2LatLng s2LatLng = S2LatLng.fromDegrees(lat, lon);
                        s2Point = s2LatLng.toPoint();
                        s2CellId = S2CellId.fromPoint(s2Point);
                        level1Mask = (1 << (int) (s2CellId.id() >>> S2IndexCreatorMain.MASK_SHIFT));
                    }
                    if ((eoProduct.level1Mask & level1Mask) != 0) {
                        if (S2CellIdInteger.containsPoint(eoProduct.cellIds, s2CellId)) {
                            List<S2Point> candidateProducts = candidatesMap.get(eoProduct);
                            if (candidateProducts == null) {
                                candidateProducts = new ArrayList<>();
                                candidatesMap.put(eoProduct, candidateProducts);
                            }
                            candidateProducts.add(s2Point);
                        }
                    }
                }
            }
        }
        System.out.println("candidatesMap = " + candidatesMap.size());
    }

    List<S2IEoProduct> uniqueProductList = new ArrayList<>(candidatesMap.size());
    uniqueProductList.addAll(candidatesMap.keySet());
    Set<EoProduct> matches = new HashSet<>();
    try (StopWatch sw = new StopWatch("  >>load and test polygons")) {
        Collections.sort(uniqueProductList, (o1, o2) -> Integer.compare(o1.productID, o2.productID));
        try (DataInputStream dis = new DataInputStream(
                new BufferedInputStream(new FileInputStream(polygonFile)))) {
            int streamPID = 0;
            for (S2IEoProduct eoProduct : uniqueProductList) {
                final int productID = eoProduct.productID;
                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(eoProduct);
                for (S2Point s2Point : s2Points) {
                    if (s2Polygon.contains(s2Point)) {
                        matches.add(eoProduct);
                        break;
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    return matches;
}

From source file:com.bc.geometry.s2.S2WKTReader.java

private S2Point getPreciseCoordinate() throws IOException, IllegalArgumentException {
    double x = getNextNumber();
    double y = getNextNumber();
    if (isNumberNext()) {
        getNextNumber();// w w w .ja  v a  2s .  com
    }
    return S2LatLng.fromDegrees(y, x).toPoint();
}

From source file:org.apache.lucene.spatial.prefix.tree.S2PrefixTree.java

@Override
public CellIterator getTreeCellIterator(Shape shape, int detailLevel) {
    if (!(shape instanceof Point)) {
        return super.getTreeCellIterator(shape, detailLevel);
    }/* w w w  .  ja va2  s  .  co m*/
    Point p = (Point) shape;
    S2CellId id = S2CellId.fromLatLng(S2LatLng.fromDegrees(p.getY(), p.getX()))
            .parent(arity * (detailLevel - 1));
    List<Cell> cells = new ArrayList<>(detailLevel);
    for (int i = 0; i < detailLevel - 1; i++) {
        cells.add(new S2PrefixTreeCell(this, id.parent(i * arity)));
    }
    cells.add(new S2PrefixTreeCell(this, id));
    return new FilterCellIterator(cells.iterator(), null);
}

From source file:com.norman0406.slimgress.ScannerView.java

private void startWorldUpdate() {
    // TODO: problems blocking execution and causing out-of-memory exception

    final Handler uiHandler = new Handler();

    long updateInterval = mGame.getKnobs().getScannerKnobs().getUpdateIntervalMS();

    Timer updateTimer = new Timer();
    updateTimer.scheduleAtFixedRate(new TimerTask() {
        final Handler timerHandler = new Handler();

        @Override//from w w w.  j a  v a  2  s.com
        public void run() {
            uiHandler.post(new Runnable() {
                @Override
                public void run() {
                    // get map boundaries (on ui thread)
                    LatLng northeast = mMap.getProjection().getVisibleRegion().latLngBounds.northeast;
                    LatLng southwest = mMap.getProjection().getVisibleRegion().latLngBounds.southwest;
                    final S2LatLngRect region = S2LatLngRect.fromPointPair(
                            S2LatLng.fromDegrees(southwest.latitude, southwest.longitude),
                            S2LatLng.fromDegrees(northeast.latitude, northeast.longitude));

                    // update world (on timer thread)
                    timerHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            if (mGame.getLocation() != null)
                                updateWorld(region, uiHandler);
                        }
                    });
                }
            });
        }
    }, 0, updateInterval);
}

From source file:com.grublr.geo.GeoDataManager.java

/**
 * Filter out any points outside of the queried area from the input list.
 * /*from ww  w .  ja  v a  2  s . c om*/
 * @param list
 *            List of items return by Amazon DynamoDB. It may contains points outside of the actual area queried.
 * 
 * @param latLngRect
 *            Queried area. Any points outside of this area need to be discarded.
 * 
 * @return List of items within the queried area.
 */
private List<Map<String, AttributeValue>> filter(List<Map<String, AttributeValue>> list,
        GeoQueryRequest geoQueryRequest) {

    List<Map<String, AttributeValue>> result = new ArrayList<Map<String, AttributeValue>>();

    S2LatLngRect latLngRect = null;
    S2LatLng centerLatLng = null;
    double radiusInMeter = 0;
    if (geoQueryRequest instanceof QueryRectangleRequest) {
        latLngRect = S2Util.getBoundingLatLngRect(geoQueryRequest);
    } else if (geoQueryRequest instanceof QueryRadiusRequest) {
        GeoPoint centerPoint = ((QueryRadiusRequest) geoQueryRequest).getCenterPoint();
        centerLatLng = S2LatLng.fromDegrees(centerPoint.getLatitude(), centerPoint.getLongitude());

        radiusInMeter = ((QueryRadiusRequest) geoQueryRequest).getRadiusInMeter();
    }

    for (Map<String, AttributeValue> item : list) {
        String geoJson = item.get(config.getGeoJsonAttributeName()).getS();
        GeoPoint geoPoint = GeoJsonMapper.geoPointFromString(geoJson);

        S2LatLng latLng = S2LatLng.fromDegrees(geoPoint.getLatitude(), geoPoint.getLongitude());
        if (latLngRect != null && latLngRect.contains(latLng)) {
            result.add(item);
        } else if (centerLatLng != null && radiusInMeter > 0
                && centerLatLng.getEarthDistance(latLng) <= radiusInMeter) {
            result.add(item);
        }
    }

    return result;
}