Class ContentFeatureSource
- All Implemented Interfaces:
FeatureSource<SimpleFeatureType,,SimpleFeature> SimpleFeatureSource
- Direct Known Subclasses:
ContentFeatureStore,CSVFeatureSource,GeoJSONFeatureSource,GraticuleFeatureSource,JDBCFeatureSource,MemoryFeatureSource,MongoFeatureSource,PropertyFeatureSource,STACFeatureSource,VectorMosaicFeatureSource,VectorTilesFeatureSource,VPFFeatureSource,WFSStoredQueryFeatureSource
This feature source works off of operations provided by FeatureCollection. Individual
SimpleFeatureCollection implementations are provided by subclasses:
#all(ContentState): Access to entire dataset #filtered(ContentState, Filter): Access to filtered
dataset
Even though a feature source is read-only, this class is transaction aware. (see
setTransaction(Transaction). The transaction is taken into account during operations such as
#getCount() and getBounds() since these values may be affected by another operation (like writing to
a FeautreStore) working against the same transaction.
Subclasses must also implement the buildFeatureType() method which builds the schema for the feature
source.
- Author:
- Jody Garnett, Refractions Research Inc., Justin Deoliveira, The Open Planning Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ContentEntryThe entry for the feature source.Hintsprotected FeatureLockCurrent feature lockprotected QueryThe query defining the feature sourceprotected QueryCapabilitiesThe query capabilities returned by this feature sourceprotected SimpleFeatureTypeCached feature type (only set if this instance is a view)protected TransactionThe transaction to work from, use {linkContentEntry.getState(Transaction)to access shared state in common to ContentFeatureSource and ContentFeatureStore working on this Transaction. -
Constructor Summary
ConstructorsConstructorDescriptionContentFeatureSource(ContentEntry entry, Query query) Creates the new feature source from a query. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccepts(Query query, FeatureVisitor visitor, ProgressListener progress) Visit the features matching the provided query.final voidaddFeatureListener(FeatureListener listener) Adds an listener or observer to the feature source.protected voidSubclass hook too add additional hints.protected abstract SimpleFeatureTypeCreates the feature type or schema for the feature source.protected QueryCapabilitiesBuilds the query capabilities for this feature source.protected booleancanEvent()Determines if the store takes responsibility for issuing events.protected booleanDeprecated.protected booleanDetermines if the datastore can natively perform a filtering.protected booleancanLimit()Deprecated.usecanLimit(Query)instead.protected booleanDetermines if the datastore can natively limit the number of features returned in a query.protected booleancanLock()Determines if thedatastorecan perform feature locking natively.protected booleanDeprecated.usecanOffset(Query)instead.protected booleanDetermines if the datastore can natively skip the firstoffsetnumber of features returned in a query.protected booleanDetermines if the datastore can natively perform reprojection.protected booleanDeprecated.usecanRetype(Query)instead.protected booleanDetermines if the datastore can natively perform "retyping" which includes limiting the number of attributes returned and reordering of those attributesprotected booleancanSort()Deprecated.usecanSort(Query)instead.protected booleanDetermines if the datastore can natively perform sorting.protected booleanDetermines if the store can natively manage transactions.protected voiddoLockInternal(String typeName, SimpleFeature feature) This method must be implemented overridden when native locking is indicated bycanLock().protected voiddoUnlockInternal(String typeName, SimpleFeature feature) This method must be implemented overridden when native locking is indicated bycanLock().protected final SimpleFeatureTypeHelper method for returning the underlying schema of the feature source.final ReferencedEnvelopeReturns the bounds of the entire feature source.final ReferencedEnvelopeReturns the bounds of the results of the specified query against the feature source.protected abstract ReferencedEnvelopegetBoundsInternal(Query query) Calculates the bounds of a specified query.final intReturns the count of the number of features of the feature source.protected abstract intgetCountInternal(Query query) Calculates the number of features of a specified query.The datastore that this feature source originated from.getEntry()The entry for the feature source.final ContentFeatureCollectionReturns the feature collection of all the features of the feature source.final ContentFeatureCollectiongetFeatures(Query query) Returns the feature collection if the features of the feature source which meet the specified query criteria.final ContentFeatureCollectiongetFeatures(Filter filter) Returns the feature collection for the features which match the specified filter.getInfo()A default ResourceInfo with a generic description.getName()Returns the same name than the feature type (ie,getSchema().getName()to honor the simple feature land common practice of calling the same both the Features produces and their typesSimpleFeatureCollection optimized for read-only access.Returns a feature reader for all features.Returns a reader for the features specified by a query.Returns a reader for features specified by a particular filter.protected abstract FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query) Subclass method for returning a native reader from the datastore.final SimpleFeatureTypeReturns the feature type or the schema of the feature source.getState()The current state for the feature source.final Set<RenderingHints.Key>The hints provided by the feature store.The current transaction the feature source is working against.final ContentFeatureSourceCreates a new feature source for the specified query.final ContentFeatureSourceprotected booleanhandleVisitor(Query query, FeatureVisitor visitor) Subclass method which allows subclasses to natively handle a visitor.final booleanisView()Indicates if this feature source is actually a view.protected QueryConvenience method for joining a query with the definining query of the feature source.final intLocks all features.final intlockFeatures(Query query) Locks features specified by a query.final intlockFeatures(Filter filter) Locks features specified by a filter.protected FeatureLockprocessLock(FeatureLock lock) If the subclass implements native locking, this method is invoked before the feature lock is (re)assigned to this store.final voidremoveFeatureListener(FeatureListener listener) Removes a listener from the feature source.protected QueryresolvePropertyNames(Query query) This method changes the query object so that all propertyName references are resolved to simple attribute names against the schema of the feature source.protected FilterresolvePropertyNames(Filter filter) Transform provided filter; resolving property namesfinal voidsetFeatureLock(FeatureLock lock) Sets the feature lock of the feature store.voidsetTransaction(Transaction transaction) Sets the current transaction the feature source is working against.final voidUnlocks all features.final voidunLockFeatures(Query query) Unlocks features specified by a query.final voidunLockFeatures(Filter filter) Unlocks features specified by a filter.
-
Field Details
-
entry
The entry for the feature source.This entry is managed by the DataStore and is shared between all live ContentFeatureSource and ContentFeatureStore instances.
-
transaction
The transaction to work from, use {linkContentEntry.getState(Transaction)to access shared state in common to ContentFeatureSource and ContentFeatureStore working on this Transaction. The use ofTransaction.AUTO_COMMITis used access the origional/live content. -
lock
Current feature lock -
hints
Hints -
query
The query defining the feature source -
schema
Cached feature type (only set if this instance is a view) -
queryCapabilities
The query capabilities returned by this feature source
-
-
Constructor Details
-
ContentFeatureSource
Creates the new feature source from a query.The query is taken into account for any operations done against the feature source. For example, when getReader(Query) is called the query specified is "joined" to the query specified in the constructor. The query parameter may be
nullto specify that the feature source represents the entire set of features.
-
-
Method Details
-
getEntry
The entry for the feature source. -
getTransaction
The current transaction the feature source is working against.This transaction is used to derive the state for the feature source. A
nullvalue for a transaction represents the auto commit transaction:Transaction.AUTO_COMMIT. -
setTransaction
Sets the current transaction the feature source is working against.transaction may be
null. This signifies that the auto-commit transaction is used:Transaction.AUTO_COMMIT.- Parameters:
transaction- The new transaction, ornull.
-
getState
The current state for the feature source.This value is derived from current transaction of the feature source.
-
getDataStore
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:
getDataStorein interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- the data source providing this
FeatureSource
-
isView
public final boolean isView()Indicates if this feature source is actually a view. -
getInfo
A default ResourceInfo with a generic description.Subclasses should override to provide an explicit ResourceInfo object for their content.
- Specified by:
getInfoin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- description of features contents
-
getName
Returns the same name than the feature type (ie,getSchema().getName()to honor the simple feature land common practice of calling the same both the Features produces and their types- Specified by:
getNamein interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- the name of the features accessible through this
FeatureSource - Since:
- 2.5
- See Also:
-
getSchema
Returns the feature type or the schema of the feature source.This method delegates to
buildFeatureType(), which must be implemented by subclasses. The result is cached inContentState.getFeatureType().- Specified by:
getSchemain interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- the schema that will apply to features retrieved from this
FeatureSource
-
getAbsoluteSchema
Helper method for returning the underlying schema of the feature source. This is a non-view this is the same as calling getSchema(), but in the view case the underlying "true" schema is returned. -
getBounds
Returns the bounds of the entire feature source.This method delegates to
getBounds(Query):return getBounds(Query.ALL).- Specified by:
getBoundsin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- The bounding envelope of the feature data; or
nullif the bounds are unknown or too costly to calculate. - Throws:
IOException- on any errors calculating the bounds
-
getBounds
Returns the bounds of the results of the specified query against the feature source.This method calls through to
getBoundsInternal(Query)which subclasses must implement. It also contains optimizations which check state for cached values.- Specified by:
getBoundsin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Parameters:
query- the query to select features- Returns:
- The bounding envelope of the feature data; or
nullif the bounds are unknown or too costly to calculate. - Throws:
IOException- on any errors calculating the bounds
-
getBoundsInternal
Calculates the bounds of a specified query. Subclasses must implement this method. If the computation is not fast, subclasses can returnnull.- Throws:
IOException
-
getCount
Returns the count of the number of features of the feature source.This method calls through to
getCountInternal(Query)which subclasses must implement. It also contains optimizations which check state for cached values.- Specified by:
getCountin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Parameters:
query- the query to select features- Returns:
- the numer of features that would be returned by the
Query; or-1if this cannot be calculated. - Throws:
IOException- if there are errors getting the count
-
getCountInternal
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.- Throws:
IOException
-
getFeatures
Returns the feature collection of all the features of the feature source.- Specified by:
getFeaturesin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Specified by:
getFeaturesin interfaceSimpleFeatureSource- Returns:
- features retrieved by the
Query - Throws:
IOException- if the underlying data source cannot be accessed.
-
getReader
Returns a feature reader for all features.This method calls through to
getReader(Query).- Throws:
IOException
-
getFeatures
Returns the feature collection if the features of the feature source which meet the specified query criteria.- Specified by:
getFeaturesin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Specified by:
getFeaturesin interfaceSimpleFeatureSource- Parameters:
query- DataAccess query for requested information, such as typeName, maxFeatures and filter.- Returns:
- features retrieved by the
Query - Throws:
IOException- if the underlying data source cannot be accessed.- See Also:
-
getReader
public final FeatureReader<SimpleFeatureType,SimpleFeature> getReader(Query query) throws IOException Returns a reader for the features specified by a query.- Throws:
IOException
-
accepts
public void accepts(Query query, FeatureVisitor visitor, ProgressListener progress) throws IOException Visit the features matching the provided query.The default information will use getReader( query ) and pass each feature to the provided visitor. Subclasses should override this method to optimise common visitors:
Often in the case of Filter.INCLUDES the information can be determined from a file header or metadata table.- Parameters:
visitor- Visitor called for each featureprogress- Used to report progress; and errors on a feature by feature basis- Throws:
IOException
-
handleVisitor
Subclass method which allows subclasses to natively handle a visitor.Subclasses would override this method and return true in cases where the specific visitor could be handled without iterating over the entire result set of query. An example would be handling visitors that calculate aggregate values.
- Parameters:
query- The query being made.visitor- The visitor to- Returns:
- true if the visitor can be handled natively, otherwise false.
- Throws:
IOException
-
getReaderInternal
protected abstract FeatureReader<SimpleFeatureType,SimpleFeature> getReaderInternal(Query query) throws IOException 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:canReproject()- handlesQuery.getCoordinateSystemReproject()internally. Example would be PostGIS using Proj to handle reproejction internallycanFilter(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>
- Throws:
IOException
-
canReproject
protected boolean canReproject()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
falsewill 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).
- See Also:
-
canLimit
Deprecated.usecanLimit(Query)instead. -
canLimit
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
falsewill 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.- See Also:
-
canOffset
Deprecated.usecanOffset(Query)instead. -
canOffset
Determines if the datastore can natively skip the firstoffsetnumber 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
falsewill case the feature reader created by the subclass to be accessed offset times before being returned to the caller. -
canFilter
Deprecated.usecanFilter(Query)instead. -
canFilter
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
falsewill cause the feature reader created by the subclass to be wrapped in a filtering feature reader when the query specifies a filter. SeeFilteringFeatureReader. -
canRetype
Deprecated.usecanRetype(Query)instead. -
canRetype
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
falsewill cause the feature reader created by the subclass to be wrapped in a retyping feature reader when the query specifies a retype.- See Also:
-
canSort
Deprecated.usecanSort(Query)instead. -
canSort
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
falsewill cause an exception to be thrown when the query specifies sorting.- See Also:
-
canTransact
protected boolean canTransact()Determines if the store can natively manage transactions.If a subclass can handle transactions natively it should override this method to return
trueand deal with transactions on its own, including firing feature modifications events.- Returns:
- true if transaction independence has custom implementation
-
canEvent
protected boolean canEvent()Determines if the store takes responsibility for issuing events.If a subclass issue events (as part of its low level writer implementation) then it should override this method to return true.
- Returns:
- true if event notification has custom implementation
-
getView
Creates a new feature source for the specified query.If the current feature source already has a defining query it is joined to the specified query.
- Throws:
IOException
-
getFeatures
Returns the feature collection for the features which match the specified filter.This method calls through to
getFeatures(Query).- Specified by:
getFeaturesin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Specified by:
getFeaturesin interfaceSimpleFeatureSource- Parameters:
filter- the filter to select features; must not benull(use Filter.INCLUDE instead)- Returns:
- features retrieved by the
Filter - Throws:
IOException- if the underlying data source cannot be accessed.- See Also:
-
getReader
public final FeatureReader<SimpleFeatureType,SimpleFeature> getReader(Filter filter) throws IOException Returns a reader for features specified by a particular filter.This method calls through to
getReader(Query).- Throws:
IOException
-
getView
- Throws:
IOException
-
addFeatureListener
Adds an listener or observer to the feature source.Listeners are stored on a per-transaction basis.
- Specified by:
addFeatureListenerin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Parameters:
listener- the new listener
-
removeFeatureListener
Removes a listener from the feature source.- Specified by:
removeFeatureListenerin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Parameters:
listener- the listener to remove
-
getSupportedHints
The hints provided by the feature store.Subclasses should implement
addHints(Set)to provide additional hints.- Specified by:
getSupportedHintsin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- a set of
RenderingHints#Keyobjects; may be empty but nevernull - See Also:
-
addHints
Subclass hook too add additional hints.By default, the followings are already present:
- Parameters:
hints- The set of hints supported by the feature source.
-
joinQuery
Convenience method for joining a query with the definining query of the feature source. -
resolvePropertyNames
This method changes the query object so that all propertyName references are resolved to simple attribute names against the schema of the feature source.For example, this method ensures that propertyName's such as "gml:name" are rewritten as simply "name".
-
resolvePropertyNames
Transform provided filter; resolving property names -
buildFeatureType
Creates the feature type or schema for the feature source.Implementations should use
SimpleFeatureTypeBuilderto 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 ...
- Throws:
IOException
-
buildQueryCapabilities
Builds the query capabilities for this feature source. The default implementation returns a newly built QueryCapabilities, subclasses are advised to build their own. -
getQueryCapabilities
SimpleFeatureCollection optimized for read-only access.Available via getView( filter ):
- getFeatures().sort( sort )
- getFeatures( filter ).sort( sort )
In particular this method of data access is intended for rendering and other high speed operations; care should be taken to optimize the use of FeatureVisitor.
- Specified by:
getQueryCapabilitiesin interfaceFeatureSource<SimpleFeatureType,SimpleFeature> - Returns:
- readonly access
-
setFeatureLock
Sets the feature lock of the feature store. -
lockFeatures
Locks all features.This method calls through to
lockFeatures(Filter).- Throws:
IOException
-
lockFeatures
Locks features specified by a query.This method calls through to
lockFeatures(Filter).- Throws:
IOException
-
lockFeatures
Locks features specified by a filter.- Throws:
IOException
-
unLockFeatures
Unlocks all features.This method calls through to
unLockFeatures(Filter).- Throws:
IOException
-
unLockFeatures
Unlocks features specified by a query.This method calls through to
unLockFeatures(Filter).- Throws:
IOException
-
unLockFeatures
Unlocks features specified by a filter.- Throws:
IOException
-
canLock
protected boolean canLock()Determines if thedatastorecan perform feature locking natively.If
#getWriterInternal(Query, int)returns afeature writerthat supports feature locking natively, it should override this method to returntrue.Not overriding this method or returning
falsewill causeContentFeatureStoreto use theInProcessLockingManagerto return aFeatureWriterthat honors locks. -
processLock
If the subclass implements native locking, this method is invoked before the feature lock is (re)assigned to this store.- Parameters:
lock- - aFeatureLockinstance- Returns:
- a processed
FeatureLockinstance
-
doLockInternal
This method must be implemented overridden when native locking is indicated bycanLock().- Parameters:
typeName-SimpleFeaturetype namefeature-SimpleFeatureinstance- Throws:
IOException
-
doUnlockInternal
This method must be implemented overridden when native locking is indicated bycanLock().- Parameters:
typeName-Featuretype namefeature-Featureinstance- Throws:
IOException
-
canFilter(Query)instead.