如何使用 rmapshaper 简化空间多边形?

How to simplify spatial polygon using rmapshaper?

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

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)

但是这个returns出现以下错误:

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

有什么方法可以解决此错误以简化我的 SP 对象?

我运行代码,如果有效,最好更新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 函数