[R-sig-Geo] From Spatial Points Data Frame to Spatial Polygons Data Frame

Agustin Lobo alobolistas at gmail.com
Thu Jan 23 14:06:38 CET 2014


Hi!

I'm trying to convert an SPointsDF of a set of points
distributed as the centers of the cells of a 4x5 grid
into a SPolygonsDF
This is because the data actually come from the cell and not
just from its center, and want to be able to export as shape and display the
polygon grid on top of other information. The central points
are not sufficient.

The way I'm doing it is not good because I lose the slot data
of the SPointsDF. I can attach the data to the polygons afterwards, but
the original points follow a weird order and I'm concerned about
not attaching the data in the correct order.
Hopefully somebody can suggest an alternative way that would keep
the data slot.

What I do is:

load("https://dl.dropboxusercontent.com/u/3180464/tmetad1.rda")
tmetadg  <- points2grid(tmetad1,tolerance=0.000856898)
tmetadg2  <- SpatialGrid(tmetadg, proj4string=CRS("+init=epsg:4326"))
tmetadpol <- as(tmetadg2, "SpatialPolygons")

I can try with:
tmetadpolDF <- SpatialPolygonsDataFrame(tmetadpol,data=tmetad1 at data,match.ID=FALSE)

but the data actually get in a wrong order (by rows instead of by columns).
The row.names of tmetad1 at coords are not saved in tmetadg, so do not
see how I could
use match.ID.

Thanks

Agus



More information about the R-sig-Geo mailing list