[R-sig-Geo] Randomly moving a locality (within set limits)

Frede Aakmann Tøgersen frtog at vestas.com
Mon Aug 25 10:26:52 CEST 2014


Hi

The following is based on http://www.movable-type.co.uk/scripts/latlong.html. 

foo <- function(origin, bearing, distance){
    ## origin (lat, lon) is the point to randomly move
    ## bearing (in degrees) is the direction in which to move
    ## the distance to move origin
    
    R = 6378.1 #Radius of the Earth in km

    bearing <- bearing/180 * pi
    
    lat1 = origin[1]/180 * pi #Current lat point converted to radians
    lon1 = origin[2]/180 * pi  #Current long point converted to radians
    
    lat2 = asin( sin(lat1)*cos(distance/R) +
        cos(lat1)*sin(distance/R)*cos(bearing))
    
    lon2 = lon1 + atan2(sin(bearing)*sin(distance/R)*cos(lat1),
        cos(distance/R)-sin(lat1)*sin(lat2))

    ## destination in degrees decimal
    destination <- c(Latitude = lat2/pi*180, Longitude = lon2/pi*180)
    
    return(destination)
}

> foo(c(52.20472, 0.14056), 90, 15)
  Latitude  Longitude 
52.2045157  0.3604334 
>

Now choose

bearing <- runif(1, 0, 360)

and

distance <- runif(1, 0, 15)

Please check the formulas against the homepage above.

Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


> -----Original Message-----
> From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-
> project.org] On Behalf Of Alastair Potts
> Sent: 22. august 2014 13:13
> To: r-sig-geo at r-project.org
> Subject: [R-sig-Geo] Randomly moving a locality (within set limits)
> 
> Hi all,
> 
> I was wondering if someone could help point me in the right direction here
> - I can't seem to find a function or post that focuses on this.
> 
> I have localities around the world. I want to be able to randomly move a
> given locality within a set radius (defined by km). So, I have a point at
> xy and want it to be shifted to some other locality within, say, 15 km of
> of its current locality.
> 
> This is simple enough using something like runif(1,-15,15), but it's the
> lat-long conversion that is confusing me (how to work out how many decimal
> degrees this might be around the point at different global localities).
> 
> Any help or pointers would be greatly appreciated.
> 
> Thanks in advance,
> 
> Cheers,
> Alastair
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list