我正在尝试在R中创建一个shapefile,稍后我将导入Fusion Table或其他一些GIS应用程序.
首先,我导入了一个包含加拿大所有人口普查区的空白shapefile.我已经根据CT的唯一ID将其他数据(以表格格式)附加到shapefile,并且我已经映射了我的结果.目前,我只需要在温哥华的那些,我想导出一个只包含Vancouver CTs的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
Run Code Online (Sandbox Code Playgroud)
我见过其他使用它的例子:writePolyShape来创建shapefile.我试过了,它在一定程度上起作用了.它创建了.shp,.dbf和.shx文件.我错过了.prj文件,我不知道如何创建它.是否有更好的方法来创建shapefile?
任何有关此事的帮助将不胜感激.
使用rgdal和writeOGR.rgdal将保留投影信息
就像是
library(rdgal)
shape <- readOGR(dsn = 'C:/TEST', layer = 'blank_ct')
# do your processing
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,]
writeOGR(shape1, dsn = 'C:/TEST', layer ='newstuff', driver = 'ESRI Shapefile')
Run Code Online (Sandbox Code Playgroud)
请注意,它dsn是包含该.shp文件的文件夹,并且layer是没有.shp扩展名的shapefile的名称.它会读取(readOGR)和write( writeOGR)中的所有组件文件(.dbf,.shp,.prj等)
| 归档时间: |
|
| 查看次数: |
15226 次 |
| 最近记录: |