Dear list members,
I'm facing the following error when I want to convert an image object
(obtained from the density function of the SpatStat package) into a asc
object using the im2asc function of adehabitat:
mais.asc <- im2asc(mais.dens)
Erreur dans im2asc(mais.dens) :
the grid cellsize should be identical for both X and Y directions.
I previously delimited my study area by a polygon, could it be the external
grid cells (cut by that polygon) that would give this error (because
leading to non-square cells...)?
Below, my code more detailed.
Thanks for any help,
Regards,
Kevin
# Maize fied for the whole region
-------------------------------------------
mais <- readShapePoly("D:/Carto/Landscape/Mais_2009.shp")
# Limiting to my study area (W.sp)
-----------------------------------------------
mais.ze <- crop (mais,W.sp)
# Deriving density of maize field throught the density function
------------------------------------------------------------------------------------
#1. find centroid of maize field
mais.ps <- SpatialPolygons2PolySet(mais.ze)
mais.centroids <- calcCentroid(mais.ps, rollup=1)
mais.df <- as.data.frame(mais.centroids)
#2. convert to point pattern class+apply density function
mais.ppp <- ppp (mais.df$X, mais.df$Y, window = W2)
mais.dens <- density(mais.ppp, sigma=1000)
#3. convert mais.dens to asc for ENFA anaysis (in adehabitat)
mais.asc <- as.asc(mais.mx)
=>Erreur dans im2asc(mais.dens) :
the grid cellsize should be identical for both X and Y directions.