使用R语言给shp文件添加字段与数据

来源:互联网 发布:app支付宝php服务端 编辑:程序博客网 时间:2024/05/28 03:04

首先安装R-ArcGIS桥工具


###给shp文件添加字段,可批量操作

library(arcgisbinding)
library(sp)
arc.check_product()##检查ArcGIS许可
#arc.progress_label("Loading Dataset")##进度条
d<-arc.open(shpfile)#shpfile为输入shp图层文件,查看d可以看到输入shp的各种信息
#注意:在运行arc.open()时,往往会报错“Error in .call_proxy("dataset.open", .Object, path) : cannot open dataset”,这种情况下往往再运行一遍arc.open()就好了。

#GRID_CODE<-arc.select(d,field)##读取输入图层中的数据,field为要读取的字段
dat <- arc.select(d)##读取输入图层中的所有数据

dat1 <- read.csv(csvfile,header = F)##excel里有表头header = T,没有表头header = F
dat1 <- t(data.frame(dat1))##只有一行的话,将行转成一列
result <- data.frame(dat,dat1)##合并shp与新加入数据
data_shp <- arc.shape(GRID_CODE)##获取输入shp文件的参考信息
data_shp@shapeinfo <- d@shapeinfo
#arc.progress_label("Writing result dataset...")
arc.write(outfile,result,coords=data_shp)
原创粉丝点击