问题
I am trying to get a pseudo barycenter for polygons in a spatial polygon dataframe. Today I stumbled upon the coordinates
function that actually returns something for a SpatialPolygonsDataFrame.
Unfortunately I found nothing in the help of coordinates
about the value for SpatialPolygonsDataFrame. Could somebody tell me what these coordinates are?
回答1:
It is the polygon centroid. The source code is found here, look for function FindCG
. The equations computed are equivalent to those found on wikipedia, but in addition deal with the special case of polygons with (near) zero area, and normalize polygon coordinates by the first point (to increase numerical precision and/or avoid overflow).
回答2:
Reading the definition of coordinates for SpatialPolygonsDataFrame I can see that it is actually the same than getSpPPolygonsLabptSlots
as it retrieves the labpt
slot, that is to say a convenient point to put a label for the polygon.
> selectMethod("coordinates",signature="SpatialPolygonsDataFrame")
Method Definition:
function (obj, ...)
{
.local <- function (obj)
{
ret = t(sapply(slot(obj, "polygons"), function(i) slot(i,
"labpt")))
dimnames(ret) = list(sapply(slot(obj, "polygons"), function(i) slot(i,
"ID")), NULL)
ret
}
.local(obj, ...)
}
来源:https://stackoverflow.com/questions/29565769/value-of-coordinates-for-a-spatialpolygonsdataframe-object