Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

trouble with writevector

185 views
Skip to first unread message

Kerry Kilshaw

unread,
Feb 13, 2024, 8:20:04 AM2/13/24
to ctmm R user group
Hi everyone

I'm trying to export a UD as a shapefile using the following script

writeVector(x = wAKDE_Doll2020, filename = "Doll 2020 wAKDE", filetype="ESRI Shapefile", convex=FALSE, level.UD=0.95,level=0.95)

and I get the following error

Error in .local(x, filename, ...) :
  no slot of name "cpp" for this object of class "SpatVector"


I successfully exported a raster file using the same dataset and the script


writeRaster(wAKDE_Doll2020, filename = "Doll 2020 wAKDE", DF="PMF", format= "GTiff", overwrite = TRUE)

What am I doing wrong??

Thanks

Kerry

Holly Gamblin

unread,
Feb 20, 2024, 12:19:11 PM2/20/24
to ctmm R user group
Hi there, 

I'm also having the same trouble with my code:

> writeVector(akde.LR17_summ, filename = "LR17summ", filetype ="ESRI Shapefile", convex = FALSE, level.UD = 0.95, level = 0.95) Error in .local(x, filename, ...) : no slot of name "cpp" for this object of class "SpatVector"

Following!

~Holly

Holly Gamblin

unread,
Feb 20, 2024, 4:34:59 PM2/20/24
to ctmm R user group
Hi, 

So, it's not the cleanest way to do it, but I was able to find a workaround to export the akde as a shapefile. I'm still curious why writeVector didn't work, but in the meantime: 

# convert akde into a SpatialPolygonsDataFrame.UD
LR17S_shp <- SpatialPolygonsDataFrame.UD(akde.LR17_summ, convex = FALSE, level.UD = 0.95, level = 0.95)
LR17S_shp <- st_as_sf(LR17S_shp) #convert the SpatialPolygonsDataFrame.UD into an sf so you can use st_write to export the shapefile:
st_write(LR17S_shp, "shapefile_out.shp", driver = "ESRI Shapefile")

Kerry Kilshaw

unread,
Feb 21, 2024, 4:01:04 PM2/21/24
to ctmm R user group
That worked!

Amazing, thanks so much Holly!!

Best

Kerry

Christen Fleming

unread,
Feb 23, 2024, 11:18:47 PM2/23/24
to ctmm R user group
Hi All,

Sorry for the delay. I'm not getting this error in my testing. Assuming your packages and R version are up to date, would one of you mind sending me a minimal working example (just a small UD object would do).

Best,
Chris

Chloé Warret Rodrigues

unread,
Feb 29, 2024, 1:42:58 PM2/29/24
to ctmm R user group
Hi Chris,

I've tested the function too since Holly warned me she was having trouble, and like everyone here I'm having the same error (well, except mine says pnt instead of cpp).

code line used +  error:
writeVector(x = akde.BJOB, filename = "BJOB_2014", filetype="ESRI Shapefile", convex=FALSE, level.UD=0.95,level=0.95)
Error in .local(x, filename, ...) : no slot of name "pnt" for this object of class "SpatVector"

I'm using R 4.3.2 since the new version has been released today. Rstudio is up to date, and all my packages too.
I've attached a csv file with 2 fox individuals I'm working on (Data available on Movebank), and a reproducible R script.

Thank you,
Best,
Chloé
Debug_writevector.R
fox_debug_writevector.csv

Christen Fleming

unread,
Mar 10, 2024, 10:30:51 PM3/10/24
to ctmm R user group
Hi All, 

Sorry for the delay - I'm teaching a new course.

I'm not getting these errors. I suspect there might conflicts in which package is getting the dispatch with multiple packages loaded. Try either only loading ctmm (and calling other package functions with package::function) or calling ctmm::writeVector directly.

Best,
Chris

Adam Mortensen

unread,
Feb 8, 2025, 4:58:59 PMFeb 8
to ctmm R user group
Hello everyone,

I'm curious if there was ever a more concrete answer to this question. I've tried the ctmm : : writevector method and am still running into issues. 
First, I tried the following line of code based on what I was reading ctmm pdf
ctmm::writeVector(UD1757_IM_Screen_pHREML_w, filename = "F1757UDSHAPE", filetype = "ESRI Shapefile", convex = FALSE, level.ud = 0.95, level = 0.95)

and got this following error

Error in .local(x, filename, ...) : unused argument (level.ud = 0.95)

I then removed the level.ud argument and got the same error that others have been mentioning (see below)

Error in .local(x, filename, ...) :
  no slot of name "cpp" for this object of class "SpatVector"

My goal is export the plots that I made based on the akde mini review into ArcGIS Pro so that I can visually show UD shaded over the relevant landscape. The code for the plots I am aiming to move to GIS can be found below.

EXT_F1757_IM_Screen <- extent(list(UD1757_IM_Screen_pHREML_w), level = 0.95)
plot(F1757_IM, UD = UD1757_IM_Screen_pHREML_w, ext = EXT_F1757_IM_Screen)
title("F1757")

Thanks,
Adam Mortensen

Kerry Kilshaw

unread,
Feb 10, 2025, 5:48:44 AMFeb 10
to ctmm R user group, Adam Mortensen
Hi Adam

I also have continued issues with the writeVector in ctmm, I got it to work once using the same script as you then after that it just comes up with different errors; this is my workaround, probably not the best but it works fine for me...

# First create a SpatialPolygonsDataFrame.UD in ctmm

SP.Mean_Fairburn_NPN <-SpatialPolygonsDataFrame.UD(Mean_Fairburn_NPN, convex = FALSE, level.UD=c(0.95,0.5),level=0.95) # create shapefile in ctmm


# Then use the raster library to write to shapefile

rgdal::writeOGR(SP.Mean_Fairburn_NPN,dsn=".",layer="Mean_Fairburn_NPN", driver="ESRI Shapefile", overwrite = TRUE) 



Or if I have a list of UD objects (I'm using some of the batch scripts from ctmmweb)

# Save UD's from homerange list as shapefiles 

for(i in 1:length(hrange_list)){ 
SP.hrange_list <-SpatialPolygonsDataFrame.UD(hrange_list[[i]],level.UD=c(0.95,0.5),level=0.95) 

rgdal::writeOGR(SP.hrange_list,dsn=getwd(),layer=paste(list(names(hrange_list[i])),sep="_"), driver="ESRI Shapefile", overwrite = TRUE) 
}
 


This seems to work really well, but I know rgdal is not really the ideal format now and I should be using sf_write or something like that but I can't get that to work either....

Hope this helps!

Kerry


Dr. Kerry Kilshaw
WildCRU, Zoology, University of Oxford
The Recanati-Kaplan Centre
Tubney House, Abingdon Road
Tubney, Abingdon OX13 5QL, UK
 


--
You received this message because you are subscribed to a topic in the Google Groups "ctmm R user group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ctmm-user/GiZtIPk5Wb0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ctmm-user+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ctmm-user/b1a607eb-4276-4870-a4e2-ea8d9bdd3888n%40googlegroups.com.

Kerry Kilshaw

unread,
Feb 10, 2025, 6:12:56 AMFeb 10
to ctmm R user group, Adam Mortensen
Holly's method above also works very well, I just retried it, I had forgotten that had worked previously, thanks Holly!!

# convert akde into a SpatialPolygonsDataFrame.UD
LR17S_shp <- SpatialPolygonsDataFrame.UD(akde.LR17_summ, convex = FALSE, level.UD = 0.95, level = 0.95)
LR17S_shp <- st_as_sf(LR17S_shp) #convert the SpatialPolygonsDataFrame.UD into an sf so you can use st_write to export the shapefile:
st_write(LR17S_shp, "shapefile_out.shp", driver = "ESRI Shapefile")

Best

Kerry


Jesse Alston

unread,
Feb 11, 2025, 3:18:31 PMFeb 11
to Kerry Kilshaw, ctmm R user group, Adam Mortensen
Hi all,

ctmm was originally built using rgdal-dependent packages (e.g., sp and raster) for GIS support, so there could still be some issues with GIS-related functions arising from the deprecation of those packages. Keep reporting them and in the meantime, we appreciate everyone sharing solutions to get around any part of the package that have not yet been fully switched over to the new dependencies.

Thanks,
Jesse

You received this message because you are subscribed to the Google Groups "ctmm R user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ctmm-user+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ctmm-user/449744571.5786548.1739185973433%40mail.yahoo.com.


--

Christen Fleming

unread,
Mar 5, 2025, 2:01:29 AMMar 5
to ctmm R user group
Hi All,

If I could reproduce the error, then I would definitely fix it. To anyone getting the error, is the terra package loaded/attached when this happens? If so, it's probably stealing the method dispatch in a way that shouldn't be possible. You could also try to run the internal function ctmm:::writeVector.UD if getMethod is confused.

Best,
Chris
Reply all
Reply to author
Forward
0 new messages