updateCatalog: Create/update a camera trap data catalog

Usage Arguments Examples

View source: R/handle_catalog.R

Usage

1
updateCatalog(verbose = FALSE)

Arguments

verbose

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (verbose = FALSE)
{
    theRepo <- getRepository()
    if (verbose)
        cat("Repo is ", theRepo, "\n")
    siteNames <- listSiteDir()
    if (verbose)
        cat("Sites: ", siteNames, "\n")
    catalogData <- list()
    for (site in siteNames) {
        sitePath <- paste(theRepo, site, sep = "/")
        if (verbose)
            cat("\tprocessing site ", site, "\n")
        if (file.exists(paste(sitePath, "metadata.txt", sep = "/"))) {
            .pkgOptions$metadata[[site]] <- .parseMetadata(path = sitePath)
        }
        else {
            warning("\tno medatata found for site ", site, "\n")
        }
        cameraNames <- listCameraDir(site)
        .pkgOptions$metadata[[site]]$cameras <- list()
        siteData <- list()
        for (camera in cameraNames) {
            cameraPath <- paste(sitePath, camera, sep = "/")
            if (verbose)
                cat("\t\tprocessing camera ", camera, "\n")
            .pkgOptions$metadata[[site]][[camera]] <- .parseMetadata(path = cameraPath)
            sdcardDirs <- listDataDir(site, camera)
            cameraData <- list()
            for (sdcard in sdcardDirs) {
                dataPath <- paste(cameraPath, sdcard, sep = "/")
                if (verbose)
                  cat("\t\t\tprocessing sdcard ", sdcard, "\n")
                sdcData <- getEXIFData(dataPath, tz = .pkgOptions$metadata[[site]][[camera]][["timezone"]])
                if (nrow(sdcData) > 0) {
                  cameraData[[sdcard]] <- sdcData
                }
            }
            cameraData <- do.call("rbind", cameraData)
            cameraData$Raw.Path <- dataPath
            cameraData$Raw.Names <- basename(as.character(cameraData$Raw.Names))
            cameraData$Camera.Serial.Number <- .pkgOptions$metadata[[site]][[camera]][["serial"]]
            cameraData$Camera.Start.Date.and.Time <- .pkgOptions$metadata[[site]][[camera]][["start"]]
            cameraData$Camera.End.Date.and.Time <- .pkgOptions$metadata[[site]][[camera]][["end"]]
            cameraData$Camera.Manufacturer <- .pkgOptions$metadata[[site]][[camera]][["make"]]
            cameraData$Camera.Model <- .pkgOptions$metadata[[site]][[camera]][["model"]]
            cameraData$Latitude <- as.numeric(.pkgOptions$metadata[[site]][[camera]][["lat"]])
            cameraData$Longitude <- as.numeric(.pkgOptions$metadata[[site]][[camera]][["lon"]])
            cameraData$Sampling.Unit.Name <- camera
            siteData[[camera]] <- cameraData
        }
        siteData <- do.call("rbind", siteData)
        catalogData[[site]] <- siteData
    }
    catalogData <- do.call("rbind", catalogData)
    row.names(catalogData) <- NULL
    invisible(catalogData)
  }

dgpreatoni/cameratraps documentation built on Nov. 4, 2019, 10:30 a.m.