【发布时间】:2013-04-12 02:51:25
【问题描述】:
我正在尝试在 R 中创建一个 shapefile,稍后将其导入 Fusion Table 或其他一些 GIS 应用程序。
首先,我导入了一个包含加拿大所有人口普查区的空白 shapefile。我已根据 CT 的唯一 ID 将其他数据(以表格格式)附加到 shapefile,并映射了我的结果。目前,我只需要温哥华的那些,我想导出一个仅包含温哥华 CT 以及我新附加的属性数据的 shapefile。
这是我的代码(出于隐私原因省略了某些部分):
shape <- readShapePoly('C:/TEST/blank_ct.shp') #Load blank shapefile
shape@data = data.frame(shape@data, data2[match(shape@data$CTUID, data2$CTUID),]) #data2 is my created attributes that I'm attaching to blank file
shape1 <-shape[shape$CMAUID == 933,] #selecting the Vancouver CTs
我已经看到了使用此方法的其他示例:writePolyShape 来创建 shapefile。我试过了,它在一定程度上奏效了。它创建了 .shp、.dbf 和 .shx 文件。我错过了 .prj 文件,我不确定如何创建它。有没有更好的方法来创建 shapefile?
我们将不胜感激任何有关此事的帮助。
【问题讨论】:
-
这就是我写文件的方式
writeOGR(obj = opno.skupaj.mean[[1]], dsn = "q:/path/to/file/spat_odstrel_skupaj.shp", layer = "spat_odstrel_skupaj", driver = "ESRI Shapefile")。请注意,图层和文件名是相同的(减去.shp)。