[GRASS-dev] [GRASS GIS] #3926: allow limit viewshed computation by angle

GRASS GIS trac at osgeo.org
Wed Oct 23 19:51:57 PDT 2019


#3926: allow limit viewshed computation by angle
--------------------------+----------------------------------
  Reporter:  annakrat     |      Owner:  grass-dev@…
      Type:  enhancement  |     Status:  new
  Priority:  normal       |  Milestone:  8.0.0
 Component:  Raster       |    Version:  unspecified
Resolution:               |   Keywords:  r.viewshed, viewshed
       CPU:  All          |   Platform:  All
--------------------------+----------------------------------

Comment (by annakrat):

 For the record, this is my attempt with hardcoded values, which fails with
 angle 1 to 270 (the viewshed is written but incorrect). Interestingly, it
 works with angle 0 to 270.

 {{{
 index 95ecd47..94d0741 100644
 --- a/raster/r.viewshed/eventlist.cpp
 +++ b/raster/r.viewshed/eventlist.cpp
 @@ -605,7 +605,20 @@ int is_point_outside_max_dist(Viewpoint vp,
 GridHeader hd,
      return 0;
  }

 +int is_point_inside_angle(Viewpoint vp,
 +                         dimensionType row, dimensionType col,
 +                         float minAngle, float maxAngle)
 +{
 +    double ang;
 +
 +    ang = atan2(vp.row -row, col - vp.col) * 180 / M_PI;
 +    if (ang < 0)
 +        ang += 360;
 +    if (ang < minAngle || ang > maxAngle)
 +        return 0;

 +    return 1;
 +}

  /* ------------------------------------------------------------
     //note: this is expensive because distance is not stored in the event
 diff --git a/raster/r.viewshed/eventlist.h b/raster/r.viewshed/eventlist.h
 index e071687..234e700 100644
 --- a/raster/r.viewshed/eventlist.h
 +++ b/raster/r.viewshed/eventlist.h
 @@ -74,7 +74,9 @@ is_point_outside_max_dist(Viewpoint vp, GridHeader hd,
                           dimensionType row, dimensionType col,
                           float maxDist);

 -
 +int is_point_inside_angle(Viewpoint vp,
 +                         dimensionType row, dimensionType col,
 +                         float minAngle, float maxAngle);

  /*sort the event list by the angle around the viewpoint) */
  void sort_event_list(AMI_STREAM < AEvent > **eventList);
 diff --git a/raster/r.viewshed/grass.cpp b/raster/r.viewshed/grass.cpp
 index b9dac21..d5fa240 100644
 --- a/raster/r.viewshed/grass.cpp
 +++ b/raster/r.viewshed/grass.cpp
 @@ -316,6 +316,11 @@ init_event_list_in_memory(AEvent * eventList, char
 *rastName,
                 (*vp, *hd, i, j, viewOptions.maxDist))
                 continue;

 +           if (!is_point_inside_angle(*vp, i, j, 1, 270)) {
 +               add_result_to_inmem_visibilitygrid(visgrid, i, j,
 +                                                  hd->nodata_value);
 +               continue;
 +           }
             /* if it got here it is not the viewpoint, not NODATA, and
                within max distance from viewpoint; generate its 3 events
                and insert them */
 }}}

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/3926#comment:1>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list