[R-sig-Geo] map to shapefile with projection info

Sebastian P. Luque spluque at gmail.com
Wed Dec 6 21:00:38 CET 2006

On Wed, 6 Dec 2006 20:28:42 +0100 (CET),
Roger Bivand <Roger.Bivand at nhh.no> wrote:


> canada <- map("world2Hires", "Canada", fill=TRUE, plot=FALSE)

> fill=TRUE retrives polygons, otherwise you get line segments. For this
> example it now works. You can also make several retrieved island belong
> to the same Polygons object by giving them the same ID. There is an
> example on the pal2SpatialPolygons help page.

Thanks Roger, I didn't pick up that effect of the 'fill' arg.  I noticed
also that I needed c("Canada", "Newfoundland"), as the latter island was
not included!  I'll report this.


> In rgdal (the PROJ.4 library is needed):

> names <- sapply(slot(canada_sp, "polygons"), function(i) slot(i, "ID"))
> canada_spdf <- SpatialPolygonsDataFrame(canada_sp,
>   data=data.frame(names=names, row.names=names))
> writeOGR(canada_spdf, dsn=".", layer="canada", driver="ESRI Shapefile")
> list.files(pattern="canada")

Exactly.  Thanks a lot.



More information about the R-sig-Geo mailing list