从点创建凸包面多边形并另存为shapefile [英] Create convex hull polygon from points and save as shapefile

查看:129
本文介绍了从点创建凸包面多边形并另存为shapefile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Needing some help re a conversion problem in R.

我已经计算出了点云的凸包.我想从形成凸包的点开始,建立一个多边形对象,并将其另存为 shapefile ,该文件可以由GIS软件(ArcMap或喜欢).

I've got calculated the convex hull of a cloud of points. I'd like, from the points forming the convex hull, to build a polygon object and save that as a shapefile that can be read by a GIS software (ArcMap or the like).

我的代码如下:

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 ???

源文件仅包含经纬度坐标,例如:

The source file only contains lat-long coordinates, e.g:

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.

I know there are packages (rgdal,maptools,..) to help with these, but I'm very unfamiliar with spatial stuff. Really all I need is to generate the polygon object and save that as shapefile.

任何帮助表示赞赏.预先感谢开发人员.

Any help appreciated. Thanks in advance, dev.

推荐答案

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

Here is a simple example to create a SpatialPolygonsDataFrame, which can be saved as a shapefile with rgdal::writeOGR():

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")

这篇关于从点创建凸包面多边形并另存为shapefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆