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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 |
#!/usr/bin/python
"""
pywps process example:
classify: Classify satellite image
"""
# Author: Stepan Kafka
# Lince:
#
# Web Processing Service implementation
# Copyright (C) 2006 Jachym Cepicky
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os,time,string,sys
class Process:
#####################################################################
#
# Configuration part of the process
#
#####################################################################
def __init__(self):
#
# Mandatory parameters
#
# Identifier - name of this process
self.Identifier = "visibility2"
# processVersion - version of this process
self.processVersion = "0.1"
# Title - title for this process
self.Title="Visibility analysis"
self.Abstract="GRASS processed line of sight analysis."
self.Abstract="Generates a raster map output in which the cells that are visible from a user-specified observer location are marked with integer values that represent the vertical a$
self.grassLocation="/home/doktoreas/data/grass/spearfish60/"
#
# Inputs
# Inputs is an array of input structure
# Inputs = [ {input1},{input2},{...} ]
#
self.Inputs = [
# 0
{
'Identifier': 'x',
'Title': 'X coordinate',
'LiteralData': {
'values':["*"],
},
'dataType': type(0.0),
},
# 1
{
'Identifier': 'y',
'Title': 'Y coordinate',
'LiteralData': {
'values':["*"],
},
'dataType': type(0.0),
},
# 2
{
'Identifier':'maxdist',
'Title': 'Maximal distance',
'Abstract':'Maximal distance of visibility (meters)',
'LiteralData': {
'values':["*"],
},
'dataType': type(0.0),
},
# 3
{
'Identifier':'observer',
'Title': 'Observer elevation',
'Abstract':'The height of observer eye over the terrain (meters)',
'LiteralData': {
'values':["*"],
},
'dataType': type(0.0),
}
]
#
# Output
# The structure is not much different from the input structure
#
self.Outputs = [
{
'Identifier': 'output',
'Title': 'Resulting output map',
'ComplexValueReference': {
'Formats':["image/png"],
}
},
]
#
# Optional attributes
#
#
# storeSuport = "true" or "false" - should the resulting map be stored on our disk?
self.storeSupport = "true"
#
# statusSupport = "true" or "false" - if statusLocation is set, the server
# will not wait for the end of the operation and will return the
# ExectuceResponce XML file immediately, without the ProcessOutput section
# but with the statusLocation parameter
self.statusSupport = "true"
# and many others
#####################################################################
#
# Execute part of the process
#
#####################################################################
def execute(self):
os.system("g.region res=60")
dist = int(self.Inputs[2]['value'])
if dist > 20000:
return "Visibility Error: maximal distance 2000 exceeded (%d)" % dist
xmin=int(self.Inputs[0]['value']) - dist
ymin=int(self.Inputs[1]['value']) - dist
xmax=int(self.Inputs[0]['value']) + dist
ymax=int(self.Inputs[1]['value']) + dist
os.system("g.region w=%i s=%i e=%i n=%i align=elevation.dem" % (xmin,ymin,xmax,ymax))
self.status=["Calculating visibility", ""]
os.system("r.los input=elevation.dem output=output coordinate=%s,%s max_dist=%i obs_elev=%s" % \
(self.Inputs[0]['value'],self.Inputs[1]['value'],dist, self.Inputs[3]['value']))
self.status=["Creating output", ""]
sys.stderr.write("r.los input=elevation.dem output=output coordinate=%s,%s max_dist=%i obs_elev=%s\n" %\
(self.Inputs[0]['value'],self.Inputs[1]['value'],dist, self.Inputs[3]['value']))
os.system("""r.mapcalc "output0=if(output,1,0)" """)
os.system("r.out.tiff -t -p input=output0 output=output0")
os.system("/usr/bin/gdal_translate -of GTiff output0.tif output.tif 1>&2")
# check the resulting file or any other variable, which interrests you
if "output.tif" in os.listdir(os.curdir):
self.Outputs[0]['value'] = "output.tif"
return
else:
return "Output file not created" |