gpt4 book ai didi

r - 从点创建凸包多边形并另存为shapefile

转载 作者:行者123 更新时间:2023-12-03 12:42:17 25 4
gpt4 key购买 nike

需要一些帮助才能解决R中的转换问题。

我已经计算出点云的convex hull。我想从形成凸包的点开始,建立一个多边形对象,并将其另存为一个可由GIS软件(ArcMap等)读取的shapefile。

我的代码如下所示:

gps <- read.csv(f)  ##reads the lat-long coordinates  file 
x <- gps$LONGITUDE ##tells R which columns is which
y <- gps$LATITUDE
z<-chull(x,y) ##calculates the convex hull --this is just a list of x-y points, N vertex
dfHull <-cbind(x[z],y[z]) ##the convex hull expressed as a list of selected x-y points
plot(dfHull) ##this plots the vertex of the polygon, just a check
lines(dfhull) ##plots the polygon in screen

##generate polygon shapefile, from dfHull, and save it externally as a shapefile ???

源文件仅包含经纬度坐标,例如:
52.73336     N  0.365974
52.7332 N 0.366051
52.73289 N 0.36636
52.73297 N 0.366258
52.73298 N 0.366243
52.733 N 0.366112
52.73308 N 0.365942
52.73317 N 0.365881
52.73321 N 0.36593
52.73328 N 0.365942
52.73352 N 0.36579
52.73362 N 0.365678
52.73391 N 0.365536
52.7373 N 0.36543
52.73289 N 0.36728

我知道有一些软件包(rgdal,maptools,..)可以帮助解决这些问题,但是我对空间方面的知识非常陌生。我真正需要的只是生成多边形对象并将其另存为shapefile。

任何帮助表示赞赏。在此先感谢开发人员。

最佳答案

这是创建SpatialPolygonsDataFrame的简单示例,可以使用rgdal::writeOGR()保存为shapefile:

set.seed(1)
dat <- matrix(stats::rnorm(2000), ncol = 2)
ch <- chull(dat)
coords <- dat[c(ch, ch[1]), ] # closed polygon

plot(dat, pch=19)
lines(coords, col="red")
library("sp")
library("rgdal")

sp_poly <- SpatialPolygons(list(Polygons(list(Polygon(coords)), ID=1)))
# set coordinate reference system with SpatialPolygons(..., proj4string=CRS(...))
# e.g. CRS("+proj=longlat +datum=WGS84")
sp_poly_df <- SpatialPolygonsDataFrame(sp_poly, data=data.frame(ID=1))
writeOGR(sp_poly_df, "chull", layer="chull", driver="ESRI Shapefile")

关于r - 从点创建凸包多边形并另存为shapefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25606512/

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