1

I use WFS quite a lot to collect my data with the script below. It works most of the time, but I notice that some of the WFS-services I come across have a limited output, as only 1000 records are collected. I know there are more records supposed to be as the manual download of these files consist of at least 2100 records.

Does anyone know what causes this, and how to work around this?

from requests import Request
from owslib.wfs import WebFeatureService
import geopandas as gpd
# enable WFS support
import fiona
import pandas as pd
fiona.drvsupport.supported_drivers['WFS'] = 'r'

# URL for WFS backend
url = "https://geoservices.noord-holland.nl/ags/services/oi_dataservice_alg/MapServer/WFSServer" \
      "?request=GetFeature&service=WFS"

# Initialize
wfs = WebFeatureService(url=url)

# Get data from WFS
# -----------------
contents = list(wfs.contents)
# Fetch the last available layer
layer = 'oi_dataservice_alg:Woningbouwplannen'

# Specify the parameters for fetching the data
params = dict(typeName=layer, outputFormat='gml3')

# Parse the URL with parameters
q = Request('GET', url, params=params).prepare().url

# Read data from URL
data = gpd.read_file(q)
1
  • 1
    https://geoservices.noord-holland.nl/ags/services/oi_dataservice_alg/MapServer/WFSServer?request=GetFeature&service=WFS&version=2.0.0&resulttype=hits&typenames=oi_dataservice_alg:Woningbouwplannen gives you the number of features
    – nmtoken
    May 5 at 13:00

1 Answer 1

7

Check the service capabilities https://geoservices.noord-holland.nl/ags/services/oi_dataservice_alg/MapServer/WFSServer?request=GetCapabilities&service=WFS&version=2.0.0

<ows:Constraint name="CountDefault">
<ows:NoValues/>
<ows:DefaultValue>1000</ows:DefaultValue>
</ows:Constraint>

That means that the limit of 1000 features is expected. Then read the standard http://docs.opengeospatial.org/is/09-025r2/09-025r2.html about startIndex and count parameters.

You can get the second page of 1000 features with a request

https://geoservices.noord-holland.nl/ags/services/oi_dataservice_alg/MapServer/WFSServer?request=GetFeature&typenames=oi_dataservice_alg:Woningbouwplannen&service=WFS&version=2.0.0&startIndex=1000

It is best to include the startIndex also to the first request &startIndex=0to guarantee that the server sorts the output in the same way and you will get the right features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.