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
.cost
= self
.addLiteralInput(identifier
="cost",
20 title
= "Start x coordinate",
23 self
.coord
= self
.addLiteralInput(identifier
="coord",
29 self
.los
= self
.addComplexOutput(identifier
= "los",
30 title
= "Resulting output map",
31 formats
= [{"mimeType":"text/xml"}])
35 self
.cmd("g.mapset mapset=nico")
36 self
.cmd("g.region -d")
37 self
.status
.set(msg
="Region setted", percentDone
=20)
38 lpoints
=self
.coord
.value
[0].split(",")
40 #Points are stored in lpoints
41 #we must find every shortest path between two consecutive point and
43 npoints
=len(lpoints
)/2
44 #the number of loop cycle in which shortest path is called is npoints-1
47 for i
in range(2,2*npoints
-1,2):
50 #Find the shortest path between the two points
51 self
.cmd("echo ""0 %s %s %s %s"" | v.net.path input=allgpx output=path --o" % (x1
,y1
,x2
,y2
))
52 #print "echo shortest between"+x1+","+y1+":"+x2+","+y2
54 #self.cmd("v.overlay")
55 #add to the final path the segment
60 self
.status
.set(msg
="Path created",percentDone
=40)
61 self
.cmd("v.out.ascii input=path output=/tmp/grass/app.point format=standard")
64 f
=open('/tmp/grass/app.point', 'r')
67 for i
in range(13,l
-2):
69 coords
=coords
+re
.sub(' +',',',h
[i
].strip())+','
70 coords
=coords
.rstrip(',')
72 self
.cmd("r.profile input=elevation profile=%s output=/tmp/grass/path.profile" % coords
)
73 self
.status
.set(msg
="Altimetric Profile created",percentDone
=60)
75 g
.title('Profilo altimetrico del sentiero')
76 g
.xlabel('Distanza percorsa')
77 g
.ylabel('Altitudine')
78 g('set terminal unknown')
79 g('set data style lines')
80 g
.plot(Gnuplot
.File('/tmp/grass/path.profile', title
=None))
81 g
.hardcopy('/tmp/grass/profile.png',terminal
= 'png')
82 self
.status
.set(msg
="Gnuplot image generated",percentDone
=70)
83 self
.cmd("v.out.ogr format=GML input=path dsn=out.xml olayer=path.xml")
84 self
.status
.set(msg
="Results saved", percentDone
=80)
87 if "out.xml" in os
.listdir(os
.curdir
):
88 self
.los
.setValue("out.xml")
91 return "Output file not created"