Closed AMBarbosa closed 2 years ago
I have added that functionality via an argument to centroids
. Do you think that is reasonable?
library(terra)
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
x <- centroids(v)
y <- centroids(v, inside=TRUE)
plot(v)
points(x)
points(y, col="red")
That's awesome, thanks! However, with inside=TRUE
for an input lines map, we get "Error: [] input must be polygons". If it's not too much trouble to implement this for lines too, that would be great. Cheers!
v <- as.lines(crop(v, ext(6, 6.2, 49, 49.6)))
plot(v)
plot(centroids(v), add=TRUE)
plot(centroids(v, inside=TRUE), add=TRUE)
Did not think of lines. Fixed now.
A function analogous to
rgeos::gPointOnSurface
orsf::st_point_on_surface
would also be useful in 'terra', as well as mentioning it in the "See also" section of?centroids
. Cheers!