R_Extracting coordinates from SpatialPolygonsDataFrame

后端 未结 5 790
無奈伤痛
無奈伤痛 2020-12-31 11:52

Is it only me who have the problem with extracting coordinates of a polygon from SpatialPolygonsDataFrame object? I am able to extract other slots of the object

5条回答
  •  再見小時候
    2020-12-31 12:30

    This took me a while to figure out too. The following function I wrote worked for me. sp.df should be SpatialPolygonsDataFrame.

    extractCoords <- function(sp.df)
    {
        results <- list()
        for(i in 1:length(sp.df@polygons[[1]]@Polygons))
        {
            results[[i]] <- sp.df@polygons[[1]]@Polygons[[i]]@coords
        }
        results <- Reduce(rbind, results)
        results
    }
    

提交回复
热议问题