Well, not a python solution, but you might find it useful.
In Windows you could try the shell (command prompt) there as well:
First get a list of your observers in a file, say obspoints.txt
v.out.ascii input=myobs@user output=c:\obspoints.txt fs=, dp=2
then run the shell's FOR command (run a help for more on the syntax)
ALL must run in ONE LINE (and you must be running Grass in from the
command prompt should be somewhere in the menu):
FOR /F "tokens=1,2,3 delims=, " %i in (obspoints.txt) do r.los
--overwrite input=mydtm@user output=obs%k coordinate=%i,%j
(here tokens are the columns, X,Y,ID - and replace r.los with the newer
r.viewshed)
Then use g.mlist to make a list of your files
g.mlist pattern=’obs*’ mapset=user sep=,
and use the output of the list with r.series (method=sum) to get what
you want.
r.series --overwrite input=amap,bmap,... output=outshed method=sum
(in r.series manual page, it is suggested that you could use g.mlist
inside r.series but I have not managed to do it correctly -maybe someone
can explain better the use of quotes?)
HTH
sotiris
On 01/08/2013 06:53 PM, Brian Sanjeewa Rupasinghe wrote:
Hi,
Thanks again. Since i use GRASS 7.0, it will not work there. I do not
think it can either be installed in GRASS for Windows through Add-on
extensions. What about using grass.mapcalc to integrate each viewshed
if there is a method of handling variables in it? If not how about
using r.series with sum? Your advice is appreciated since i am
pretty new to GRASS.
On Tue, Jan 8, 2013 at 9:19 PM, Leonidas Liakos
<leonidas_liakos@yahoo.gr <mailto:leonidas_liakos@yahoo.gr>> wrote:
Do you need cumulative viewshed analysis?
Maybe r.cva is for you:
http://www.ucl.ac.uk/~tcrnmar/GIS/r.cva.html
<http://www.ucl.ac.uk/~tcrnmar/GIS/r.cva.html>
------------------------------------------------------------------------
*Απο:* Brian Sanjeewa Rupasinghe <jinkabs@gmail.com
<mailto:jinkabs@gmail.com>>
*Προς:* Anna Kratochvílová <kratochanna@gmail.com
<mailto:kratochanna@gmail.com>>; grass-user@lists.osgeo.org
<mailto:grass-user@lists.osgeo.org>
*Στάλθηκε:* 2:45 μ.μ. Τρίτη, 8 Ιανουαρίου 2013
*Θέμα:* Re: [GRASS-user] Using a variable inside GRASS commands
with Python code/ grass.mapcalc
Hi,
Many thanks. It worked for me. Then i have a similar problem in
GRASS.mapcalc. What i need next is to add viewshed of each
observer location cumulatively while looping through the observer
locations in order to have final integrated viewshed analysis map.
So i used the following command in Python (some code ommitted)
for i in:
grass.run_command('r.viewshed', input = rinput, output =
'viewshed', coordinate = [x,y], obs_elev = oelv, tgt_elev = th,
memory = 4098, flags = 'b', overwrite = True, quiet = True)
grass.mapcalc("viewshed_cum = viewshed + viewshed_cum", overwrite
= True, quiet = True)
It seems that expressions like sum = c + sum does not work inside
grass.mapcalc.Is <http://grass.mapcalc.is/> there any alternative
or other way around to get this done? I am using GRASS 7 in Windows 7.
Cheers, Brian
On Tue, Jan 8, 2013 at 1:25 PM, Anna Kratochvílová
<kratochanna@gmail.com <mailto:kratochanna@gmail.com>> wrote:
Hi Brian,
On Tue, Jan 8, 2013 at 6:51 AM, Brian Sanjeewa Rupasinghe
<jinkabs@gmail.com <mailto:jinkabs@gmail.com>> wrote:
> Hi all
>
> I am generating viewshed of each observer location by
iterating through a
> set of observer coordinate file through
> Python code in Windows 7 . Below is the python command used
in grass for
> each iteration. According to this, each time
> loop iterates, output is overwritten with the same name. Now
what i need is
> to keep each output of all the observer locations. For this,
i need to
> concatanate output name (i.e. 'viewshed' with loop index i
which will be
> 'viewshed' + str(i) ). How is that possible within
> this grass.run_command?
>
just set a variable within each loop and use it in the
run_command:
for i in ... :
out = 'viewshed' + str(i)
grass.run_command('r.viewshed', input = rinput, output = out, ...)
Regards,
Anna
> grass.run_command('r.viewshed', input = rinput, output =
'viewshed',
> coordinate = [x,y], obs_elev = oelv, tgt_elev = th, memory =
4098, flags =
> 'b', overwrite = True, quiet = True)
>
> Cheers, Brian
>
> _______________________________________________
> grass-user mailing list
> grass-user@lists.osgeo.org <mailto:grass-user@lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/grass-user
>
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org <mailto:grass-user@lists.osgeo.org>
http://lists.osgeo.org/mailman/listinfo/grass-user
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user