gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:11:10 25 4
gpt4 key购买 nike

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

  x           y       
615028.3 2261614
615016.3 2261635
614994.4 2261652

CSV 文件 here .

我想加载 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")

在最后一个命令 (writeSpatialShape) R 中给出以下错误:
Error in writeSpatialShape("LL2", "test") : 
x is acharacterobject, not a compatible Spatial*DataFrame

当我从控制台读取 LLcoor 时,它似乎已经是一个空间数据帧。使用 writeOGR(RGdal 包)写入形状文件也会出现类似错误。任何提示都非常感谢。

最佳答案

你的例子有问题。倒数第二行也失败了。

无论如何,您的错误很明显。您提供的是变量“LL2”的名称而不是变量本身。但在你的例子中,LLcoor也不是 UTMcoor格式正确,可用于 writeOGRwriteSpatialShape .您需要先将它们转换为 SpatialDataframe ,例如:

UTMcoor.df <- SpatialPointsDataFrame(UTMcoor, data.frame(id=1:length(UTMcoor)))

关于r - 使用 R 将坐标表转换为形状文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23784427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com