本文介绍了如何使用R软件包从点创建泰森多边形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有多组积分(不同年份〜20) 我想使用r个空间包为每组点创建泰森多边形。 > 我知道这可以使用GIS来完成,但是因为我想要一个批处理过程,R中的某些内容会很有帮助。 / p> 解决方案您没有给我们访问您的数据,但这里有一个代表世界各城市的点的例子,由Carson Farmer在他的博客中描述。希望它能让你开始... $ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ v $ ){ require(deldir) require(sp) if(.hasSlot(x,'coords')){ crds< - x @ coords } else crds< -x z< - deldir(crds [,1],crds [,2])w< - tile.list(z) polys< - vector (mode ='list',length = length(w)) for(i in seq(along = polys)){ pcrds } SP< - SpatialPolygons(多边形) voronoi< - SpatialPolygonsDataFrame(SP,data = data.frame(x = crds [,1] ,y = crds [,2],row.names = sapply(slot(SP,'polygons'), function(x)slot(x,'ID')))) } 示例1:输入是SpatialPointsDataFrame: #阅读poi nt shapefile转换成Voronoi图 library(rgdal) dsn< - system.file(vectors,package =rgdal)[1] cities< - (v)b v 例子2:输入是x,y坐标的向量: dat v2 plot(v2) I have multiple sets of points (for different years ~20)I want to generate thiessen polygons for each set of points using r spatial packages.I know this can be done using GIS but as i want a batch process something in R would behelpful. 解决方案 You haven't given us access to your data, but here's an example for points representing cities of the world, using an approach described by Carson Farmer on his blog. Hopefully it'll get you started...# Carson's Voronoi polygons functionvoronoipolygons <- function(x) { require(deldir) require(sp) if (.hasSlot(x, 'coords')) { crds <- x@coords } else crds <- x z <- deldir(crds[,1], crds[,2]) w <- tile.list(z) polys <- vector(mode='list', length=length(w)) for (i in seq(along=polys)) { pcrds <- cbind(w[[i]]$x, w[[i]]$y) pcrds <- rbind(pcrds, pcrds[1,]) polys[[i]] <- Polygons(list(Polygon(pcrds)), ID=as.character(i)) } SP <- SpatialPolygons(polys) voronoi <- SpatialPolygonsDataFrame(SP, data=data.frame(x=crds[,1], y=crds[,2], row.names=sapply(slot(SP, 'polygons'), function(x) slot(x, 'ID'))))}Example 1: Input is a SpatialPointsDataFrame:# Read in a point shapefile to be converted to a Voronoi diagramlibrary(rgdal)dsn <- system.file("vectors", package = "rgdal")[1]cities <- readOGR(dsn=dsn, layer="cities")v <- voronoipolygons(cities)plot(v)Example 2: Input is vectors of x, y coordinates:dat <- data.frame(x=runif(100), y=runif(100))v2 <- voronoipolygons(dat)plot(v2) 这篇关于如何使用R软件包从点创建泰森多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-30 02:36