【问题标题】:How to simplify spatial polygon using rmapshaper?如何使用 rmapshaper 简化空间多边形?
【发布时间】:2020-08-03 08:49:07
【问题描述】:

我正在尝试使用以下代码简化空间多边形数据框:

library(rmapshaper)
library(rgdal)
countyshapes <- readOGR("https://raw.githubusercontent.com/kjhealy/us-county/master/data/geojson/gz_2010_us_050_00_500k.json")
countyshapes <- ms_simplify(countyshapes, keep = 0.1)

但这会返回以下错误:

Error in sp::SpatialPolygonsDataFrame(polys, data = input@data) : 
  row.names of data and Polygons IDs do not match

有没有办法解决这个错误来简化我的 SP 对象?

【问题讨论】:

    标签: r leaflet rgdal


    【解决方案1】:

    我运行了代码,如果它有效,最好更新 rmapshaper 包:

    packageVersion("rmapshaper") 
    #[1] ‘0.4.4’
    
    countyshapes[1:5,]
    #An object of class "SpatialPolygonsDataFrame"
    #Slot "data":
    #  GEO_ID STATE COUNTY      NAME   LSAD CENSUSAREA
    #1 0500000US01029    01    029  Cleburne County    560.100
    #2 0500000US01031    01    031    Coffee County    678.972
    #3 0500000US01037    01    037     Coosa County    650.926
    #4 0500000US01039    01    039 Covington County   1030.456
    #5 0500000US01041    01    041  Crenshaw County    608.840
    

    另一种选择是使用sf::st_transform 函数

    【讨论】:

      猜你喜欢
      • 2012-05-27
      • 1970-01-01
      • 2018-09-30
      • 2012-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多