1
votes

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?

2
it's a centroid, just the geometric middle, not guaranteed to intersect thr polygonmdsumner
@mdsumner would you have any reference on how it is computed ?cmbarbu

2 Answers

4
votes

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

0
votes

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, ...)
}