geopython / OWSLib

OWSLib is a Python package for client programming with Open Geospatial Consortium (OGC) web service (hence OWS) interface standards, and their related content models.
https://owslib.readthedocs.io
BSD 3-Clause "New" or "Revised" License
391 stars 277 forks source link

Specifying OutputFormat in WFS #137

Closed rsignell-usgs closed 10 years ago

rsignell-usgs commented 10 years ago

I would like to use OWSLib to request a JSON response from a WFS service.

This works, but doesn't use OWSLib:

import requests
import json
url = 'https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288?service=wfs&version=1.0.0&request=GetFeature&typeNames=sb:Project_Area&outputFormat=application/json'
resp = requests.get(url)
data = json.loads(resp.text)
print data

returns:

{u'type': u'FeatureCollection', u'features': [{u'geometry': {u'type': u'MultiPolygon', u'coordinates': [[[[559501.5991923176, 254222.22111433744], [551009.4896312356, 242024.4637447819], [547072.238834735, 241059.45129466802], [546531.8318626732, 239515.43137446046], [547419.6433167756, 234420.1656378135], [541513.7671220265, 224306.8351605311], [538769.4260442778, 225640.16826280206], [537753.9839519188, 227851.86409860104], [537651.4051570185, 234116.65830690414], [537576.5163255259, 240519.044322595], [539390.7397317551, 243028.07669291645], [545952.8243925907, 244494.89561710507], [557185.5693120286, 255534.63804651052], [559501.5991923176, 254222.22111433744]]]]}, u'properties': {u'Id': 0}, u'type': u'Feature', u'id': u'Project_Area.1', u'geometry_name': u'the_geom'}]}

How would I accomplish this using OWSLib?

I didn't see how to specify outputFormat here: https://github.com/geopython/OWSLib/blob/master/owslib/feature/wfs100.py#L137-L139

I got this far:

endpoint='https://www.sciencebase.gov/catalogMaps/mapping/ows/53398e51e4b0db25ad10d288'
from owslib.wfs import WebFeatureService
wfs = WebFeatureService(endpoint)
shapefiles = wfs.contents.keys()
feature = wfs.getfeature(typename=shapefiles[0], maxfeatures=1, propertyname=None, outputFormat='application/json')

but this returns: TypeError: getfeature() got an unexpected keyword argument 'outputFormat'

rsignell-usgs commented 10 years ago

@tomkralidis, this has to be something simple, right?

kwilcox commented 10 years ago

Doesn't look like this is possible right now. It should be based on WFS 1.1.0:

The optional outputFormat attribute specifies the format of the response to a 
GetFeature request. The default value is text/xml; subtype=gml/3.1.1 indicating that a 
valid GML3 [2] document, that validates against a valid GML3 application schema 
(generated using the DescribeFeatureType request), must be generated. For backward 
compatability, the values GML2 or text/xml; subtype=gml/2.1.2 may be specified 
indicating that a valid GML2 document, that validates against a valid GML2 application 
schema, must be generated.

Other output formats (including older versions of GML, non-XML, binary and vendor 
specific formats) are also possible as long at the appropriate values for the outputFormat 
attribute are advertised in the capabilities document [clause 13]. This specification 
recommends that a descriptive narative be included in the capabilities document for each 
output format listed there. This, however, is not a mandatory requirement
tomkralidis commented 10 years ago

@kwilcox can't we only apply outputformat if specified?

rsignell-usgs commented 10 years ago

so fixed in #140. Nice.