Example usage for com.google.common.geometry S2Polygon initToIntersection

List of usage examples for com.google.common.geometry S2Polygon initToIntersection

Introduction

In this page you can find the example usage for com.google.common.geometry S2Polygon initToIntersection.

Prototype

public void initToIntersection(final S2Polygon a, final S2Polygon b) 

Source Link

Document

Initialize this polygon to the intersection, union, or difference (A - B) of the given two polygons.

Usage

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

@SuppressWarnings("unchecked")
@Override//from   w  w w.jav a2 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");
}