Skip to content

Making an hexagonal grid using spsample

9 messages · Manuel Spínola, Marcelino de la Cruz Rot, Rolf Turner +1 more

#
Dear list members,

I am trying to make an spatial hexagonal grid in R using the spsample
function. I would like hexagons of 1 ha = 10000 sq meters.


First I used a cell size of 62.04 m as the side of the hexagon.

data(meuse.grid)
gridded(meuse.grid) = ~x + y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
xx <- spsample(meuse.grid, type = "hexagonal", cellsize = 62.04)
xx <- HexPoints2SpatialPolygons(xx)
rgeos::gArea(xx, byid=TRUE)

It gave me an area per hexagon = 3333.299

Second I used a cell size of 62.04 * 2 = 124.08 m as the long diagonal of
the hexagon

data(meuse.grid)
gridded(meuse.grid) = ~x + y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
xx <- spsample(meuse.grid, type = "hexagonal", cellsize = 62.04*2)
xx <- HexPoints2SpatialPolygons(xx)
rgeos::gArea(xx, byid=TRUE)

It gave me an area per hexagon = 13333.19

Both results are wrong, because I was expecting close to 10000.

How can I make a spatial grid of 1 ha (or other size) in R?

Manuel
#
Hi  Manuel,

I do answer to the question "How can I make a spatial grid of 1 ha (or 
other size) in R?"

You can use function hextess in spatstat

library(spatstat)

# some arbitrary area, with coordinates in hectometres
  W <- Window(chorley)

# As Rolf said, hexagons of 1ha should have side of 402.0673 metres, so, 
in hectometres:

s <- 4.020673

plot(hextess(W, s))
plot(hexgrid(W, s), add=TRUE)


Cheers,

Marcelino

El 03/03/2017 a las 20:03, Manuel Sp?nola escribi?:

  
    
#
On 04/03/17 08:38, Marcelino de la Cruz Rot wrote:
Marcelino,

Actually I said hexagons of area *42* ha should have side length equal 
to 402.0673 metres.

Moreover the Chorley data set has units of *kilometres* not hectometres,
so that should be s <- 0.4020673.  Or, to avoid just a touch of 
round-off error, s <- sqrt(2*0.42)/3^0.75.

Note that if you then do

xxx <- hextess(W,s,trim=FALSE)
unique(sapply(tiles(xxx),area.owin))

you get 0.42 --- i.e. 0.42 square kilometres, or 42 hectares.

cheers,

Rolf
#
My apologies for such a pair (or more) of embarrassing mistakes!

I should read a bit more these days...


Marcelino



El 04/03/2017 a las 2:31, Rolf Turner escribi?:

  
    
#
Thank you very much to both.

Manuel

2017-03-04 6:35 GMT-06:00 Marcelino de la Cruz Rot <
marcelino.delacruz at urjc.es>:

  
    
#
On 05/03/17 01:35, Marcelino de la Cruz Rot wrote:

            
I'm just happy to see that this sort of mistake happens to others as 
well as to my very good self! :-)

cheers,

Rolf
1 day later
#
http://www.keittlab.org/
On Fri, Mar 3, 2017 at 1:03 PM, Manuel Sp?nola <mspinola10 at gmail.com> wrote:

            
You might search the list. I posted R code a long time ago that builds a
hexagonal tessellation over a rectangle. I think Edzer used that to add the
hexagonal option to spsample.

THK

  
  
#
Thank you very much Tim.

Manuel

2017-03-06 14:20 GMT-06:00 Tim Keitt <tkeitt at utexas.edu>: