View Ticket
Not logged in
Ticket Hash: db0c391f2ae7119bd9a799449cfac3c7b4bb5752
Title: ImportWFS - test_wfs_paging: weird checks
Status: Fixed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2016-12-05 18:09:27
Version Found In: 4.4.0-dev
User Comments:
mj10777 added on 2016-09-02 12:38:56:

For the last few days, I have been attempting to get ImportWFS(..) working correctly.
This has mostly been done from spatialite_gui
The Server I am calling, supports 2.0.0 as default:

wget 'http://fbinter.stadt-berlin.de/fb/wfs/geometry/senstadt/re_alkis_flurstuecke?&SERVICE=WFS&REQUEST=GetCapabilities' -O wget/re_alkis_flurstuecke.default.txt
When attempting to use 2.0.0: nothing works.
When attempting to use 1.1.0 with single WMS request: it works.
When attempting to use 1.1.0 with paging WMS: it fails, returning:
    the WFS server doesn't seem to support STARTINDEX
Using the command created by spatialite_gui with a wget command: results are returned
wget 'http://fbinter.stadt-berlin.de/fb/wfs/geometry/senstadt/re_alkis_flurstuecke?service=WFS&version=1.1.0&request=GetFeature&typeName=fis:re_alkis_flurstuecke&srsName=urn:ogc:def:crs:EPSG:6.9:25833&BBOX=389000,5817000,393000,5820000&maxFeatures=100&startIndex=0' -O wget/berlin_389_5817.110.0.gml

After a lot of debugging (mainly in 'test_wfs_paging'), I attempted to understand why this is failing:
tests:
    1: rows returned < page_size
      no: they are the same; requested 100 (of 5969 possible) and received 100
        thus the paging is working
    2: is the (text-version) of the first geometry the same as the last
      no: nor will it ever be likely to be the same
        so this, seems to me, is an invalid check
    3: is the (attr1->column->name) the same as (attr1->column->name)
      well (umm..) yes, indeed it is and will, most likely, always be so
        changing to if (strcmp (attr1->column->name, attr2->column->name) != 0) would be a more useful check
    4: is the (attr1->value) the same as (attr2->value)
      not tested: but a valid test

Changing test 1 to check
    rows returned <= page_size
runs, but brings unexpected results:
    1st time: 16400 rows
    2nd time 1700 rows

Test 2 cannot be correct, nor do I understand the sense of comparing the geometries.
Test 3 needs to be corrected
Test 4 is meaningfull

I assume the goal is:
    to insure that the last record is complete

The sql used for the 2nd time was:
-- export SPATIALITE_SECURITY=relaxed
-- rm wfs_berlin_build.db ; spatialite wfs_berlin_build.db < wfs_berlin_build.sql 
SELECT ImportWFS
( -- 5969 rows
 "http://fbinter.stadt-berlin.de/fb/wfs/geometry/senstadt/re_alkis_flurstuecke?service=WFS&version=1.1.0&request=GetFeature&typeName=fis:re_alkis_flurstuecke&srsName=urn:ogc:def:crs:EPSG:6.9:25833&BBOX=389000,5817000,393000,5820000",
 "fis:re_alkis_flurstuecke",
 "berlin_389_5817", 
 "id_flur",
 0,-1,1
);
SELECT ImportWFS
( -- first time 16400 rows; second time 1700 rows
 "http://fbinter.stadt-berlin.de/fb/wfs/geometry/senstadt/re_alkis_flurstuecke?service=WFS&version=1.1.0&request=GetFeature&typeName=fis:re_alkis_flurstuecke&srsName=urn:ogc:def:crs:EPSG:6.9:25833&BBOX=389000,5817000,393000,5820000",
 "fis:re_alkis_flurstuecke",
 "berlin_389_5817_100", 
 "id_flur",
 0,100,1
);

Tomorrow I will look further into this, looking at what is being returned in qgis.


anonymous added on 2016-11-01 11:58:23:
The test request is wrong because paging in WFS 2.0 is based on startIndex and count (not maxfeatures).

I suppose that what the test tries to do is something like
1) read first 100 features with &count=100 and startIndex=0
2) read the 100th feature with &count=1 and startIndex=99 (Note that startIndex is zero based!)

If 1) and 2) returns the same feature then startIndex and count are supported. 

Notice also that the first request must also have startIndex=0 because for GeoServer, which is quite a common WFS server, &count=100&startIndex=0 gives a different result than &count=100 alone

Here are some queries to test with:

http://avoindata.maanmittauslaitos.fi/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeName=mtk:jarvi&srsName=urn:ogc:def:crs:EPSG::3067&count=100
last feature jarvi.114385

http://avoindata.maanmittauslaitos.fi/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeName=mtk:jarvi&srsName=urn:ogc:def:crs:EPSG::3067&count=100&startIndex=0
last feature jarvi.144

http://avoindata.maanmittauslaitos.fi/geoserver/wfs?service=WFS&version=2.0.0&request=GetFeature&typeName=mtk:jarvi&srsName=urn:ogc:def:crs:EPSG::3067&count=100&startIndex=99
feature jarvi.144 -> paging works

sandro added on 2016-12-05 18:09:27:
there was some confusion in code implementing WFS paging.

just a quick recall so to delimit the problem:
a. WFS paging is a mandatory capability only starting since WFS 2.0.0; the standard keywords are "startIndex"/"count", and the first feature will always be identified by index=0
b. both MapServer and GeoServer introduced WFS paging on WFS 1.0.0, but this was NON-STANDARD capability not supported by other products; in this case the magic keywords are "startIndex"/"maxFeatures". 
   Caveat: GeoServer assumed that the first feature was identified by index=0, but MapServer assumed index=1
   the "weird checks" reported by Mark simply are a very reasonable heuristic intended to discriminate between MapServer and GeoServer so to choose the appropriate start index.
c. WFS 2.0.0 introduced yet another relevant change; WFS 1.x has a "typeName" keyword, but WFS 2.x pretends "typeNames" (note the plural !!!)

applied patch: now the WFS importer pedantically supports the different version-depending keywords.
- the WFS server in Finland (clearly GeoServer) now nicely works using either WFS 1.x or WFS 2.x
- the WFS server in Berlin (unknown model, but I strongly suspect it's ESRI) only works when using WFS 2.x because it's completely unable to support WFS 1.x paging.