Converting a “map” object to a “SpatialPolygon” object

后端 未结 2 543
臣服心动
臣服心动 2020-12-10 02:52

I am guessing there is a simple solution to the problem I have been having, but I am having some trouble.

I am trying to convert the following map objec

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 03:30

    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"))
    

提交回复
热议问题