R语言与GIS:[4]操作ArcGIS中的矢量数据
读取Shapefile
利用R读取Shapefile,主要用到readShapeSpatial方法,该方法将shapefile数据读取为一个Spatial*DataFrame对象,其使用方法如下:
readShapeSpatial(fn, proj4string=CRS(as.character(NA)),verbose=FALSE, repair=FALSE, IDvar=NULL, force_ring=FALSE,delete_null_obj=FALSE, retrieve_ABS_null=FALSE)
其中,fn为shapefile的存储路径以及文件名,IDvar为shapefile属性中ID属性名称,proj4string用于指定参考系统,示例代码如下:
>F.shapefile<-readShapeSpatial(file.path("C:/Users/GAOXIANG/Documents/ArcGIS/LINE"),IDvar="FID")
> plot(F.shapefile)
结果如下图所示:
保存新要素,代码如下:
> file.path_old<-file.path("C:\\Users\\GAOXIANG\\Documents\\ArcGIS")
> file.path_new<-paste(file.path_old,"LINE_NEW",sep="\\")
> writeSpatialShape(F.shapefile_new, file.path_new)
检查新要素属性:
> getinfo.shape(paste(file.path_new,".shp",sep=""))
Shapefile type: PolyLine, (3), # of Shapes: 109
最终结果如下图所示: