[R-sig-Geo] Verify units of distance between coordinates

Roger Bivand Roger.Bivand at nhh.no
Thu Aug 28 17:02:26 CEST 2014


On Thu, 28 Aug 2014, Roger Bivand wrote:

> On Thu, 28 Aug 2014, Sarah Goslee wrote:
>
>> On Thu, Aug 28, 2014 at 9:32 AM, Michael Sumner <mdsumner at gmail.com> wrote:
>>> On Thu, Aug 28, 2014 at 10:50 PM, Sarah Goslee <sarah.goslee at gmail.com> 
>>> wrote:
>>>> They don't make sense.
>>>> 
>>>> Best: convert them into a projection where the distances are in meters
>>>> already, like UTM. Then distances calculated on your new coordinates
>>>> are in meters.
>>> 
>>> However great circle from lat/lon is arguably the best since you can
>>> really do get distance along a great circle (on the ellipsoid or the
>>> sphere). (There are several algorithms, and also other methods for
>>> e.g. loxodromes, and even other definitions of "straight".)
>>> 
>>> No projection has the property that any straight line is a great
>>> circle, and most certainly *not* any of UTM family.
>> 
>> True, but as long as your points are reasonably close together,
>> something like UTM is a very useful approximation. And even great
>> circle is an approximation. The best answer depends on the data and
>> the objectives (as always!).
>
> The OP didn't say how the distances were computed:
>
> library(sp)
> locs <- SpatialPoints(cbind(Lon = c(29.6000, 29.7333, 30.3887, 30.6667,
> 30.6833, 30.8667), Lat = c(-4.9000, -4.6000, -5.1280, -1.0667, -2.7500,
> -3.3833)), proj4string=CRS("+proj=longlat +datum=WGS84") )
> src <- SpatialPoints(cbind(LonWater = c(29.63333, 29.63333, 30.25000,
> 30.65000, 30.35444, 30.83278), LatWater = c(-4.31667, -4.31667, -4.76667,
> -1.35000, -2.46667, -3.57000)),
> proj4string=CRS("+proj=longlat +datum=WGS84"))
>
> plot(locs)
> plot(src, add=TRUE, col="red")
>
> Naively using spDistsN1 appears to replicate the distances the OP got:
>
> D0 <- lapply(1:length(locs), function(i) spDistsN1(src, locs[i],
> longlat=FALSE))
>
> which is wrong.
>
> D0 <- lapply(1:length(locs), function(i) spDistsN1(src, locs[i],
> longlat=TRUE))

Sorry:

D <- lapply(1:length(locs), function(i) spDistsN1(src, locs[i],
  longlat=TRUE))

of course.

>
> is in km, but the minimum criterion is met by multiple pairs of points:
>
> D1 <- lapply(D, function(x) x-min(x))
> D1
>
> so finding out which source is closest still isn't well-defined. To get 
> minimum distances by location:
>
> D2 <- sapply(D, min)
>
> The spDists* functions use GC distances on a WGS84 ellipsoid, so are closer 
> than a spheroid (many online shortcuts use spheroids), and will be OK if the 
> input coordinates are also WGS84.
>
> Hope this helps,
>
> Roger
>
>> 
>>> Cheers, Mike.
>>> 
>>> 
>>>> 
>>>> Latitude and longitude don't translate neatly into distances on their 
>>>> own.
>>>> 
>>>> Second best: find and use a great circle distance function that can
>>>> determine the correct distances for where those lat/lon coordinates
>>>> are on the earth's surface. There's been discussion on this list
>>>> before about calculating distances from geographic coordinates; google
>>>> should find them.
>>>> 
>>>> Sarah
>>>> 
>>>> On Thu, Aug 28, 2014 at 8:44 AM, Justin Michell <jwm302 at gmail.com> wrote:
>>>>> Dear geo R group
>>>>> 
>>>>> I have a data frame like this:
>>>>> 
>>>>> df <- data.frame(Lon = 
>>>>> c(29.6000,29.7333,30.3887,30.6667,30.6833,30.8667), Lat = 
>>>>> c(-4.9000,-4.6000,-5.1280,-1.0667,-2.7500,-3.3833),
>>>>>                   LonWater = 
>>>>> c(29.63333,29.63333,30.25000,30.65000,30.35444,30.83278), LatWater = 
>>>>> c(-4.31667,-4.31667,-4.76667,-1.35000,-2.46667,-3.57000), DstClW = 
>>>>> c(0.5842815,0.3004491,0.3870362,0.2837918,0.4340793,0.1897561) )
>>>>> 
>>>>> At these locations (Lon, Lat pairs) I calculated the shortest distance 
>>>>> to a water source (DstClW) and where that source is (LonWater, 
>>>>> LatWater).
>>>>> 
>>>>> I want to now determine what units DstClW is in, and also verify that 
>>>>> these distances make sense and were calculated correctly.
>>>>> 
>>>>> Any suggestions as to how this might be done?
>>>>> 
>>>>> Regards
>>>>> Justin Michell
>>>>> 
>>>>> 
>> 
>> 
>> 
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list