Thanks for your reply Mathieu,

Well I went a bit further in trying to resolve the problem and found out 
that when applying this density.ppp function of SpatStat the resulting 
image contains pixel with different xy dimensions. There is the problem 
I think:

 >summary(mais.dens )
     real-valued pixel image
     500 x 500 pixel array (ny, nx)
     enclosing rectangle: [158814.835784285, 242204.064319242] x 
[85205.9013486226, 142933.765576564]     units
/*dimensions of each pixel: 167 x 115 units */

And somehow function im2asc do not allow for converting such image. But 
I cannot find how to change settings of density.ppp to get an image with 
same XY array. Guess it should be possible but...

Yes I saw that adehabitat was rearranged, and I'm using the latest 
version if no error from my side.

Here the idea was to get a map of the density of maize field as a 
covariate to use in ENFA. This is the reason why I do not use the point 
directly in ENFA. My point layer for ENFA is the localisation of shot 
wild boar.

Maybe as you suggest I could use other function to get the same result.

Thanks again for your help and further advices,

Kevin



Le 23/01/2012 14:49, Mathieu Basille a écrit :
> 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.
>>
>


-- 
Morelle Kevin
Université de Liège - Gembloux Agro-Bio Tech
Unité de Gestion des Ressources forestières et des Milieux naturels
--------
University of Liège - Gembloux Agro-Bio Tech
Unit of Forest and Nature Management
--------
2, Passage des Déportés
B-5030  GEMBLOUX
BELGIQUE

Tél : + 32 (0)81 62.22.14
Fax : + 32 (0)81 62.23.01
E-mail : kevin.morelle@ulg.ac.be
Web : http://www.fsagx.ac.be/gf/


	[[alternative HTML version deleted]]

