Class SpatialIndexFeatureSource

  • All Implemented Interfaces:
    FeatureSource<SimpleFeatureType,​SimpleFeature>, SimpleFeatureSource

    public class SpatialIndexFeatureSource
    extends Object
    implements SimpleFeatureSource
    A FeatureSource using a spatial index to hold on to features and serve them up for fast display.

    This is a port of Andrea's CachingFeatureSource (which is slightly more compliced and rebuilds the cache as an origional feature source changes). Our implementation here knows up front that the features are in memory and does its best to take advantage of the fact. A caching feature source for fast data access.

    Please note that this FeatureSource is strictly "read-only" and thus does not support feature events.

    • Method Detail

      • getBounds

        public ReferencedEnvelope getBounds()
                                     throws IOException
        Description copied from interface: FeatureSource
        Get the spatial bounds of the feature data. This is equivalent to calling getBounds(Query.ALL).

        It is possible that this method will return null if the calculation of bounds is judged to be too costly by the implementing class. In this case, you might call getFeatures().getBounds() instead.

        Specified by:
        getBounds in interface FeatureSource<SimpleFeatureType,​SimpleFeature>
        Returns:
        The bounding envelope of the feature data; or null if the bounds are unknown or too costly to calculate.
        Throws:
        IOException - on any errors calculating the bounds
      • getBounds

        public ReferencedEnvelope getBounds​(Query query)
                                     throws IOException
        Description copied from interface: FeatureSource
        Get the spatial bounds of the features that would be returned by the given Query.

        It is possible that this method will return null if the calculation of bounds is judged to be too costly by the implementing class. In this case, you might call getFeatures(query).getBounds() instead.

        Specified by:
        getBounds in interface FeatureSource<SimpleFeatureType,​SimpleFeature>
        Parameters:
        query - the query to select features
        Returns:
        The bounding envelope of the feature data; or null if the bounds are unknown or too costly to calculate.
        Throws:
        IOException - on any errors calculating the bounds
      • getCount

        public int getCount​(Query query)
                     throws IOException
        Description copied from interface: FeatureSource
        Gets the number of the features that would be returned by the given Query, taking into account any settings for max features and start index set on the Query.

        It is possible that this method will return -1 if the calculation of number of features is judged to be too costly by the implementing class. In this case, you might call getFeatures(query).size() instead.

        Example use:

         int count = featureSource.getCount();
         if( count == -1 ){
            count = featureSource.getFeatures( "typeName", count ).size();
         }
        Specified by:
        getCount in interface FeatureSource<SimpleFeatureType,​SimpleFeature>
        Parameters:
        query - the query to select features
        Returns:
        the numer of features that would be returned by the Query; or -1 if this cannot be calculated.
        Throws:
        IOException - if there are errors getting the count
      • getSchema

        public SimpleFeatureType getSchema()
        Description copied from interface: FeatureSource
        Retrieves the schema (feature type) that will apply to features retrieved from this FeatureSource.

        For a homogeneous data source such as a shapefile or a database table, this schema be that of all features. For a heterogeneous data source, e.g. a GML document, the schema returned is the lowest common denominator across all features.

        Specified by:
        getSchema in interface FeatureSource<SimpleFeatureType,​SimpleFeature>
        Returns:
        the schema that will apply to features retrieved from this FeatureSource
      • getName

        public Name getName()
        Description copied from interface: FeatureSource
        Returns the name of the features (strictly, the name of the AttributeDescriptor for the features) accessible through this FeatureSource.

        The value returned by this method can be different to that returned by featureSource.getSchema().getType().getName(). This is because there is a distinction between the name applied to features and the name of a feature type. When working with SimpleFeature and SimpleFeatureType, for example with a shapefile data source, it is common practice for feature and feature type names to be the same. However, this is not the case more generally. For instance, a database can contain two tables with the same structure. The feature name will refer to the table while the feature type name refers to the schema (table structure).

        Specified by:
        getName in interface FeatureSource<SimpleFeatureType,​SimpleFeature>
        Returns:
        the name of the features accessible through this FeatureSource