问题描述
我在绘制真实的R中地理像素时遇到问题.这些文件附带了每日单个坐标和像素大小(面积)的列表.与此分开的还有一个Z元素.数据结构看起来是这样的:
I am having issues plotting true to geographic extent pixels in R. the files come with a list of daily single coordinates and pixel size (area). There is also a Z element separate from this. The data structure looks this way:
X <- c(1,3,6,7)
Y <- c(3,2,7,8)
Z <- c(38,23,12,12)
Area <- c(32,23,45,67)
X和Y以经度和纬度为单位,而面积以平方公里为单位.我可以使用以下方法轻松创建点要素:
The X and Y are in degrees longitude and latitude while the area is in square kilometres. I create the point features easily using:
library(sp)
A <- cbind(X,Y,Z,Area)
B <- SpatialPoints(A)
我使用面积值轻松确定绘制的"cex"来绘制这些图形. Z列是强度,我使用这些值确定颜色.如何使用R中每个点的面积创建空间多边形要素?我将使用这些点来创建栅格化的栅格.
I plot these easily using the area values to determine the "cex" for plotting. The Z column is intensity and I use these values to determine the colours . How do I create spatial polygons features using the areas for each point in R? I would be using these points to create gridded rasters.
推荐答案
这应该可以解决问题:
library(rgeos) ## for gBuffer()
library(raster) ## for bind()
ww <- sqrt(B$Area)/2 ## Widths of buffers needed to produce desired areas
pp <- list()
for(i in seq_along(B)) {
pp[i] <- gBuffer(B[i], width=ww[i], quadsegs=1, capStyle="SQUARE")
}
PP <- do.call(bind, pp)
## Check that it worked
plot(PP)
plot(B, add=TRUE)
text(B, labels=1:4, adj=c(-1,0), col="red")
这篇关于从R中的单个中心坐标和面积创建方形多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!