inbo / camtrapdp

R package to read and manipulate Camera Trap Data Packages (Camtrap DP)
https://inbo.github.io/camtrapdp/
Other
5 stars 0 forks source link

Filter `spatial` and `temporal` in metadata with `filter_deployments()` #72

Closed peterdesmet closed 1 month ago

peterdesmet commented 3 months ago

The spatial and temporal properties in the metadata are derived from the deployments. filter_deployments() affects these ranges and should therefore update those (potentially with a flag, update_metadata = TRUE). At the moment, this is less important because the metadata are not used within the R environment, but it will become important once packages are written back to disk.

sannegovaert commented 2 months ago

I would assume that in x$spatial$coordinates the coordinates of the deployments are provided, but this is not the case. What are these coordinates? Or is this a mistake in the example dataset?

library(camtrapdp)
x <- example_dataset()
x$spatial
# $type
# [1] "Polygon"
# 
# $bbox
# [1]  4.013 50.699  5.659 51.496
# 
# $coordinates
# , , 1
# 
# [,1]  [,2]  [,3]  [,4]  [,5]
# [1,] 4.013 5.659 5.659 4.013 4.013
# 
# , , 2
# 
# [,1]   [,2]   [,3]   [,4]   [,5]
# [1,] 50.699 50.699 51.496 51.496 50.699

deployments(x) %>%  select(deploymentID, latitude, longitude)
# deploymentID latitude longitude
# <chr>           <dbl>     <dbl>
# 1 00a2c20d         51.5      4.77
# 2 29b7d356         51.2      5.66
# 3 577b543a         51.2      5.66
# 4 62c200a9         50.7      4.01
peterdesmet commented 2 months ago

The example dataset in Camtrap DP v1.0 contains a bbox that can be removed. It is already in the main branch.

The numbers provided in x$spatial$coordinates are coordinates from deployments, as a bounding box starting in the top right corner, and walking around the edge counterclockwise, defining each corner. The last point is repeated (to close the box):

  1. x_east, y_north
  2. x_west, y_north
  3. x_west, y_south
  4. x_east, y_south
  5. x_east, y_north

x_east = max(longitude), x_west = min(longitude), y_north = max(latitude), y_south = min(latitude)

I would definitely create a helper function (build_spatial) for this.

sannegovaert commented 2 months ago

When filtering results in no records, what should x$spatial than look like?

library(dplyr)
x <- example_dataset()
x_empty <- filter_deployments(x, latitude < 0, longitude < 0)
x_empty$spatial
# $type
# [1] "Polygon"
# 
# $bbox
# [1] NA NA NA NA
# 
# $coordinates
# , , 1
# 
# [,1] [,2] [,3] [,4] [,5]
# [1,]   NA   NA   NA   NA   NA
# 
# , , 2
# 
# [,1] [,2] [,3] [,4] [,5]
# [1,]   NA   NA   NA   NA   NA

or

x_empty$spatial
# NA

or

x_empty$spatial
# $type
# [1] "Polygon"
# 
# $bbox
# NA
# 
# $coordinates
# NA

Or something else?

peterdesmet commented 2 months ago

If there are no deployments, set spatial to NULL (same for temporal). Since it's a required term in Camtrap DP, that will raise a validation error when validating with frictionless, but that is expected.

damianooldoni commented 1 month ago

I will remove this issue from the camtraptor sprint project as it is not related to camtraptor. Probably to be added to another project?