5 import os
,time
,string
,sys
,Gnuplot
,re
6 from pywps
.Process
.Process
import WPSProcess
8 class Process(WPSProcess
):
10 WPSProcess
.__init
__(self
,
11 identifier
= "shortestpath",
12 title
="Shortest path",
13 abstract
="Find the shortest path on the Trentino SAT network",
15 storeSupported
= True,
16 statusSupported
= True,
19 self
.x1
= self
.addLiteralInput(identifier
="x1",
20 title
= "Start x coordinate",
23 self
.y1
= self
.addLiteralInput(identifier
="y1",
24 title
= "Start y coordinate",
27 self
.x2
= self
.addLiteralInput(identifier
="x2",
28 title
= "End x coordinate",
31 self
.y2
= self
.addLiteralInput(identifier
="y2",
32 title
= "End y coordinate",
35 self
.cost
= self
.addLiteralInput(identifier
="cost",
36 title
= "Start x coordinate",
39 self
.los
= self
.addComplexOutput(identifier
= "los",
40 title
= "Resulting output map",
41 formats
= [{"mimeType":"text/xml"}])
44 self
.cmd("g.mapset mapset=nico")
45 self
.cmd("g.region -d")
46 self
.status
.set(msg
="Region setted", percentDone
=20)
47 # self.cmd("v.buffer input=roads output=roads_buff buffer=100 scale=1.0 tolerance=0.01")
48 # if int(self.cost.value) == 1:
49 # self.cmd("echo '0 %s %s %s %s ' | v.net.path in=roads_buff out=path afcolumn=COST2 dmax=5000 abcolumn=COST2 1>&2" %\
50 # (self.x1.value,self.y1.value,self.x2.value,self.y2.value))
52 # self.cmd("v.net.path in=roads out=path dmax=5000 --o >&2" %\
53 # self.cmd("echo 0 %s %s %s %s | v.net.path input=roads output=path --o" %\
54 # self.cmd("v.net.path input=allgpx output=path ","1 %s %s %s %s" %
55 #(self.x1.value,self.y1.value,self.x2.value,self.y2.value))
56 self
.cmd("echo ""0 %s %s %s %s"" | v.net.path input=allgpx output=path --o" % (self
.x1
.value
,self
.y1
.value
,self
.x2
.value
,self
.y2
.value
))
57 self
.status
.set(msg
="Path created",percentDone
=40)
58 # self.cmd("r.profile input=elevation.10m output=app.p profile=591525.38,4914696.00,600678.75,4925038.12")
59 # self.cmd("echo $(tail -n +13 /home/nico/app.point | head -n -2 | tr " " "," | tr \"\n\" \" \" | tr -d \" \" | tail -c +2) > /home/nico/point")
60 self
.cmd("v.out.ascii input=path output=/tmp/grass/app.point format=standard")
63 f
=open('/tmp/grass/app.point', 'r')
69 #check if the coordinates are correct
72 coords
=coords
+re
.sub(' +',',',line
.strip())+','
73 coords
=coords
.rstrip(',')
76 #Elaboro path per avere le coordinate necessarie
77 self
.cmd("r.profile input=elevation profile=%s output=/tmp/grass/path.profile" % coords
)
78 self
.status
.set(msg
="Altimetric Profile created",percentDone
=60)
80 g
.title('Profilo altimetrico del sentiero')
81 g
.xlabel('Distanza percorsa')
82 g
.ylabel('Altitudine')
83 g('set terminal unknown')
84 g('set data style lines')
85 g
.plot(Gnuplot
.File('/tmp/grass/path.profile', title
=None))
86 g
.hardcopy('/tmp/grass/tmp.png',terminal
= 'png')
87 self
.status
.set(msg
="Gnuplot image generated",percentDone
=70)
88 self
.cmd("v.out.ogr format=GML input=path dsn=out.xml olayer=path.xml")
89 self
.status
.set(msg
="Results saved", percentDone
=80)
92 if "out.xml" in os
.listdir(os
.curdir
):
93 self
.los
.setValue("out.xml")
96 return "Output file not created"