0

I see that spDists can return distances between two shapefiles in either Euclidean distance, or Great Circle distance, and that if you are looking at the distance between shapefiles, that distance will be specified in terms of their projection.

However, I am looking at the distances between two un-projected SpatialPointsDataFrames. Both have the following CRS: +proj=longlat +datum=WGS84 +no_defs

The code that I'm using is here:

mindist = apply(spDists(dhs2016, znshp), 1, min)

Both dhs2016 and znshp are SpatialPointsDataFrames, and this apply() finds the minimum distance between each point in dhs2016 and its nearest point in znshp. I can see that R is measuring distance as Great Circle distance (I think Euclidean would be going "through" the globe?), by playing with the longlat= argument. But what are the units? I'm guessing km, but not sure.

Jessica Burnett
  • 395
  • 1
  • 13
Leah Bevis
  • 317
  • 1
  • 11
  • Can you please provide a reprex, or at least post the code you are calling? Otherwise, it's difficult to tell whether the units are represented as degrees or radians. – Jessica Burnett Nov 24 '21 at 20:22
  • Absolutely, sorry. Altered it above to include the code. – Leah Bevis Nov 24 '21 at 23:00
  • The [documentation](https://stackoverflow.com/questions/67194497/spproj4stringobj-crs-object-has-comment-which-is-lost-in-output-in-r) for `sp::spDists` says: "spDistsN1 returns a numeric vector of distances in the metric of the points if longlat=FALSE, or in kilometers if longlat=TRUE." Therefore, I suspect your units are in decimal degrees because the `longlat` argument defaults to FALSE, which calculates Euclidean distance (sqrt of sum of sqs) – Jessica Burnett Nov 25 '21 at 21:03
  • Actually the longlat defaults to TRUE -- that's why I say that I can tell it's in Great Circle Distance. If I try FALSE it gives me the error "argument longlat conflicts with CRS(x); using the value FALSE." So I know it's great circle distance. Howeer, the help file also says "if x is a Spatial object, longlat should not be specified but will be derived from is.projected(x)" -- however, I don't know what would be "derived" from the non-projected CRS above. – Leah Bevis Nov 29 '21 at 00:56
  • can you provide samples of the data? – Jessica Burnett Nov 30 '21 at 00:03
  • I can, though it requires exporting both shapefiles from R; I'll try to do this today/tonight. I think the key info is that they are SpatialPointsDataFrames with identical CRS = +proj=longlat +datum=WGS84 +no_defs. I just don't know how R measures Great Circle distance in a lat/lon, non-projected coordinate system. This info has to be out there, but I can't find it. – Leah Bevis Nov 30 '21 at 19:27
  • You can do `dput(SPDF[1:100,])` to add samples of the data (here, first 100 rows/features of the attributes are included) to your original post to provide reprex for us to test – Jessica Burnett Nov 30 '21 at 19:55

0 Answers0