I have 15 viewsheds (view 0-14) from which I would like to export the cell count. I can do this for one viewshed through:


viewshedSize=grass.read_command("r.stats", overwrite=True,flags="c", input="view0")
countsperline= viewshedSize.split("\n")
count.append(type(float(countsperline[1].split(" ")[1])))

How can I run a loop to do this for each viewshed?

  • Hi New Contributor. It looks like you are asking how to write a for loop in Python? I'm not certain, but if so, the question is better asked on a different site, and the answer is for i in range(13): And then in the loop maybe replace "view0" with "view"+str(i) – mankoff May 20 '20 at 14:35
  • Thank you, appreciate the help. Will try another site for future python related questions – grassgis1234 May 20 '20 at 16:10
  • See here: grass.osgeo.org/grass7/manuals/addons/r.viewshed.cva.html for a Python implementation of cumulative viewsheds: r.viewshed.cva undertakes a "cumulative viewshed analysis" using a vector points map as input "viewing" locations, using r.viewshed to calculate the individual viewsheds. – markusN May 22 '20 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.