Try manual and OWSLib methods to retrieve WFS data as JSON from a version 1.1.0 server.

The two methods should return the same result, but only the manual method is returning points in the (lon,lat) order requested by srsName=EPSG:4326. The OWSLib version results are still coming back with the default 1.1.0 order (lat,lon), indicating that srsName=EPSG:4326 was not passed to the WFS


In [30]:
# some USGS ScienceBase Geoserver WFS endpoints:
endpoint='https://www.sciencebase.gov/catalogMaps/mapping/ows/5342c5fce4b0aa151574a8ed'

Method 1: building WFS request by hand and using requests


In [ ]:
import requests
import geojson

In [38]:
url = ('%s?service=wfs&version=1.1.0&request=GetFeature&'
'typeNames=%s&srsName=EPSG:4326&outputFormat=application/json') % (endpoint, 'sb:Conservation_Zone_WGS84')
print url


https://www.sciencebase.gov/catalogMaps/mapping/ows/5342c5fce4b0aa151574a8ed?service=wfs&version=1.1.0&request=GetFeature&typeNames=sb:Conservation_Zone_WGS84&srsName=EPSG:4326&outputFormat=application/json

In [ ]:
json_response=requests.get(url).text

Here we get [lon,lat] ordering of points, as requested by using srsName=EPSG:4326


In [39]:
print json_response[:300]


{"type":"FeatureCollection","features":[{"type":"Feature","id":"Conservation_Zone_WGS84.1","geometry":{"type":"MultiPolygon","coordinates":[[[[-74.09688169446223,39.81487959537135],[-74.09587338924456,39.81488113835475],[-74.09614209870023,39.8143317590967],[-74.09633047532941,39.8137616151959],[-74

Method 2: Use OWSLib to construct the request


In [42]:
from owslib.wfs import WebFeatureService

In [43]:
wfs = WebFeatureService(endpoint, version='1.1.0')
print wfs.version


1.1.0

In [44]:
json_response = wfs.getfeature(typename=['sb:Conservation_Zone_WGS84'], propertyname=None, srsname='EPSG:4326', outputFormat='application/json').read()

Here we get still getting [lat,lon] ordering of points, the default if no srsName is provided, despite requesting srsname='EPSG:4326'


In [45]:
json_response[:300]


Out[45]:
'{"type":"FeatureCollection","features":[{"type":"Feature","id":"Conservation_Zone_WGS84.1","geometry":{"type":"MultiPolygon","coordinates":[[[[39.81487959537135,-74.09688169446223],[39.81488113835475,-74.09587338924456],[39.8143317590967,-74.09614209870023],[39.8137616151959,-74.09633047532941],[39.'

In [ ]: