I have some SpatVector objects from which I would like to get the point coordinates back out. From the documentation and examples, it looks like as.data.frame should do the job…
sq = terra::vect(cbind(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)), type = "points", crs = "local")
terra::as.data.frame(sq)
… but I am only getting empty values.
data frame with 0 columns and 0 rows
What is the correct way to get the matrix/data.frame of coordinates in this situation?
>Solution :
terra::geom() returns a matrix with i.a. coordinate columns which you can convert to a data frame as follows (using your example data sq):
sq |> geom() |> as.data.frame()
geom part x y hole
1 1 1 0 0 0
2 2 1 1 0 0
3 3 1 1 1 0
4 4 1 0 1 0
5 5 1 0 0 0