g简化R

时间:2016-01-16 12:38:34

标签: r shapefile

我无法在R

中简化shapefile

此处的Shapefile:https://geoportal.statistics.gov.uk/Docs/Boundaries/Local_authority_district_(GB)_2014_Boundaries_(Generalised_Clipped).zip

library(tmap)
library(maptools)
library(ggmap)

England <- readOGR(dsn = "...")

#works fine
print(qtm(England, "LAD14CD", borders = NA, fill.title = "A-Level" )) 

# simplify the polygons
England<-gSimplify(England,tol=0.01, topologyPreserve=TRUE)

print(qtm(England, "LAD14CD", borders = NA, fill.title = "A-Level" )) 

给出错误:

Error in process_fill(data, g$tm_fill, gborders, gt, gf, z = z + which(plot.order ==  : 
Fill argument neither colors nor valid variable name(s)

如果查看英国数据对象,您可以看到它已从大空间polygonDataFrame更改为大空间多边形并删除了@data

相反,如果您尝试仅简化Shapefile中的多边形:

England@polygons<-gSimplify(England@polygons,tol=0.01, topologyPreserve=TRUE)

它说:

Error in gSimplify(England@polygons, tol = 0.01, topologyPreserve = TRUE) : 
cannot get a slot ("proj4string") from an object of type "list"

如何从shapefile中简化多边形?

1 个答案:

答案 0 :(得分:7)

gSimplify的回报只是几何,而不是属性,因此您必须使用简化几何和原始属性数据构建新的SpatialPolygonsDataFrame

> England2 <-gSimplify(England,tol=0.01, topologyPreserve=TRUE)
> England3 = SpatialPolygonsDataFrame(England2, data=England@data)

我认为保证多边形的顺序相同,除非有任何简化。检查length(England2)England的行数相同,或者匹配ID上的行。