Creating a raster with an hexagonal grid
Manuel, I might be mistaken, but as far as I understand, rasters in R use square pixels... and thats how the raster data are typically stored in raster file types and used by other GIS packages, with cell size referring to the square dimensions of pixels. Thus, all of the ideas are based on that assumption. These are just some thoughts of alternative ways to present and analyze the data in R, without using an explicit 'hexagon-based raster' type of data format. (Somebody please chime in and correct me if I'm wrong... if there is some sort of 'hexagon' type for raster formats in R... or even if there is a generally appropriate storage type for hexagon-based rasters in general, I'd love to hear about this) For visualization, here are a couple of thoughts: 1) Rasterize the hexagonal SpatialPolygonDataFrame to a finer resolution, with nearest neighbor resampling, such that the resulting raster section for each polygon would look something like this: http://en.wikipedia.org/wiki/User:Smcgruer#mediaviewer/File:Hexagonal_hyper_pixel.svg 2) Stick with the hexagons as SpatialPolygonDataFrames, and plot the colors based on the landscape metric values; there's a package for Chloropleth maps (I've never used it, but looks handy...): http://cran.r-project.org/web/packages/choroplethr/; * Also, this presentation looks useful: http://www.slideshare.net/tjagger/r-spatial-analysis-using-sp Re the latter part of your question on Analysis and prediction with hexagonal pixels, I think it depends on the goals/methods of your analysis. 1) If your analyses are focused in each pixel individually (e.g., for distribution modeling, folks typically develop and predict models for a stack of pixels under a specific point - not the relation between adjacent pixels and such), then just use an appropriately sized square-pixel based raster. 2) If your analyses generally rely on the centers of adjacent pixels being the same distances apart regardless of the direction (e.g., for animal movement), can you just work with the centroids of the Hexagonal polygons? Hope that helps. Cheers, mike
On Fri, Mar 6, 2015 at 9:00 AM, Manuel Sp?nola <mspinola10 at gmail.com> wrote:
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]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo