【问题标题】:gSimplify not simplifying shapefile in RgSimplify 不简化 R 中的 shapefile
【发布时间】:2016-01-16 12:38:34
【问题描述】:

我无法在 R 中简化 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)

如果您查看 UK 数据对象,您会发现它已从大型空间多边形数据帧更改为大型空间多边形并删除了 @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 中的多边形?

【问题讨论】:

标签: r shapefile


【解决方案1】:

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

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

我认为多边形可以保证是相同的顺序,除非任何东西都被简化了。检查length(England2)England 的行数相同,或匹配ID 上的行。

【讨论】:

  • 了解如何进行 ID 匹配会很有帮助。
  • 我努力进行上述 ID 匹配,但我不知道如何排列。从 gSimplify 出来的 ID 似乎只是 1、2、3、... N,不管有多少多边形被丢弃
猜你喜欢
  • 1970-01-01
  • 2019-10-30
  • 2013-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-05
  • 2014-01-30
相关资源
最近更新 更多