2

In Python, how can I encode "complex" (vector) data for a WPS call that just echoes back the data, and decodes the data from the result. I was planning on using OWSLib on the client side and PyWPS-4 on the server side.

This what I have so far for the server:

import flask
import pywps

class EchoVector(pywps.Process):
    def __init__(self):
        inputs = [pywps.ComplexInput('message',
                                     'Input message',
                                     supported_formats=[pywps.Format('application/gml+xml')],
                                     mode=pywps.validator.mode.MODE.STRICT)]

        outputs = [pywps.ComplexOutput('response',
                                       'Output response',
                                       supported_formats=[pywps.Format('application/gml+xml')])]

        super(EchoVector, self).__init__(
            self._handler,
            identifier='echo_vector',
            title='Echo Vector Test',
            abstract='Returns the given vector',
            version='1.0.0.0',
            inputs=inputs,
            outputs=outputs,
            store_supported=True,
            status_supported=True
        )

    def _handler(self, request, response):
        response.outputs['response'].data = request.inputs['message'][0].data

        return response

app = flask.Flask(__name__)

wps_processes = [EchoVector()]

service = pywps.Service(wps_processes)

@app.route('/wps', methods=['GET', 'POST'])
def wps():
    return service

bind_host='127.0.0.1'
app.run(threaded=True,host=bind_host)

This is what I have so far for the client:

import owslib.wps
import collections

url = "http://127.0.0.1:5000/wps"
wps = owslib.wps.WebProcessingService(url, verbose=False, skip_caps=True)
wps.getcapabilities()

process_name = "echo_vector"
inputs = [("message", owslib.wps.GMLMultiPolygonFeatureCollection([[(-102.8184, 39.5273),
                                                                    (-102.8184, 37.418),
                                                                    (-101.2363, 37.418),
                                                                    (-101.2363, 39.5273),
                                                                    (-102.8184, 39.5273)]]))]

execution = wps.execute(process_name, inputs)

for output in execution.processOutputs:
    owslib.wps.printInputOutput(output)

I get am getting an "Invalid mimeType value text/xml for input message" exception.

This code is also available in this GitHub repository

2

The problem here is that OGR’s ExportToGML doesn’t declare a namespace prefix / uri in the output, which would make the ExecuteResponse XML choke parsers. I've opened a GDAL ticket to address this.

In the meantime, as a workaround, you can adjust the output of ExportToGML as described here, i.e.:

def _setNamespace(xml, prefix, uri):
    return xml.replace('>', ' xmlns:%s="%s">' % (prefix, uri), 1)

better_gml = _setNamespace(geom.ExportToGML(), 'gml', 'http://www.opengis.net/gml')
| improve this answer | |

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.