terra icon indicating copy to clipboard operation
terra copied to clipboard

Non expected output of `distance` between `SpatVector` objects

Open LuisLauM opened this issue 4 months ago • 1 comments

Hello.

I am having a little problem with the distance function. When I apply it on two SpatVector objects that have CRS WGS84 (EPSG:4326), the results it returns don't seem to be in meters or km. Maybe I am forgetting some intermediate step, but I don't know which one exactly. I leave my script and the reproducible data:

require(terra)

# Read main polygon of Peru
peru <- vect(x = "gadm41_PER.gpkg", 
             layer = "ADM_ADM_0")

# Convert lon/lat coordinates 
read.csv(file = "lonlat_pts.csv") |> 
  
  # Convert to SpatVector object
  vect(crs = "EPSG:4326") |> 
  
  # Calculate distances in meters
  distance(y = peru, unit = "m")

When I change the unit argument from m to km, the results are divided by 1000 (logically), but the values are not correct and seem to be affected on a scale of ~105. That is, 1m in the result (of the script) represents ~105m in reality.

Data:

I'm using the latest (Github) version of terra: 1.7.82

LuisLauM avatar Oct 07 '24 09:10 LuisLauM