mil.nga.geopackage.extension.index.GeometryIndex Java Examples

The following examples show how to use mil.nga.geopackage.extension.index.GeometryIndex. 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: FeatureIndexGeoPackageResults.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Iterator<FeatureRow> iterator() {
    return new Iterator<FeatureRow>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean hasNext() {
            return geometryIndices.hasNext();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public FeatureRow next() {
            GeometryIndex geometryIndex = geometryIndices.next();
            FeatureRow featureRow = featureTableIndex.getFeatureRow(geometryIndex);
            return featureRow;
        }
    };
}
 
Example #2
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createGeometryIndexTable() {
	verifyWritable();

	boolean created = false;
	GeometryIndexDao dao = getGeometryIndexDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createGeometryIndex() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + GeometryIndex.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #3
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean indexGeometryIndexTable() {
	verifyWritable();

	boolean indexed = false;
	GeometryIndexDao dao = getGeometryIndexDao();
	try {
		if (dao.isTableExists()) {
			indexed = tableCreator.indexGeometryIndex() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + GeometryIndex.class.getSimpleName()
						+ " table exists to index",
				e);
	}
	return indexed;
}
 
Example #4
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean unindexGeometryIndexTable() {
	verifyWritable();

	boolean unindexed = false;
	GeometryIndexDao dao = getGeometryIndexDao();
	try {
		if (dao.isTableExists()) {
			unindexed = tableCreator.unindexGeometryIndex() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + GeometryIndex.class.getSimpleName()
						+ " table exists to unindex",
				e);
	}
	return unindexed;
}
 
Example #5
Source File: GeoPackageDaoManager.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
Example #6
Source File: FeatureIndexGeoPackageResults.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Iterator<FeatureRow> iterator() {
	return new Iterator<FeatureRow>() {

		/**
		 * {@inheritDoc}
		 */
		@Override
		public boolean hasNext() {
			return geometryIndices.hasNext();
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public FeatureRow next() {
			GeometryIndex geometryIndex = geometryIndices.next();
			FeatureRow featureRow = featureTableIndex
					.getFeatureRow(geometryIndex);
			return featureRow;
		}
	};
}
 
Example #7
Source File: FeatureTableIndexUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Validate a Geometry Index result
 * 
 * @param featureTableIndex
 * @param geometryIndex
 */
private static void validateGeometryIndex(
		FeatureTableIndex featureTableIndex, GeometryIndex geometryIndex) {
	FeatureRow featureRow = featureTableIndex.getFeatureRow(geometryIndex);
	TestCase.assertNotNull(featureRow);
	TestCase.assertEquals(featureTableIndex.getTableName(),
			geometryIndex.getTableName());
	TestCase.assertEquals(geometryIndex.getGeomId(), featureRow.getId());
	GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

	TestCase.assertNotNull(envelope);

	TestCase.assertEquals(envelope.getMinX(), geometryIndex.getMinX());
	TestCase.assertEquals(envelope.getMaxX(), geometryIndex.getMaxX());
	TestCase.assertEquals(envelope.getMinY(), geometryIndex.getMinY());
	TestCase.assertEquals(envelope.getMaxY(), geometryIndex.getMaxY());
	if (envelope.isHasZ()) {
		TestCase.assertEquals(envelope.getMinZ(), geometryIndex.getMinZ());
		TestCase.assertEquals(envelope.getMaxZ(), geometryIndex.getMaxZ());
	} else {
		TestCase.assertNull(geometryIndex.getMinZ());
		TestCase.assertNull(geometryIndex.getMaxZ());
	}
	if (envelope.isHasM()) {
		TestCase.assertEquals(envelope.getMinM(), geometryIndex.getMinM());
		TestCase.assertEquals(envelope.getMaxM(), geometryIndex.getMaxM());
	} else {
		TestCase.assertNull(geometryIndex.getMinM());
		TestCase.assertNull(geometryIndex.getMaxM());
	}
}
 
Example #8
Source File: FeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Query for feature results in the bounding box
 *
 * @param webMercatorBoundingBox
 *            web mercator bounding box
 * @return geometry index results
 */
public CloseableIterator<GeometryIndex> queryIndexedFeatures(
		BoundingBox webMercatorBoundingBox) {

	// Create an expanded bounding box to handle features outside the tile
	// that overlap
	BoundingBox expandedQueryBoundingBox = expandBoundingBox(
			webMercatorBoundingBox);

	// Query for geometries matching the bounds in the index
	CloseableIterator<GeometryIndex> results = featureIndex
			.query(expandedQueryBoundingBox, WEB_MERCATOR_PROJECTION);

	return results;
}
 
Example #9
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int zoom, BoundingBox boundingBox,
		CloseableIterator<GeometryIndex> results) {

	FeatureTileGraphics graphics = new FeatureTileGraphics(tileWidth,
			tileHeight);

	// Feature projection to web mercator projection
	ProjectionTransform webMercatorTransform = getWebMercatorTransform();
	BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

	boolean drawn = false;
	while (results.hasNext()) {
		GeometryIndex geometryIndex = results.next();
		FeatureRow featureRow = getFeatureIndex()
				.getFeatureRow(geometryIndex);
		if (drawFeature(zoom, boundingBox, expandedBoundingBox,
				webMercatorTransform, graphics, featureRow)) {
			drawn = true;
		}
	}
	try {
		results.close();
	} catch (IOException e) {
		log.log(Level.WARNING, "Failed to close geometry index results", e);
	}

	BufferedImage image = null;
	if (drawn) {
		image = graphics.createImage();
		image = checkIfDrawn(image);
	} else {
		graphics.dispose();
	}

	return image;
}
 
Example #10
Source File: NumberFeaturesTile.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int tileWidth, int tileHeight,
		long tileFeatureCount,
		CloseableIterator<GeometryIndex> geometryIndexResults) {

	String featureText = String.valueOf(tileFeatureCount);
	BufferedImage image = drawTile(tileWidth, tileHeight, featureText);

	return image;
}
 
Example #11
Source File: FeatureTableIndexUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Validate a Geometry Index result
 *
 * @param featureTableIndex
 * @param geometryIndex
 */
private static void validateGeometryIndex(
        FeatureTableIndex featureTableIndex, GeometryIndex geometryIndex) {
    FeatureRow featureRow = featureTableIndex.getFeatureRow(geometryIndex);
    TestCase.assertNotNull(featureRow);
    TestCase.assertEquals(featureTableIndex.getTableName(),
            geometryIndex.getTableName());
    TestCase.assertEquals(geometryIndex.getGeomId(), featureRow.getId());
    GeometryEnvelope envelope = featureRow.getGeometryEnvelope();

    TestCase.assertNotNull(envelope);

    TestCase.assertEquals(envelope.getMinX(), geometryIndex.getMinX());
    TestCase.assertEquals(envelope.getMaxX(), geometryIndex.getMaxX());
    TestCase.assertEquals(envelope.getMinY(), geometryIndex.getMinY());
    TestCase.assertEquals(envelope.getMaxY(), geometryIndex.getMaxY());
    if (envelope.isHasZ()) {
        TestCase.assertEquals(envelope.getMinZ(), geometryIndex.getMinZ());
        TestCase.assertEquals(envelope.getMaxZ(), geometryIndex.getMaxZ());
    } else {
        TestCase.assertNull(geometryIndex.getMinZ());
        TestCase.assertNull(geometryIndex.getMaxZ());
    }
    if (envelope.isHasM()) {
        TestCase.assertEquals(envelope.getMinM(), geometryIndex.getMinM());
        TestCase.assertEquals(envelope.getMaxM(), geometryIndex.getMaxM());
    } else {
        TestCase.assertNull(geometryIndex.getMinM());
        TestCase.assertNull(geometryIndex.getMaxM());
    }
}
 
Example #12
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeometryIndexDao getGeometryIndexDao() {
	return createDao(GeometryIndex.class);
}
 
Example #13
Source File: NGAExtensions.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Copy the Geometry Index extension for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @param newTable
 *            new table name
 * @since 3.3.0
 */
public static void copyGeometryIndex(GeoPackageCore geoPackage,
		String table, String newTable) {

	try {

		ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

		if (extensionsDao.isTableExists()) {

			List<Extensions> extensions = extensionsDao.queryByExtension(
					FeatureTableCoreIndex.EXTENSION_NAME, table);

			if (!extensions.isEmpty()) {

				Extensions extension = extensions.get(0);
				extension.setTableName(newTable);
				extensionsDao.create(extension);

				TableIndexDao tableIndexDao = geoPackage.getTableIndexDao();
				if (tableIndexDao.isTableExists()) {

					TableIndex tableIndex = tableIndexDao.queryForId(table);
					if (tableIndex != null) {

						tableIndex.setTableName(newTable);
						tableIndexDao.create(tableIndex);

						if (geoPackage.isTable(GeometryIndex.TABLE_NAME)) {

							CoreSQLUtils.transferTableContent(
									geoPackage.getDatabase(),
									GeometryIndex.TABLE_NAME,
									GeometryIndex.COLUMN_TABLE_NAME,
									newTable, table);

						}
					}
				}
			}
		}

	} catch (Exception e) {
		logger.log(Level.WARNING,
				"Failed to create Geometry Index for table: " + newTable
						+ ", copied from table: " + table,
				e);
	}

}
 
Example #14
Source File: FeatureTiles.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Draw a tile image from the x, y, and zoom level by querying features in
 * the tile location
 *
 * @param x
 *            x coordinate
 * @param y
 *            y coordinate
 * @param zoom
 *            zoom level
 * @return drawn image, or null
 */
public BufferedImage drawTileQueryIndex(int x, int y, int zoom) {

	// Get the web mercator bounding box
	BoundingBox webMercatorBoundingBox = TileBoundingBoxUtils
			.getWebMercatorBoundingBox(x, y, zoom);

	BufferedImage image = null;

	// Query for the geometry count matching the bounds in the index
	long tileCount = queryIndexedFeaturesCount(webMercatorBoundingBox);

	// Draw if at least one geometry exists
	if (tileCount > 0) {

		// Query for geometries matching the bounds in the index
		CloseableIterator<GeometryIndex> results = queryIndexedFeatures(
				webMercatorBoundingBox);

		try {

			if (maxFeaturesPerTile == null
					|| tileCount <= maxFeaturesPerTile.longValue()) {

				// Draw the tile image
				image = drawTile(zoom, webMercatorBoundingBox, results);

			} else if (maxFeaturesTileDraw != null) {

				// Draw the max features tile
				image = maxFeaturesTileDraw.drawTile(tileWidth, tileHeight,
						tileCount, results);
			}
		} finally {
			try {
				results.close();
			} catch (IOException e) {
				LOGGER.log(Level.WARNING,
						"Failed to close result set for query on x: " + x
								+ ", y: " + y + ", zoom: " + zoom,
						e);
			}
		}
	}

	return image;
}
 
Example #15
Source File: FeatureIndexGeoPackageResults.java    From geopackage-java with MIT License 3 votes vote down vote up
/**
 * Constructor
 *
 * @param featureTableIndex
 *            feature table index
 * @param count
 *            count
 * @param geometryIndices
 *            geometry indices
 */
public FeatureIndexGeoPackageResults(FeatureTableIndex featureTableIndex,
		long count, CloseableIterator<GeometryIndex> geometryIndices) {
	this.featureTableIndex = featureTableIndex;
	this.count = count;
	this.geometryIndices = geometryIndices;
}
 
Example #16
Source File: FeatureTiles.java    From geopackage-java with MIT License 3 votes vote down vote up
/**
 * Query for feature results in the x, y, and zoom
 *
 * @param x
 *            x coordinate
 * @param y
 *            y coordinate
 * @param zoom
 *            zoom level
 * @return feature count
 * @since 3.2.0
 */
public CloseableIterator<GeometryIndex> queryIndexedFeatures(int x, int y,
		int zoom) {

	// Get the web mercator bounding box
	BoundingBox webMercatorBoundingBox = TileBoundingBoxUtils
			.getWebMercatorBoundingBox(x, y, zoom);

	// Query for the geometries matching the bounds in the index
	return queryIndexedFeatures(webMercatorBoundingBox);
}
 
Example #17
Source File: CustomFeaturesTile.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Draw a custom tile
 *
 * @param tileWidth
 *            tile width to draw
 * @param tileHeight
 *            tile height to draw
 * @param tileFeatureCount
 *            count of features in the requested tile
 * @param geometryIndexResults
 *            results as geometry index results
 * @return custom image, or null
 */
public BufferedImage drawTile(int tileWidth, int tileHeight,
		long tileFeatureCount,
		CloseableIterator<GeometryIndex> geometryIndexResults);
 
Example #18
Source File: FeatureTiles.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Draw a tile image from geometry index results
 *
 * @param zoom
 *            zoom level
 * @param webMercatorBoundingBox
 *            web mercator bounding box
 * @param results
 *            results
 * @return image
 * @since 2.0.0
 */
public abstract BufferedImage drawTile(int zoom,
		BoundingBox webMercatorBoundingBox,
		CloseableIterator<GeometryIndex> results);
 
Example #19
Source File: FeatureIndexGeoPackageResults.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Constructor
 *
 * @param featureTableIndex feature table index
 * @param count             count
 * @param geometryIndices   geometry indices
 */
public FeatureIndexGeoPackageResults(FeatureTableIndex featureTableIndex, long count, CloseableIterator<GeometryIndex> geometryIndices) {
    this.featureTableIndex = featureTableIndex;
    this.count = count;
    this.geometryIndices = geometryIndices;
}