ctmm - writeShapefile

138 views
Skip to first unread message

spete...@gmail.com

unread,
Feb 20, 2019, 7:23:11 AM2/20/19
to ctmm R user group
Hello,

I am still new to ctmm and tackle the following problem(s):

I have 199 tracks (cat tracks) downloaded as csv file (see below) from Movebank.
Running my script (see below), I get the sKDE polygons I want, but using writeShapefile I am loosing all attributes (e.g. individual-local-identifier, individual-taxon-canonical-name).

Is there any way to include such attribute from the original Movebank csv file in the output shapefile?

Hope anyone can help
Cheers
stefan


My_ctmm_cat_tracks_script.R :

install.packages("proj4")
install.packages('bit64')
install.packages('ctmm')
library(ctmm)
tracks <- as.telemetry('PetcatsSA199.csv',timeformat="",timezone="UTC",projection=NULL,timeout=Inf,na.rm="row",drop=TRUE)
trackIDs <- names(tracks)
no_tracks <- length(trackIDs)
folder <- paste(getwd(),"/shp-output2", sep="")
for(i in 1:no_tracks) {
  track_i <- tracks[i]
  names(track_i) <- "1"
  track_h <- track_i$'1'
  GUESS <- ctmm.guess(track_h,interactive=FALSE)
  print(i)
  FIT <- ctmm.fit(track_h,GUESS)
  UD <- akde(track_h,FIT)
  assign(paste("UD", i, sep = ""), UD) 
  writeShapefile(UD,folder,file=NULL,level.UD=0.95,level=0.95)
}



PetcatsSA199.csv (extraction):
event-id
visible
timestamp
location-long
location-lat
sensor-type
individual-taxon-canonical-name
tag-local-identifier
individual-local-identifier
study-name
5555318653
TRUE
8/28/2015 11:18
138.6275
-35.0034
gps
Felis catus
117
117
PetcatsSA199
5555318654
TRUE
8/28/2015 11:21
138.6275
-35.0034
gps
Felis catus
117
117
PetcatsSA199
5555318656
TRUE
8/28/2015 11:27
138.6274
-35.0036
gps
Felis catus
117
117
PetcatsSA199
5555318669
...
TRUE
...
8/28/2015 12:08
...
138.6273
...
-35.0033
...
gps
...
Felis catus
...
117
...
117
...
PetcatsSA199
...

Christen Fleming

unread,
Feb 20, 2019, 10:49:38 PM2/20/19
to ctmm R user group
Hi Stefan,

You could name the shape files according to the identity variable stored in the objects, with something like file=track_i@info$identity. Is that what you are looking for?
I'm not very familiar with the shapefile format to know what other options there are.

Best,
Chris

spete...@gmail.com

unread,
Feb 21, 2019, 6:18:33 AM2/21/19
to ctmm R user group
Hi Christen

many thanks for your reply.
I finally solved my problem by just using the looping identifier i as file name:
writeShapefile(UD,folder,file=i,level.UD=0.95,level=0.95)

Regards
Stefan

Ingo Miller

unread,
Oct 3, 2020, 10:19:30 AM10/3/20
to ctmm R user group
Hi Stefan or Chris,

I adopted the loop function for my data set. It works fine, however, I would like to assign my original anaimal IDs to the objects instead of numbering them. As I'm very new to for loop funtions, I couldn't figure out how the change the (above) code. 
Any help would be much appreciated.

Cheers
Ingo 

Christen Fleming

unread,
Oct 3, 2020, 6:53:32 PM10/3/20
to ctmm R user group
Hi Ingo,

In most cases, you could just do something like file=names(tracks)[i] instead of file=i.

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