[mapserver-dev] Incorrect behavior of WFS GetFeature

Even Rouault even.rouault at spatialys.com
Sun Aug 25 11:32:41 PDT 2019


On dimanche 25 août 2019 20:09:32 CEST Tamas Szekeres wrote:
> Hi Devs,
> 
> I did some investigation regarding to the current GetFeature implementation
> (in master), but I doubt if that is working properly as it stands now. I've
> executed the query (with pagination) against a postgis database in the
> debugger and it doesn't seem to be working.
> 
> Currently the following approach is used in mapserver:
> 
> 1. An initial query is issued by msWFSRetrieveFeatures (in mapwfs.c) where
> the subset of the features are added to the result cache (from startindex
> limiting to maxfeatures)
> 2. The total count of the features are computed by
> msWFSComputeMatchingFeatures (in mapwfs.c) in which the result set is saved
> and the original layer is closed and reopened and a count(..) aggregate
> query is initiated afterwards (in msPostGISLayerGetShapeCount).
> 3. The result set is then restored and GetShape is called for each item
> using the same layer.
> 
> The main problem with this approach that in #2 the original layer is closed
> and reopened therefore the resultset stored by the driver is invalidated.
> The driver specific GetShapeCount will create a new resultset either with 1
> element (the count), or the entire set of shapes if it falls back to the
> stock LayerDefaultGetShapeCount. This resultset will then be used in #3
> where the resultindex references refer to incorrect features.

Hum I see...

Several workarounds come to mind:
- make sure that your features are always retrieved in the same order by 
adding an ORDER BY clause to your DATA clause
- set the wfs_features_cache_size metadata item
(see https://mapserver.org/ogc/wfs_server.html?highlight=features_cache_count) 
so that the result of the first query is entirely cached in RAM

> 
> Would that be an option to implement msWFSComputeMatchingFeatures in that
> way so that the original layer is not getting closed and reopened?

This is likely to be involved as I guess those open/closings are the ones done 
in mapquery.c

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the mapserver-dev mailing list