Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non expected output of distance between SpatVector objects #1615

Open
LuisLauM opened this issue Oct 7, 2024 · 1 comment
Open

Non expected output of distance between SpatVector objects #1615

LuisLauM opened this issue Oct 7, 2024 · 1 comment

Comments

@LuisLauM
Copy link

LuisLauM commented Oct 7, 2024

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

@kadyb
Copy link
Contributor

kadyb commented Oct 7, 2024

This is described in the docs:

If x is a SpatVector: The distance is always expressed in meter, except when the coordinate reference system is longitude/latitude AND one of the SpatVector(s) consists of lines or polygons. In that case the distance is in degrees, and thus not very useful (this will be fixed soon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants