Search in sources :

Example 6 with MultiPolygon

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

the class GoogleMapShapeConverter method toGeometry.

/**
 * Convert a GoogleMapShape to a Geometry
 *
 * @param shape google map shape
 * @return geometry
 */
public Geometry toGeometry(GoogleMapShape shape) {
    Geometry geometry = null;
    Object shapeObject = shape.getShape();
    switch(shape.getGeometryType()) {
        case POINT:
            LatLng point = null;
            switch(shape.getShapeType()) {
                case LAT_LNG:
                    point = (LatLng) shapeObject;
                    break;
                case MARKER_OPTIONS:
                    MarkerOptions markerOptions = (MarkerOptions) shapeObject;
                    point = markerOptions.getPosition();
                    break;
                case MARKER:
                    Marker marker = (Marker) shapeObject;
                    point = marker.getPosition();
                    break;
                default:
                    throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
            }
            if (point != null) {
                geometry = toPoint(point);
            }
            break;
        case LINESTRING:
        case CIRCULARSTRING:
            List<LatLng> lineStringPoints = null;
            switch(shape.getShapeType()) {
                case POLYLINE_OPTIONS:
                    PolylineOptions polylineOptions = (PolylineOptions) shapeObject;
                    lineStringPoints = polylineOptions.getPoints();
                    break;
                case POLYLINE:
                    Polyline polyline = (Polyline) shapeObject;
                    lineStringPoints = polyline.getPoints();
                    break;
                case POLYLINE_MARKERS:
                    PolylineMarkers polylineMarkers = (PolylineMarkers) shapeObject;
                    if (!polylineMarkers.isValid()) {
                        throw new GeoPackageException(PolylineMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
                    }
                    if (!polylineMarkers.isDeleted()) {
                        lineStringPoints = getPointsFromMarkers(polylineMarkers.getMarkers());
                    }
                    break;
                default:
                    throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
            }
            if (lineStringPoints != null) {
                switch(shape.getGeometryType()) {
                    case LINESTRING:
                        geometry = toLineString(lineStringPoints);
                        break;
                    case CIRCULARSTRING:
                        geometry = toCircularString(lineStringPoints);
                        break;
                    default:
                        throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
                }
            }
            break;
        case POLYGON:
            List<LatLng> polygonPoints = null;
            List<List<LatLng>> holePointList = null;
            switch(shape.getShapeType()) {
                case POLYGON_OPTIONS:
                    PolygonOptions polygonOptions = (PolygonOptions) shapeObject;
                    polygonPoints = polygonOptions.getPoints();
                    holePointList = polygonOptions.getHoles();
                    break;
                case POLYGON:
                    com.google.android.gms.maps.model.Polygon polygon = (com.google.android.gms.maps.model.Polygon) shapeObject;
                    polygonPoints = polygon.getPoints();
                    holePointList = polygon.getHoles();
                    break;
                case POLYGON_MARKERS:
                    PolygonMarkers polygonMarkers = (PolygonMarkers) shapeObject;
                    if (!polygonMarkers.isValid()) {
                        throw new GeoPackageException(PolygonMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
                    }
                    if (!polygonMarkers.isDeleted()) {
                        polygonPoints = getPointsFromMarkers(polygonMarkers.getMarkers());
                        holePointList = new ArrayList<>();
                        for (PolygonHoleMarkers hole : polygonMarkers.getHoles()) {
                            if (!hole.isDeleted()) {
                                List<LatLng> holePoints = getPointsFromMarkers(hole.getMarkers());
                                holePointList.add(holePoints);
                            }
                        }
                    }
                    break;
                default:
                    throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
            }
            if (polygonPoints != null) {
                geometry = toPolygon(polygonPoints, holePointList);
            }
            break;
        case MULTIPOINT:
            List<LatLng> multiPoints = null;
            switch(shape.getShapeType()) {
                case MULTI_LAT_LNG:
                    MultiLatLng multiLatLng = (MultiLatLng) shapeObject;
                    multiPoints = multiLatLng.getLatLngs();
                    break;
                case MULTI_MARKER:
                    MultiMarker multiMarker = (MultiMarker) shapeObject;
                    multiPoints = getPointsFromMarkers(multiMarker.getMarkers());
                    break;
                default:
                    throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
            }
            if (multiPoints != null) {
                geometry = toMultiPoint(multiPoints);
            }
            break;
        case MULTILINESTRING:
        case COMPOUNDCURVE:
            switch(shape.getShapeType()) {
                case MULTI_POLYLINE_OPTIONS:
                    MultiPolylineOptions multiPolylineOptions = (MultiPolylineOptions) shapeObject;
                    switch(shape.getGeometryType()) {
                        case MULTILINESTRING:
                            geometry = toMultiLineStringFromOptions(multiPolylineOptions);
                            break;
                        case COMPOUNDCURVE:
                            geometry = toCompoundCurveFromOptions(multiPolylineOptions);
                            break;
                        default:
                            throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
                    }
                    break;
                case MULTI_POLYLINE:
                    MultiPolyline multiPolyline = (MultiPolyline) shapeObject;
                    switch(shape.getGeometryType()) {
                        case MULTILINESTRING:
                            geometry = toMultiLineString(multiPolyline.getPolylines());
                            break;
                        case COMPOUNDCURVE:
                            geometry = toCompoundCurve(multiPolyline.getPolylines());
                            break;
                        default:
                            throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
                    }
                    break;
                case MULTI_POLYLINE_MARKERS:
                    MultiPolylineMarkers multiPolylineMarkers = (MultiPolylineMarkers) shapeObject;
                    if (!multiPolylineMarkers.isValid()) {
                        throw new GeoPackageException(MultiPolylineMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
                    }
                    if (!multiPolylineMarkers.isDeleted()) {
                        List<List<LatLng>> multiPolylineMarkersList = new ArrayList<>();
                        for (PolylineMarkers polylineMarkers : multiPolylineMarkers.getPolylineMarkers()) {
                            if (!polylineMarkers.isDeleted()) {
                                multiPolylineMarkersList.add(getPointsFromMarkers(polylineMarkers.getMarkers()));
                            }
                        }
                        switch(shape.getGeometryType()) {
                            case MULTILINESTRING:
                                geometry = toMultiLineStringFromList(multiPolylineMarkersList);
                                break;
                            case COMPOUNDCURVE:
                                geometry = toCompoundCurveFromList(multiPolylineMarkersList);
                                break;
                            default:
                                throw new GeoPackageException("Unhandled " + shape.getGeometryType().getName());
                        }
                    }
                    break;
                default:
                    throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
            }
            break;
        case MULTIPOLYGON:
            switch(shape.getShapeType()) {
                case MULTI_POLYGON_OPTIONS:
                    MultiPolygonOptions multiPolygonOptions = (MultiPolygonOptions) shapeObject;
                    geometry = toMultiPolygonFromOptions(multiPolygonOptions);
                    break;
                case MULTI_POLYGON:
                    mil.nga.geopackage.map.geom.MultiPolygon multiPolygon = (mil.nga.geopackage.map.geom.MultiPolygon) shapeObject;
                    geometry = toMultiPolygon(multiPolygon.getPolygons());
                    break;
                case MULTI_POLYGON_MARKERS:
                    MultiPolygonMarkers multiPolygonMarkers = (MultiPolygonMarkers) shapeObject;
                    if (!multiPolygonMarkers.isValid()) {
                        throw new GeoPackageException(MultiPolygonMarkers.class.getSimpleName() + " is not valid to create " + shape.getGeometryType().getName());
                    }
                    if (!multiPolygonMarkers.isDeleted()) {
                        List<Polygon> multiPolygonMarkersList = new ArrayList<>();
                        for (PolygonMarkers polygonMarkers : multiPolygonMarkers.getPolygonMarkers()) {
                            if (!polygonMarkers.isDeleted()) {
                                List<LatLng> multiPolygonPoints = getPointsFromMarkers(polygonMarkers.getMarkers());
                                List<List<LatLng>> multiPolygonHolePoints = new ArrayList<>();
                                for (PolygonHoleMarkers hole : polygonMarkers.getHoles()) {
                                    if (!hole.isDeleted()) {
                                        List<LatLng> holePoints = getPointsFromMarkers(hole.getMarkers());
                                        multiPolygonHolePoints.add(holePoints);
                                    }
                                }
                                multiPolygonMarkersList.add(toPolygon(multiPolygonPoints, multiPolygonHolePoints));
                            }
                        }
                        geometry = createMultiPolygon(multiPolygonMarkersList);
                    }
                    break;
                default:
                    throw new GeoPackageException("Not a valid " + shape.getGeometryType().getName() + " shape type: " + shape.getShapeType());
            }
            break;
        case POLYHEDRALSURFACE:
        case TIN:
        case TRIANGLE:
            throw new GeoPackageException("Unsupported GeoPackage type: " + shape.getGeometryType());
        case GEOMETRYCOLLECTION:
            @SuppressWarnings("unchecked") List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shapeObject;
            GeometryCollection<Geometry> geometryCollection = new GeometryCollection<>(false, false);
            for (GoogleMapShape shapeListItem : shapeList) {
                Geometry subGeometry = toGeometry(shapeListItem);
                if (subGeometry != null) {
                    geometryCollection.addGeometry(subGeometry);
                }
            }
            if (geometryCollection.numGeometries() > 0) {
                geometry = geometryCollection;
            }
            break;
        default:
    }
    return geometry;
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) ArrayList(java.util.ArrayList) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions) GeometryCollection(mil.nga.sf.GeometryCollection) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(com.google.android.gms.maps.model.LatLng) MultiPolygon(mil.nga.sf.MultiPolygon) CurvePolygon(mil.nga.sf.CurvePolygon) Polygon(mil.nga.sf.Polygon) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) Marker(com.google.android.gms.maps.model.Marker) Geometry(mil.nga.sf.Geometry) MultiPolygon(mil.nga.sf.MultiPolygon) Polyline(com.google.android.gms.maps.model.Polyline) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 7 with MultiPolygon

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

the class GoogleMapShapeConverter method toPolygons.

/**
 * Convert a {@link MultiPolygon} to a {@link MultiPolygonOptions}
 *
 * @param multiPolygon multi polygon
 * @return multi polygon options
 */
public MultiPolygonOptions toPolygons(MultiPolygon multiPolygon) {
    MultiPolygonOptions polygons = new MultiPolygonOptions();
    for (Polygon polygon : multiPolygon.getPolygons()) {
        PolygonOptions polygonOptions = toPolygon(polygon);
        polygons.add(polygonOptions);
    }
    return polygons;
}
Also used : PolygonOptions(com.google.android.gms.maps.model.PolygonOptions) MultiPolygon(mil.nga.sf.MultiPolygon) CurvePolygon(mil.nga.sf.CurvePolygon) Polygon(mil.nga.sf.Polygon)

Aggregations

MultiPolygon (mil.nga.sf.MultiPolygon)7 Polygon (mil.nga.sf.Polygon)6 CurvePolygon (mil.nga.sf.CurvePolygon)5 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)4 GeoPackageException (mil.nga.geopackage.GeoPackageException)2 Geometry (mil.nga.sf.Geometry)2 LatLng (com.google.android.gms.maps.model.LatLng)1 Marker (com.google.android.gms.maps.model.Marker)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 Polyline (com.google.android.gms.maps.model.Polyline)1 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CircularString (mil.nga.sf.CircularString)1 CompoundCurve (mil.nga.sf.CompoundCurve)1 GeometryCollection (mil.nga.sf.GeometryCollection)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