Search in sources :

Example 1 with GeometryType

use of mil.nga.sf.GeometryType 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 2 with GeometryType

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

Example 3 with GeometryType

use of mil.nga.sf.GeometryType in project joa by sebastianfrey.

the class GeoPackageService method getQueryables.

@Override
public Queryables getQueryables(String serviceId, String collectionId) {
    try (GeoPackage gpkg = loadService(serviceId)) {
        ObjectType schema = JSONSchemaBuilder.objectType().title(collectionId).schema(Schemas.DRAFT_2019_09);
        FeatureDao featureDao = loadCollection(gpkg, collectionId);
        String geometryColumn = featureDao.getGeometryColumnName();
        featureDao.getColumns().stream().forEach((column) -> {
            if (column.isGeometry()) {
                return;
            }
            Long max = column.getMax();
            Object defaultValue = column.getDefaultValue();
            GenericType<?> type = null;
            switch(column.getDataType()) {
                case BOOLEAN:
                    type = JSONSchemaBuilder.booleanType();
                    break;
                case BLOB:
                case TINYINT:
                case TEXT:
                    type = JSONSchemaBuilder.stringType().maxLength(max);
                    break;
                case DATE:
                    type = JSONSchemaBuilder.stringType().maxLength(max).format("date");
                    break;
                case DATETIME:
                    type = JSONSchemaBuilder.stringType().maxLength(max).format("date-time");
                    break;
                case DOUBLE:
                case FLOAT:
                case REAL:
                    type = JSONSchemaBuilder.numberType();
                    break;
                case INT:
                case INTEGER:
                case MEDIUMINT:
                case SMALLINT:
                    type = JSONSchemaBuilder.integerType().maximum(max);
                    break;
                default:
                    break;
            }
            if (type == null) {
                return;
            }
            String columnName = column.getName();
            type.title(columnName);
            if (defaultValue != null) {
                type.defaultValue(defaultValue.toString());
            }
            schema.property(columnName, type);
        });
        GeometryType geometryType = featureDao.getGeometryType();
        JSONSchema geometrySchema = null;
        switch(geometryType) {
            case GEOMETRY:
                geometrySchema = Schemas.GeoJSON.geometry();
                break;
            case POINT:
                geometrySchema = Schemas.GeoJSON.point();
                break;
            case LINESTRING:
                geometrySchema = Schemas.GeoJSON.lineString();
                break;
            case POLYGON:
                geometrySchema = Schemas.GeoJSON.polygon();
                break;
            case MULTIPOINT:
                geometrySchema = Schemas.GeoJSON.multiPoint();
                break;
            case MULTILINESTRING:
                geometrySchema = Schemas.GeoJSON.multiLineString();
                break;
            case MULTIPOLYGON:
                geometrySchema = Schemas.GeoJSON.multiPolygon();
                break;
            default:
                break;
        }
        if (geometrySchema != null) {
            schema.property(geometryColumn, geometrySchema);
        }
        return new Queryables().serviceId(serviceId).collectionId(collectionId).schema(schema);
    }
}
Also used : ObjectType(com.github.sebastianfrey.joa.models.schema.type.ObjectType) GeometryType(mil.nga.sf.GeometryType) Queryables(com.github.sebastianfrey.joa.models.Queryables) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) JSONSchema(com.github.sebastianfrey.joa.models.schema.JSONSchema) GeoPackage(mil.nga.geopackage.GeoPackage)

Example 4 with GeometryType

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

the class GoogleMapShapeConverterUtils method testShapes.

/**
 * Test shapes
 *
 * @param geoPackage
 * @throws SQLException
 */
public static void testShapes(GeoPackage geoPackage) throws SQLException {
    GeometryColumnsDao geometryColumnsDao = geoPackage.getGeometryColumnsDao();
    if (geometryColumnsDao.isTableExists()) {
        List<GeometryColumns> results = geometryColumnsDao.queryForAll();
        for (GeometryColumns geometryColumns : results) {
            FeatureDao dao = geoPackage.getFeatureDao(geometryColumns);
            GoogleMapShapeConverter converter = new GoogleMapShapeConverter(dao.getProjection());
            converter.setExteriorOrientation(null);
            converter.setHoleOrientation(null);
            // Query for all
            FeatureCursor cursor = dao.queryForAll();
            while (cursor.moveToNext()) {
                FeatureRow featureRow = cursor.getRow();
                GeoPackageGeometryData geometryData = featureRow.getGeometry();
                if (geometryData != null) {
                    Geometry geometry = geometryData.getGeometry();
                    GeometryType geometryType = geometry.getGeometryType();
                    switch(geometryType) {
                        case POINT:
                            convertPoint(converter, (Point) geometry);
                            break;
                        case LINESTRING:
                            convertLineString(converter, (LineString) geometry);
                            break;
                        case POLYGON:
                            convertPolygon(converter, (Polygon) geometry);
                            break;
                        case MULTIPOINT:
                            convertMultiPoint(converter, (MultiPoint) geometry);
                            break;
                        case MULTILINESTRING:
                            convertMultiLineString(converter, (MultiLineString) geometry);
                            break;
                        case MULTIPOLYGON:
                            convertMultiPolygon(converter, (MultiPolygon) geometry);
                            break;
                        case CIRCULARSTRING:
                            convertLineString(converter, (CircularString) geometry);
                            break;
                        case COMPOUNDCURVE:
                            convertCompoundCurve(converter, (CompoundCurve) geometry);
                            break;
                        case POLYHEDRALSURFACE:
                            convertMultiPolygon(converter, (PolyhedralSurface) geometry);
                            break;
                        case TIN:
                            convertMultiPolygon(converter, (TIN) geometry);
                            break;
                        case TRIANGLE:
                            convertPolygon(converter, (Triangle) geometry);
                            break;
                        default:
                    }
                }
            }
            cursor.close();
        }
    }
}
Also used : GeometryColumns(mil.nga.geopackage.features.columns.GeometryColumns) Geometry(mil.nga.sf.Geometry) GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) GeometryType(mil.nga.sf.GeometryType) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) FeatureCursor(mil.nga.geopackage.features.user.FeatureCursor) GeometryColumnsDao(mil.nga.geopackage.features.columns.GeometryColumnsDao)

Aggregations

GeometryType (mil.nga.sf.GeometryType)4 Geometry (mil.nga.sf.Geometry)3 GeoPackageException (mil.nga.geopackage.GeoPackageException)2 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)2 CompoundCurve (mil.nga.sf.CompoundCurve)2 Queryables (com.github.sebastianfrey.joa.models.Queryables)1 JSONSchema (com.github.sebastianfrey.joa.models.schema.JSONSchema)1 ObjectType (com.github.sebastianfrey.joa.models.schema.type.ObjectType)1 GeoPackage (mil.nga.geopackage.GeoPackage)1 GeometryColumns (mil.nga.geopackage.features.columns.GeometryColumns)1 GeometryColumnsDao (mil.nga.geopackage.features.columns.GeometryColumnsDao)1 FeatureCursor (mil.nga.geopackage.features.user.FeatureCursor)1 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)1 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)1 CircularString (mil.nga.sf.CircularString)1 Curve (mil.nga.sf.Curve)1 CurvePolygon (mil.nga.sf.CurvePolygon)1 LineString (mil.nga.sf.LineString)1 MultiLineString (mil.nga.sf.MultiLineString)1 MultiPoint (mil.nga.sf.MultiPoint)1