Create square polygons from single-center coordinates and an area in R

I am having trouble building true for pixels of geographic extent in R. The files contain a list of daily single coordinates and pixel size (area). There is also an element Z from this. The data structure is as follows:

 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 and Y are in degrees of longitude and latitude, and the area is in square kilometers. I easily create point functions using:

library(sp)
A <- cbind(X,Y,Z,Area)
B <- SpatialPoints(A)

I draw them easily using area values ​​to determine the "cex" for plotting. Column Z is the intensity, and I use these values ​​to determine the colors. How to create spatial polygon objects using areas for each point in R? I would use these points to create mesh rasters.

+2
1

:

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

enter image description here

+3

Source: https://habr.com/ru/post/1659749/


All Articles