mil.nga.geopackage.features.index.FeatureIndexManager Java Examples

The following examples show how to use mil.nga.geopackage.features.index.FeatureIndexManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoPackageImpl.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getFeatureBoundingBox(Projection projection,
                                         String table, boolean manual) {

    BoundingBox boundingBox = null;

    FeatureIndexManager indexManager = new FeatureIndexManager(context, this, table);
    try {
        if (manual || indexManager.isIndexed()) {
            boundingBox = indexManager.getBoundingBox(projection);
        }
    } finally {
        indexManager.close();
    }

    return boundingBox;
}
 
Example #2
Source File: AlterTableUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Test the feature indexes
 *
 * @param indexManager    index manager
 * @param geoPackageCount GeoPackage index count
 * @param rTreeCount      RTree index count
 */
private static void testIndex(FeatureIndexManager indexManager,
                              int geoPackageCount, int rTreeCount) {

    TestCase.assertTrue(
            indexManager.isIndexed(FeatureIndexType.GEOPACKAGE));
    indexManager.prioritizeQueryLocation(FeatureIndexType.GEOPACKAGE);
    TestCase.assertEquals(geoPackageCount, indexManager.count());

    //TestCase.assertTrue(indexManager.isIndexed(FeatureIndexType.RTREE));
    if (indexManager.isIndexed(FeatureIndexType.RTREE)) {
        indexManager.prioritizeQueryLocation(FeatureIndexType.RTREE);
        TestCase.assertEquals(rTreeCount, indexManager.count());
    }

}
 
Example #3
Source File: GeoPackageImpl.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getFeatureBoundingBox(Projection projection,
		String table, boolean manual) {

	BoundingBox boundingBox = null;

	FeatureIndexManager indexManager = new FeatureIndexManager(this, table);
	try {
		if (manual || indexManager.isIndexed()) {
			boundingBox = indexManager.getBoundingBox(projection);
		}
	} finally {
		indexManager.close();
	}

	return boundingBox;
}
 
Example #4
Source File: FeatureOverlayQuery.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Query for features in the bounding box
 *
 * @param columns     columns
 * @param boundingBox query bounding box
 * @param projection  bounding box projection
 * @return feature index results, must be closed
 * @since 3.5.0
 */
public FeatureIndexResults queryFeatures(String[] columns, BoundingBox boundingBox, Projection projection) {

    if (projection == null) {
        projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
    }

    // Query for features
    FeatureIndexManager indexManager = featureTiles.getIndexManager();
    if (indexManager == null) {
        throw new GeoPackageException("Index Manager is not set on the Feature Tiles and is required to query indexed features");
    }
    FeatureIndexResults results = indexManager.query(columns, boundingBox, projection);
    return results;
}
 
Example #5
Source File: FeatureIndexManagerUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate a Feature Row result
 *
 * @param featureIndexManager
 * @param featureRow
 * @param queryEnvelope
 */
private static void validateFeatureRow(
        FeatureIndexManager featureIndexManager, FeatureRow featureRow,
        GeometryEnvelope queryEnvelope, boolean includeEmpty) {
    TestCase.assertNotNull(featureRow);
    GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

    if (!includeEmpty) {
        TestCase.assertNotNull(envelope);

        if (queryEnvelope != null) {
            TestCase.assertTrue(envelope.getMinX() <= queryEnvelope
                    .getMaxX());
            TestCase.assertTrue(envelope.getMaxX() >= queryEnvelope
                    .getMinX());
            TestCase.assertTrue(envelope.getMinY() <= queryEnvelope
                    .getMaxY());
            TestCase.assertTrue(envelope.getMaxY() >= queryEnvelope
                    .getMinY());
            if (envelope.isHasZ()) {
                if (queryEnvelope.hasZ()) {
                    TestCase.assertTrue(envelope.getMinZ() <= queryEnvelope
                            .getMaxZ());
                    TestCase.assertTrue(envelope.getMaxZ() >= queryEnvelope
                            .getMinZ());
                }
            }
            if (envelope.isHasM()) {
                if (queryEnvelope.hasM()) {
                    TestCase.assertTrue(envelope.getMinM() <= queryEnvelope
                            .getMaxM());
                    TestCase.assertTrue(envelope.getMaxM() >= queryEnvelope
                            .getMinM());
                }
            }
        }
    }
}
 
Example #6
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createGeometryIndexExtension(Context context, GeoPackage geoPackage) {

        List<String> featureTables = geoPackage.getFeatureTables();
        for (String featureTable : featureTables) {

            FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
            FeatureIndexManager indexer = new FeatureIndexManager(context, geoPackage, featureDao);
            indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
            indexer.index();
            indexer.close();
        }

    }
 
Example #7
Source File: FeatureTilesTest.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Test feature tiles
 *
 * @throws java.sql.SQLException
 */
public void testFeatureTiles(boolean useIcon) throws SQLException {

    FeatureDao featureDao = FeatureTileUtils.createFeatureDao(geoPackage);

    int num = FeatureTileUtils.insertFeatures(geoPackage, featureDao);

    FeatureTiles featureTiles = FeatureTileUtils.createFeatureTiles(activity, geoPackage, featureDao, useIcon);

    try {
        FeatureIndexer indexer = new FeatureIndexer(activity, featureDao);
        try {
            indexer.index();
        } finally {
            indexer.close();
        }

        FeatureIndexManager indexManager = new FeatureIndexManager(activity, geoPackage, featureDao);
        featureTiles.setIndexManager(indexManager);

        indexManager.setIndexLocation(FeatureIndexType.GEOPACKAGE);
        int indexed = indexManager.index();
        assertEquals(num, indexed);

        createTiles(featureTiles, 0, 3);
    } finally {
        featureTiles.close();
    }
}
 
Example #8
Source File: IndexerTask.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Index features
 *
 * @param activity
 * @param callback
 * @param database
 * @param tableName
 * @param indexLocation
 */
public static void indexFeatures(Activity activity, IIndexerTask callback,
                                 String database, String tableName,
                                 FeatureIndexType indexLocation) {

    GeoPackageManager manager = GeoPackageFactory.getManager(activity);
    GeoPackage geoPackage = manager.open(database);

    FeatureDao featureDao = geoPackage.getFeatureDao(tableName);

    FeatureIndexManager indexer = new FeatureIndexManager(activity, geoPackage, featureDao);
    indexer.setIndexLocation(indexLocation);

    ProgressDialog progressDialog = new ProgressDialog(activity);
    final IndexerTask indexTask = new IndexerTask(activity,
            callback, progressDialog, geoPackage, indexer);

    int max = featureDao.count();
    indexTask.setMax(max);
    indexer.setProgress(indexTask);

    progressDialog.setMessage(activity
            .getString(R.string.geopackage_table_index_features_index_title)
            + ": "
            + geoPackage.getName() + " - " + tableName);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setIndeterminate(false);
    progressDialog.setMax(max);
    progressDialog.setButton(ProgressDialog.BUTTON_NEGATIVE,
            activity.getString(R.string.button_cancel_label),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    indexTask.cancel(true);
                }
            });

    indexTask.execute();
}
 
Example #9
Source File: FeatureIndexManagerUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate a Feature Row result
 *
 * @param featureIndexManager
 * @param featureRow
 * @param queryEnvelope
 */
private static void validateFeatureRow(
		FeatureIndexManager featureIndexManager, FeatureRow featureRow,
		GeometryEnvelope queryEnvelope, boolean includeEmpty) {
	TestCase.assertNotNull(featureRow);
	GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

	if (!includeEmpty) {
		TestCase.assertNotNull(envelope);

		if (queryEnvelope != null) {
			TestCase.assertTrue(
					envelope.getMinX() <= queryEnvelope.getMaxX());
			TestCase.assertTrue(
					envelope.getMaxX() >= queryEnvelope.getMinX());
			TestCase.assertTrue(
					envelope.getMinY() <= queryEnvelope.getMaxY());
			TestCase.assertTrue(
					envelope.getMaxY() >= queryEnvelope.getMinY());
			if (envelope.isHasZ()) {
				if (queryEnvelope.hasZ()) {
					TestCase.assertTrue(
							envelope.getMinZ() <= queryEnvelope.getMaxZ());
					TestCase.assertTrue(
							envelope.getMaxZ() >= queryEnvelope.getMinZ());
				}
			}
			if (envelope.isHasM()) {
				if (queryEnvelope.hasM()) {
					TestCase.assertTrue(
							envelope.getMinM() <= queryEnvelope.getMaxM());
					TestCase.assertTrue(
							envelope.getMaxM() >= queryEnvelope.getMinM());
				}
			}
		}
	}
}
 
Example #10
Source File: AlterTableUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test the feature indexes
 * 
 * @param indexManager
 *            index manager
 * @param geoPackageCount
 *            GeoPackage index count
 * @param rTreeCount
 *            RTree index count
 */
private static void testIndex(FeatureIndexManager indexManager,
		int geoPackageCount, int rTreeCount) {

	TestCase.assertTrue(
			indexManager.isIndexed(FeatureIndexType.GEOPACKAGE));
	indexManager.prioritizeQueryLocation(FeatureIndexType.GEOPACKAGE);
	TestCase.assertEquals(geoPackageCount, indexManager.count());

	TestCase.assertTrue(indexManager.isIndexed(FeatureIndexType.RTREE));
	indexManager.prioritizeQueryLocation(FeatureIndexType.RTREE);
	TestCase.assertEquals(rTreeCount, indexManager.count());

}
 
Example #11
Source File: FeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Constructor, auto creates the index manager for indexed tables and feature styles for styled tables
 *
 * @param context    context
 * @param geoPackage GeoPackage
 * @param featureDao feature dao
 * @param density    display density: {@link android.util.DisplayMetrics#density}
 * @param width      drawn tile width
 * @param height     drawn tile height
 * @since 3.2.0
 */
public FeatureTiles(Context context, GeoPackage geoPackage, FeatureDao featureDao, float density, int width, int height) {

    this.context = context;
    this.featureDao = featureDao;
    if (featureDao != null) {
        this.projection = featureDao.getProjection();
    }

    this.density = TileUtils.tileDensity(density, width, height);

    tileWidth = width;
    tileHeight = height;

    createEmptyImage();

    compressFormat = CompressFormat.valueOf(context.getString(R.string.feature_tiles_compress_format));

    pointPaint.setAntiAlias(true);
    pointRadius = Float.valueOf(context.getString(R.string.feature_tiles_point_radius));

    linePaint.setAntiAlias(true);
    lineStrokeWidth = Float.valueOf(context.getString(R.string.feature_tiles_line_stroke_width));
    linePaint.setStrokeWidth(this.density * lineStrokeWidth);
    linePaint.setStyle(Style.STROKE);

    polygonPaint.setAntiAlias(true);
    polygonStrokeWidth = Float.valueOf(context.getString(R.string.feature_tiles_polygon_stroke_width));
    polygonPaint.setStrokeWidth(this.density * polygonStrokeWidth);
    polygonPaint.setStyle(Style.STROKE);

    Resources resources = context.getResources();
    fillPolygon = resources.getBoolean(R.bool.feature_tiles_polygon_fill);
    polygonFillPaint.setAntiAlias(true);
    polygonFillPaint.setStyle(Style.FILL);
    polygonFillPaint.setAlpha(resources.getInteger(R.integer.feature_tiles_polygon_fill_alpha));

    if (geoPackage != null) {

        indexManager = new FeatureIndexManager(context, geoPackage, featureDao);
        if (!indexManager.isIndexed()) {
            indexManager.close();
            indexManager = null;
        }

        featureTableStyles = new FeatureTableStyles(geoPackage, featureDao.getTable());
        if (!featureTableStyles.has()) {
            featureTableStyles = null;
        }

    }

    calculateDrawOverlap();
}
 
Example #12
Source File: OAPIFeatureGeneratorTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test a WFS server and create a GeoPackage
 *
 * @param server      server url
 * @param collection  collection name
 * @param name        geoPackage and table name
 * @param limit       request limit
 * @param totalLimit  total limit
 * @param boundingBox bounding box
 * @param time        time
 * @param period      period or end time
 * @throws SQLException upon error
 */
private void testServer(String server, String collection, String name,
                        Integer limit, Integer totalLimit, BoundingBox boundingBox,
                        String time, String period) throws SQLException {

    GeoPackageManager geoPackageManager = GeoPackageFactory.getManager(activity);

    geoPackageManager.delete(collection);

    geoPackageManager.create(collection);

    GeoPackage geoPackage = geoPackageManager.open(collection);

    OAPIFeatureGenerator generator = new OAPIFeatureGenerator(
            geoPackage, name, server, collection);
    generator.setLimit(limit);
    generator.setTotalLimit(totalLimit);
    generator.setBoundingBox(boundingBox);
    generator.setTime(time);
    generator.setPeriod(period);
    generator.setDownloadAttempts(3);

    int count = generator.generateFeatures();
    if (totalLimit != null) {
        TestCase.assertEquals(totalLimit.intValue(), count);
    }

    FeatureDao featureDao = generator.getFeatureDao();
    if (totalLimit != null) {
        TestCase.assertEquals(totalLimit.intValue(), featureDao.count());
    }

    FeatureIndexManager indexer = new FeatureIndexManager(activity, geoPackage, featureDao);
    indexer.setIndexLocation(FeatureIndexType.GEOPACKAGE);
    indexer.index();
    indexer.close();

    BoundingBox dataBounds = geoPackage
            .getBoundingBox(featureDao.getTableName());
    Contents contents = featureDao.getContents();
    contents.setBoundingBox(dataBounds);
    geoPackage.getContentsDao().update(contents);

    geoPackage.close();

}
 
Example #13
Source File: IndexerTask.java    From geopackage-mapcache-android with MIT License 3 votes vote down vote up
/**
 * Constructor
 *
 * @param activity
 * @param callback
 * @param progressDialog
 * @param geoPackage
 * @param indexer
 */
public IndexerTask(Activity activity, IIndexerTask callback,
                   ProgressDialog progressDialog, GeoPackage geoPackage, FeatureIndexManager indexer) {
    this.activity = activity;
    this.callback = callback;
    this.progressDialog = progressDialog;
    this.geoPackage = geoPackage;
    this.indexer = indexer;
}
 
Example #14
Source File: FeatureTiles.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Get the index manager
 *
 * @return index manager or null
 * @since 1.1.0
 */
public FeatureIndexManager getIndexManager() {
    return indexManager;
}
 
Example #15
Source File: FeatureTiles.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Set the index
 *
 * @param indexManager index manager
 * @since 1.1.0
 */
public void setIndexManager(FeatureIndexManager indexManager) {
    this.indexManager = indexManager;
}