Changeset 50005


Ignore:
Timestamp:
Dec 31, 2011 5:43:47 AM (4 years ago)
Author:
mmetz
Message:

r.viewshed: add latlong support (backport from trunk)

Location:
grass-addons/grass6/raster/r.viewshed
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • grass-addons/grass6/raster/r.viewshed/eventlist.cpp

    r50003 r50005  
    523523{
    524524
    525     double eventy, eventx;
     525    double eventy, eventx, dist;
    526526
    527527    calculate_event_position(a, vp.row, vp.col, &eventy, &eventx);
    528528
    529     double dist = (eventx - vp.col) * (eventx - vp.col) +
    530         (eventy - vp.row) * (eventy - vp.row);
    531     /*don't take sqrt, it is expensive; suffices for comparison */
     529    if (G_projection() == PROJECTION_LL) {
     530        struct Cell_head window;
     531       
     532        G_get_window(&window);
     533       
     534        dist = G_distance(G_col_to_easting(vp.col + 0.5, &window),
     535                          G_row_to_northing(vp.row + 0.5, &window),
     536                          G_col_to_easting(eventx + 0.5, &window),
     537                          G_row_to_northing(eventy + 0.5, &window));
     538
     539        dist = dist * dist;
     540    }
     541    else {
     542        /*don't take sqrt, it is expensive; suffices for comparison */
     543        dist = (eventx - vp.col) * (eventx - vp.col) +
     544            (eventy - vp.row) * (eventy - vp.row);
     545    }
     546
    532547    return dist;
    533548}
     
    540555{
    541556
    542     double eventy, eventx;
     557    double eventy, eventx, dist;
    543558
    544559    calculate_event_position(a, vp.row, vp.col, &eventy, &eventx);
    545     double dist = (eventx - vp.col) * (eventx - vp.col) +
    546         (eventy - vp.row) * (eventy - vp.row);
    547     /*don't take sqrt, it is expensive; suffices for comparison */
     560
     561    if (G_projection() == PROJECTION_LL) {
     562        struct Cell_head window;
     563       
     564        G_get_window(&window);
     565       
     566        dist = G_distance(G_col_to_easting(vp.col + 0.5, &window),
     567                          G_row_to_northing(vp.row + 0.5, &window),
     568                          G_col_to_easting(eventx + 0.5, &window),
     569                          G_row_to_northing(eventy + 0.5, &window));
     570
     571        dist = dist * dist;
     572    }
     573    else {
     574        /*don't take sqrt, it is expensive; suffices for comparison */
     575        dist = (eventx - vp.col) * (eventx - vp.col) +
     576            (eventy - vp.row) * (eventy - vp.row);
     577    }
    548578
    549579    print_event(a, 2);
     
    579609
    580610/* ------------------------------------------------------------
    581    //note: this is expensive because distance is not storedin the event
     611   //note: this is expensive because distance is not stored in the event
    582612   //and must be computed on the fly */
    583613int DistanceCompare::compare(const AEvent & a, const AEvent & b)
     
    595625
    596626    calculate_event_position(a, globalVP.row, globalVP.col, &eventy, &eventx);
    597     da = (eventx - globalVP.col) * (eventx - globalVP.col) +
    598         (eventy - globalVP.row) * (eventy - globalVP.row);
     627    if (G_projection() == PROJECTION_LL) {
     628        struct Cell_head window;
     629       
     630        G_get_window(&window);
     631       
     632        da = G_distance(G_col_to_easting(globalVP.col + 0.5, &window),
     633                          G_row_to_northing(globalVP.row + 0.5, &window),
     634                          G_col_to_easting(eventx + 0.5, &window),
     635                          G_row_to_northing(eventy + 0.5, &window));
     636
     637        da = da * da;
     638    }
     639    else {
     640        /*don't take sqrt, it is expensive; suffices for comparison */
     641        da = (eventx - globalVP.col) * (eventx - globalVP.col) +
     642            (eventy - globalVP.row) * (eventy - globalVP.row);
     643    }
     644
     645
    599646    calculate_event_position(b, globalVP.row, globalVP.col, &eventy, &eventx);
    600     db = (eventx - globalVP.col) * (eventx - globalVP.col) +
    601         (eventy - globalVP.row) * (eventy - globalVP.row);
     647    if (G_projection() == PROJECTION_LL) {
     648        struct Cell_head window;
     649       
     650        G_get_window(&window);
     651       
     652        db = G_distance(G_col_to_easting(globalVP.col + 0.5, &window),
     653                          G_row_to_northing(globalVP.row + 0.5, &window),
     654                          G_col_to_easting(eventx + 0.5, &window),
     655                          G_row_to_northing(eventy + 0.5, &window));
     656
     657        db = db * db;
     658    }
     659    else {
     660        /*don't take sqrt, it is expensive; suffices for comparison */
     661        db = (eventx - globalVP.col) * (eventx - globalVP.col) +
     662            (eventy - globalVP.row) * (eventy - globalVP.row);
     663    }
    602664
    603665    if (da > db) {
  • grass-addons/grass6/raster/r.viewshed/statusstructure.cpp

    r50003 r50005  
    117117       
    118118    double diffElev = elev - vp->elev;
    119     double dx = ((double)sn->col - vp->col) * hd.ew_res;
    120     double dy = ((double)sn->row - vp->row) * hd.ns_res;
    121119   
    122     sn->dist2vp = (dx * dx) + (dy * dy);
     120    if (G_projection() == PROJECTION_LL) {
     121        double dist = G_distance(G_col_to_easting(sn->col + 0.5, &(hd.window)),
     122                                 G_row_to_northing(sn->row + 0.5, &(hd.window)),
     123                                 G_col_to_easting(vp->col + 0.5, &(hd.window)),
     124                                 G_row_to_northing(vp->row + 0.5, &(hd.window)));
     125
     126        sn->dist2vp = dist * dist;
     127    }
     128    else {
     129        double dx = ((double)sn->col - vp->col) * hd.ew_res;
     130        double dy = ((double)sn->row - vp->row) * hd.ns_res;
     131       
     132        sn->dist2vp = (dx * dx) + (dy * dy);
     133    }
    123134
    124135    if (diffElev == 0) {
     
    163174       
    164175    double diffElev = elev - vp->elev;
    165     double dx = (col - vp->col) * hd.ew_res;
    166     double dy = (row - vp->row) * hd.ns_res;
    167     double dist2vp = (dx * dx) + (dy * dy);
    168 
     176    double dist2vp;
     177
     178    if (G_projection() == PROJECTION_LL) {
     179        double dist = G_distance(G_col_to_easting(col + 0.5, &(hd.window)),
     180                                 G_row_to_northing(row + 0.5, &(hd.window)),
     181                                 G_col_to_easting(vp->col + 0.5, &(hd.window)),
     182                                 G_row_to_northing(vp->row + 0.5, &(hd.window)));
     183
     184        dist2vp = dist * dist;
     185    }
     186    else {
     187        double dx = (col - vp->col) * hd.ew_res;
     188        double dy = (row - vp->row) * hd.ns_res;
     189       
     190        dist2vp = (dx * dx) + (dy * dy);
     191    }
    169192
    170193    /* PI / 2 above, - PI / 2 below */
Note: See TracChangeset for help on using the changeset viewer.