Search in sources :

Example 1 with Curve

use of mil.nga.sf.Curve in project geopackage-android-map by ngageoint.

the class GoogleMapShapeConverter method toCurvePolygon.

/**
 * Convert a {@link CurvePolygon} to a {@link PolygonOptions}
 *
 * @param curvePolygon curve polygon
 * @return polygon options
 * @since 1.4.1
 */
public PolygonOptions toCurvePolygon(CurvePolygon<Curve> curvePolygon) {
    PolygonOptions polygonOptions = new PolygonOptions();
    List<Curve> rings = curvePolygon.getRings();
    if (!rings.isEmpty()) {
        Double z = null;
        // Add the polygon points
        Curve curve = rings.get(0);
        if (curve instanceof CompoundCurve) {
            CompoundCurve compoundCurve = (CompoundCurve) curve;
            for (LineString lineString : compoundCurve.getLineStrings()) {
                // Try to simplify the number of points in the compound curve
                List<Point> points = simplifyPoints(lineString.getPoints());
                for (Point point : points) {
                    LatLng latLng = toLatLng(point);
                    polygonOptions.add(latLng);
                    if (point.hasZ()) {
                        z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                    }
                }
            }
        } else if (curve instanceof LineString) {
            LineString lineString = (LineString) curve;
            // Try to simplify the number of points in the curve
            List<Point> points = simplifyPoints(lineString.getPoints());
            for (Point point : points) {
                LatLng latLng = toLatLng(point);
                polygonOptions.add(latLng);
                if (point.hasZ()) {
                    z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                }
            }
        } else {
            throw new GeoPackageException("Unsupported Curve Type: " + curve.getClass().getSimpleName());
        }
        // Add the holes
        for (int i = 1; i < rings.size(); i++) {
            Curve hole = rings.get(i);
            List<LatLng> holeLatLngs = new ArrayList<>();
            if (hole instanceof CompoundCurve) {
                CompoundCurve holeCompoundCurve = (CompoundCurve) hole;
                for (LineString holeLineString : holeCompoundCurve.getLineStrings()) {
                    // Try to simplify the number of points in the hole
                    List<Point> holePoints = simplifyPoints(holeLineString.getPoints());
                    for (Point point : holePoints) {
                        LatLng latLng = toLatLng(point);
                        holeLatLngs.add(latLng);
                        if (point.hasZ()) {
                            z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                        }
                    }
                }
            } else if (hole instanceof LineString) {
                LineString holeLineString = (LineString) hole;
                // Try to simplify the number of points in the hole
                List<Point> holePoints = simplifyPoints(holeLineString.getPoints());
                for (Point point : holePoints) {
                    LatLng latLng = toLatLng(point);
                    holeLatLngs.add(latLng);
                    if (point.hasZ()) {
                        z = (z == null) ? point.getZ() : Math.max(z, point.getZ());
                    }
                }
            } else {
                throw new GeoPackageException("Unsupported Curve Hole Type: " + hole.getClass().getSimpleName());
            }
            polygonOptions.addHole(holeLatLngs);
        }
        if (curvePolygon.hasZ() && z != null) {
            polygonOptions.zIndex(z.floatValue());
        }
    }
    return polygonOptions;
}
Also used : CompoundCurve(mil.nga.sf.CompoundCurve) PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) Curve(mil.nga.sf.Curve) CompoundCurve(mil.nga.sf.CompoundCurve) ArrayList(java.util.ArrayList) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.google.android.gms.maps.model.LatLng) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 2 with Curve

use of mil.nga.sf.Curve in project geopackage-android-map by ngageoint.

the class GoogleMapShapeConverter method toShape.

/**
 * Convert a {@link Geometry} to a Map shape
 *
 * @param geometry geometry
 * @return google map shape
 */
@SuppressWarnings("unchecked")
public GoogleMapShape toShape(Geometry geometry) {
    GoogleMapShape shape = null;
    GeometryType geometryType = geometry.getGeometryType();
    switch(geometryType) {
        case POINT:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.LAT_LNG, toLatLng((Point) geometry));
            break;
        case LINESTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYLINE_OPTIONS, toPolyline((LineString) geometry));
            break;
        case POLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON_OPTIONS, toPolygon((Polygon) geometry));
            break;
        case MULTIPOINT:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_LAT_LNG, toLatLngs((MultiPoint) geometry));
            break;
        case MULTILINESTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYLINE_OPTIONS, toPolylines((MultiLineString) geometry));
            break;
        case MULTIPOLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON_OPTIONS, toPolygons((MultiPolygon) geometry));
            break;
        case CIRCULARSTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYLINE_OPTIONS, toPolyline((CircularString) geometry));
            break;
        case COMPOUNDCURVE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYLINE_OPTIONS, toPolylines((CompoundCurve) geometry));
            break;
        case CURVEPOLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON_OPTIONS, toCurvePolygon((CurvePolygon<Curve>) geometry));
            break;
        case POLYHEDRALSURFACE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON_OPTIONS, toPolygons((PolyhedralSurface) geometry));
            break;
        case TIN:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON_OPTIONS, toPolygons((TIN) geometry));
            break;
        case TRIANGLE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON_OPTIONS, toPolygon((Triangle) geometry));
            break;
        case GEOMETRYCOLLECTION:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.COLLECTION, toShapes((GeometryCollection<Geometry>) geometry));
            break;
        default:
            throw new GeoPackageException("Unsupported Geometry Type: " + geometryType.getName());
    }
    return shape;
}
Also used : Geometry(mil.nga.sf.Geometry) GeometryType(mil.nga.sf.GeometryType) Curve(mil.nga.sf.Curve) CompoundCurve(mil.nga.sf.CompoundCurve) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Aggregations

GeoPackageException (mil.nga.geopackage.GeoPackageException)2 CompoundCurve (mil.nga.sf.CompoundCurve)2 Curve (mil.nga.sf.Curve)2 LatLng (com.google.android.gms.maps.model.LatLng)1 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Geometry (mil.nga.sf.Geometry)1 GeometryType (mil.nga.sf.GeometryType)1 LineString (mil.nga.sf.LineString)1 MultiLineString (mil.nga.sf.MultiLineString)1 MultiPoint (mil.nga.sf.MultiPoint)1 Point (mil.nga.sf.Point)1