gCentroid shifting centroid towards concentration of points
Asked Answered
G

1

0

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()

Why isn't it plotting it at the center? enter image description here

Gimlet answered 9/4, 2018 at 15:29 Comment(3)
if you apply gCentroid to the bounding box does it still plot like that?Taffrail
good idea, let me tryGimlet
however, the draw back of finding the centroid of the bounding box is that it won't be very well placed for 'strangely' shaped polygonsGimlet
T
2

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)) 

enter image description here

Td answered 9/4, 2018 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.