-
Notifications
You must be signed in to change notification settings - Fork 31
Interactive trajectory tool in rpostgisLT
rpostgisLT is a package that seamlessly transfers animal trajectory (movement) data sets between R objects (ltraj
from the package adehabitatLT; for trajectory analysis) and PostgreSQL/PostGIS databases (in the rpostgisLT
-created pgtraj
data structure; for storage and analysis). rpostgisLT
was developed during Google Summer of Code (GSoC) 2016, and the current CRAN release provides the fundamental R functions to build the pgtraj
framework in a PostGIS database, transfer ltraj
<-> pgtraj
, create pgtraj
from existing database tables, and manage pgtraj
.
The goal for GSoC 2017 is to build a feature-rich interactive trajectory plotting (mapping) tool in rpostgisLT
to create, manage, and explore pgtraj
, with a emphasis on fine scale trajectory analyses, environmental data viewing and data extraction. Particular focus for the project would be examine how to best utilize the strengths of multiple softwares (PostGIS, R, QGIS, etc.) and languages (SQL, PL/pgSQL, R, python, JavaScript, etc.) to build an efficient and user-friendly tool.
rpostgisLT
was initiated in 2016 by Mathieu Basille, David Bucklin, and Balázs Dukai (GSOC student 2016), with contribution from Clément Calenge.
Related to trajectories and interactive plotting in R:
adehabitatLT
: This package provides the trajectory framework (ltraj
) in R relied on by rpostgisLT
, and a large collection of trajectory manipulation and analysis tools. The function trajdyn
is a current implementation of interactive trajectory (ltraj
) viewing in R, which provides a basic set of viewer controls (step-by-step viewing, burst (sub-trajectory) plotting, distance measuring, identify relocations, etc.), and can use other spatial data as a background for the trajectory. However, it lacks a modern mapping interface, the ability to create/modify trajectories, or do spatial analysis with environmental layers.
The package hab
provides a version of trajdyn
which enhances it's exploration and data manipulation capabilities (e.g., only display k previous points/steps, update interactively a new or existing variable in infolocs).
move
, trip
, and trajectories
all provide classes and methods to handle trajectories in R, but interactive plotting is not a feature of any of these packages.
shiny
: package for building interactive web applications supports interactive plotting through reactive programming. shiny
base functions include a variety of UI input element creators (e.g., dateRangeInput
, sliderInput
) for interactive control, though fine-scale trajectory plotting (e.g., step-by-step analysis) and interactive selection of plot elements may require a custom solution in shiny.
leaflet
: R package interface to the Leaflet open-source JavaScript library for interactive mapping. Provides a wide variety of base maps, and plotting of points, lines, polygons, and raster datasets.
Spatial data in R: (not at all exhaustive, but likely most relevant to this project). Also see the CRAN task view:
sp
: Provides classes and methods for spatial data in R. Also of note is sf
, which supports simple feature encoding of spatial data and access to a large library of geometric operations.
rgeos
: Interface to the Geometry Engine - Open Source (GEOS), a large set of geometric operator (e.g., Intersection, Union, Buffer, etc.) functions for sp
objects
rpostgis
: companion package for rpostgisLT
which provides an interface between R (Spatial*
-class objects from sp
, Raster*
-class objects from the raster
package) and PostGIS for spatial data transfer, and database management.
RQGIS
: an interface for R and QGIS, the popular open-source desktop GIS, using the QGIS Python API, allowing access in R to a large library of spatial functions provided by QGIS.
Other
QGIS is a full-featured desktop GIS that provides useful tools in it's base package for PostGIS database users, like a database manager to directly load spatial tables, like the ones pgtraj
are stored in. R scripts can also be directly run from QGIS using base toolbox functionalities. QGIS has a large library of contributed Plugins, (for instance, spatial-temporal data can be animated with TimeManager) but no specific plugin exists for trajectory viewing/manipulation.
The expected output is a functional interactive trajectory viewer fully integrated with rpostgisLT
to create, edit, and analyze/explore pgtraj
. This could be implemented in several ways:
- a web application developed with
leaflet
and/orshiny
run from an R function - an extension of QGIS which can run
rpostgisLT
and other R package (e.g.,adehabitatLT
) functions directly
Part of the project will include preliminary period of research and testing to determine which implementation to use.
The viewer will be expected to:
- have an interactive map which can load spatial data into the map from the database, or the current data environment
- create
pgtraj
from loaded datasets/database tables - edit
pgtraj
(cut trajectories into bursts, remove/add locations or steps, filter trajectories according to step attributes) - analyze
pgtraj
trajectory with step-by-step control (as inadehabitatLT::trajdyn
), providing step attribute information (length, time, angle, etc) - load and animate one to many
pgtraj
simultaneously - extract data from other spatial datasets (points, polygons, lines, rasters) to trajectories and add it to
pgtraj
'infolocs'
Full documentation and a vignette/user guide will also be expected for the resulting tool.
The resulting product's target audience is researchers of animal movement working with telemetry datasets, but it should also appeal as well as anyone using R to work with trajectories. With a good UI and documentation, it could also be useful to a large base of users working with spatial/temporal datasets.
- David Bucklin is a geographer specialized in spatial technologies (GIS, remote sensing, and GPS), with an emphasis on their application in conservation biology and ecology; he is an expert in spatial databases and spatial data management, and develops tools and techniques for geo-processing workflows. He is a lead developer and the package maintainer for
rpostgis
andrpostgisLT
. - Mathieu Basille is an Assistant Professor at the University of Florida, with his main program dealing with animal movement and distribution. As a quantitative ecologist, he is bringing an extensive knowledge of R, in particular in the context of movement ecology. He is a lead developer for
hab
,rpostgis
andrpostgisLT
. - Clement Calenge is a biometrician at the intersection of three scientific domains: biology, statistics and computer science. He developed the adehabitat suite to provide adequate mathematical models and statistical methods to analyse biological data structures, such as animal location or movement data.
Test 1. Using the example data (gps_data
) as below, with tags from 2 roe deer:
library(rpostgis)
data("roe_gps_data")
gps_data<-rbind(roe_gps_data$GSM01511[c("gps_sensors_code","utc_date","utc_time","latitude","longitude")],
roe_gps_data$GSM01512[c("gps_sensors_code","utc_date","utc_time","latitude","longitude")])
- create an
ltraj
(adehabitatLT::as.ltraj
) from the dataset - run
hab::trajdyn
on the ltraj - save the
ltraj
to a databasepgtraj
usingrpostgisLT
(make sure that the correct time zone and geographic projection are set for the ltraj first!)
Test 2. Using the same example data from question 1 (gps_data
):
- write an R function to launch a Shiny app with an interactive Leaflet map, displaying the gps_data as a trajectory (a set of steps between successive points). Add a slider to interactively subset the trajectory displayed in the map by time.
Test 3. Using gps_data
and raster
as below:
library(rpostgisLT)
data("roe_gps_data")
gps_data<-roe_gps_data$GSM01511[c("utc_date","utc_time","latitude","longitude")]
data("roe_raster")
raster<-roe_raster$srtm_dem
In a new PostgreSQL/PostGIS database, use rpostgis
and rpostgisLT
to (1) send gps_data
to the database in a new table and (2) create a new pgtraj
from data in the new database table (using rpostgisLT::as_pgtraj
), with each year-month combination as a separate burst.
Send raster
to the database as well, in a separate schema.
Write code to summarize the average elevation of each step (i.e., intersect the trajectory steps with the raster and average the pixel values):
- in R
- In PostGIS (SQL) and/or (bonus) with a new PL/pgSQL function
- In QGIS (python) and/or (bonus) RQGIS
BONUS = Add the average elevation values to the pgtraj infolocs
table (see as_pgtraj
on how to add infolocs to a new pgtraj
; it maybe useful to add a dummy variable to the gps_data
table and specify that in info_cols
).
Students, please post a link to your test results here.
Balázs Dukai: https://github.com/balazsdukai/rpostgisLT_test/blob/master/test2017.md