asPgtraj: Imports location data from a database table into the pgtraj...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/asPgtraj.R

Description

asPgtraj populates a pgtraj schema from the data provided in relocations_table. If the provided schema doesn't exist, it will be created. On successful data input, asPgtraj creates two database views for each new pgtraj. These views are named parameters_<pgtraj_name>, step_geometry_<pgtraj_name> and described in more detail in the package vignette.

Usage

1
2
3
4
asPgtraj(conn, relocations_table, schema = "traj", pgtrajs = "pgtraj",
  animals = "animal", bursts = NULL, relocations, timestamps = NULL,
  rids = "rid", srid = NULL, tzone = NULL, note = NULL,
  clauses = NULL, info_cols = NULL, info_table = NULL, info_rids = NULL)

Arguments

conn

Connection object created with RPostgreSQL

relocations_table

String. Name of the schema and table that stores the relocations, e.g. c("schema","relocations")

schema

String. Name of the schema that stores or will store the pgtraj data model (Default = "traj").

pgtrajs

String. Name of the pgtraj or name of the field that stores the pgtraj names.

animals

String. Name of the animal or name of the field that stores the animal names.

bursts

String. (Optional) name of the burst or name of the field that stores the burst names. If not given, each animal will have one burst.

relocations

String. Name of the field that contains the relocations in relocations_table. Relocations can be provided either as columns names containing X,Y coordinates (e.g., c("x","y")) or a PostGIS geometry (e.g., "geom"). In both cases all relocations in relocations_table must have the same projection. If provided as coordinates in two columns, projection will be undefined unless srid is defined.

timestamps

String. Name of the field in relocations_table that contains the timestamps. If NULL, Type I trajectory is assumed.

rids

String. Name of the field in relocations_table that contains the numeric IDs of relocations. If timestamps = NULL, relocations will be sorted by the ascending numeric IDs in this field.

srid

Integer. Optional SRID (spatial reference ID) of (x,y) coordinates provided for relocations. Ignored if relocations is a geometry type.

tzone

String. Time zone specification for the timestamps column. If not specified, the database server time zone will be used (usually the server's local time zone).

note

String. Comment on the pgtraj. The comment is only used in the database and not transferred into the ltraj.

clauses

character, additional SQL to append to modify data selected from relocations_table. Must begin with WHERE ..., and cannot contain ORDER BY or LIMIT clauses.

info_cols

String. Optional character vector of database table column names storing additional information on relocations (replicating "infolocs" from the adehabitatLT object ltraj).

info_table

Character vector of c("schema","table") holding the info_cols. If info_cols are in relocations_table, leave NULL.

info_rids

String. Column name of unique integer ID in info_table to join with rids from relocations_table. If info_cols are in relocations_table, leave NULL.

Details

Opening and closing PostgreSQL connections have to be done manually by the user. However, the function checks if the provided connection is still valid.

Note that the arguments pgtrajs, animals, bursts, and note can refer to either a column name in relocations_table, or a string value. If the value is a column name, the values for the corresponding attribute (e.g., animals) will be the values from that column. When providing a string value, the value will be applied to that attribute for the entire pgtraj.

Burst names must be unique across a pgtraj. If it is not desired to further subset individual animal trajectories, leave bursts = NULL, in which case burst names will be equal to the animal name.

The time zone of the pgtraj is set to the local time zone of the user.

Value

TRUE on success

Author(s)

Balázs Dukai balazs.dukai@gmail.com

David Bucklin dbucklin@ufl.edu

References

https://CRAN.R-project.org/package=adehabitatLT/vignettes/adehabitatLT.pdf

See Also

Section on pgtraj data model in the package vignette.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## Not run: 
asPgtraj(conn, 
        relocations_table = c("example_data","relocations_plus"),
        pgtrajs = "id",
        animals = "animal",
        bursts = "burst",
        relocations = "geom",
        timestamps = "time",
        rids = "gid",
        note = "trajectories in 2015",
        clauses = "WHERE extract(year FROM acquisition_time) = 2015",
        info_cols = c("dist_to_road","land_cover","error_class")
        )

## End(Not run)

## Not run: 
asPgtraj(conn, 
        relocations_table = c("example_data","relocations_plus"),
        schema = "traj_t4",
        pgtrajs = "id",
        animals = "animal",
        bursts = "burst",
        relocations = c("x","y"),
        timestamps = "time",
        rids = "gid")

## End(Not run)

mablab/rpostgisLT documentation built on May 10, 2020, 9:35 a.m.