diff --git a/NEWS.md b/NEWS.md
index 2d2da09..df05fe0 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -8,7 +8,7 @@ if anything is new or missing.
## Endpoints
-- Same endpoints as in v1.1.0
+- Same endpoints as in `v1.1.0`
+ `get_raster()` communicates with the 4Wings API to get fishing effort
+ `get_vessel_info()` communicates with the Vessels API
+ `get_event()` communicates with the Events API
@@ -50,6 +50,9 @@ script and copy the string of the request when [filling an issue](https://github
+ The `region` argument now accepts `sf` polygons rather than a GeoJSON string
+ Parameters `start_date` and `end_date` replace `date_range` for consistency with other functions
+### Additional changes
+
+- Option `USER_JSON` has been renamed to `USER_SHAPEFILE` for clarity (addresses #161)
# gfwr 1.1.0
diff --git a/R/get_endpoint.R b/R/get_endpoint.R
index 2cf200b..3763da2 100644
--- a/R/get_endpoint.R
+++ b/R/get_endpoint.R
@@ -1,7 +1,7 @@
#'
#' Function to get API dataset name for given event type
#'
-#' @param dataset_type Type of dataset to get API dataset name for. It can be
+#' @param dataset_type Type of dataset to get API dataset name for. It can be "raster",
#' "ENCOUNTER", "LOITERING", "FISHING", "PORT_VISIT", "GAP", "EEZ", "RFMO" or "MPA"
#' @param ... Other arguments that would depend on the dataset type.
#' @importFrom httr2 request
diff --git a/R/get_event.R b/R/get_event.R
index 02c7e7d..d7711c6 100644
--- a/R/get_event.R
+++ b/R/get_event.R
@@ -16,7 +16,7 @@
#' @param confidences Confidence levels (1-4) of events (port visits only)
#' @param region sf shape to filter raster or GFW region code (such as an
#' EEZ code). See details about formatting the geojson
-#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or 'USER_JSON')
+#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')
#' @param gap_intentional_disabling Logical. Whether the Gap events are intentional,
#' according to Global Fishing Watch algorithms
#' @param key Authorization token. Can be obtained with gfw_auth() function
@@ -125,6 +125,18 @@
#' region_source = 'EEZ',
#' flags = 'CHN',
#' key = gfw_auth())
+#'
+#' # fishing events in user shapefile
+#' test_polygon <- sf::st_bbox(c(xmin = -70, xmax = -40, ymin = -10, ymax = 5),
+#' crs = 4326) |>
+#' sf::st_as_sfc() |>
+#' sf::st_as_sf()
+#'get_event(event_type = 'FISHING',
+#' start_date = "2020-10-01",
+#' end_date = "2020-12-31",
+#' region = test_polygon,
+#' region_source = 'USER_SHAPEFILE',
+#' key = gfw_auth())
#' }
#' @export
@@ -233,8 +245,9 @@ get_event <- function(event_type,
} else if (region_source == 'RFMO' & is.character(region)) {
region = rjson::toJSON(list(region = list(dataset = 'public-rfmo',
id = region)))
- } else if (region_source == 'USER_JSON') {
- if (methods::is(region, 'sf') & base::class(region$geometry)[1] %in% c("sfc_POLYGON","sfc_MULTIPOLYGON")) {
+ } else if (region_source == 'USER_SHAPEFILE') {
+ if (methods::is(region, 'sf') & any(base::class(sf::st_geometry(region)) %in% c("sfc_POLYGON","sfc_MULTIPOLYGON"))
+ ) {
region <- sf_to_geojson(region, endpoint = 'event')
} else {
stop('custom region is not an sf polygon')
@@ -250,7 +263,7 @@ get_event <- function(event_type,
list(startDate = jsonlite::unbox(start)),
list(endDate = jsonlite::unbox(end))
))
- } else if (region_source == 'USER_JSON') {
+ } else if (region_source == 'USER_SHAPEFILE') {
body_args <- jsonlite::toJSON(c(body_args,
list(startDate = jsonlite::unbox(start)), # removes from array
@@ -341,7 +354,7 @@ get_event <- function(event_type,
#' @param region_source Optional but mandatory if using the argument region.
#' Source of the region. If 'EEZ','MPA', 'RFMO',
#' then the value for the argument region must be the code for that region.
-#' If 'USER_JSON', then region has to be an sf object
+#' If 'USER_SHAPEFILE', then region has to be an sf object
#' @param region GFW region code (such as an EEZ, MPA or RFMO code) or a
#' formatted geojson shape. See Details about formatting the geojson.
#' @param duration duration, in minutes, of the event, ex. 30
@@ -492,7 +505,7 @@ get_event_stats <- function(event_type,
} else if (region_source == 'RFMO' & is.character(region)) {
region = rjson::toJSON(list(region = list(dataset = 'public-rfmo',
id = region)))
- } else if (region_source == 'USER_JSON') {
+ } else if (region_source == 'USER_SHAPEFILE') {
if (methods::is(region, 'sf') & base::class(region$geometry)[1] %in% c("sfc_POLYGON","sfc_MULTIPOLYGON")) {
region <- sf_to_geojson(region, endpoint = 'event')
} else {
@@ -510,7 +523,7 @@ get_event_stats <- function(event_type,
list(endDate = jsonlite::unbox(end)),
list(timeseriesInterval = jsonlite::unbox(interval))
))
- } else if (region_source == 'USER_JSON') {
+ } else if (region_source == 'USER_SHAPEFILE') {
body_args <- jsonlite::toJSON(c(body_args,
list(startDate = jsonlite::unbox(start)), # removes from array
diff --git a/R/get_raster.R b/R/get_raster.R
index c3e17ef..a9c8bd2 100644
--- a/R/get_raster.R
+++ b/R/get_raster.R
@@ -11,7 +11,7 @@
#' @param end_date End of date range to search events, in YYYY-MM-DD format and excluding this date
#' @param region sf shape to filter raster or GFW region code (such as a
#' Marine Regions Geographic Identifier or EEZ code).
-#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or 'USER_JSON')
+#' @param region_source source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')
#' @param key Authorization token. Can be obtained with `gfw_auth()` function
#' @param print_request Boolean. Whether to print the request, for debugging
#' purposes. When contacting the GFW team it will be useful to send this string
@@ -50,7 +50,7 @@
#' start_date = '2021-01-01',
#' end_date = '2021-10-01',
#' region = test_shape,
-#' region_source = 'USER_JSON',
+#' region_source = 'USER_SHAPEFILE',
#' key = gfw_auth(),
#' print_request = TRUE)
#' }
@@ -90,9 +90,9 @@ if (is.null(region_source)) stop("region_source and region params are required")
if (length(region) > 1) stop("only 1 RFMO region must be provided")
region <- rjson::toJSON(list(region = list(dataset = 'public-rfmo',
id = region)))
- } else if (region_source == 'USER_JSON') {
- if (methods::is(region, 'sf') & base::class(region$geometry)[1] %in% c("sfc_POLYGON","sfc_MULTIPOLYGON")
- ) {
+ } else if (region_source == 'USER_SHAPEFILE') {
+ if (methods::is(region, 'sf') & any(base::class(sf::st_geometry(region)) %in% c("sfc_POLYGON","sfc_MULTIPOLYGON"))
+ ) {
region <- sf_to_geojson(region, endpoint = 'raster')
} else {
stop('custom region is not an sf polygon')
diff --git a/R/utils.R b/R/utils.R
index 64b1c6a..efdbae7 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -152,7 +152,7 @@ get_regions <- function(region_source = 'EEZ',
result <- get_endpoint(dataset_type = region_source) %>%
httr2::req_headers(Authorization = paste("Bearer", key, sep = " ")) %>%
httr2::req_user_agent(gfw_user_agent()) %>%
- httr2::req_error(body = parse_response_error) %>%
+ # httr2::req_error(body = parse_response_error) %>%
httr2::req_perform(.) %>%
httr2::resp_body_json(.) %>%
dplyr::bind_rows()
diff --git a/README.Rmd b/README.Rmd
index 3bce9a8..5a812f5 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -290,12 +290,12 @@ and converts the response to a data frame. In order to use it, you should specif
* The variable to group by: `FLAG`, `GEARTYPE`, `FLAGANDGEARTYPE`, `MMSI` or `VESSEL_ID`
* The date range `note: this must be 366 days or less`
* The region polygon in `sf` format or the region code (such as an EEZ code) to filter the raster
-* The source for the specified region. Currently, `EEZ`, `MPA`, `RFMO` or `USER_JSON` (for `sf` shapefiles).
+* The source for the specified region. Currently, `EEZ`, `MPA`, `RFMO` or `USER_SHAPEFILE` (for `sf` shapefiles).
### Examples
-You can load a sample shapefile inside `gfwr` to see how `'USER_JSON'` works:
+You can load a sample shapefile inside `gfwr` to see how `'USER_SHAPEFILE'` works:
```{r example_map_1}
data("test_shape")
@@ -307,7 +307,7 @@ get_raster(
start_date = '2021-01-01',
end_date = '2021-02-01',
region = test_shape,
- region_source = 'USER_JSON',
+ region_source = 'USER_SHAPEFILE',
key = key
)
```
diff --git a/README.md b/README.md
index 6891639..bbe9c41 100644
--- a/README.md
+++ b/README.md
@@ -176,8 +176,8 @@ get_vessel_info(query = 224224000,
#> # A tibble: 2 × 9
#> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³
#> To specify more than one This is useful especially because a vessel can have different
@@ -640,8 +640,8 @@ When no events are available, the You can load a sample shapefile inside ,
@@ -303,15 +303,15 @@ get_vessel_info(ids = "8c7304226-6c71-edbe-0b63-c246734b3c01",
#> # A tibble: 2 × 6
#> name flag ssvid sourceCode dateFrom dateTo
#>
-#> 1 2022-12-19T00:00:00Z 2024-05-01T00:00:00Z 210631000
,
#> # matchFields
, lengthM
-#> 1 2012-01-01T00:00:00Z 2024-05-01T00:00:00Z 548012100
,
#> # matchFields
#> 1 2020-01-05 04:58:45 2020-01-05 06:31:45 379d… fish… 43.7 -124.
, distances
, vessel
,
#> # event_info
```
@@ -617,12 +617,12 @@ should specify:
- The region polygon in `sf` format or the region code (such as an EEZ
code) to filter the raster
- The source for the specified region. Currently, `EEZ`, `MPA`, `RFMO`
- or `USER_JSON` (for `sf` shapefiles).
+ or `USER_SHAPEFILE` (for `sf` shapefiles).
### Examples
-You can load a sample shapefile inside `gfwr` to see how `'USER_JSON'`
-works:
+You can load a sample shapefile inside `gfwr` to see how
+`'USER_SHAPEFILE'` works:
``` r
data("test_shape")
@@ -634,7 +634,7 @@ get_raster(
start_date = '2021-01-01',
end_date = '2021-02-01',
region = test_shape,
- region_source = 'USER_JSON',
+ region_source = 'USER_SHAPEFILE',
key = key
)
#> Rows: 2526 Columns: 6
@@ -689,16 +689,16 @@ get_raster(spatial_resolution = 'LOW',
#> # A tibble: 611 × 6
#> Lat Lon `Time Range` flag `Vessel IDs` `Apparent Fishing Hours`
#>
Examples#> # A tibble: 2 × 9
#> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³
#> <chr> <chr> <chr> <int>
-#> 1 3c99c326… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2015
-#> 2 6632c9eb… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2019
+#> 1 6632c9eb… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2019
+#> 2 3c99c326… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2015
#> # ℹ abbreviated names: ¹geartypes_geartype_name, ²geartypes_geartype_source,
#> # ³geartypes_geartype_yearFrom
#> # ℹ 5 more variables: geartypes_geartype_yearTo <int>,
@@ -327,9 +327,9 @@
Examples#> # A tibble: 3 × 9
#> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³
#> <chr> <chr> <chr> <int>
-#> 1 58cf536b… CARRIER GFW_VESSEL_LIST 2012
+#> 1 1da8dbc2… CARRIER GFW_VESSEL_LIST 2022
#> 2 0b7047cb… CARRIER GFW_VESSEL_LIST 2019
-#> 3 1da8dbc2… CARRIER GFW_VESSEL_LIST 2022
+#> 3 58cf536b… CARRIER GFW_VESSEL_LIST 2012
#> # ℹ abbreviated names: ¹geartypes_geartype_name, ²geartypes_geartype_source,
#> # ³geartypes_geartype_yearFrom
#> # ℹ 5 more variables: geartypes_geartype_yearTo <int>,
@@ -340,7 +340,7 @@
Examples#> # A tibble: 3 × 13
#> vesselId ssvid shipname nShipname flag callsign imo messagesCounter
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int>
-#> 1 1da8dbc23-3c48-… 6135… GABU RE… GABUREEF… CMR TJMC996 8300… 71775911
+#> 1 1da8dbc23-3c48-… 6135… GABU RE… GABUREEF… CMR TJMC996 8300… 72480839
#> 2 0b7047cb5-58c8-… 2141… GABU RE… GABUREEF… MDA ER2732 8300… 70035084
#> 3 58cf536b1-1fca-… 6168… GABU RE… GABUREEF… COM D6FJ2 8300… 32121624
#> # ℹ 5 more variables: positionsCounter <int>, sourceCode <list>,
@@ -389,15 +389,15 @@
Examples#> # A tibble: 2 × 6
#> name flag ssvid sourceCode dateFrom dateTo
#> <chr> <chr> <chr> <list> <chr> <chr>
-#> 1 COLINER CYP 210631000 <chr [1]> 2014-01-01T00:16:58Z 2024-04-30T23:41:06Z
+#> 1 COLINER CYP 210631000 <chr [1]> 2014-01-01T00:16:58Z 2024-05-31T23:44:00Z
#> 2 COLINER CYP 273379740 <chr [1]> 2015-02-27T10:59:43Z 2018-03-21T07:13:09Z
#>
#> $registryPublicAuthorizations
#> # A tibble: 2 × 4
#> dateFrom dateTo ssvid sourceCode
#> <chr> <chr> <chr> <list>
-#> 1 2022-12-19T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]>
-#> 2 2020-01-01T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]>
+#> 1 2022-12-19T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]>
+#> 2 2020-01-01T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]>
#>
#> $combinedSourcesInfo
#> # A tibble: 2 × 9
@@ -415,7 +415,7 @@
Examples#> # A tibble: 1 × 13
#> vesselId ssvid shipname nShipname flag callsign imo messagesCounter
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int>
-#> 1 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263226124
+#> 1 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263878798
#> # ℹ 5 more variables: positionsCounter <int>, sourceCode <list>,
#> # matchFields <chr>, transmissionDateFrom <chr>, transmissionDateTo <chr>
vesselId
, you can submit a
@@ -438,18 +438,18 @@ Examples#> # A tibble: 3 × 1
#> registryInfoTotalRecords
#> <int>
-#> 1 1
+#> 1 2
#> 2 1
-#> 3 2
+#> 3 1
#>
#> $registryInfo
#> # A tibble: 4 × 15
#> id sourceCode ssvid flag shipname nShipname callsign imo
#> <chr> <list> <chr> <chr> <chr> <chr> <chr> <chr>
-#> 1 b82d02e5c2c11e5fe536… <chr [5]> 4417… KOR ADRIA ADRIA DTBY3 8919…
-#> 2 685862e0626f6234c844… <chr [5]> 5480… PHL JOHNREY… JOHNREYN… DUQA7 8118…
-#> 3 a8d00ce54b37add7f85a… <chr [6]> 2106… CYP FRIO FO… FRIOFORW… 5BWC3 9076…
-#> 4 a8d00ce54b37add7f85a… <chr [2]> 2733… RUS FRIO FO… FRIOFORW… UCRZ 9076…
+#> 1 a8d00ce54b37add7f85a… <chr [6]> 2106… CYP FRIO FO… FRIOFORW… 5BWC3 9076…
+#> 2 a8d00ce54b37add7f85a… <chr [2]> 2733… RUS FRIO FO… FRIOFORW… UCRZ 9076…
+#> 3 685862e0626f6234c844… <chr [5]> 5480… PHL JOHNREY… JOHNREYN… DUQA7 8118…
+#> 4 b82d02e5c2c11e5fe536… <chr [5]> 4417… KOR ADRIA ADRIA DTBY3 8919…
#> # ℹ 7 more variables: latestVesselInfo <lgl>, transmissionDateFrom <chr>,
#> # transmissionDateTo <chr>, geartypes <list>, lengthM <dbl>, tonnageGt <dbl>,
#> # vesselInfoReference <chr>
@@ -458,34 +458,34 @@
Examples#> # A tibble: 4 × 6
#> name flag ssvid sourceCode dateFrom dateTo
#> <chr> <chr> <chr> <list> <chr> <chr>
-#> 1 DONGWON INDUSTRIES KOR 441734000 <chr [2]> 2014-01-18T19… 2024-…
-#> 2 TRANS PACIFIC JOURNEY FISHING PHL 548012100 <chr [3]> 2017-02-07T00… 2019-…
-#> 3 COLINER CYP 210631000 <chr [1]> 2014-01-01T00… 2024-…
-#> 4 COLINER CYP 273379740 <chr [1]> 2015-02-27T10… 2018-…
+#> 1 COLINER CYP 210631000 <chr [1]> 2014-01-01T00… 2024-…
+#> 2 COLINER CYP 273379740 <chr [1]> 2015-02-27T10… 2018-…
+#> 3 TRANS PACIFIC JOURNEY FISHING PHL 548012100 <chr [3]> 2017-02-07T00… 2019-…
+#> 4 DONGWON INDUSTRIES KOR 441734000 <chr [2]> 2014-01-18T19… 2024-…
#>
#> $registryPublicAuthorizations
#> # A tibble: 6 × 4
#> dateFrom dateTo ssvid sourceCode
#> <chr> <chr> <chr> <list>
-#> 1 2013-09-20T00:00:00Z 2024-05-01T00:00:00Z 441734000 <chr [1]>
-#> 2 2015-10-08T00:00:00Z 2020-07-21T00:00:00Z 441734000 <chr [1]>
+#> 1 2022-12-19T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]>
+#> 2 2020-01-01T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]>
#> 3 2012-01-01T00:00:00Z 2024-05-01T00:00:00Z 548012100 <chr [1]>
#> 4 2012-01-01T00:00:00Z 2017-10-25T00:00:00Z 548012100 <chr [1]>
-#> 5 2022-12-19T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]>
-#> 6 2020-01-01T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]>
+#> 5 2013-09-20T00:00:00Z 2024-06-01T00:00:00Z 441734000 <chr [1]>
+#> 6 2015-10-08T00:00:00Z 2020-07-21T00:00:00Z 441734000 <chr [1]>
#>
#> $combinedSourcesInfo
#> # A tibble: 8 × 9
#> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³
#> <chr> <chr> <chr> <int>
-#> 1 6583c51e… OTHER COMBINATION_OF_REGIST… 2013
-#> 2 6583c51e… OTHER COMBINATION_OF_REGIST… 2013
-#> 3 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014
-#> 4 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014
-#> 5 55889aef… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017
-#> 6 71e7da67… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017
-#> 7 da1cd7e1… CARRIER GFW_VESSEL_LIST 2015
-#> 8 8c730422… CARRIER GFW_VESSEL_LIST 2013
+#> 1 da1cd7e1… CARRIER GFW_VESSEL_LIST 2015
+#> 2 8c730422… CARRIER GFW_VESSEL_LIST 2013
+#> 3 71e7da67… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017
+#> 4 55889aef… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017
+#> 5 6583c51e… OTHER COMBINATION_OF_REGIST… 2013
+#> 6 6583c51e… OTHER COMBINATION_OF_REGIST… 2013
+#> 7 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014
+#> 8 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014
#> # ℹ abbreviated names: ¹geartypes_geartype_name, ²geartypes_geartype_source,
#> # ³geartypes_geartype_yearFrom
#> # ℹ 5 more variables: geartypes_geartype_yearTo <int>,
@@ -496,9 +496,9 @@
Examples#> # A tibble: 3 × 13
#> vesselId ssvid shipname nShipname flag callsign imo messagesCounter
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int>
-#> 1 6583c51e3-3626-… 4417… ADRIA ADRIA KOR DTBY3 8919… 3742574
+#> 1 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263878798
#> 2 71e7da672-2451-… 5480… JOHN RE… JOHNREYN… PHL DUQA-7 8118… 1967237
-#> 3 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263226124
+#> 3 6583c51e3-3626-… 4417… ADRIA ADRIA KOR DTBY3 8919… 3742574
#> # ℹ 5 more variables: positionsCounter <int>, sourceCode <list>,
#> # matchFields <chr>, transmissionDateFrom <chr>, transmissionDateTo <chr>
Examples= "2020-02-01",
key = key
)
-#> [1] "Downloading 34 events from GFW"
-#> # A tibble: 34 × 11
+#> [1] "Downloading 37 events from GFW"
+#> # A tibble: 37 × 11
#> start end id type lat lon regions
#> <dttm> <dttm> <chr> <chr> <dbl> <dbl> <list>
#> 1 2020-01-05 04:58:45 2020-01-05 06:31:45 379d… fish… 43.7 -124. <named list>
@@ -654,7 +654,7 @@
Examples#> 8 2020-01-10 18:21:53 2020-01-12 03:13:04 6739… fish… 38.0 -73.9 <named list>
#> 9 2020-01-13 12:45:32 2020-01-13 15:38:38 46f8… fish… 38.0 -73.9 <named list>
#> 10 2020-01-13 13:20:55 2020-01-13 15:07:53 2333… fish… 43.7 -124. <named list>
-#> # ℹ 24 more rows
+#> # ℹ 27 more rows
#> # ℹ 4 more variables: boundingBox <list>, distances <list>, vessel <list>,
#> # event_info <list>
get_event()
function
@@ -691,14 +691,14 @@ Fishing effort API
Examples
gfwr
to see how
-'USER_JSON'
works:'USER_SHAPEFILE'
works:
data("test_shape")
@@ -709,7 +709,7 @@ Examples= '2021-01-01',
end_date = '2021-02-01',
region = test_shape,
- region_source = 'USER_JSON',
+ region_source = 'USER_SHAPEFILE',
key = key
)
#> Rows: 2526 Columns: 6
@@ -762,16 +762,16 @@ Examples#> # A tibble: 611 × 6
#> Lat Lon `Time Range` flag `Vessel IDs` `Apparent Fishing Hours`
#> <dbl> <dbl> <dbl> <chr> <dbl> <dbl>
-#> 1 4.8 -5.9 2021 CHN 2 46.9
-#> 2 5.2 -4 2021 CPV 1 0.15
-#> 3 5.2 -4 2021 SLV 3 9.07
-#> 4 5.2 -4 2021 ESP 9 15.8
-#> 5 5.2 -4 2021 LBR 2 58.7
-#> 6 5.1 -4 2021 GHA 6 4.82
-#> 7 3 -3.9 2021 SLV 1 1.49
-#> 8 2.5 -5.4 2021 FRA 1 8.92
-#> 9 2.7 -4.1 2021 ESP 1 3.77
-#> 10 3.7 -7 2021 FRA 1 2.39
+#> 1 5 -5.5 2021 CHN 1 3.66
+#> 2 5.2 -4 2021 SLV 3 9.07
+#> 3 5.2 -4 2021 LBR 2 58.7
+#> 4 4.5 -4 2021 SLV 2 9.14
+#> 5 4.5 -3.8 2021 SLV 1 7.15
+#> 6 2.5 -5.4 2021 FRA 1 8.92
+#> 7 2 -4.2 2021 FRA 1 7.98
+#> 8 4.1 -7 2021 ESP 1 2.72
+#> 9 3.8 -5.9 2021 BLZ 1 7.67
+#> 10 3 -5.7 2021 ESP 1 0.57
#> # ℹ 601 more rows
You could search for just one word in the name of the EEZ and then decide which one you want:
@@ -805,16 +805,16 @@A similar approach can be used to search for a specific Marine Protected Area, in this case the Phoenix Island Protected Area @@ -842,16 +842,16 @@
It is also possible to filter rasters to one of the five regional fisheries management organizations (RFMO) that manage tuna and tuna-like @@ -912,8 +912,8 @@
-#check registry info:
+# # matchFields <chr>, transmissionDateFrom <chr>, transmissionDateTo <chr>
+#check registry info:
one_AIS$registryInfo %>% relocate(transmissionDateFrom, transmissionDateTo) #changing column order for visualization
# # A tibble: 1 × 15
# transmissionDateFrom transmissionDateTo id sourceCode ssvid flag shipname
# <chr> <chr> <chr> <list> <chr> <chr> <chr>
-# 1 2014-01-01T03:28:33Z 2024-04-30T21:44:3… 4550… <chr [1]> 7010… ARG ATLANTI…
+# 1 2014-01-01T03:28:33Z 2024-05-31T23:56:3… 4550… <chr [1]> 7010… ARG ATLANTI…
# # ℹ 8 more variables: nShipname <chr>, callsign <chr>, imo <chr>,
# # latestVesselInfo <lgl>, geartypes <list>, lengthM <dbl>, tonnageGt <int>,
# # vesselInfoReference <chr>
This other vessel has had three identities based on AIS, but these are easy to reconstruct:
-+-three_AIS <- get_vessel_info(where= "ssvid='412217989'") #one registry, three AIS # see AIS-based indentities: three_AIS$selfReportedInfo %>% relocate(transmissionDateFrom, transmissionDateTo) # # A tibble: 3 × 13 # transmissionDateFrom transmissionDateTo vesselId ssvid shipname nShipname # <chr> <chr> <chr> <chr> <chr> <chr> -# 1 2021-11-29T06:20:07Z 2024-06-28T23:58:36Z b373b6306-… 4122… HAO YAN… HAOYANG77 +# 1 2021-11-29T06:20:07Z 2024-07-20T23:59:49Z b373b6306-… 4122… HAO YAN… HAOYANG77 # 2 2014-03-29T00:32:05Z 2021-11-27T20:13:55Z 305097c65-… 4122… JIN LIA… JINLIAOY… # 3 2012-08-01T01:47:23Z 2014-03-29T00:14:05Z 95a173191-… 4316… HAKKO M… HAKKOMAR… # # ℹ 7 more variables: flag <chr>, callsign <chr>, imo <chr>, # # messagesCounter <int>, positionsCounter <int>, sourceCode <list>, -# # matchFields <chr>
-#check registry info: +# # matchFields <chr> +#check registry info: three_AIS$registryInfo # # A tibble: 1 × 15 # id sourceCode ssvid flag shipname nShipname callsign imo @@ -424,7 +422,7 @@
Matching AIS and registries: # # vesselInfoReference <chr>
However, sometimes a vessel found in AIS has no registry information and the registry fields come back empty.
-+get_vessel_info(where = "ssvid='71000036'") # $dataset # # A tibble: 1 × 1 @@ -470,15 +468,14 @@
Matching AIS and registries: # # matchFields <chr>, transmissionDateFrom <chr>, transmissionDateTo <chr>
It is also possible that a search returns a vessel with no matching AIS information and no registry
-+-noAIS_noReg <- get_vessel_info(where = "imo='44201155'") #no AIS, no registry information noAIS_noReg$registryInfoTotalRecords # # A tibble: 1 × 1 # registryInfoTotalRecords # <int> -# 1 0
--noAIS_noReg$selfReported +# 1 0 +noAIS_noReg$selfReported # # A tibble: 1 × 13 # vesselId ssvid shipname nShipname flag callsign imo messagesCounter # <chr> <chr> <chr> <chr> <lgl> <chr> <chr> <int> diff --git a/docs/articles/making-maps.html b/docs/articles/making-maps.html index 49c0990..e11efa3 100644 --- a/docs/articles/making-maps.html +++ b/docs/articles/making-maps.html @@ -150,26 +150,23 @@
Setup #> filter, lag #> The following objects are masked from 'package:base': #> -#> intersect, setdiff, setequal, union
--library(tidyr) +#> intersect, setdiff, setequal, union +library(tidyr) library(sf) -#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
--library(rnaturalearth) +#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE +library(rnaturalearth) library(rnaturalearthdata) #> #> Attaching package: 'rnaturalearthdata' #> The following object is masked from 'package:rnaturalearth': #> -#> countries110
To make our maps a little nicer, let’s define a custom
-ggplot2
theme and a color palette for our heatmaps of apparent fishing effort.+# Map theme with dark background map_theme <- ggplot2::theme_minimal() + ggplot2::theme( @@ -188,7 +185,7 @@
Setup # Palette for fishing activity map_effort_light <- c("#ffffff", "#eeff00", "#3b9088","#0c276c")
We’ll also define a common date range to use for querying data.
-@@ -199,16 +196,16 @@+start_date <- '2021-01-01' end_date <- '2021-03-31'
Making heatm
The
gfwr
functionget_raster()
provides aggregated gridded (e.g. raster) data for AIS-based apparent fishing -effort (SAR). It was designed to provide data for a specific region, -offering users the ability to select from multiple built-in region types -by specifying a specific Exclusive Economic Zone (EEZ), Marine Protected +effort. It was designed to provide data for a specific region, offering +users the ability to select from multiple built-in region types by +specifying a specific Exclusive Economic Zone (EEZ), Marine Protected Area (MPA), or Regional Fisheries Management Organization (RFMO).The list of available regions for each type, and their
-label
andid
, can be accessed with theget_regions()
function.+-eez_regions <- get_regions(region_source = 'EEZ', key = gfw_key)
+eez_regions #> # A tibble: 282 × 3 #> id label iso3 @@ -244,7 +241,7 @@
Making heatm later). We could look up the Italian EEZ
id
in theeez_regions
table we just created, but let’s useget_region_id()
. -+# Use get_region_id function to get EEZ code for Italy ita_eez_code <- get_region_id(region_name = "ITA", region_source = "EEZ", key = gfw_auth())
#> # A tibble: 1 × 3 @@ -258,7 +255,7 @@
Making heatm APIs for more info about these parameter options.
In this case, let’s request data during our time range at 100th degree resolution and grouped by flag State:
-+# Download data for the Italian EEZ eez_fish_df <- get_raster( spatial_resolution = "HIGH", @@ -281,26 +278,26 @@
Making heatm #> Lat Lon `Time Range` flag `Vessel IDs` `Apparent Fishing Hours` #> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> #> 1 44.2 9.19 2021 ITA 12 54.0 -#> 2 37.5 12.9 2021 ITA 12 19.0 -#> 3 37.4 13.2 2021 ITA 13 22.6 -#> 4 37.4 13.1 2021 ITA 13 15.9 -#> 5 37.4 13.1 2021 ITA 19 24.4 -#> 6 37.4 13.2 2021 ITA 16 15.7 -#> 7 37.4 13.2 2021 ITA 14 23.0 -#> 8 37.3 13.3 2021 ITA 13 14.7 -#> 9 37.3 13.4 2021 ITA 13 10.5 -#> 10 37.0 13.9 2021 ITA 21 30.2 +#> 2 45.1 12.4 2021 ITA 13 39.3 +#> 3 45.1 12.4 2021 ITA 17 43.8 +#> 4 45.1 12.5 2021 ITA 12 46.8 +#> 5 45.1 12.5 2021 ITA 15 58.2 +#> 6 45.1 12.5 2021 ITA 19 77.4 +#> 7 45.1 12.5 2021 ITA 16 57.8 +#> 8 45.0 12.5 2021 ITA 12 34.4 +#> 9 45.1 12.5 2021 ITA 14 54.3 +#> 10 45.0 12.6 2021 ITA 14 30.6 #> # ℹ 69,132 more rows
Because the data includes fishing by all flag states, to make a map of all activity, we first need to summarize activity by grid cell.
-+eez_fish_all_df <- eez_fish_df %>% group_by(Lat, Lon) %>% summarize(fishing_hours = sum(`Apparent Fishing Hours`, na.rm = T)) #> `summarise()` has grouped output by 'Lat'. You can override using the `.groups` #> argument.
Now we can use
-ggplot2
to plot the data:+eez_fish_all_df %>% filter(fishing_hours >= 1) %>% ggplot() + @@ -327,7 +324,7 @@
Making heatm
As another example, let’s request low resolution apparent fishing effort data within the jurisdiction of the Indian Ocean Tuna Commission (IOTC), grouped yearly by gear type:
-+# Download data for the IOTC iotc_fish_df <- get_raster( spatial_resolution = "LOW", @@ -347,22 +344,23 @@
Making heatm #> ℹ Use `spec()` to retrieve the full column specification for this data. #> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
+#> Lat Lon `Time Range` geartype `Vessel IDs` Apparent Fishing Hou…¹ +#> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> +#> 1 -32.3 98.9 2021 drifting_longli… 13 68.4 +#> 2 -32.3 99.1 2021 drifting_longli… 12 90.4 +#> 3 -32.4 99.1 2021 drifting_longli… 12 98.2 +#> 4 -32.4 99.7 2021 drifting_longli… 9 38.2 +#> 5 -32.4 99.6 2021 drifting_longli… 12 50.8 +#> 6 -32.9 98.8 2021 drifting_longli… 14 60.9 +#> 7 -33 99 2021 drifting_longli… 26 292. +#> 8 -33.1 99 2021 drifting_longli… 14 98.5 +#> 9 -33.1 99.1 2021 drifting_longli… 14 96.0 +#> 10 -32.9 99.5 2021 drifting_longli… 14 73.3 +#> # ℹ 106,219 more rows +#> # ℹ abbreviated name: ¹`Apparent Fishing Hours`#> # A tibble: 106,229 × 6 -#> Lat Lon `Time Range` geartype `Vessel IDs` `Apparent Fishing Hours` -#> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> -#> 1 7.7 98.3 2021 trawlers 10 548. -#> 2 7.7 98.4 2021 trawlers 10 586. -#> 3 6.4 99.5 2021 trawlers 9 356. -#> 4 5.6 99.8 2021 trawlers 11 130. -#> 5 6.2 100 2021 trawlers 22 2365. -#> 6 6.2 99.9 2021 trawlers 10 146. -#> 7 6.1 100 2021 trawlers 23 1443. -#> 8 6.2 100. 2021 trawlers 24 2127. -#> 9 6.1 100. 2021 trawlers 25 1382. -#> 10 6.2 100. 2021 trawlers 10 219. -#> # ℹ 106,219 more rows
This time, instead of aggregating all activity, let’s plot the activity of a specific gear type:
-+iotc_p1 <- iotc_fish_df %>% filter(geartype == 'drifting_longlines') %>% filter(`Apparent Fishing Hours` >= 1) %>% @@ -445,7 +443,7 @@
andPlotting vessel eventsregion
region_source
arguments like we did in the previous example. -+# using same example as above encounters_df <- get_event(event_type = "ENCOUNTER", encounter_types = "CARRIER-FISHING", @@ -460,7 +458,7 @@
to remove duplicate positions. We’ll also use thePlotting vessel eventsevent_id
lon
andlat
coordinates to create asf
object for each encounter event. -+encounters_sf_df <- encounters_df %>% tidyr::separate(id, c("event_id","vessel_number")) %>% filter(vessel_number == 1) %>% @@ -468,12 +466,12 @@
Plotting vessel events select(event_id, type, geometry)
To assist with plotting, let’s get the bounding box of the encounter events.
-+enc_bbox <- st_bbox(encounters_sf_df)
Now let’s add the encounters layer to our previous map of drifting longline effort in the IOTC and use the bounding box to restrict the plot to the area with encounters.
-+iotc_p1 + geom_sf(data = encounters_sf_df, aes(color = type), @@ -501,7 +499,7 @@
Making maps for custom regions
+my_shp <- tibble( lon = c(-96,-96,-66,-66,-96), lat = c(-24,4,4,-24,-24) @@ -516,7 +514,7 @@
Making maps for custom regions#> deprecated. It might return a CRS with a non-EPSG compliant axis order.
Plot the
-sf
object to confirm it was created successfully.+ggplot() + geom_sf(data = ne_countries(returnclass = "sf", scale = "small")) + geom_sf( @@ -528,11 +526,11 @@
Making maps for custom regions
+my_shp_bbox <- st_bbox(my_shp)
Now we’re ready to request data in our custom region from
-get_raster()
andget_event()
.+my_raster_df <- get_raster( spatial_resolution = "LOW", temporal_resolution = "YEARLY", @@ -540,7 +538,7 @@
Making maps for custom regions= start_date, end_date = end_date, region = my_shp, - region_source = "USER_JSON" + region_source = "USER_SHAPEFILE" ) #> Rows: 12120 Columns: 6 #> ── Column specification ──────────────────────────────────────────────────────── @@ -552,27 +550,27 @@
Making maps for custom regions#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
For events, we’ll request high-confidence port visits by fishing vessels
-++ region_source = "USER_SHAPEFILE") +#> [1] "Downloading 3985 events from GFW"my_port_events_df <- get_event(event_type = "PORT_VISIT", confidences = 4, vessel_types = "FISHING", start_date = start_date, end_date = end_date, region = my_shp, - region_source = "USER_JSON") -#> [1] "Downloading 3983 events from GFW"
and loitering events by refrigerated cargo vessels
-+my_loitering_events_df <- get_event(event_type = "LOITERING", vessel_types = "CARRIER", start_date = start_date, end_date = end_date, region = my_shp, - region_source = "USER_JSON") + region_source = "USER_SHAPEFILE") #> [1] "Downloading 50 events from GFW"
As before, let’s summarize the raster to plot all fishing activity by fishing vessels
-+my_raster_all_df <- my_raster_df %>% group_by(Lat, Lon) %>% summarize(fishing_hours = sum(`Apparent Fishing Hours`, na.rm = T)) @@ -580,7 +578,7 @@
Making maps for custom regions#> argument.
and combine our two event datasets and create
-sf
objects for each event.+my_events_sf <- my_port_events_df %>% select(id, lon, lat, type) %>% bind_rows( @@ -591,7 +589,7 @@
Making maps for custom regionsselect(id, type, geometry)
Finally, let’s plot the fishing effort raster and overlay the loitering events and port visits.
-+my_raster_all_df %>% filter(fishing_hours > 1) %>% ggplot() + diff --git a/docs/articles/making-maps_files/figure-html/ita_plot-1.png b/docs/articles/making-maps_files/figure-html/ita_plot-1.png index 291f303..884f896 100644 Binary files a/docs/articles/making-maps_files/figure-html/ita_plot-1.png and b/docs/articles/making-maps_files/figure-html/ita_plot-1.png differ diff --git a/docs/articles/making-maps_files/figure-html/loitering_ports_fishing_map-1.png b/docs/articles/making-maps_files/figure-html/loitering_ports_fishing_map-1.png index a506c4e..9d49d21 100644 Binary files a/docs/articles/making-maps_files/figure-html/loitering_ports_fishing_map-1.png and b/docs/articles/making-maps_files/figure-html/loitering_ports_fishing_map-1.png differ diff --git a/docs/index.html b/docs/index.html index f99a004..3214578 100644 --- a/docs/index.html +++ b/docs/index.html @@ -215,8 +215,8 @@
Examples#> # A tibble: 2 × 9 #> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³ #> <chr> <chr> <chr> <int> -#> 1 3c99c326… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2015 -#> 2 6632c9eb… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2019 +#> 1 6632c9eb… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2019 +#> 2 3c99c326… PURSE_SEINE_SUPPORT GFW_VESSEL_LIST 2015 #> # ℹ abbreviated names: ¹geartypes_geartype_name, ²geartypes_geartype_source, #> # ³geartypes_geartype_yearFrom #> # ℹ 5 more variables: geartypes_geartype_yearTo <int>, @@ -273,9 +273,9 @@
Examples#> # A tibble: 3 × 9 #> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³ #> <chr> <chr> <chr> <int> -#> 1 58cf536b… CARRIER GFW_VESSEL_LIST 2012 +#> 1 1da8dbc2… CARRIER GFW_VESSEL_LIST 2022 #> 2 0b7047cb… CARRIER GFW_VESSEL_LIST 2019 -#> 3 1da8dbc2… CARRIER GFW_VESSEL_LIST 2022 +#> 3 58cf536b… CARRIER GFW_VESSEL_LIST 2012 #> # ℹ abbreviated names: ¹geartypes_geartype_name, ²geartypes_geartype_source, #> # ³geartypes_geartype_yearFrom #> # ℹ 5 more variables: geartypes_geartype_yearTo <int>, @@ -286,7 +286,7 @@
Examples#> # A tibble: 3 × 13 #> vesselId ssvid shipname nShipname flag callsign imo messagesCounter #> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> -#> 1 1da8dbc23-3c48-… 6135… GABU RE… GABUREEF… CMR TJMC996 8300… 71775911 +#> 1 1da8dbc23-3c48-… 6135… GABU RE… GABUREEF… CMR TJMC996 8300… 72480839 #> 2 0b7047cb5-58c8-… 2141… GABU RE… GABUREEF… MDA ER2732 8300… 70035084 #> 3 58cf536b1-1fca-… 6168… GABU RE… GABUREEF… COM D6FJ2 8300… 32121624 #> # ℹ 5 more variables: positionsCounter <int>, sourceCode <list>, @@ -328,15 +328,15 @@
Examples#> # A tibble: 2 × 6 #> name flag ssvid sourceCode dateFrom dateTo #> <chr> <chr> <chr> <list> <chr> <chr> -#> 1 COLINER CYP 210631000 <chr [1]> 2014-01-01T00:16:58Z 2024-04-30T23:41:06Z +#> 1 COLINER CYP 210631000 <chr [1]> 2014-01-01T00:16:58Z 2024-05-31T23:44:00Z #> 2 COLINER CYP 273379740 <chr [1]> 2015-02-27T10:59:43Z 2018-03-21T07:13:09Z #> #> $registryPublicAuthorizations #> # A tibble: 2 × 4 #> dateFrom dateTo ssvid sourceCode #> <chr> <chr> <chr> <list> -#> 1 2022-12-19T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]> -#> 2 2020-01-01T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]> +#> 1 2022-12-19T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]> +#> 2 2020-01-01T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]> #> #> $combinedSourcesInfo #> # A tibble: 2 × 9 @@ -354,7 +354,7 @@
Examples#> # A tibble: 1 × 13 #> vesselId ssvid shipname nShipname flag callsign imo messagesCounter #> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> -#> 1 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263226124 +#> 1 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263878798 #> # ℹ 5 more variables: positionsCounter <int>, sourceCode <list>, #> # matchFields <chr>, transmissionDateFrom <chr>, transmissionDateTo <chr>
To specify more than one
@@ -376,18 +376,18 @@vesselId
, you can submit a vector:Examples#> # A tibble: 3 × 1 #> registryInfoTotalRecords #> <int> -#> 1 1 +#> 1 2 #> 2 1 -#> 3 2 +#> 3 1 #> #> $registryInfo #> # A tibble: 4 × 15 #> id sourceCode ssvid flag shipname nShipname callsign imo #> <chr> <list> <chr> <chr> <chr> <chr> <chr> <chr> -#> 1 685862e0626f6234c844… <chr [5]> 5480… PHL JOHNREY… JOHNREYN… DUQA7 8118… -#> 2 b82d02e5c2c11e5fe536… <chr [5]> 4417… KOR ADRIA ADRIA DTBY3 8919… -#> 3 a8d00ce54b37add7f85a… <chr [6]> 2106… CYP FRIO FO… FRIOFORW… 5BWC3 9076… -#> 4 a8d00ce54b37add7f85a… <chr [2]> 2733… RUS FRIO FO… FRIOFORW… UCRZ 9076… +#> 1 a8d00ce54b37add7f85a… <chr [6]> 2106… CYP FRIO FO… FRIOFORW… 5BWC3 9076… +#> 2 a8d00ce54b37add7f85a… <chr [2]> 2733… RUS FRIO FO… FRIOFORW… UCRZ 9076… +#> 3 685862e0626f6234c844… <chr [5]> 5480… PHL JOHNREY… JOHNREYN… DUQA7 8118… +#> 4 b82d02e5c2c11e5fe536… <chr [5]> 4417… KOR ADRIA ADRIA DTBY3 8919… #> # ℹ 7 more variables: latestVesselInfo <lgl>, transmissionDateFrom <chr>, #> # transmissionDateTo <chr>, geartypes <list>, lengthM <dbl>, tonnageGt <dbl>, #> # vesselInfoReference <chr> @@ -396,34 +396,34 @@
Examples#> # A tibble: 4 × 6 #> name flag ssvid sourceCode dateFrom dateTo #> <chr> <chr> <chr> <list> <chr> <chr> -#> 1 TRANS PACIFIC JOURNEY FISHING PHL 548012100 <chr [3]> 2017-02-07T00… 2019-… -#> 2 DONGWON INDUSTRIES KOR 441734000 <chr [2]> 2014-01-18T19… 2024-… -#> 3 COLINER CYP 210631000 <chr [1]> 2014-01-01T00… 2024-… -#> 4 COLINER CYP 273379740 <chr [1]> 2015-02-27T10… 2018-… +#> 1 COLINER CYP 210631000 <chr [1]> 2014-01-01T00… 2024-… +#> 2 COLINER CYP 273379740 <chr [1]> 2015-02-27T10… 2018-… +#> 3 TRANS PACIFIC JOURNEY FISHING PHL 548012100 <chr [3]> 2017-02-07T00… 2019-… +#> 4 DONGWON INDUSTRIES KOR 441734000 <chr [2]> 2014-01-18T19… 2024-… #> #> $registryPublicAuthorizations #> # A tibble: 6 × 4 #> dateFrom dateTo ssvid sourceCode #> <chr> <chr> <chr> <list> -#> 1 2012-01-01T00:00:00Z 2024-05-01T00:00:00Z 548012100 <chr [1]> -#> 2 2012-01-01T00:00:00Z 2017-10-25T00:00:00Z 548012100 <chr [1]> -#> 3 2013-09-20T00:00:00Z 2024-05-01T00:00:00Z 441734000 <chr [1]> -#> 4 2015-10-08T00:00:00Z 2020-07-21T00:00:00Z 441734000 <chr [1]> -#> 5 2022-12-19T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]> -#> 6 2020-01-01T00:00:00Z 2024-05-01T00:00:00Z 210631000 <chr [1]> +#> 1 2022-12-19T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]> +#> 2 2020-01-01T00:00:00Z 2024-06-01T00:00:00Z 210631000 <chr [1]> +#> 3 2012-01-01T00:00:00Z 2024-05-01T00:00:00Z 548012100 <chr [1]> +#> 4 2012-01-01T00:00:00Z 2017-10-25T00:00:00Z 548012100 <chr [1]> +#> 5 2013-09-20T00:00:00Z 2024-06-01T00:00:00Z 441734000 <chr [1]> +#> 6 2015-10-08T00:00:00Z 2020-07-21T00:00:00Z 441734000 <chr [1]> #> #> $combinedSourcesInfo #> # A tibble: 8 × 9 #> vesselId geartypes_geartype_n…¹ geartypes_geartype_s…² geartypes_geartype_y…³ #> <chr> <chr> <chr> <int> -#> 1 55889aef… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017 -#> 2 71e7da67… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017 -#> 3 6583c51e… OTHER COMBINATION_OF_REGIST… 2013 -#> 4 6583c51e… OTHER COMBINATION_OF_REGIST… 2013 -#> 5 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014 -#> 6 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014 -#> 7 da1cd7e1… CARRIER GFW_VESSEL_LIST 2015 -#> 8 8c730422… CARRIER GFW_VESSEL_LIST 2013 +#> 1 da1cd7e1… CARRIER GFW_VESSEL_LIST 2015 +#> 2 8c730422… CARRIER GFW_VESSEL_LIST 2013 +#> 3 71e7da67… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017 +#> 4 55889aef… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2017 +#> 5 6583c51e… OTHER COMBINATION_OF_REGIST… 2013 +#> 6 6583c51e… OTHER COMBINATION_OF_REGIST… 2013 +#> 7 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014 +#> 8 6583c51e… TUNA_PURSE_SEINES COMBINATION_OF_REGIST… 2014 #> # ℹ abbreviated names: ¹geartypes_geartype_name, ²geartypes_geartype_source, #> # ³geartypes_geartype_yearFrom #> # ℹ 5 more variables: geartypes_geartype_yearTo <int>, @@ -434,9 +434,9 @@
Examples#> # A tibble: 3 × 13 #> vesselId ssvid shipname nShipname flag callsign imo messagesCounter #> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> -#> 1 71e7da672-2451-… 5480… JOHN RE… JOHNREYN… PHL DUQA-7 8118… 1967237 -#> 2 6583c51e3-3626-… 4417… ADRIA ADRIA KOR DTBY3 8919… 3742574 -#> 3 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263226124 +#> 1 8c7304226-6c71-… 2106… FRIO FO… FRIOFORW… CYP 5BWC3 9076… 263878798 +#> 2 71e7da672-2451-… 5480… JOHN RE… JOHNREYN… PHL DUQA-7 8118… 1967237 +#> 3 6583c51e3-3626-… 4417… ADRIA ADRIA KOR DTBY3 8919… 3742574 #> # ℹ 5 more variables: positionsCounter <int>, sourceCode <list>, #> # matchFields <chr>, transmissionDateFrom <chr>, transmissionDateTo <chr>
This is useful especially because a vessel can have different
@@ -550,8 +550,8 @@vesselId
s in time. Check the function documentation for examples with the other function arguments and our dedicated vignette for more information about vessel identity .Examples= "2020-02-01", key = key ) -#> [1] "Downloading 34 events from GFW" -#> # A tibble: 34 × 11 +#> [1] "Downloading 37 events from GFW" +#> # A tibble: 37 × 11 #> start end id type lat lon regions #> <dttm> <dttm> <chr> <chr> <dbl> <dbl> <list> #> 1 2020-01-05 04:58:45 2020-01-05 06:31:45 379d… fish… 43.7 -124. <named list> @@ -564,7 +564,7 @@
Examples#> 8 2020-01-10 18:21:53 2020-01-12 03:13:04 6739… fish… 38.0 -73.9 <named list> #> 9 2020-01-13 12:45:32 2020-01-13 15:38:38 46f8… fish… 38.0 -73.9 <named list> #> 10 2020-01-13 13:20:55 2020-01-13 15:07:53 2333… fish… 43.7 -124. <named list> -#> # ℹ 24 more rows +#> # ℹ 27 more rows #> # ℹ 4 more variables: boundingBox <list>, distances <list>, vessel <list>, #> # event_info <list>
When no events are available, the
@@ -591,12 +591,12 @@get_event()
function returns nothing.Fishing effort API
Examples
-You can load a sample shapefile inside
+gfwr
to see how'USER_JSON'
works:You can load a sample shapefile inside
gfwr
to see how'USER_SHAPEFILE'
works:data("test_shape") @@ -607,7 +607,7 @@
Examples= '2021-01-01', end_date = '2021-02-01', region = test_shape, - region_source = 'USER_JSON', + region_source = 'USER_SHAPEFILE', key = key ) #> Rows: 2526 Columns: 6 @@ -656,16 +656,16 @@
Examples#> # A tibble: 611 × 6 #> Lat Lon `Time Range` flag `Vessel IDs` `Apparent Fishing Hours` #> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> -#> 1 4.8 -5.9 2021 CHN 2 46.9 -#> 2 5.2 -4 2021 CPV 1 0.15 -#> 3 5.2 -4 2021 SLV 3 9.07 -#> 4 5.2 -4 2021 ESP 9 15.8 -#> 5 5.2 -4 2021 LBR 2 58.7 -#> 6 5.1 -4 2021 GHA 6 4.82 -#> 7 3 -3.9 2021 SLV 1 1.49 -#> 8 2.5 -5.4 2021 FRA 1 8.92 -#> 9 2.7 -4.1 2021 ESP 1 3.77 -#> 10 3.7 -7 2021 FRA 1 2.39 +#> 1 5 -5.5 2021 CHN 1 3.66 +#> 2 5.2 -4 2021 SLV 3 9.07 +#> 3 5.2 -4 2021 LBR 2 58.7 +#> 4 4.5 -4 2021 SLV 2 9.14 +#> 5 4.5 -3.8 2021 SLV 1 7.15 +#> 6 2.5 -5.4 2021 FRA 1 8.92 +#> 7 2 -4.2 2021 FRA 1 7.98 +#> 8 4.1 -7 2021 ESP 1 2.72 +#> 9 3.8 -5.9 2021 BLZ 1 7.67 +#> 10 3 -5.7 2021 ESP 1 0.57 #> # ℹ 601 more rows
You could search for just one word in the name of the EEZ and then decide which one you want:
A similar approach can be used to search for a specific Marine Protected Area, in this case the Phoenix Island Protected Area (PIPA)
It is also possible to filter rasters to one of the five regional fisheries management organizations (RFMO) that manage tuna and tuna-like species. These include
"ICCAT"
,"IATTC"
,"IOTC"
,"CCSBT"
and"WCPFC"
.+#> # ℹ 27 more rows@@ -794,8 +794,8 @@Examples= 'EEZ', key = key)$label) %>% dplyr::select(-start, -end) -#> [1] "Downloading 34 events from GFW" -#> # A tibble: 34 × 6 +#> [1] "Downloading 37 events from GFW" +#> # A tibble: 37 × 6 #> # Rowwise: #> id type lat lon eez eez_name #> <chr> <chr> <dbl> <dbl> <chr> <chr> @@ -809,7 +809,7 @@
Examples#> 8 6739137b68e5fb477de38226f57892f7 fishing 38.0 -73.9 8456 United States #> 9 46f8debd1e55a894ca26ac74faf11162 fishing 38.0 -73.9 8456 United States #> 10 23330ffa0e1bbab43ead8328456c45aa fishing 43.7 -124. 8456 United States -#> # ℹ 24 more rows
When your API request times out diff --git a/docs/news/index.html b/docs/news/index.html index d159e9b..a8bad74 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -68,7 +68,7 @@
gfwr 2.0.0the API documentation and the migration guide if anything is new or missing.
Endpoints
-
- Same endpoints as in v1.1.0 +
- Same endpoints as in
v1.1.0
get_raster()
communicates with the 4Wings API to get fishing effort- @@ -114,10 +114,14 @@
+Major changes and new features
get_raster()
- All parameters must now be specified using UPPER CASE (ex.
-spatial_resolution = "LOW"
instead ofspatial_resolution = "low"
)- The
+region
argument now acceptssf
polygons rather than a GeoJSON string- The
region
argument now acceptssf
polygons rather than a GeoJSON string.- Parameters
start_date
andend_date
replacedate_range
for consistency with other functions++Additional changes
+
- Option
USER_JSON
has been renamed toUSER_SHAPEFILE
for clarity (addresses #161)diff --git a/docs/reference/get_event_stats.html b/docs/reference/get_event_stats.html index 9a57d03..3ec435c 100644 --- a/docs/reference/get_event_stats.html +++ b/docs/reference/get_event_stats.html @@ -123,7 +123,7 @@gfwr 1.1.0
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3febec2..012a6ce 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,7 +5,7 @@ articles: gfwr: gfwr.html identity: identity.html making-maps: making-maps.html -last_built: 2024-07-02T01:22Z +last_built: 2024-07-22T21:21Z urls: reference: https://globalfishingwatch.github.io/gfwr/reference article: https://globalfishingwatch.github.io/gfwr/articles diff --git a/docs/reference/get_endpoint.html b/docs/reference/get_endpoint.html index c66fb1f..5bb024d 100644 --- a/docs/reference/get_endpoint.html +++ b/docs/reference/get_endpoint.html @@ -75,7 +75,7 @@Function to get API dataset name for given event type
Arguments
- dataset_type
-Type of dataset to get API dataset name for. It can be +
- diff --git a/docs/reference/get_event.html b/docs/reference/get_event.html index f93ccff..afe3277 100644 --- a/docs/reference/get_event.html +++ b/docs/reference/get_event.html @@ -133,7 +133,7 @@
Type of dataset to get API dataset name for. It can be "raster", "ENCOUNTER", "LOITERING", "FISHING", "PORT_VISIT", "GAP", "EEZ", "RFMO" or "MPA"
Arguments
- region_source
-- +
source of the region ('EEZ','MPA', 'RFMO' or 'USER_JSON')
source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')
- gap_intentional_disabling
@@ -261,6 +261,18 @@Examples
region_source = 'EEZ', flags = 'CHN', key = gfw_auth()) + +# fishing events in user shapefile +test_polygon <- sf::st_bbox(c(xmin = -70, xmax = -40, ymin = -10, ymax = 5), + crs = 4326) |> + sf::st_as_sfc() |> + sf::st_as_sf() +get_event(event_type = 'FISHING', + start_date = "2020-10-01", + end_date = "2020-12-31", + region = test_polygon, + region_source = 'USER_SHAPEFILE', + key = gfw_auth()) }Arguments
+If 'USER_SHAPEFILE', then region has to be an sf object Optional but mandatory if using the argument region. Source of the region. If 'EEZ','MPA', 'RFMO', then the value for the argument region must be the code for that region. -If 'USER_JSON', then region has to be an sf object
region diff --git a/docs/reference/get_raster.html b/docs/reference/get_raster.html index ed472b1..0eb5835 100644 --- a/docs/reference/get_raster.html +++ b/docs/reference/get_raster.html @@ -118,7 +118,7 @@Arguments
region_source -+ source of the region ('EEZ','MPA', 'RFMO' or 'USER_JSON')
source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')
key @@ -154,7 +154,7 @@Examples
start_date = '2021-01-01', end_date = '2021-10-01', region = test_shape, - region_source = 'USER_JSON', + region_source = 'USER_SHAPEFILE', key = gfw_auth(), print_request = TRUE) } diff --git a/man/get_endpoint.Rd b/man/get_endpoint.Rd index 36dc9d8..73336da 100644 --- a/man/get_endpoint.Rd +++ b/man/get_endpoint.Rd @@ -7,7 +7,7 @@ get_endpoint(dataset_type, ...) } \arguments{ -\item{dataset_type}{Type of dataset to get API dataset name for. It can be +\item{dataset_type}{Type of dataset to get API dataset name for. It can be "raster", "ENCOUNTER", "LOITERING", "FISHING", "PORT_VISIT", "GAP", "EEZ", "RFMO" or "MPA"} \item{...}{Other arguments that would depend on the dataset type.} diff --git a/man/get_event.Rd b/man/get_event.Rd index 3cde7b0..5c0cb5b 100644 --- a/man/get_event.Rd +++ b/man/get_event.Rd @@ -49,7 +49,7 @@ vector with any combination of: "CARRIER-FISHING", "FISHING-CARRIER", \item{region}{sf shape to filter raster or GFW region code (such as an EEZ code). See details about formatting the geojson} -\item{region_source}{source of the region ('EEZ','MPA', 'RFMO' or 'USER_JSON')} +\item{region_source}{source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')} \item{gap_intentional_disabling}{Logical. Whether the Gap events are intentional, according to Global Fishing Watch algorithms} @@ -157,5 +157,17 @@ get_event(event_type = 'FISHING', region_source = 'EEZ', flags = 'CHN', key = gfw_auth()) + +# fishing events in user shapefile +test_polygon <- sf::st_bbox(c(xmin = -70, xmax = -40, ymin = -10, ymax = 5), + crs = 4326) |> + sf::st_as_sfc() |> + sf::st_as_sf() +get_event(event_type = 'FISHING', + start_date = "2020-10-01", + end_date = "2020-12-31", + region = test_polygon, + region_source = 'USER_SHAPEFILE', + key = gfw_auth()) } } diff --git a/man/get_event_stats.Rd b/man/get_event_stats.Rd index e7b8b85..18e517c 100644 --- a/man/get_event_stats.Rd +++ b/man/get_event_stats.Rd @@ -43,7 +43,7 @@ vector with any combination of: "CARRIER-FISHING", "FISHING-CARRIER", \item{region_source}{Optional but mandatory if using the argument region. Source of the region. If 'EEZ','MPA', 'RFMO', then the value for the argument region must be the code for that region. -If 'USER_JSON', then region has to be an sf object} +If 'USER_SHAPEFILE', then region has to be an sf object} \item{region}{GFW region code (such as an EEZ, MPA or RFMO code) or a formatted geojson shape. See Details about formatting the geojson.} diff --git a/man/get_raster.Rd b/man/get_raster.Rd index d3e7404..4daba71 100644 --- a/man/get_raster.Rd +++ b/man/get_raster.Rd @@ -36,7 +36,7 @@ or "HIGH" = 0.01 degree} \item{region}{sf shape to filter raster or GFW region code (such as a Marine Regions Geographic Identifier or EEZ code).} -\item{region_source}{source of the region ('EEZ','MPA', 'RFMO' or 'USER_JSON')} +\item{region_source}{source of the region ('EEZ','MPA', 'RFMO' or 'USER_SHAPEFILE')} \item{key}{Authorization token. Can be obtained with \code{gfw_auth()} function} @@ -68,7 +68,7 @@ get_raster(spatial_resolution = 'LOW', start_date = '2021-01-01', end_date = '2021-10-01', region = test_shape, - region_source = 'USER_JSON', + region_source = 'USER_SHAPEFILE', key = gfw_auth(), print_request = TRUE) } diff --git a/vignettes/articles/gfwr.Rmd b/vignettes/articles/gfwr.Rmd index ebf5429..deb705a 100644 --- a/vignettes/articles/gfwr.Rmd +++ b/vignettes/articles/gfwr.Rmd @@ -292,12 +292,12 @@ and converts the response to a data frame. In order to use it, you should specif * The variable to group by: `FLAG`, `GEARTYPE`, `FLAGANDGEARTYPE`, `MMSI` or `VESSEL_ID` * The date range `note: this must be 366 days or less` * The region polygon in `sf` format or the region code (such as an EEZ code) to filter the raster -* The source for the specified region. Currently, `EEZ`, `MPA`, `RFMO` or `USER_JSON` (for `sf` shapefiles). +* The source for the specified region. Currently, `EEZ`, `MPA`, `RFMO` or `USER_SHAPEFILE` (for `sf` shapefiles). ### Examples -You can load a sample shapefile inside `gfwr` to see how `'USER_JSON'` works: +You can load a sample shapefile inside `gfwr` to see how `'USER_SHAPEFILE'` works: ```{r example_map_1} data("test_shape") @@ -309,7 +309,7 @@ get_raster( start_date = '2021-01-01', end_date = '2021-02-01', region = test_shape, - region_source = 'USER_JSON', + region_source = 'USER_SHAPEFILE', key = key ) ``` diff --git a/vignettes/articles/making-maps.Rmd b/vignettes/articles/making-maps.Rmd index faece91..f48c283 100644 --- a/vignettes/articles/making-maps.Rmd +++ b/vignettes/articles/making-maps.Rmd @@ -86,7 +86,7 @@ end_date <- '2021-03-31' ## Making heatmaps of apparent fishing effort with `get_raster()` -The `gfwr` function `get_raster()` provides aggregated gridded (e.g. raster) data for AIS-based apparent fishing effort (SAR). It was designed to provide data for a specific region, offering users the ability to select from multiple built-in region types by specifying a specific Exclusive Economic Zone (EEZ), Marine Protected Area (MPA), or Regional Fisheries Management Organization (RFMO). +The `gfwr` function `get_raster()` provides aggregated gridded (e.g. raster) data for AIS-based apparent fishing effort. It was designed to provide data for a specific region, offering users the ability to select from multiple built-in region types by specifying a specific Exclusive Economic Zone (EEZ), Marine Protected Area (MPA), or Regional Fisheries Management Organization (RFMO). The list of available regions for each type, and their `label` and `id`, can be accessed with the `get_regions()` function. @@ -316,7 +316,7 @@ my_raster_df <- get_raster( start_date = start_date, end_date = end_date, region = my_shp, - region_source = "USER_JSON" + region_source = "USER_SHAPEFILE" ) ``` @@ -329,7 +329,7 @@ my_port_events_df <- get_event(event_type = "PORT_VISIT", start_date = start_date, end_date = end_date, region = my_shp, - region_source = "USER_JSON") + region_source = "USER_SHAPEFILE") ``` and loitering events by refrigerated cargo vessels @@ -340,7 +340,7 @@ my_loitering_events_df <- get_event(event_type = "LOITERING", start_date = start_date, end_date = end_date, region = my_shp, - region_source = "USER_JSON") + region_source = "USER_SHAPEFILE") ``` As before, let's summarize the raster to plot all fishing activity by fishing vessels