[gdal-dev] WFS driver bug2 - MAXFEATURES not working

Odd Ragnar Lydersen Odd-Ragnar.Lydersen at powel.no
Wed Oct 19 06:17:52 PDT 2016


Now I have come around to test this a bit more.
 
1) I tried the same as you did, only for wfs v. 1.1.0

ogrinfo -ro "WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.1.0&MAXFEATURES=1"  continents -al  -spat 0 45 15 50
INFO: Open of `WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.1.0&MAXFEATURES=1'
      using driver `WFS' successful.
Metadata:
  ABSTRACT=This demonstration server showcases MapServer (www.mapserver.org) and its OGC support
  PROVIDER_NAME=Gateway Geomatics
  TITLE=WMS Demo Server for MapServer

Layer name: continents
Metadata:
  TITLE=World continents
Geometry: Unknown (any)
Feature Count: 0
...

Not working in version 1.1.0.

2) I add the spatial filter to the URL, using BBOX.

ogrinfo -ro "WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.1.0&MAXFEATURES=1&BBOX=0,45,15,50"  continents -al
INFO: Open of `WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.1.0&MAXFEATURES=1&BBOX=0,45,15,50'
      using driver `WFS' successful.
Metadata:
  ABSTRACT=This demonstration server showcases MapServer (www.mapserver.org) and its OGC support
  PROVIDER_NAME=Gateway Geomatics
  TITLE=WMS Demo Server for MapServer

Layer name: continents
Metadata:
  TITLE=World continents
Geometry: Unknown (any)
Feature Count: 1
...

Working in version 1.1.0, when adding BBOX to URL.

3) Then I tested this out in our application, and all is well if I read GDAL:WFS without really using the C++ api, and just setting up the config file with the correct URL-parameters. Both version 1.0.0 and 1.1.0 works.

Shouldn't this work just as well using the C++ API calls, to set up the spatial constraints, and maxfeatures?
Now I'm rather editing the URL to get the result I want, and that is OK, but a bit awkward and cumbersome.

>Odd-Ragnar<

-----Opprinnelig melding-----
Fra: Even Rouault [mailto:even.rouault at spatialys.com] 
Sendt: torsdag 29. september 2016 11.20
Til: gdal-dev at lists.osgeo.org
Kopi: Odd Ragnar Lydersen <Odd-Ragnar.Lydersen at powel.no>
Emne: Re: [gdal-dev] WFS driver bug2 - MAXFEATURES not working

Le jeudi 29 septembre 2016 10:06:12, Odd Ragnar Lydersen a écrit :
> So I have tried to dig a bit more into this, and I have noticed a few 
> things.
> 
> 
> 1)      I set MAXFEATURES=60 in the url
> 
> 2)      I select the layer I want to work with, let's call it MyLayer.
> 
> 3)      I call SetSpatialFilterRect() on the MyLayer and set it to a small
> area containing 11 points.
> 
> 4)      I call GetFeatureCount() on MyLayer, and then I get 60 features
> returned, even though I know it should be spatially bound to an area 
> containing only 11 features.
> 
> 5)      Then I should be iterating through all the features, using
> GetNextFeature(), but no features are read.
> 
> In 4), the result from GetFeatureCount(), should have been 11.
> In 5), I should have been able to read the expected 11 features.
> 

The WFS driver has quite a bunch of optimizations (and workarounds for buggy implementations), which are as many doors for more or less subtle bugs, but in my below testing, that seems to work :

$ python
>>> from osgeo import ogr
>>> ds = 
>>> ogr.Open('WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.0.0&MA
>>> XFEATURES=1') lyr = ds.GetLayerByName('continents')
>>> lyr.SetSpatialFilterRect(0,45,15,50)
>>> print(lyr.GetFeatureCount())
1
>>> f = lyr.GetNextFeature()
>>> print(f['NA2DESC'])
'Italy'
>>> f = lyr.GetNextFeature()
>>> print(f)
None

or from the command line :
$ ogrinfo -ro "WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.0.0&MAXFEATURES=1"  continents -al  -spat 0 45 15 50
INFO: Open of `WFS:http://demo.mapserver.org/cgi-bin/wfs?VERSION=1.0.0&MAXFEATURES=1'
      using driver `WFS' successful.
Metadata:
  ABSTRACT=This demonstration server showcases MapServer (www.mapserver.org) and its OGC support
  TITLE=WMS Demo Server for MapServer

Layer name: continents
Metadata:
  TITLE=World continents
Geometry: Unknown (any)
Feature Count: 1
Extent: (13.427750, 45.697224) - (13.439472, 45.711639) Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
Geometry Column = msGeometry
gml_id: String (0.0) NOT NULL
NA2DESC: String (0.0)
NA3DESC: String (0.0)
OGRFeature(continents):22518
  gml_id (String) = continents.22518
  NA2DESC (String) = Italy
  NA3DESC (String) = Europe
  POLYGON ((13.437944 45.708195,13.438861 45.706806,13.439472 45.705387,13.438694 45.702862,13.436277 45.700832,13.432834 45.697224,13.431194 45.697472,13.430611
45.699085,13.432083 45.702999,13.432167 45.704613,13.430305 45.707443,13.42775 45.709583,13.4285 45.711639,13.43275 45.710167,13.437944 45.708195))





Even

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


More information about the gdal-dev mailing list