[R-sig-Geo] How to create a SpatialPolygonsDataFrame object
Roger Bivand
Roger.Bivand at nhh.no
Tue Nov 10 09:20:12 CET 2009
On Mon, 9 Nov 2009, Chen, Shaofei wrote:
> Hello everyone,
>
> I can read polygon shape files into SpatialPolygonsDataFrame objects
> using maptools library. But how to create a SpatialPolygonsDataFrame
> object, for example, a 400 by 400 polygon? Thank you in advance!
Something like:
library(sp)
crds <- cbind(x=c(0, 0, 400, 400, 0), y=c(0, 400, 400, 0, 0))
# str(crds)
Pl <- Polygon(crds)
# str(Pl)
ID <- "400x400"
Pls <- Polygons(list(Pl), ID=ID)
# str(Pls)
SPls <- SpatialPolygons(list(Pls))
# str(SPls)
df <- data.frame(value=1, row.names=ID)
# str(df)
SPDF <- SpatialPolygonsDataFrame(SPls, df)
# str(SPDF)
Uncomment the # str() lines to follow the development of the structure of
the object.
Hope this helps,
Roger
>
> Best,
> Shaofei
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list