[R-sig-Geo] Converting image to asc

Mathieu Basille basille at ase-research.org
Mon Jan 23 14:49:12 CET 2012


Dear Kevin,

I'm not sure how to solve your exact problem, since you don't provide a 
reproducible code, but here are a couple of comments:

1) You shouldn't use the old 'adehabitat' any more. This package has been 
split in four new ones, namely, adehabitatMA for map management, 
adehabitatLT for trajectories, adehabitatHR for home-range analyses, and 
adehabitatHS for habitat selection analyses. You can simply install them 
all by

install.packages("adehabitatHS")

The main benefit of it is that adehabitat does not use its own map classes 
any more, but use sp classes instead. This might well correct the 
conversion problem, which would thus be from spatstat to sp now.

2) You could also use kernelUD from adehabitatHR directly. The output would 
most certainly be suited for other analyses using adehabitatXY.

3) I'm not sure I understand why you first derive a density for an ENFA 
analysis. Why don't you use directly the centroid coordinates as points in 
the ENFA?

Hope this helps,
Mathieu.


Le 23/01/2012 04:11, Kévin Morelle a écrit :
> 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.
>

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the R-sig-Geo mailing list