[R-sig-Geo] Creating a raster with an hexagonal grid

Manuel Spínola mspinola10 at gmail.com
Fri Mar 6 16:00:05 CET 2015


Dear list members,

I would like to make a raster with hexagonals pixels.

r = raster("raster.tif")

ras = as(r, "SpatialPixelsDataFrame")
image(ras)
HexPts <-spsample(ras,type="hexagonal", cellsize = 1000, offset = c(0,0))
points(HexPts, pch = "+")
HexPols <- HexPoints2SpatialPolygons(HexPts)
row.names(HexPols)<-as.character(HexPols at plotOrder)
HexPolsdf = SpatialPolygonsDataFrame(HexPols, data.frame(hex= c(1:72)))
plot(HexPolsdf, add = T)
text(coordinates(HexPolsdf), labels=HexPolsdf at plotOrder)

# calculate landscape metrics with land.metrics (spatialEco package) for
each  hexagon

lm = land.metrics(x=HexPolsdf, y=rb, bkgd = 0, Trace = F)

I want to make a raster with one of the landscape metrics assigned to each
hexagon (a raster with hexagonal pixels)

HexPolsdf$CantHab = lm$prop.landscape

raster = raster(HexPolsdf)

# rasterize

rastercant = rasterize(HexPolsdf, raster, field = "CantHab")
plot(rastercant)

However the raster doesn´t show hexagonal pixels, it shows square pixels.


How can I make the raster showing hexagonal pixels and make the predictions
to a final raster with hexagonal pixels.

Best,

Manuel






-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspinola at una.ac.cr
mspinola10 at gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río <https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list