Class VectorTilesFeatureSource
- All Implemented Interfaces:
FeatureSource<SimpleFeatureType,
,SimpleFeature> SimpleFeatureSource
This class provides GeoTools feature access to a single vector layer from a tile archive. It handles the complexity of:
- Converting between GeoTools queries and tile-based queries
- Automatic zoom level selection based on query resolution hints
- Spatial filtering and bounding box optimization
- Coordinate reference system transformation
- Feature attribute filtering and property selection
- Pagination (offset/limit support)
Query Optimization:
- Zoom Level Selection: Automatically selects the best zoom level based on
Hints.GEOMETRY_DISTANCE
,Hints.GEOMETRY_SIMPLIFICATION
, orHints.GEOMETRY_GENERALIZATION
hints - Spatial Filtering: Extracts bounding boxes from query filters to minimize tile reads
- CRS Transformation: Efficiently transforms geometries using affine transformations where possible
- Pre-filtering: Applies filters at the vector tile level before converting to GeoTools features
Supported Operations:
canFilter(Query)
- Full filter support including spatial and attribute filterscanReproject()
- Automatic CRS transformationcanRetype(Query)
- Property selection and schema subsettingcanOffset(Query)
andcanLimit(Query)
- Pagination supportcanSort(Query)
- Natural order only (tile order)
Feature Type Schema: The schema is automatically derived from the vector layer metadata (TileJSON), with field types mapped from TileJSON types (String, Number, Boolean) to Java types.
- See Also:
-
VectorTilesDataStore
VectorTilesFeatureReader
VectorTileStore
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final VectorLayer
TileJSON layer metadataFields inherited from class ContentFeatureSource
entry, hints, lock, query, queryCapabilities, schema, transaction
-
Constructor Summary
ConstructorsConstructorDescriptionVectorTilesFeatureSource
(ContentEntry entry, VectorLayer layerMetadata) Creates a new feature source for a vector layer. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds rendering hints supported by this feature source.protected SimpleFeatureType
Creates the feature type or schema for the feature source.protected boolean
Determines if the datastore can natively perform a filtering.protected boolean
Determines if the datastore can natively limit the number of features returned in a query.protected boolean
Determines if the datastore can natively skip the firstoffset
number of features returned in a query.protected boolean
Determines if the datastore can natively perform reprojection.protected boolean
Determines if the datastore can natively perform "retyping" which includes limiting the number of attributes returned and reordering of those attributesprotected boolean
Determines if the datastore can natively perform sorting.protected String
dedupGeometryName
(Set<String> attributeNames) protected int
determineZoomLevel
(Query query) Determines the optimal zoom level for a query based on resolution hints and layer constraints.protected Class<?>
fieldTypeToBinding
(String fieldType) protected MathTransform
findMathTransform
(Query query) protected ReferencedEnvelope
protected ReferencedEnvelope
getBoundsInternal
(Query query) Calculates the bounds of a specified query.protected int
getCountInternal
(Query query) Calculates the number of features of a specified query.The datastore that this feature source originated from.protected TileMatrixSet
Returns the tile matrix set for this vector layer.protected CoordinateReferenceSystem
getQueryCRS
(Query query) protected FeatureReader<SimpleFeatureType,
SimpleFeature> getReaderInternal
(Query query) Subclass method for returning a native reader from the datastore.protected VectorTileStore
protected SimpleFeatureType
protected CoordinateReferenceSystem
Methods inherited from class ContentFeatureSource
accepts, addFeatureListener, buildQueryCapabilities, canEvent, canFilter, canLimit, canLock, canOffset, canRetype, canSort, canTransact, doLockInternal, doUnlockInternal, getAbsoluteSchema, getBounds, getBounds, getCount, getEntry, getFeatures, getFeatures, getFeatures, getInfo, getName, getQueryCapabilities, getReader, getReader, getReader, getSchema, getState, getSupportedHints, getTransaction, getView, getView, handleVisitor, isView, joinQuery, lockFeatures, lockFeatures, lockFeatures, processLock, removeFeatureListener, resolvePropertyNames, resolvePropertyNames, setFeatureLock, setTransaction, unLockFeatures, unLockFeatures, unLockFeatures
-
Field Details
-
layerMetadata
protected final VectorLayer layerMetadataTileJSON layer metadata
-
-
Constructor Details
-
VectorTilesFeatureSource
Creates a new feature source for a vector layer.- Parameters:
entry
- the content entry for this feature typelayerMetadata
- the TileJSON metadata for this vector layer
-
-
Method Details
-
canRetype
Description copied from class:ContentFeatureSource
Determines if the datastore can natively perform "retyping" which includes limiting the number of attributes returned and reordering of those attributesIf the subclass can handle retyping natively it should override this method to return
true
. In this case it must do the retyping or throw an exception.Not overriding this method or returning
false
will cause the feature reader created by the subclass to be wrapped in a retyping feature reader when the query specifies a retype.- Overrides:
canRetype
in classContentFeatureSource
- Returns:
true
- See Also:
-
canReproject
protected boolean canReproject()Description copied from class:ContentFeatureSource
Determines if the datastore can natively perform reprojection.If the subclass can handle reprojection natively then it should override this method to return
true
. In this case it must do the reprojection or throw an exception.Not overriding this method or returning
false
will case the feature reader created by the subclass to be wrapped in a reprojecting decorator when the query specifies a coordinate system reproject (using crs and crsReproject)To handle reprojection an implementation should:
Query.getCoordinateSystem()
- optional override - if provided this is used instead of the native CRS provided by the data format (as a workaround for clients).- <@link
Query.getCoordinateSystemReproject()
- if this value is provided it is used to set up a transform from the origional CRS (native or from query).
- Overrides:
canReproject
in classContentFeatureSource
- Returns:
true
- See Also:
-
ContentFeatureSource.canReproject()
reprojectFunction(Query)
-
canFilter
Description copied from class:ContentFeatureSource
Determines if the datastore can natively perform a filtering.If the subclass can handle filtering natively it should override this method to return
true
. In this case it must do the filtering or throw an exception. This includes the case of partial native filtering where the datastore can only handle part of the filter natively. In these cases it is up to the subclass to apply a decorator to the reader it returns which will handle any part of the filter can was not applied natively. SeeFilteringFeatureReader
.Not overriding this method or returning
false
will cause the feature reader created by the subclass to be wrapped in a filtering feature reader when the query specifies a filter. SeeFilteringFeatureReader
.- Overrides:
canFilter
in classContentFeatureSource
- Returns:
true
- See Also:
-
ContentFeatureSource.canFilter()
preFilter(Query)
postFilter(Query)
-
canOffset
Description copied from class:ContentFeatureSource
Determines if the datastore can natively skip the firstoffset
number of features returned in a query.If the subclass can handle a map feature cap natively then it should override this method to return
true
. In this case it must do the cap or throw an exception.Not overriding this method or returning
false
will case the feature reader created by the subclass to be accessed offset times before being returned to the caller.- Overrides:
canOffset
in classContentFeatureSource
- Returns:
true
- See Also:
-
canLimit
Description copied from class:ContentFeatureSource
Determines if the datastore can natively limit the number of features returned in a query.If the subclass can handle a map feature cap natively then it should override this method to return
true
. In this case it must do the cap or throw an exception.Not overriding this method or returning
false
will case the feature reader created by the subclass to be wrapped in a max feature capping decorator when the query specifies a max feature cap.- Overrides:
canLimit
in classContentFeatureSource
- Returns:
true
- See Also:
-
canSort
Description copied from class:ContentFeatureSource
Determines if the datastore can natively perform sorting.If the subclass can handle retyping natively it should override this method to return
true
. In this case it must do the retyping or throw an exception.Not overriding this method or returning
false
will cause an exception to be thrown when the query specifies sorting.- Overrides:
canSort
in classContentFeatureSource
- Returns:
true
for natural order,false
otherwise- See Also:
-
getDataStore
Description copied from class:ContentFeatureSource
The datastore that this feature source originated from.Subclasses may wish to extend this method in order to type narrow its return type.
- Specified by:
getDataStore
in interfaceFeatureSource<SimpleFeatureType,
SimpleFeature> - Overrides:
getDataStore
in classContentFeatureSource
- Returns:
- the data source providing this
FeatureSource
-
getTileStore
protected VectorTileStore getTileStore() -
getMatrixSet
protected TileMatrixSet getMatrixSet()Returns the tile matrix set for this vector layer.- Returns:
- the tile matrix set defining the tiling scheme
-
addHints
Adds rendering hints supported by this feature source.Supported hints include:
Hints.FEATURE_DETACHED
- Features can be safely modifiedHints.JTS_GEOMETRY_FACTORY
- Custom geometry factoryHints.JTS_COORDINATE_SEQUENCE_FACTORY
- Custom coordinate sequence factoryHints.GEOMETRY_GENERALIZATION
- Topology-preserving simplification distanceHints.GEOMETRY_SIMPLIFICATION
- Non-topology-preserving simplification distanceHints.GEOMETRY_DISTANCE
- Target resolution for zoom level selectionHints.GEOMETRY_CLIP
- Tile clip mask for rendering (this is an "output" hint, added to each returnedProperty.getUserData()
map. SeeVectorTilesFeatureReader
)
- Overrides:
addHints
in classContentFeatureSource
- Parameters:
hints
- the set to add supported hints to
-
buildFeatureType
Description copied from class:ContentFeatureSource
Creates the feature type or schema for the feature source.Implementations should use
SimpleFeatureTypeBuilder
to build the feature type. Also, the builder should be injected with the feature factory which has been set on the DataStore (seeContentDataStore.getFeatureFactory()
. Example:SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setFeatureTypeFactory( getDataStore().getFeatureTypeFactory() ); //build the feature type ...
- Specified by:
buildFeatureType
in classContentFeatureSource
- Throws:
IOException
-
getCountInternal
Description copied from class:ContentFeatureSource
Calculates the number of features of a specified query. Subclasses must implement this method. If the computation is not fast, it's possible to return -1.- Specified by:
getCountInternal
in classContentFeatureSource
- Returns:
-1
, too complex to calculate, tiles have different number of features at different zoom levels- Throws:
IOException
-
getBoundsInternal
Description copied from class:ContentFeatureSource
Calculates the bounds of a specified query. Subclasses must implement this method. If the computation is not fast, subclasses can returnnull
.- Specified by:
getBoundsInternal
in classContentFeatureSource
- Throws:
IOException
-
getBoundsInternal
-
getReaderInternal
protected FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query) throws IOException Description copied from class:ContentFeatureSource
Subclass method for returning a native reader from the datastore.It is important to note that if the native reader intends to handle any of the following natively:
- reprojection
- filtering
- max feature limiting
- sorting
- locking
- transactions
true
:ContentFeatureSource.canReproject()
- handlesQuery.getCoordinateSystemReproject()
internally. Example would be PostGIS using Proj to handle reproejction internallyContentFeatureSource.canFilter(Query)
- handlesinternally.</li> <li>{@link #canLimit(Query)} - handles {@link Query#getMaxFeatures()} and {@link Query#getStartIndex()} internally.</li> <li>{@link #canSort(Query)} - handles {@link Query#getSortBy()} natively.</li> <li>{@link #canRetype(Query)} - handles {@link Query#getProperties()} natively. Example would be only parsing the properties the user asks for from an XML file</li> <li>{@link #canLock()} - handles read-locks natively</li> <li>{@link #canTransact()} - handles transactions natively</li> </ul> </p>
- Specified by:
getReaderInternal
in classContentFeatureSource
- Throws:
IOException
-
findMathTransform
-
getQueryCRS
-
retype
-
tileMatrixsetCRS
- Throws:
IOException
-
determineZoomLevel
Determines the optimal zoom level for a query based on resolution hints and layer constraints.This method selects the best zoom level by considering:
- Query resolution hints (
Hints.GEOMETRY_DISTANCE
,Hints.GEOMETRY_SIMPLIFICATION
,Hints.GEOMETRY_GENERALIZATION
) - Layer-specific min/max zoom levels from
VectorLayer.minZoom()
andVectorLayer.maxZoom()
- Tile matrix set available zoom levels
- Query strategy (SPEED vs QUALITY)
For SPEED strategy (when simplification hints are present), starts from the minimum zoom level to favor performance. For QUALITY strategy (no simplification hints), starts from the layer's minimum zoom level to favor detail.
- Parameters:
query
- the query containing resolution hints- Returns:
- the selected zoom level
- Query resolution hints (
-
fieldTypeToBinding
-
dedupGeometryName
-