Search in sources :

Example 1 with DataColumnsDao

use of mil.nga.geopackage.extension.schema.columns.DataColumnsDao in project geopackage-android-map by ngageoint.

the class TestUtils method createFeatureTable.

/**
 * Create the feature table with data columns entry
 *
 * @param geoPackage
 * @param contents
 * @param geometryColumn
 * @param geometryType
 * @return
 * @throws SQLException
 */
public static FeatureTable createFeatureTable(GeoPackage geoPackage, Contents contents, String geometryColumn, GeometryType geometryType) throws SQLException {
    FeatureTable table = buildFeatureTable(contents.getTableName(), geometryColumn, geometryType);
    geoPackage.createFeatureTable(table);
    double random = Math.random();
    DataColumnsDao dataColumnsDao = SchemaExtension.getDataColumnsDao(geoPackage);
    DataColumns dataColumns = new DataColumns();
    dataColumns.setContents(contents);
    dataColumns.setColumnName(TEST_INTEGER_COLUMN);
    dataColumns.setName(contents.getTableName());
    dataColumns.setTitle("TEST_TITLE");
    dataColumns.setDescription("TEST_DESCRIPTION");
    dataColumns.setMimeType("TEST_MIME_TYPE");
    if (random < (1.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_RANGE_CONSTRAINT);
    } else if (random < (2.0 / 3.0)) {
        dataColumns.setConstraintName(SAMPLE_ENUM_CONSTRAINT);
    } else {
        dataColumns.setConstraintName(SAMPLE_GLOB_CONSTRAINT);
    }
    dataColumnsDao.create(dataColumns);
    return table;
}
Also used : FeatureTable(mil.nga.geopackage.features.user.FeatureTable) DataColumns(mil.nga.geopackage.extension.schema.columns.DataColumns) DataColumnsDao(mil.nga.geopackage.extension.schema.columns.DataColumnsDao)

Example 2 with DataColumnsDao

use of mil.nga.geopackage.extension.schema.columns.DataColumnsDao in project geopackage-android-map by ngageoint.

the class FeatureInfoBuilder method buildResultsInfoMessage.

/**
 * Build a feature results information message
 *
 * @param results       feature index results
 * @param tolerance     distance tolerance
 * @param clickLocation map click location
 * @param projection    desired geometry projection
 * @return results message or null if no results
 */
public String buildResultsInfoMessage(FeatureIndexResults results, double tolerance, LatLng clickLocation, Projection projection) {
    String message = null;
    // Fine filter results so that the click location is within the tolerance of each feature row result
    FeatureIndexResults filteredResults = fineFilterResults(results, tolerance, clickLocation);
    long featureCount = filteredResults.count();
    if (featureCount > 0) {
        int maxFeatureInfo = 0;
        if (geometryType == GeometryType.POINT) {
            maxFeatureInfo = maxPointDetailedInfo;
        } else {
            maxFeatureInfo = maxFeatureDetailedInfo;
        }
        if (featureCount <= maxFeatureInfo) {
            StringBuilder messageBuilder = new StringBuilder();
            messageBuilder.append(name).append("\n");
            int featureNumber = 0;
            DataColumnsDao dataColumnsDao = getDataColumnsDao();
            for (FeatureRow featureRow : filteredResults) {
                featureNumber++;
                if (featureNumber > maxFeatureInfo) {
                    break;
                }
                if (featureCount > 1) {
                    if (featureNumber > 1) {
                        messageBuilder.append("\n");
                    } else {
                        messageBuilder.append("\n").append(featureCount).append(" Features").append("\n");
                    }
                    messageBuilder.append("\n").append("Feature ").append(featureNumber).append(":").append("\n");
                }
                int geometryColumn = featureRow.getGeometryColumnIndex();
                for (int i = 0; i < featureRow.columnCount(); i++) {
                    if (i != geometryColumn) {
                        Object value = featureRow.getValue(i);
                        if (value != null) {
                            String columnName = featureRow.getColumnName(i);
                            columnName = getColumnName(dataColumnsDao, featureRow, columnName);
                            messageBuilder.append("\n").append(columnName).append(": ").append(value);
                        }
                    }
                }
                GeoPackageGeometryData geomData = featureRow.getGeometry();
                if (geomData != null && geomData.getGeometry() != null) {
                    boolean printFeatures = false;
                    if (geomData.getGeometry().getGeometryType() == GeometryType.POINT) {
                        printFeatures = detailedInfoPrintPoints;
                    } else {
                        printFeatures = detailedInfoPrintFeatures;
                    }
                    if (printFeatures) {
                        if (projection != null) {
                            projectGeometry(geomData, projection);
                        }
                        messageBuilder.append("\n\n");
                        messageBuilder.append(GeometryPrinter.getGeometryString(geomData.getGeometry()));
                    }
                }
            }
            message = messageBuilder.toString();
        } else {
            StringBuilder messageBuilder = new StringBuilder();
            messageBuilder.append(name).append("\n\t").append(featureCount).append(" features");
            if (clickLocation != null) {
                messageBuilder.append(" near location:\n");
                Point point = new Point(clickLocation.longitude, clickLocation.latitude);
                messageBuilder.append(GeometryPrinter.getGeometryString(point));
            }
            message = messageBuilder.toString();
        }
    }
    return message;
}
Also used : GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) DataColumnsDao(mil.nga.geopackage.extension.schema.columns.DataColumnsDao) Point(mil.nga.sf.Point) Point(mil.nga.sf.Point) FeatureIndexResults(mil.nga.geopackage.features.index.FeatureIndexResults)

Example 3 with DataColumnsDao

use of mil.nga.geopackage.extension.schema.columns.DataColumnsDao in project geopackage-android-map by ngageoint.

the class FeatureInfoBuilder method buildTableDataAndClose.

/**
 * Build a feature results information message
 *
 * @param results       feature index results
 * @param tolerance     distance tolerance
 * @param clickLocation map click location
 * @param projection    desired geometry projection
 * @return feature table data or null if not results
 */
public FeatureTableData buildTableDataAndClose(FeatureIndexResults results, double tolerance, LatLng clickLocation, Projection projection) {
    FeatureTableData tableData = null;
    // Fine filter results so that the click location is within the tolerance of each feature row result
    FeatureIndexResults filteredResults = fineFilterResults(results, tolerance, clickLocation);
    long featureCount = filteredResults.count();
    if (featureCount > 0) {
        int maxFeatureInfo = 0;
        if (geometryType == GeometryType.POINT) {
            maxFeatureInfo = maxPointDetailedInfo;
        } else {
            maxFeatureInfo = maxFeatureDetailedInfo;
        }
        if (featureCount <= maxFeatureInfo) {
            DataColumnsDao dataColumnsDao = getDataColumnsDao();
            List<FeatureRowData> rows = new ArrayList<>();
            for (FeatureRow featureRow : filteredResults) {
                Map<String, Object> values = new HashMap<>();
                String geometryColumnName = null;
                int geometryColumn = featureRow.getGeometryColumnIndex();
                for (int i = 0; i < featureRow.columnCount(); i++) {
                    Object value = featureRow.getValue(i);
                    String columnName = featureRow.getColumnName(i);
                    columnName = getColumnName(dataColumnsDao, featureRow, columnName);
                    if (i == geometryColumn) {
                        geometryColumnName = columnName;
                        if (projection != null && value != null) {
                            GeoPackageGeometryData geomData = (GeoPackageGeometryData) value;
                            projectGeometry(geomData, projection);
                        }
                    }
                    if (value != null) {
                        values.put(columnName, value);
                    }
                }
                FeatureRowData featureRowData = new FeatureRowData(values, geometryColumnName);
                rows.add(featureRowData);
            }
            tableData = new FeatureTableData(featureDao.getTableName(), featureCount, rows);
        } else {
            tableData = new FeatureTableData(featureDao.getTableName(), featureCount);
        }
    }
    results.close();
    return tableData;
}
Also used : GeoPackageGeometryData(mil.nga.geopackage.geom.GeoPackageGeometryData) FeatureTableData(mil.nga.geopackage.tiles.overlay.FeatureTableData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DataColumnsDao(mil.nga.geopackage.extension.schema.columns.DataColumnsDao) Point(mil.nga.sf.Point) FeatureRowData(mil.nga.geopackage.tiles.overlay.FeatureRowData) FeatureRow(mil.nga.geopackage.features.user.FeatureRow) FeatureIndexResults(mil.nga.geopackage.features.index.FeatureIndexResults)

Example 4 with DataColumnsDao

use of mil.nga.geopackage.extension.schema.columns.DataColumnsDao 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)

Aggregations

DataColumnsDao (mil.nga.geopackage.extension.schema.columns.DataColumnsDao)4 FeatureIndexResults (mil.nga.geopackage.features.index.FeatureIndexResults)3 FeatureRow (mil.nga.geopackage.features.user.FeatureRow)3 GeoPackageGeometryData (mil.nga.geopackage.geom.GeoPackageGeometryData)3 Point (mil.nga.sf.Point)2 Bitmap (android.graphics.Bitmap)1 TileOverlayOptions (com.google.android.gms.maps.model.TileOverlayOptions)1 TileProvider (com.google.android.gms.maps.model.TileProvider)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BoundingBox (mil.nga.geopackage.BoundingBox)1 GeoPackage (mil.nga.geopackage.GeoPackage)1 GeoPackageManager (mil.nga.geopackage.GeoPackageManager)1 ContentsDao (mil.nga.geopackage.contents.ContentsDao)1 ExtensionsDao (mil.nga.geopackage.extension.ExtensionsDao)1 MetadataDao (mil.nga.geopackage.extension.metadata.MetadataDao)1 MetadataExtension (mil.nga.geopackage.extension.metadata.MetadataExtension)1 MetadataReferenceDao (mil.nga.geopackage.extension.metadata.reference.MetadataReferenceDao)1 SchemaExtension (mil.nga.geopackage.extension.schema.SchemaExtension)1 DataColumns (mil.nga.geopackage.extension.schema.columns.DataColumns)1