Converting a "map" object to a "SpatialPolygon" object Converting a "map" object to a "SpatialPolygon" object r r

Converting a "map" object to a "SpatialPolygon" object


Just found some code in the text "Applied Spatial Data Analysis with R". It works great!

require(maps)usa <- map("state", fill = TRUE)require(sp)require(maptools)IDs <- sapply(strsplit(usa$names, ":"), function(x) x[1])usa <- map2SpatialPolygons(usa, IDs=IDs, proj4string=CRS("+proj=longlat +datum=WGS84"))


Polygons have surface (area), therefore the key argument is fill = TRUE in

usa <- map('state', fill = TRUE)

Changing the argument value to TRUE stops the error message.