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

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

Introduction

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

Prototype

public S2Point toPoint() 

Source Link

Document

Convert an S2LatLng to the equivalent unit-length vector (S2Point).

Usage

From source file:com.norman0406.slimgress.API.Common.Utils.java

public static String[] getCellIdsFromLocationArea(Location location, double areaM2, int minLevel,
        int maxLevel) {
    final double radius_m2 = 6371 * 1000;
    final double sr = areaM2 / (radius_m2 * radius_m2);

    S2LatLng pointLatLng = S2LatLng.fromE6(location.getLatitude(), location.getLongitude());
    S2Cap cap = S2Cap.fromAxisArea(pointLatLng.toPoint(), sr);

    return getCellIdsFromRegion(cap, minLevel, maxLevel);
}

From source file:com.bc.fiduceo.geometry.s2.BcS2GeometryFactory.java

static List<S2Point> extractS2Points(List<Point> points) {
    final ArrayList<S2Point> loopPoints = new ArrayList<>();

    for (final Point point : points) {
        final S2LatLng s2LatLng = (S2LatLng) point.getInner();
        loopPoints.add(s2LatLng.toPoint());
    }//from ww  w  . ja  va 2 s  . co  m
    return loopPoints;
}

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.BcS2Polygon.java

@SuppressWarnings("unchecked")
@Override/*w w  w  .j  a  v a  2  s.co m*/
public Geometry getIntersection(Geometry other) {
    if (other instanceof BcS2Polygon) {
        final S2Polygon intersection = new S2Polygon();
        intersection.initToIntersection(googlePolygon, (S2Polygon) other.getInner());
        return new BcS2Polygon(intersection);
    } else if (other instanceof BcS2MultiLineString) {
        List<S2Polyline> s2PolylineList = (List<S2Polyline>) other.getInner();
        List<S2Polyline> intersectionResult = new ArrayList<>();
        for (final S2Polyline s2Polyline : s2PolylineList) {
            intersectionResult.addAll(googlePolygon.intersectWithPolyLine(s2Polyline));
        }
        return new BcS2MultiLineString(intersectionResult);
    } else if (other instanceof BcS2Point) {
        final S2LatLng inner = (S2LatLng) other.getInner();
        if (googlePolygon.contains(inner.toPoint())) {
            return other;
        } else {
            return new BcS2Point(null); // "empty point" tb 2016-11-07
        }
    }

    throw new RuntimeException("intersection type not implemented");
}

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 w w w . j  av a 2s  . 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;
}

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 {//from  ww w.  j av  a2s. com
        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;
}