0

I'm making a QGIS plugin that uses grass:r.viewshed to analyze the area of terrain visible from different points. However, I've noticed, that when using a viewpoint where the elevation between the viewpoint and terrain is greater than the maximum distance parameter, points are still highlighted on the terrain. Surely these should be marked as invisible as they are outside of the view range?

This is my code for the viewshed:


try:
    params = {'input' : rasterName,
              'coordinates': coordStr,
              'observer_elevation': 60000 + depthAtPoint,
              'target_elevation': 3,
              'max_distance': 50000,
              'memory': viewshedMemory,
              'output': pointPath,
              '-b':True}
                    
    result = processing.run("grass7:r.viewshed", 
                             params,
                             feedback=feedback)
except QgsProcessingException as e: #Handle and print any processing exceptions
    print(e)

rasterName contains the name of the raster. In this example I'm using the raster SR_50M_alaska_nad.tif from QGIS's sample data library. (https://download.qgis.org/downloads/data/)

coordStr are the coordinates of the viewpoint.

depthAtPoint is the depth/elevation value sampled from the raster at the coordinates of the viewpoint. I've added 60000 to it in the parameters, which should mean that the terrain is completely out of view from the viewpoint (since the maximum distance is only 50000). But in my results, it still seems to be highlighted, which is the problem. As you can see below, the terrain is still highlighted (red) by the viewshed. Surely it shouldn't be, as the distance from terrain to viewpoint is greater than the max distance?

Image showing the area of terrain highlighted

1 Answer 1

1

The maximum distance is computed as a 2D distance, elevation is not taken into account.

4
  • Would there be any way for this to be changed to a 3D distance?
    – oliver
    Commented May 21 at 7:36
  • 1
    A simplified way would be to provide max distance = sqrt(max 3D distance squared - observer height squared). That assumes flat terrain. You could also postprocess the result by computing the 3D distance for each visible pixel and exclude them based on that. Anything more complex would have to be implemented in r.viewshed, I would be happy to review the pull request.
    – Anna
    Commented May 22 at 12:28
  • Thanks for the informative response. I'm using a similar implementation of that 3D method you mentioned, so glad to see I'm on the right track. Would this also apply to target elevation?
    – oliver
    Commented May 24 at 8:07
  • I would say yes.
    – Anna
    Commented May 26 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.