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

后端 未结 2 532
臣服心动
臣服心动 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:23

    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.

    0 讨论(0)
  • 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"))
    
    0 讨论(0)
提交回复
热议问题