Class WFSHitsCountUtil
resultType=hits GetFeature request when GeoTools does not.
GeoTools only does a hits request for WFS 1.x. For WFS 2.0.0 the StrictWFS_2_0_Strategy does not support
hits (its pull parser can't read the count), so FeatureSource.getCount(Query) always returns -1 without
asking the server. This class does the hits request itself, using the GeoTools request so the filter is encoded the
same way as for the GetFeature request for the features, and reads the numberMatched attribute.
A hits request always counts, also on MapServer which returns numberMatched="unknown" in a GetFeature
response with features (unless wfs_compute_number_matched is set). Counting can be slow for large layers. See
getCount(SimpleFeatureSource, Query, Duration, Duration) for not waiting long for a slow count.
-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetCount(org.geotools.api.data.SimpleFeatureSource fs, org.geotools.api.data.Query query) Count the features of a feature source.static intgetCount(org.geotools.api.data.SimpleFeatureSource fs, org.geotools.api.data.Query query, Duration hitsTimeout, Duration slowHitsTtl) Count the features of a feature source likegetCount(SimpleFeatureSource, Query), but without waiting long for a slow hits request.static intRead the number of features from a GetFeature hits response: thenumberMatchedattribute (WFS 2.0.0) or thenumberOfFeaturesattribute (WFS 1.x) of the rootFeatureCollectionelement.
-
Method Details
-
getCount
public static int getCount(org.geotools.api.data.SimpleFeatureSource fs, org.geotools.api.data.Query query) throws IOException Count the features of a feature source. CallsFeatureSource.getCount(Query)and if that returns -1 for a WFS which GeoTools does not count with a hits request (WFS 2.0.0), does a hits request.- Parameters:
fs- the feature source, may be of any typequery- the query- Returns:
- the number of features, or -1 if unknown
- Throws:
IOException- whenFeatureSource.getCount(Query)fails; a failing hits request returns -1
-
getCount
public static int getCount(org.geotools.api.data.SimpleFeatureSource fs, org.geotools.api.data.Query query, Duration hitsTimeout, Duration slowHitsTtl) throws IOException Count the features of a feature source likegetCount(SimpleFeatureSource, Query), but without waiting long for a slow hits request. For when the count is nice to have, such as the total for a page of features.A hits request which takes longer than
hitsTimeoutis aborted and the feature type is remembered as slow, so it isn't counted with a hits request forslowHitsTtland the count is -1 without waiting. Some servers count very slowly for large layers (PDOK NWB wegvakken: ~18 s for a hits request versus 0.1 s for a page of features), while counting is quick for most.- Parameters:
fs- the feature source, may be of any typequery- the queryhitsTimeout- how long to wait for a hits request, in whole seconds (at least 1 s, the HTTP read timeout)slowHitsTtl- how long not to count a feature type after its hits request timed out- Returns:
- the number of features, or -1 if unknown or too slow to count
- Throws:
IOException- whenFeatureSource.getCount(Query)fails; a failing hits request returns -1
-
parseNumberMatched
Read the number of features from a GetFeature hits response: thenumberMatchedattribute (WFS 2.0.0) or thenumberOfFeaturesattribute (WFS 1.x) of the rootFeatureCollectionelement.- Parameters:
in- the response- Returns:
- the number of features, or -1 if the response is not a feature collection (for example an exception
report) or the number is not a non-negative integer (for example
"unknown") - Throws:
XMLStreamException- if the response is not XML
-