create spatial polgyon from the Akde object

99 views
Skip to first unread message

Carl-Evan Jefferies

unread,
Oct 18, 2021, 4:55:01 PM10/18/21
to ctmm R user group
Hi Chris,

I am currently running through the vignette as practice for my own project, and I would like to overlay the adke object onto some spatial habitat data. I would then like to clip the adke object to the associated habitat data used by an individual.

I am looking to extract the middle 95% contour from the UD2 object and convert it into a spatial object/polygon that includes the spatial extent of the middle 95% contour. 

Looking at the cran information for the package, I am wondering if using the spatialpolygonsdataframe.UD is the appropriate method of converting the object to a polygon and that the level.UD is the correct argument to be used to determine the middle contour. 

I am a little confused on the difference between using the different export tools from cran like SpatialPointsDataframe.telemetry vs. SpatialPolygonsdataframe.UD, SpatialPolygonsDataframe.telemetry etc.

UD2spatialpolygon<- SpatialPolygonsDataFrame.UD(UD2,level.UD=0.95,level=0.95)

Thanks,

Carl 

Christen Fleming

unread,
Oct 18, 2021, 8:39:19 PM10/18/21
to ctmm R user group
Hi Carl,

I think you have everything straight.

SpatialPolygonsDataFrame.UD(UD2,level.UD=0.95,level=0.95) will export the 95% home-range area, with 95% CIs. The middle contour will be the point estimate for the 95% home-range area, which is probably what you want. Adjusting the level.UD argument will adjust the home-range prediction coverage. E.g., the 50% home-range area is expected to contain 50% of future locations, assuming that movement behaviors do not change.

Export functions ending in .telemetry are for telemetry objects only. (In those cases I couldn't import the sp functions as generic functions, due to the way that they were designed, and function.class is R's S3 notation. I will update the documentation to make that clearer.) For UD objects, your options are polygons, rasters, and shapefiles.

Best,
Chris

Connor O'Malley

unread,
Oct 29, 2021, 3:40:36 PM10/29/21
to ctmm R user group
Hey guys,
I'd like to isolate that middle polygon for functions such as raster::extract()... any suggestions for how to go about this? I suppose raster::extract() would return 3 values for the three polygons and I could just take the middle one. I'm beginner/intermediate so any help is appreciated!
Connor

Carl-Evan Jefferies

unread,
Oct 29, 2021, 3:47:59 PM10/29/21
to ctmm R user group
Thanks Chris! 
Conner: I will let Chris explain but I have used something similar that may help...

UD2.spatial <- SpatialPolygonsDataFrame.UD(UD2,level.UD=.95,level=.95)
plot(UD2.spatial)

#subset the CI's and extract shape of middle contour
UD2.polygon <- subset(UD2.spatial, name == "moose 95% est")  

# Change the coordinate reference system of the UD2.polygon to albers to match the one of vri
UD2.polygon_aea <- spTransform(UD2.polygon,crs(vri))

# Check that the spatial transform worked
crs(UD2.polygon_aea)
crs(vri)

# clip the vri to UD2 within middle polygon
raster::intersect(vri, UD2.polygon_aea)

Christen Fleming

unread,
Oct 29, 2021, 4:42:21 PM10/29/21
to ctmm R user group
Hi Connor,

Exporting to the raster, gives you a raster of the density or distribution function, which does not directly contain the coverage area polygons (which would be contained by a spatial polygon export). extract() on those rasters would tell you something like the local probability density (PDF) or what % coverage area you are in (CDF). I'm not exactly sure what you are trying to do, but maybe Carl has answered your question.

Best,
Chris

Connor O'Malley

unread,
Oct 31, 2021, 1:40:03 PM10/31/21
to ctmm R user group
Hey Carl and Chris,
That worked! Thanks. If folks wanted to go the shapefile route I believe this achieves a similar effect:

shapefile_polygons <- as.sf(akde_object, level.UD=0.95, level=0.95)

middle_polygon <- shapefile_polygons[2,]  #selects the second row which is the 95% est middle polygon

z <- crs(my_base_data)
final_polygon <- st_transform(middle_polygon, crs=z) # match crs to base data so everything is aligned 

Thanks again! Best,
Connor
Reply all
Reply to author
Forward
0 new messages