小编anh*_*.hv的帖子

使用R将坐标表转换为形状文件

我在UTM区域48中有一个点坐标数据集.

  x           y       
615028.3  2261614    
615016.3  2261635    
614994.4  2261652    
Run Code Online (Sandbox Code Playgroud)

CSV文件在这里.

我想加载CSV并使用R创建shapefile.我的代码是:

library(maptools)
library(rgdal)
library(sp)

    UTMcoor=read.csv(file="https://dl.dropboxusercontent.com/u/549234/s1.csv")
    coordinates(UTMcoor)=~X+Y
    proj4string(UTMcoor)=CRS("++proj=utm +zone=48") # set it to UTM
    LLcoor<-spTransform(UTMcoor,CRS("+proj=longlat")) #set it to Lat Long
    plot(LLcoor)
    points(LLcoor$X,LLcoor$Y,pch=19,col="blue",cex=0.8) #to test if coordinate can be plot as point map
    writeOGR(UTMcoor, dsn="c:/todel" ,layer="tsb",driver="ESRI Shapefile")
    writeSpatialShape("LLcoor","test")
Run Code Online (Sandbox Code Playgroud)

在最后一个命令(writeSpatialShape)中,R给出以下错误:

Error in writeSpatialShape("LL2", "test") : 
  x is acharacterobject, not a compatible Spatial*DataFrame
Run Code Online (Sandbox Code Playgroud)

当我从控制台读取LLcoor时,它似乎已经是一个Spatial DataFrame.使用writeOGR(RGdal包)编写形状文件也会产生类似的错误.任何提示都非常感谢.

r shapefile

6
推荐指数
1
解决办法
9867
查看次数

标签 统计

r ×1

shapefile ×1