How can I get total featurecount from a WFS service? I need to download all features, 1000 at a time, so I want to know when to stop (Or can I just keep going until the response is empty?)
I've tried to find something here, but I dont:
https://slwgeo.artdata.slu.se/geoserver/wfs?request=GetCapabilities
The service name is: SLW:AllSwedishOccurrences
This is the code I'm using which is working but I need to know when to stop.
import os
from owslib.wfs import WebFeatureService
downloadto = '/home/bera/GIS/csvfiler_paging/'
wfs1 = WebFeatureService(url=r'https://slwgeo.artdata.slu.se/geoserver/wfs?', version='1.1.0')
wfs1.timeout=120
for i in range(0,10000,1000): #I need ot replace 10000 with the total feature count
print(i)
response = wfs1.getfeature(typename='SLW:AllSwedishOccurrences', maxfeatures=1000, outputFormat='csv', startindex=i)
outfile=os.path.join(downloadto,'data_{0}.csv'.format(str(i)))
out=open(outfile, 'wb')
out.write(response.read())
out.close()
Best Answer
I never found how to do it in Python with owslib.wfs, therefore i use the GetFeature request of WFS v.1.1.0 with parameter resulttype=hits (as in Only return the NumberOfFeatures in a WFS query) and the Python library requests
From WFS GetFeature request blank XML for some FeatureTypes