FAQ Answer:
Can I access Timelapse Data with Postgres?

Timelapse data (.ddb) files are actually SQLite databases. Because SQL is fairly standard, queries on that data can be done not only by a SQLite systems (e.g., DB Browser for SQLite), but other database systems as well.

PostgreSQL is one such example, where it can be used to create complex SQL queries, including how to display results via a GIS system. While I have not used PostgreSQL myself, Kevin Floyd of Island Conservation (New Zealand) sent me these notes on how to access Timelapse data using it. He said:

I am using a foreign data wrapper to link the TimelapseData.ddb file into a postgres database. This allows me to link the data to the camera spatial locations and create all sorts of queries to help understand what our animals are up to.  Having the data linked into the Postgres database allows more query functions and makes it easier to generate camera trap nights, relative abundance etc live from Timelapse without exporting from or adding views to the ddb. 

The instructions he provided assumes you are using PostgreSQL 11 or higher, and that postgis and ogr_fdw are part of the installed postgres package.

Create required extensions

  • CREATE EXTENSION postgis;  ‘ required for spatial data, geometry
  • CREATE EXTENSION ogr_fdw;  required for foreign tables

Create Foreign Server
(Note: Change ‘filepath’ to your file path)

  • CREATE SERVER timelapse_srv
  • FOREIGN DATA WRAPPER ogr_fdw
  • OPTIONS (datasource ‘C:\User\Documents\CameraImages\TimelapseData.ddb’, format ‘SQLite’)

Create Schema for foreign tables

  • CREATE SCHEMA timelapse AUTHORIZATION postgres;

Import all tables into schema.
(Note: if timelapse database fields are changed then the tables will need to be recreated.)

  • IMPORT FOREIGN SCHEMA ogr_all
  • FROM SERVER timelapse_srv
  • INTO timelapse;

All timelapse tables should now be linked into Postgres.  Now the data can be queried with Postgres and also joined to spatial tables. This means you now have a live link to the timelapse database and can create views etc for data analysis without having to export from timelapse or change anything within the ddb file.

Create a view for joining spatial data

Assuming you have folder names that match camera codes, you can create a view for joining spatial data by using the relativepath column to get the camera code. 

  • CREATE OR REPLACE VIEW timelapse.vw_data_table
    AS SELECT split_part(d.relativepath::text, ‘\’::text, 1) AS camera,
    d.*
    FROM timelapse.datatable d;

Or you can join directly to add a geometry column to the datatable, if you have a spatial table of camera locations with name and desc columns (ie imported into postgres from a gpx file)

  • CREATE OR REPLACE VIEW public.vw_data_table_geom
    AS SELECT
    c.name,
    c.“desc”,
    d.*,
    c.geom
    FROM timelapse.datatable d
    JOIN camera c ON split_part(d.relativepath::text, ‘\’::text, 1) = c.name::text;