[R-sig-Geo] Making an hexagonal grid using spsample
Timothée Giraud
timothee.giraud at cnrs.fr
Mon Mar 6 16:42:50 CET 2017
Hi,
I understand you find a solution via hextess from spatstat.
However, this is a solution with spsample from sp.
Actually, the cellsize argument of spsample defines the distance between
the center of consecutives hexagons.
So it is the length of 2 medians of one of the 6 equilateral triangles
composing the hexagon.
You can obtain the correct cellsize with:
- the formula that calculates the median length for a given equilateral
triangle length size,
- the formula that calculate the area of an hexagon with a given side
length.
library(sp)
data(meuse.grid)
gridded(meuse.grid) = ~x+y
plot(meuse.grid)
# targeted area in meters
A <- 10000
# Corresponding cellsize :
CS <- 2 * sqrt(A/((3*sqrt(3)/2))) * sqrt(3)/2
# hexagons
HexPts <-spsample(x = meuse.grid, type = "hexagonal", cellsize = CS)
HexPols <- HexPoints2SpatialPolygons(HexPts)
plot(HexPols, add=TRUE)
# check
rgeos::gArea(HexPols, byid = T)[1:10]
Since you asked me about getGridLayer via PM, this function of the
cartography package uses spsample with its cellsize argument, maybe I
should add a "targeted area" argument...
More information about the R-sig-Geo
mailing list