ctmm-initiative / ctmm

Continuous-Time Movement Modeling. Functions for identifying, fitting, and applying continuous-space, continuous-time stochastic movement models to animal tracking data.
http://biology.umd.edu/movement.html
47 stars 12 forks source link

extending as.telemetry to accept point Simple Features. #43

Open jfsmenezes opened 1 year ago

jfsmenezes commented 1 year ago

Hi,

I have used this package a couple times, and in both cases I found myself transforming the data from a simple feature (package sf ) to a data.frame so it can be processed by as.telemetry().

So, to avoid this repetition, I made a method to as.telemetry() for sf point objects and I tought it might be useful for other users. See below:

as.telemetry.sf = function(object, timeformat="",timezone="UTC", projection=NULL,timeout=Inf,na.rm="row",mark.rm=FALSE,keep=FALSE,drop=TRUE,...) {
    if(st_geometry_type(object,by_geometry=FALSE)!="POINT") {stop("only point features supported at the moment")}
    library(sf)

    coords <- st_coordinates(object)
    object$location.long <- coords[,1]
    object$location.lat  <- coords[,2]
    datum <- st_crs(object)$proj4string

    object <- st_drop_geometry(object)

    DATA <- as.telemetry(object,datum=datum,timeformat=timeformat,timezone=timezone,projection=projection,timeout=timeout,na.rm=na.rm,mark.rm=mark.rm,keep=keep,drop=drop)

    return(DATA)
}

Hope it helps!

chfleming commented 1 year ago

Thanks @jfsmenezes , I'll put it on the to-do list.

kaijagahm commented 1 year ago

+1 to this--I have the same use case.

JosiahParry commented 1 year ago

+1 to this.