Search in sources :

Example 1 with GeoPackageException

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

the class GoogleMapShapeConverter method addShapeToMapAsMarkers.

/**
 * Add a shape to the map as markers
 *
 * @param map                      google map
 * @param shape                    google map shape
 * @param markerOptions            marker options
 * @param polylineMarkerOptions    polyline marker options
 * @param polygonMarkerOptions     polygon marker options
 * @param polygonMarkerHoleOptions polygon marker hole options
 * @param globalPolylineOptions    global polyline options
 * @param globalPolygonOptions     global polygon options
 * @return google map shape markers
 */
public GoogleMapShapeMarkers addShapeToMapAsMarkers(GoogleMap map, GoogleMapShape shape, MarkerOptions markerOptions, MarkerOptions polylineMarkerOptions, MarkerOptions polygonMarkerOptions, MarkerOptions polygonMarkerHoleOptions, PolylineOptions globalPolylineOptions, PolygonOptions globalPolygonOptions) {
    GoogleMapShapeMarkers shapeMarkers = new GoogleMapShapeMarkers();
    GoogleMapShape addedShape = null;
    switch(shape.getShapeType()) {
        case LAT_LNG:
            if (markerOptions == null) {
                markerOptions = new MarkerOptions();
            }
            Marker latLngMarker = addLatLngToMap(map, (LatLng) shape.getShape(), markerOptions);
            shapeMarkers.add(latLngMarker);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.MARKER, latLngMarker);
            break;
        case MARKER_OPTIONS:
            MarkerOptions shapeMarkerOptions = (MarkerOptions) shape.getShape();
            if (markerOptions != null) {
                shapeMarkerOptions.icon(markerOptions.getIcon());
                shapeMarkerOptions.anchor(markerOptions.getAnchorU(), markerOptions.getAnchorV());
                shapeMarkerOptions.draggable(markerOptions.isDraggable());
                shapeMarkerOptions.visible(markerOptions.isVisible());
                shapeMarkerOptions.zIndex(markerOptions.getZIndex());
            }
            Marker markerOptionsMarker = addMarkerOptionsToMap(map, shapeMarkerOptions);
            shapeMarkers.add(markerOptionsMarker);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.MARKER, markerOptionsMarker);
            break;
        case POLYLINE_OPTIONS:
            PolylineMarkers polylineMarkers = addPolylineToMapAsMarkers(map, (PolylineOptions) shape.getShape(), polylineMarkerOptions, globalPolylineOptions);
            shapeMarkers.add(polylineMarkers);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.POLYLINE_MARKERS, polylineMarkers);
            break;
        case POLYGON_OPTIONS:
            PolygonMarkers polygonMarkers = addPolygonToMapAsMarkers(shapeMarkers, map, (PolygonOptions) shape.getShape(), polygonMarkerOptions, polygonMarkerHoleOptions, globalPolygonOptions);
            shapeMarkers.add(polygonMarkers);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.POLYGON_MARKERS, polygonMarkers);
            break;
        case MULTI_LAT_LNG:
            MultiLatLng multiLatLng = (MultiLatLng) shape.getShape();
            if (markerOptions != null) {
                multiLatLng.setMarkerOptions(markerOptions);
            }
            MultiMarker multiMarker = addLatLngsToMap(map, multiLatLng);
            shapeMarkers.add(multiMarker);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.MULTI_MARKER, multiMarker);
            break;
        case MULTI_POLYLINE_OPTIONS:
            MultiPolylineMarkers multiPolylineMarkers = addMultiPolylineToMapAsMarkers(shapeMarkers, map, (MultiPolylineOptions) shape.getShape(), polylineMarkerOptions, globalPolylineOptions);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.MULTI_POLYLINE_MARKERS, multiPolylineMarkers);
            break;
        case MULTI_POLYGON_OPTIONS:
            MultiPolygonMarkers multiPolygonMarkers = addMultiPolygonToMapAsMarkers(shapeMarkers, map, (MultiPolygonOptions) shape.getShape(), polygonMarkerOptions, polygonMarkerHoleOptions, globalPolygonOptions);
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.MULTI_POLYGON_MARKERS, multiPolygonMarkers);
            break;
        case COLLECTION:
            List<GoogleMapShape> addedShapeList = new ArrayList<>();
            @SuppressWarnings("unchecked") List<GoogleMapShape> shapeList = (List<GoogleMapShape>) shape.getShape();
            for (GoogleMapShape shapeListItem : shapeList) {
                GoogleMapShapeMarkers shapeListItemMarkers = addShapeToMapAsMarkers(map, shapeListItem, markerOptions, polylineMarkerOptions, polygonMarkerOptions, polygonMarkerHoleOptions, globalPolylineOptions, globalPolygonOptions);
                shapeMarkers.add(shapeListItemMarkers);
                addedShapeList.add(shapeListItemMarkers.getShape());
            }
            addedShape = new GoogleMapShape(shape.getGeometryType(), GoogleMapShapeType.COLLECTION, addedShapeList);
            break;
        default:
            throw new GeoPackageException("Unsupported Shape Type: " + shape.getShapeType());
    }
    shapeMarkers.setShape(addedShape);
    return shapeMarkers;
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) ArrayList(java.util.ArrayList) Marker(com.google.android.gms.maps.model.Marker) ArrayList(java.util.ArrayList) List(java.util.List) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 2 with GeoPackageException

use of mil.nga.geopackage.GeoPackageException 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 3 with GeoPackageException

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

the class GoogleMapShapeConverter method addToMap.

/**
 * Convert a {@link Geometry} to a Map shape and add it
 *
 * @param map      google map
 * @param geometry geometry
 * @return google map shape
 */
@SuppressWarnings("unchecked")
public GoogleMapShape addToMap(GoogleMap map, Geometry geometry) {
    GoogleMapShape shape = null;
    GeometryType geometryType = geometry.getGeometryType();
    switch(geometryType) {
        case POINT:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MARKER, addLatLngToMap(map, toLatLng((Point) geometry)));
            break;
        case LINESTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYLINE, addPolylineToMap(map, toPolyline((LineString) geometry)));
            break;
        case POLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON, addPolygonToMap(map, toPolygon((Polygon) geometry)));
            break;
        case MULTIPOINT:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_MARKER, addLatLngsToMap(map, toLatLngs((MultiPoint) geometry)));
            break;
        case MULTILINESTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYLINE, addPolylinesToMap(map, toPolylines((MultiLineString) geometry)));
            break;
        case MULTIPOLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON, addPolygonsToMap(map, toPolygons((MultiPolygon) geometry)));
            break;
        case CIRCULARSTRING:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYLINE, addPolylineToMap(map, toPolyline((CircularString) geometry)));
            break;
        case COMPOUNDCURVE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYLINE, addPolylinesToMap(map, toPolylines((CompoundCurve) geometry)));
            break;
        case CURVEPOLYGON:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON, addPolygonToMap(map, toCurvePolygon((CurvePolygon<Curve>) geometry)));
            break;
        case POLYHEDRALSURFACE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON, addPolygonsToMap(map, toPolygons((PolyhedralSurface) geometry)));
            break;
        case TIN:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.MULTI_POLYGON, addPolygonsToMap(map, toPolygons((TIN) geometry)));
            break;
        case TRIANGLE:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.POLYGON, addPolygonToMap(map, toPolygon((Triangle) geometry)));
            break;
        case GEOMETRYCOLLECTION:
            shape = new GoogleMapShape(geometryType, GoogleMapShapeType.COLLECTION, addToMap(map, (GeometryCollection<Geometry>) geometry));
            break;
        default:
            throw new GeoPackageException("Unsupported Geometry Type: " + geometryType.getName());
    }
    return shape;
}
Also used : MultiPoint(mil.nga.sf.MultiPoint) MultiLineString(mil.nga.sf.MultiLineString) CompoundCurve(mil.nga.sf.CompoundCurve) CircularString(mil.nga.sf.CircularString) Triangle(mil.nga.sf.Triangle) CurvePolygon(mil.nga.sf.CurvePolygon) MultiPoint(mil.nga.sf.MultiPoint) Point(mil.nga.sf.Point) PolyhedralSurface(mil.nga.sf.PolyhedralSurface) Geometry(mil.nga.sf.Geometry) GeometryType(mil.nga.sf.GeometryType) LineString(mil.nga.sf.LineString) MultiLineString(mil.nga.sf.MultiLineString) MultiPolygon(mil.nga.sf.MultiPolygon) TIN(mil.nga.sf.TIN) MultiPolygon(mil.nga.sf.MultiPolygon) CurvePolygon(mil.nga.sf.CurvePolygon) Polygon(mil.nga.sf.Polygon) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 4 with GeoPackageException

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

the class TestSetupTeardown method setUpCreate.

/**
 * Set up the create database
 *
 * @param activity
 * @param testContext
 * @param features
 * @param allowEmptyFeatures
 * @param tiles
 * @return
 * @throws SQLException
 * @throws IOException
 */
public static GeoPackage setUpCreate(Activity activity, Context testContext, boolean features, boolean allowEmptyFeatures, boolean tiles) throws SQLException, IOException {
    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    // Delete
    manager.delete(TestConstants.TEST_DB_NAME);
    // Create
    manager.create(TestConstants.TEST_DB_NAME);
    // Open
    GeoPackage geoPackage = manager.open(TestConstants.TEST_DB_NAME);
    if (geoPackage == null) {
        throw new GeoPackageException("Failed to open database");
    }
    TestCase.assertEquals("Application Id", geoPackage.getApplicationId(), GeoPackageConstants.APPLICATION_ID);
    TestCase.assertEquals("User Version", geoPackage.getUserVersion().intValue(), GeoPackageConstants.USER_VERSION);
    String userVersionString = String.valueOf(geoPackage.getUserVersion());
    String majorVersion = userVersionString.substring(0, userVersionString.length() - 4);
    String minorVersion = userVersionString.substring(userVersionString.length() - 4, userVersionString.length() - 2);
    String patchVersion = userVersionString.substring(userVersionString.length() - 2);
    TestCase.assertEquals("Major User Version", geoPackage.getUserVersionMajor().intValue(), Integer.valueOf(majorVersion).intValue());
    TestCase.assertEquals("Minor User Version", geoPackage.getUserVersionMinor().intValue(), Integer.valueOf(minorVersion).intValue());
    TestCase.assertEquals("Patch User Version", geoPackage.getUserVersionPatch().intValue(), Integer.valueOf(patchVersion).intValue());
    if (features) {
        setUpCreateFeatures(geoPackage, allowEmptyFeatures);
    }
    if (tiles) {
        setUpCreateTiles(testContext, geoPackage);
    }
    setUpCreateCommon(geoPackage);
    return geoPackage;
}
Also used : GeoPackageManager(mil.nga.geopackage.GeoPackageManager) GeoPackage(mil.nga.geopackage.GeoPackage) GeoPackageException(mil.nga.geopackage.GeoPackageException)

Example 5 with GeoPackageException

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

the class FeatureInfoBuilder method projectGeometry.

/**
 * Project the geometry into the provided projection
 *
 * @param geometryData geometry data
 * @param projection   projection
 */
public void projectGeometry(GeoPackageGeometryData geometryData, Projection projection) {
    if (geometryData.getGeometry() != null) {
        SpatialReferenceSystemDao srsDao = SpatialReferenceSystemDao.create(featureDao.getDb());
        try {
            int srsId = geometryData.getSrsId();
            SpatialReferenceSystem srs = srsDao.queryForId((long) srsId);
            if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) {
                Projection geomProjection = srs.getProjection();
                GeometryTransform transform = GeometryTransform.create(geomProjection, projection);
                Geometry projectedGeometry = transform.transform(geometryData.getGeometry());
                geometryData.setGeometry(projectedGeometry);
                SpatialReferenceSystem projectionSrs = srsDao.getOrCreateCode(projection.getAuthority(), Long.parseLong(projection.getCode()));
                geometryData.setSrsId((int) projectionSrs.getSrsId());
            }
        } catch (SQLException e) {
            throw new GeoPackageException("Failed to project geometry to projection with Authority: " + projection.getAuthority() + ", Code: " + projection.getCode(), e);
        }
    }
}
Also used : GeometryTransform(mil.nga.sf.proj.GeometryTransform) Geometry(mil.nga.sf.Geometry) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) SQLException(java.sql.SQLException) SpatialReferenceSystem(mil.nga.geopackage.srs.SpatialReferenceSystem) Projection(mil.nga.proj.Projection) GeoPackageException(mil.nga.geopackage.GeoPackageException) Point(mil.nga.sf.Point)

Aggregations

GeoPackageException (mil.nga.geopackage.GeoPackageException)10 Geometry (mil.nga.sf.Geometry)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GeoPackage (mil.nga.geopackage.GeoPackage)3 CompoundCurve (mil.nga.sf.CompoundCurve)3 Point (mil.nga.sf.Point)3 LatLng (com.google.android.gms.maps.model.LatLng)2 Marker (com.google.android.gms.maps.model.Marker)2 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)2 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 GeoPackageManager (mil.nga.geopackage.GeoPackageManager)2 Curve (mil.nga.sf.Curve)2 CurvePolygon (mil.nga.sf.CurvePolygon)2 GeometryType (mil.nga.sf.GeometryType)2 LineString (mil.nga.sf.LineString)2 MultiLineString (mil.nga.sf.MultiLineString)2 MultiPoint (mil.nga.sf.MultiPoint)2