[R-sig-Geo] Converting Spatial Polygons to data frame for krige.conv

Ben Madin lists at remoteinformation.com.au
Mon May 30 18:28:15 CEST 2011


Thanks Tom,

On 30/05/2011, at 2:24 PM, Tom Gottfried wrote:

> do you want the coordinates of all the vertices of your polygons?
> Have a look at ?geometry. But this doesn't take you down to a mere list of coordinates. There might be a more elegant way, but you can try that little function to achieve this:
> 
>    asText.SpatialPolygonsDataFrame <- function(obj){
>        coords <- matrix(double(), ncol=3)
>        for (Polygons in obj at polygons){
>            for (Polygon in Polygons at Polygons){
>                coords <- rbind(coords,
>                    cbind(as.integer(Polygons at ID), Polygon at coords),
>                    c(as.integer(Polygons at ID), NA, NA))
>                }
>            }
>        return(coords)
>        }

Perfect. It's where I thought I was going, but it probably would have taken me about two days!

cheers

Ben



More information about the R-sig-Geo mailing list