Search in sources :

Example 1 with Geometry

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

the class GoogleMapShapeConverter method toShapes.

/**
 * Convert a {@link GeometryCollection} to a list of Map shapes
 *
 * @param geometryCollection geometry collection
 * @return google map shapes
 */
public List<GoogleMapShape> toShapes(GeometryCollection<Geometry> geometryCollection) {
    List<GoogleMapShape> shapes = new ArrayList<>();
    for (Geometry geometry : geometryCollection.getGeometries()) {
        GoogleMapShape shape = toShape(geometry);
        shapes.add(shape);
    }
    return shapes;
}
Also used : Geometry(mil.nga.sf.Geometry) ArrayList(java.util.ArrayList)

Example 2 with Geometry

use of mil.nga.sf.Geometry 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 3 with Geometry

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

the class TestUtils method addRowsToFeatureTable.

/**
 * Add rows to the feature table
 *
 * @param geoPackage
 * @param geometryColumns
 * @param table
 * @param numRows
 * @param hasZ
 * @param hasM
 * @param allowEmptyFeatures
 * @throws SQLException
 */
public static void addRowsToFeatureTable(GeoPackage geoPackage, GeometryColumns geometryColumns, FeatureTable table, int numRows, boolean hasZ, boolean hasM, boolean allowEmptyFeatures) throws SQLException {
    FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
    for (int i = 0; i < numRows; i++) {
        FeatureRow newRow = dao.newRow();
        for (FeatureColumn column : table.getColumns()) {
            if (!column.isPrimaryKey()) {
                // Leave nullable columns null 20% of the time
                if (!column.isNotNull()) {
                    if (allowEmptyFeatures && Math.random() < .2) {
                        continue;
                    }
                }
                if (column.isGeometry()) {
                    Geometry geometry = null;
                    switch(column.getGeometryType()) {
                        case POINT:
                            geometry = createPoint(hasZ, hasM);
                            break;
                        case LINESTRING:
                            geometry = createLineString(hasZ, hasM, false);
                            break;
                        case POLYGON:
                            geometry = createPolygon(hasZ, hasM);
                            break;
                        default:
                            throw new UnsupportedOperationException("Not implemented for geometry type: " + column.getGeometryType());
                    }
                    GeoPackageGeometryData geometryData = new GeoPackageGeometryData(geometryColumns.getSrsId());
                    geometryData.setGeometry(geometry);
                    newRow.setGeometry(geometryData);
                } else {
                    Object value = null;
                    switch(column.getDataType()) {
                        case TEXT:
                            String text = UUID.randomUUID().toString();
                            if (column.getMax() != null && text.length() > column.getMax()) {
                                text = text.substring(0, column.getMax().intValue());
                            }
                            value = text;
                            break;
                        case REAL:
                        case DOUBLE:
                            value = Math.random() * 5000.0;
                            break;
                        case BOOLEAN:
                            value = Math.random() < .5 ? false : true;
                            break;
                        case INTEGER:
                        case INT:
                            value = (int) (Math.random() * 500);
                            break;
                        case BLOB:
                            byte[] blob = UUID.randomUUID().toString().getBytes();
                            if (column.getMax() != null && blob.length > column.getMax()) {
                                byte[] blobLimited = new byte[column.getMax().intValue()];
                                ByteBuffer.wrap(blob, 0, column.getMax().intValue()).get(blobLimited);
                                blob = blobLimited;
                            }
                            value = blob;
                            break;
                        default:
                            throw new UnsupportedOperationException("Not implemented for data type: " + column.getDataType());
                    }
                    newRow.setValue(column.getName(), value);
                }
            }
        }
        dao.create(newRow);
    }
}
Also used : Geometry(mil.nga.sf.Geometry) GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureColumn(mil.nga.geopackage.features.user.FeatureColumn) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) LineString(mil.nga.sf.LineString) Point(mil.nga.sf.Point)

Example 4 with Geometry

use of mil.nga.sf.Geometry 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)

Example 5 with Geometry

use of mil.nga.sf.Geometry 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

Geometry (mil.nga.sf.Geometry)9 GeoPackageException (mil.nga.geopackage.GeoPackageException)4 ArrayList (java.util.ArrayList)3 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)3 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)3 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)3 Point (mil.nga.sf.Point)3 GeometryColumnsDao (mil.nga.geopackage.features.columns.GeometryColumnsDao)2 FeatureCursor (mil.nga.geopackage.features.user.FeatureCursor)2 SpatialReferenceSystemDao (mil.nga.geopackage.srs.SpatialReferenceSystemDao)2 CompoundCurve (mil.nga.sf.CompoundCurve)2 GeometryType (mil.nga.sf.GeometryType)2 LineString (mil.nga.sf.LineString)2 Bitmap (android.graphics.Bitmap)1 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 PolygonOptions (com.google.android.gms.maps.model.PolygonOptions)1 Polyline (com.google.android.gms.maps.model.Polyline)1 PolylineOptions (com.google.android.gms.maps.model.PolylineOptions)1