FeatureIndexManager builds and queries spatial indexes on a feature table. Indexed queries are significantly faster than full-table scans when filtering by bounding box or geometry envelope. Two index backends are supported: RTree (SQLite virtual table, recommended) and GeoPackage (NGA extension tables).
Always call
close() on the FeatureIndexManager when you are done with it to release internal connections.Constructor
An open
GeoPackage instance.Either the name of the feature table as a string, or an existing
FeatureDao for that table.Index lifecycle
setIndexLocation()
Sets the preferred index backend to use forindex() calls and subsequent write operations.
The index backend to target. See
FeatureIndexType below.index()
Builds the spatial index (at the configured index location) if it does not already exist. Returns the number of features indexed.Count of indexed features. Returns
0 if the index already exists and force was not set.indexType()
Builds the index at the explicitly specified type, optionally forcing a re-index.Index backend to use. Defaults to the configured index location.
When
true, drops and rebuilds the index even if one already exists. Defaults to false.isIndexed()
Returnstrue if any supported index exists for this feature table.
isIndexedForType()
Returnstrue if an index of the specified type exists.
deleteIndexType()
Deletes the index at the specified (or configured) location.close()
Closes internal index connections. Call this when theFeatureIndexManager is no longer needed.
Querying
All query methods return aFeatureIndexResults that must be closed after iteration.
query()
Returns indexed features, optionally filtered by a raw SQLWHERE clause.
SQL
WHERE expression without the WHERE keyword. Omit to return all indexed features.Bind arguments that replace
? placeholders in where.queryAll()
Returns all indexed features without a filter. Equivalent to callingquery() with no arguments.
queryWithBoundingBox()
Returns features whose geometries intersect the given bounding box. The bounding box is expected to be in the same projection as the feature table.Bounding box filter in the feature table’s native projection.
Optional additional SQL
WHERE clause.Bind arguments for the
where clause.queryWithBoundingBoxAndProjection()
Returns features whose geometries intersect the given bounding box, converting coordinates from the supplied projection to the feature table’s native projection before querying.Bounding box in the coordinate system of
projection.The projection of the bounding box coordinates (e.g.
Projections.getWGS84Projection()).Optional additional SQL
WHERE clause.Bind arguments for the
where clause.queryWithGeometryEnvelope()
Returns features whose geometries intersect the givenGeometryEnvelope.
Geometry envelope to filter by, from
@ngageoint/simple-features-js.Optional additional SQL
WHERE clause.queryWithFieldValues()
Returns features where all provided field values match, backed by the spatial index.Counting
countAll()
Returns the total number of indexed features.count()
Returns the count of features matching the optionalWHERE clause.
SQL
WHERE expression.Bind arguments.
countWithBoundingBox()
Returns the count of features intersecting the given bounding box.countWithGeometryEnvelope()
Returns the count of features intersecting the given geometry envelope.FeatureIndexType
FeatureIndexType is an enum that identifies which index backend to use.
| Value | Description |
|---|---|
RTREE | SQLite RTree virtual table. Fastest and zero-copy; updated automatically by database triggers. |
GEOPACKAGE | NGA GeoPackage extension tables. More portable but slower to build. |
NONE | No index. Queries fall back to a full-table scan via ManualFeatureQuery. |