Search in sources :

Example 1 with GeometryColumnsDao

use of mil.nga.geopackage.features.columns.GeometryColumnsDao in project geopackage-android-map by ngageoint.

the class ReadmeTest method testGeoPackage.

/**
 * Test GeoPackage
 *
 * @param context        context
 * @param geoPackageFile GeoPackage file
 * @param map            Google map
 * @throws IOException  upon error
 * @throws SQLException upon error
 */
private void testGeoPackage(Context context, File geoPackageFile, GoogleMap map) throws IOException, SQLException {
    // Context context = ...;
    // File geoPackageFile = ...;
    // GoogleMap map = ...;
    // Get a manager
    GeoPackageManager manager = GeoPackageFactory.getManager(context);
    // Import database
    boolean imported = manager.importGeoPackage(geoPackageFile);
    // Available databases
    List<String> databases = manager.databases();
    // Open database
    GeoPackage geoPackage = manager.open(databases.get(0));
    // GeoPackage Table DAOs
    SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
    ContentsDao contentsDao = geoPackage.getContentsDao();
    GeometryColumnsDao geomColumnsDao = geoPackage.getGeometryColumnsDao();
    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
    SchemaExtension schemaExtension = new SchemaExtension(geoPackage);
    DataColumnsDao dao = schemaExtension.getDataColumnsDao();
    DataColumnConstraintsDao dataColumnConstraintsDao = schemaExtension.getDataColumnConstraintsDao();
    MetadataExtension metadataExtension = new MetadataExtension(geoPackage);
    MetadataDao metadataDao = metadataExtension.getMetadataDao();
    MetadataReferenceDao metadataReferenceDao = metadataExtension.getMetadataReferenceDao();
    ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();
    // Feature and tile tables
    List<String> features = geoPackage.getFeatureTables();
    List<String> tiles = geoPackage.getTileTables();
    // Query Features
    String featureTable = features.get(0);
    FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
    GoogleMapShapeConverter converter = new GoogleMapShapeConverter(featureDao.getProjection());
    FeatureCursor featureCursor = featureDao.queryForAll();
    try {
        for (FeatureRow featureRow : featureCursor) {
            GeoPackageGeometryData geometryData = featureRow.getGeometry();
            if (geometryData != null && !geometryData.isEmpty()) {
                Geometry geometry = geometryData.getGeometry();
                GoogleMapShape shape = converter.toShape(geometry);
                GoogleMapShape mapShape = GoogleMapShapeConverter.addShapeToMap(map, shape);
            // ...
            }
        }
    } finally {
        featureCursor.close();
    }
    // Query Tiles
    String tileTable = tiles.get(0);
    TileDao tileDao = geoPackage.getTileDao(tileTable);
    TileCursor tileCursor = tileDao.queryForAll();
    try {
        for (TileRow tileRow : tileCursor) {
            byte[] tileBytes = tileRow.getTileData();
            Bitmap tileBitmap = tileRow.getTileDataBitmap();
        // ...
        }
    } finally {
        tileCursor.close();
    }
    // Retrieve Tiles by XYZ
    GeoPackageTileRetriever retriever = new GeoPackageTileRetriever(tileDao);
    GeoPackageTile geoPackageTile = retriever.getTile(2, 2, 2);
    if (geoPackageTile != null) {
        byte[] tileBytes = geoPackageTile.getData();
        Bitmap tileBitmap = geoPackageTile.getBitmap();
    // ...
    }
    // Retrieve Tiles by Bounding Box
    TileCreator tileCreator = new TileCreator(tileDao, ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM));
    GeoPackageTile geoPackageTile2 = tileCreator.getTile(new BoundingBox(-90.0, 0.0, 0.0, 66.513260));
    if (geoPackageTile2 != null) {
        byte[] tileBytes = geoPackageTile2.getData();
        Bitmap tileBitmap = geoPackageTile2.getBitmap();
    // ...
    }
    // Tile Provider (GeoPackage or Google API)
    TileProvider overlay = GeoPackageOverlayFactory.getTileProvider(tileDao);
    TileOverlayOptions overlayOptions = new TileOverlayOptions();
    overlayOptions.tileProvider(overlay);
    overlayOptions.zIndex(-1);
    map.addTileOverlay(overlayOptions);
    BoundingBox boundingBox = BoundingBox.worldWebMercator();
    Projection projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
    // Index Features
    FeatureIndexManager indexer = new FeatureIndexManager(context, geoPackage, featureDao);
    indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
    int indexedCount = indexer.index();
    // Query Indexed Features in paginated chunks
    FeatureIndexResults indexResults = indexer.queryForChunk(boundingBox, projection, 50);
    FeaturePaginatedCursor paginatedCursor = indexer.paginate(indexResults);
    for (FeatureRow featureRow : paginatedCursor) {
        GeoPackageGeometryData geometryData = featureRow.getGeometry();
        if (geometryData != null && !geometryData.isEmpty()) {
            Geometry geometry = geometryData.getGeometry();
        // ...
        }
    }
    // Feature Tile Provider (dynamically draw tiles from features)
    FeatureTiles featureTiles = new DefaultFeatureTiles(context, featureDao, context.getResources().getDisplayMetrics().density);
    // Set max features to draw per tile
    featureTiles.setMaxFeaturesPerTile(1000);
    // Custom feature tile implementation
    NumberFeaturesTile numberFeaturesTile = new NumberFeaturesTile(context);
    // Draw feature count tiles when max features passed
    featureTiles.setMaxFeaturesTileDraw(numberFeaturesTile);
    // Set index manager to query feature indices
    featureTiles.setIndexManager(indexer);
    FeatureOverlay featureOverlay = new FeatureOverlay(featureTiles);
    // Set zoom level to start showing tiles
    featureOverlay.setMinZoom(featureDao.getZoomLevel());
    TileOverlayOptions featureOverlayOptions = new TileOverlayOptions();
    featureOverlayOptions.tileProvider(featureOverlay);
    // Draw the feature tiles behind map markers
    featureOverlayOptions.zIndex(-1);
    map.addTileOverlay(featureOverlayOptions);
    // URL Tile Generator (generate tiles from a URL)
    TileGenerator urlTileGenerator = new UrlTileGenerator(context, geoPackage, "url_tile_table", "http://url/{z}/{x}/{y}.png", 0, 0, boundingBox, projection);
    int urlTileCount = urlTileGenerator.generateTiles();
    // Feature Tile Generator (generate tiles from features)
    TileGenerator featureTileGenerator = new FeatureTileGenerator(context, geoPackage, "tiles_" + featureTable, featureTiles, 1, 2, boundingBox, projection);
    int featureTileCount = featureTileGenerator.generateTiles();
    // Close feature tiles (and indexer)
    featureTiles.close();
    // Close database when done
    geoPackage.close();
}
Also used : MetadataReferenceDao(mil.nga.geopackage.extension.metadata.reference.MetadataReferenceDao) GeoPackageTileRetriever(mil.nga.geopackage.tiles.retriever.GeoPackageTileRetriever) DataColumnsDao(mil.nga.geopackage.extension.schema.columns.DataColumnsDao) Projection(mil.nga.proj.Projection) DefaultFeatureTiles(mil.nga.geopackage.tiles.features.DefaultFeatureTiles) FeatureDao(mil.nga.geopackage.features.user.FeatureDao) GeoPackage(mil.nga.geopackage.GeoPackage) MetadataExtension(mil.nga.geopackage.extension.metadata.MetadataExtension) TileProvider(com.google.android.gms.maps.model.TileProvider) FeatureOverlay(mil.nga.geopackage.map.tiles.overlay.FeatureOverlay) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) Bitmap(android.graphics.Bitmap) FeaturePaginatedCursor(mil.nga.geopackage.features.user.FeaturePaginatedCursor) DataColumnConstraintsDao(mil.nga.geopackage.extension.schema.constraints.DataColumnConstraintsDao) BoundingBox(mil.nga.geopackage.BoundingBox) TileCreator(mil.nga.geopackage.tiles.retriever.TileCreator) MetadataDao(mil.nga.geopackage.extension.metadata.MetadataDao) FeatureIndexResults(mil.nga.geopackage.features.index.FeatureIndexResults) GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) SchemaExtension(mil.nga.geopackage.extension.schema.SchemaExtension) TileOverlayOptions(com.google.android.gms.maps.model.TileOverlayOptions) ExtensionsDao(mil.nga.geopackage.extension.ExtensionsDao) NumberFeaturesTile(mil.nga.geopackage.tiles.features.custom.NumberFeaturesTile) GeoPackageManager(mil.nga.geopackage.GeoPackageManager) UrlTileGenerator(mil.nga.geopackage.tiles.UrlTileGenerator) GoogleMapShapeConverter(mil.nga.geopackage.map.geom.GoogleMapShapeConverter) GoogleMapShape(mil.nga.geopackage.map.geom.GoogleMapShape) Geometry(mil.nga.sf.Geometry) GeoPackageTile(mil.nga.geopackage.tiles.retriever.GeoPackageTile) DefaultFeatureTiles(mil.nga.geopackage.tiles.features.DefaultFeatureTiles) FeatureTiles(mil.nga.geopackage.tiles.features.FeatureTiles) TileMatrixDao(mil.nga.geopackage.tiles.matrix.TileMatrixDao) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureIndexManager(mil.nga.geopackage.features.index.FeatureIndexManager) TileRow(mil.nga.geopackage.tiles.user.TileRow) TileGenerator(mil.nga.geopackage.tiles.TileGenerator) FeatureTileGenerator(mil.nga.geopackage.tiles.features.FeatureTileGenerator) UrlTileGenerator(mil.nga.geopackage.tiles.UrlTileGenerator) FeatureCursor(mil.nga.geopackage.features.user.FeatureCursor) FeatureTileGenerator(mil.nga.geopackage.tiles.features.FeatureTileGenerator) TileMatrixSetDao(mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao) ContentsDao(mil.nga.geopackage.contents.ContentsDao) TileDao(mil.nga.geopackage.tiles.user.TileDao) TileCursor(mil.nga.geopackage.tiles.user.TileCursor) GeometryColumnsDao(mil.nga.geopackage.features.columns.GeometryColumnsDao)

Example 2 with GeometryColumnsDao

use of mil.nga.geopackage.features.columns.GeometryColumnsDao in project geopackage-android-map by ngageoint.

the class TestSetupTeardown method setUpCreateFeatures.

/**
 * Set up create for features test
 *
 * @param geoPackage
 * @param allowEmptyFeatures
 * @throws SQLException
 */
private static void setUpCreateFeatures(GeoPackage geoPackage, boolean allowEmptyFeatures) throws SQLException {
    // Get existing SRS objects
    SpatialReferenceSystemDao srsDao = geoPackage.getSpatialReferenceSystemDao();
    SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);
    SpatialReferenceSystem undefinedCartesianSrs = srsDao.queryForId(-1l);
    SpatialReferenceSystem undefinedGeographicSrs = srsDao.queryForId(0l);
    TestCase.assertNotNull(epsgSrs);
    TestCase.assertNotNull(undefinedCartesianSrs);
    TestCase.assertNotNull(undefinedGeographicSrs);
    // Create the Geometry Columns table
    geoPackage.createGeometryColumnsTable();
    // Create new Contents
    ContentsDao contentsDao = geoPackage.getContentsDao();
    Contents point2dContents = new Contents();
    point2dContents.setTableName("point2d");
    point2dContents.setDataType(ContentsDataType.FEATURES);
    point2dContents.setIdentifier("point2d");
    // point2dContents.setDescription("");
    // point2dContents.setLastChange(new Date());
    point2dContents.setMinX(-180.0);
    point2dContents.setMinY(-90.0);
    point2dContents.setMaxX(180.0);
    point2dContents.setMaxY(90.0);
    point2dContents.setSrs(epsgSrs);
    Contents polygon2dContents = new Contents();
    polygon2dContents.setTableName("polygon2d");
    polygon2dContents.setDataType(ContentsDataType.FEATURES);
    polygon2dContents.setIdentifier("polygon2d");
    // polygon2dContents.setDescription("");
    // polygon2dContents.setLastChange(new Date());
    polygon2dContents.setMinX(0.0);
    polygon2dContents.setMinY(0.0);
    polygon2dContents.setMaxX(10.0);
    polygon2dContents.setMaxY(10.0);
    polygon2dContents.setSrs(undefinedGeographicSrs);
    Contents point3dContents = new Contents();
    point3dContents.setTableName("point3d");
    point3dContents.setDataType(ContentsDataType.FEATURES);
    point3dContents.setIdentifier("point3d");
    // point3dContents.setDescription("");
    // point3dContents.setLastChange(new Date());
    point3dContents.setMinX(-180.0);
    point3dContents.setMinY(-90.0);
    point3dContents.setMaxX(180.0);
    point3dContents.setMaxY(90.0);
    point3dContents.setSrs(undefinedCartesianSrs);
    Contents lineString3dMContents = new Contents();
    lineString3dMContents.setTableName("lineString3dM");
    lineString3dMContents.setDataType(ContentsDataType.FEATURES);
    lineString3dMContents.setIdentifier("lineString3dM");
    // lineString3dMContents.setDescription("");
    // lineString3dMContents.setLastChange(new Date());
    lineString3dMContents.setMinX(-180.0);
    lineString3dMContents.setMinY(-90.0);
    lineString3dMContents.setMaxX(180.0);
    lineString3dMContents.setMaxY(90.0);
    lineString3dMContents.setSrs(undefinedCartesianSrs);
    // Create Data Column Constraints table and rows
    TestUtils.createConstraints(geoPackage);
    // Create data columns table
    (new SchemaExtension(geoPackage)).createDataColumnsTable();
    String geometryColumn = "geometry";
    // Create the feature tables
    FeatureTable point2dTable = TestUtils.createFeatureTable(geoPackage, point2dContents, geometryColumn, GeometryType.POINT);
    FeatureTable polygon2dTable = TestUtils.createFeatureTable(geoPackage, polygon2dContents, geometryColumn, GeometryType.POLYGON);
    FeatureTable point3dTable = TestUtils.createFeatureTable(geoPackage, point3dContents, geometryColumn, GeometryType.POINT);
    FeatureTable lineString3dMTable = TestUtils.createFeatureTable(geoPackage, lineString3dMContents, geometryColumn, GeometryType.LINESTRING);
    // Create the contents
    contentsDao.create(point2dContents);
    contentsDao.create(polygon2dContents);
    contentsDao.create(point3dContents);
    contentsDao.create(lineString3dMContents);
    // Create new Geometry Columns
    GeometryColumnsDao geometryColumnsDao = geoPackage.getGeometryColumnsDao();
    GeometryColumns point2dGeometryColumns = new GeometryColumns();
    point2dGeometryColumns.setContents(point2dContents);
    point2dGeometryColumns.setColumnName(geometryColumn);
    point2dGeometryColumns.setGeometryType(GeometryType.POINT);
    point2dGeometryColumns.setSrs(point2dContents.getSrs());
    point2dGeometryColumns.setZ((byte) 0);
    point2dGeometryColumns.setM((byte) 0);
    geometryColumnsDao.create(point2dGeometryColumns);
    GeometryColumns polygon2dGeometryColumns = new GeometryColumns();
    polygon2dGeometryColumns.setContents(polygon2dContents);
    polygon2dGeometryColumns.setColumnName(geometryColumn);
    polygon2dGeometryColumns.setGeometryType(GeometryType.POLYGON);
    polygon2dGeometryColumns.setSrs(polygon2dContents.getSrs());
    polygon2dGeometryColumns.setZ((byte) 0);
    polygon2dGeometryColumns.setM((byte) 0);
    geometryColumnsDao.create(polygon2dGeometryColumns);
    GeometryColumns point3dGeometryColumns = new GeometryColumns();
    point3dGeometryColumns.setContents(point3dContents);
    point3dGeometryColumns.setColumnName(geometryColumn);
    point3dGeometryColumns.setGeometryType(GeometryType.POINT);
    point3dGeometryColumns.setSrs(point3dContents.getSrs());
    point3dGeometryColumns.setZ((byte) 1);
    point3dGeometryColumns.setM((byte) 0);
    geometryColumnsDao.create(point3dGeometryColumns);
    GeometryColumns lineString3dMGeometryColumns = new GeometryColumns();
    lineString3dMGeometryColumns.setContents(lineString3dMContents);
    lineString3dMGeometryColumns.setColumnName(geometryColumn);
    lineString3dMGeometryColumns.setGeometryType(GeometryType.LINESTRING);
    lineString3dMGeometryColumns.setSrs(lineString3dMContents.getSrs());
    lineString3dMGeometryColumns.setZ((byte) 1);
    lineString3dMGeometryColumns.setM((byte) 1);
    geometryColumnsDao.create(lineString3dMGeometryColumns);
    // Populate the feature tables with rows
    TestUtils.addRowsToFeatureTable(geoPackage, point2dGeometryColumns, point2dTable, 3, false, false, allowEmptyFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, polygon2dGeometryColumns, polygon2dTable, 3, false, false, allowEmptyFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, point3dGeometryColumns, point3dTable, 3, true, false, allowEmptyFeatures);
    TestUtils.addRowsToFeatureTable(geoPackage, lineString3dMGeometryColumns, lineString3dMTable, 3, true, true, allowEmptyFeatures);
}
Also used : GeometryColumns(mil.nga.geopackage.features.columns.GeometryColumns) SpatialReferenceSystemDao(mil.nga.geopackage.srs.SpatialReferenceSystemDao) SchemaExtension(mil.nga.geopackage.extension.schema.SchemaExtension) FeatureTable(mil.nga.geopackage.features.user.FeatureTable) Contents(mil.nga.geopackage.contents.Contents) SpatialReferenceSystem(mil.nga.geopackage.srs.SpatialReferenceSystem) ContentsDao(mil.nga.geopackage.contents.ContentsDao) GeometryColumnsDao(mil.nga.geopackage.features.columns.GeometryColumnsDao)

Example 3 with GeometryColumnsDao

use of mil.nga.geopackage.features.columns.GeometryColumnsDao 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

GeometryColumnsDao (mil.nga.geopackage.features.columns.GeometryColumnsDao)3 ContentsDao (mil.nga.geopackage.contents.ContentsDao)2 SchemaExtension (mil.nga.geopackage.extension.schema.SchemaExtension)2 GeometryColumns (mil.nga.geopackage.features.columns.GeometryColumns)2 FeatureCursor (mil.nga.geopackage.features.user.FeatureCursor)2 FeatureDao (mil.nga.geopackage.features.user.FeatureDao)2 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)2 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)2 SpatialReferenceSystemDao (mil.nga.geopackage.srs.SpatialReferenceSystemDao)2 Geometry (mil.nga.sf.Geometry)2 Bitmap (android.graphics.Bitmap)1 TileOverlayOptions (com.google.android.gms.maps.model.TileOverlayOptions)1 TileProvider (com.google.android.gms.maps.model.TileProvider)1 BoundingBox (mil.nga.geopackage.BoundingBox)1 GeoPackage (mil.nga.geopackage.GeoPackage)1 GeoPackageManager (mil.nga.geopackage.GeoPackageManager)1 Contents (mil.nga.geopackage.contents.Contents)1 ExtensionsDao (mil.nga.geopackage.extension.ExtensionsDao)1 MetadataDao (mil.nga.geopackage.extension.metadata.MetadataDao)1 MetadataExtension (mil.nga.geopackage.extension.metadata.MetadataExtension)1