/
grassbuffer.py
53 lines (41 loc) · 1.82 KB
/
grassbuffer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from pywps import Process, LiteralInput, ComplexInput, ComplexOutput, Format
from pywps.validator.mode import MODE
__author__ = 'Jachym'
class GrassBuffer(Process):
def __init__(self):
inputs = [ComplexInput('poly_in', 'Input1',
supported_formats=[Format('application/gml+xml')],
mode=MODE.SIMPLE),
LiteralInput('buffer', 'Buffer', data_type='float',
allowed_values=(0, 1, 10, (10, 10, 100), (100, 100, 1000)))]
outputs = [ComplexOutput('buff_out', 'Buffered',
supported_formats=[
Format('application/gml+xml')
])]
super(GrassBuffer, self).__init__(
self._handler,
identifier='grassbuffer',
version='0.1',
title="GRASS v.buffer",
abstract='The process uses the GRASS GIS \
v.buffer module to generate buffers around inputs ',
profile='',
inputs=inputs,
outputs=outputs,
store_supported=True,
status_supported=True,
# grass_location="/tmp/outputs/pyws_process_GMkyxP/pywps_location"
grass_location="epsg:3857"
)
def _handler(self, request, response):
from grass.pygrass.modules import Module
Module('v.import',
input=request.inputs['poly_in'][0].file,
epsg=3857, output='poly', extent='input')
Module('v.buffer',
input='poly',
distance=request.inputs['buffer'][0].data,
output='buffer')
Module('v.out.ogr', input='buffer', output='buffer.gml', format='GML')
response.outputs['buff_out'].file = 'buffer.gml'
return response