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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Jan 23 15:03:05 CET 2014


try:

x = as(SpatialPixelsDataFrame(tmetad1, tmetad1 at data, tolerance=.00086),
	"SpatialPolygonsDataFrame")
spplot(x[2])

On 01/23/2014 02:06 PM, Agustin Lobo wrote:
> 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
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140123/cc727864/attachment.bin>


More information about the R-sig-Geo mailing list