I have a SpatialPointsDataFrame defining SD boundary, however when I compute the center with gCentroid
it's shifted.
c. = rgeos::gCentroid(c.) %>% as.data.frame()
I have a SpatialPointsDataFrame defining SD boundary, however when I compute the center with gCentroid
it's shifted.
c. = rgeos::gCentroid(c.) %>% as.data.frame()
It is because the mass of points is higher in the lower right corner. If you transform your object to a SpatialPolygons
object (making it one shape) then it works:
poly <- SpatialPolygons(Srl = list(Polygons( srl = list(Polygon(coords = coordinates(dat))), ID = 1)))
gCentroid(spgeom = poly)
plot(poly)
axis(1)
axis(2)
points(gCentroid(poly))
© 2022 - 2024 — McMap. All rights reserved.