Created
September 9, 2020 12:05
-
-
Save nf-s/b73af087e315f50b24260b58b0383594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from pywps import Process, ComplexInput, ComplexOutput, Format | |
class WpsTestProcess(Process): | |
def __init__(self): | |
inputs = [ComplexInput('in', 'GeoJSON Input', | |
supported_formats=[Format("application/vnd.geo+json", | |
schema="http://geojson.org/geojson-spec.html#geojson")])] | |
outputs = [ComplexOutput('out', 'Referenced Output', | |
supported_formats=[Format("application/vnd.terriajs.catalog-member+json")]), | |
ComplexOutput('another_output', 'Referenced Output', | |
supported_formats=[Format("application/vnd.terriajs.catalog-member+json")]) | |
] | |
super(WpsTestProcess, self).__init__( | |
self._handler, | |
identifier='wps_test_process', | |
title='WPS Process title', | |
version='1.0.0', | |
abstract="WPS process abstract", | |
inputs=inputs, | |
outputs=outputs, | |
store_supported=True, | |
status_supported=True | |
) | |
def _handler(self, request, response): | |
# input geojson | |
input_fc = json.loads(request.inputs['in'][0].data) | |
# do something... | |
# Return terria catalog json (containing input geojson) | |
output_terria_catalog = {"name": "Some WPS Process Result | |
"type": "geojson", | |
"clampToGround": True, | |
"isEnabled": True, | |
"isShown": True, | |
"opacity": 1, | |
"data": input_fc} | |
out_bytes = json.dumps(output_terria_catalog, indent=2) | |
response.outputs['out'].output_format = 'application/vnd.terriajs.catalog-member+json' | |
response.outputs['out'].data = out_bytes | |
# You could have another output catalog item... | |
out2_bytes = json.dumps(output_terria_catalog, indent=2) | |
response.outputs['another_output'].output_format = 'application/vnd.terriajs.catalog-member+json' | |
response.outputs['another_output'].data = out2_bytes | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment