5959# ' # Assuming 'dat_PUs' is an existing sf object of planning units in your package.
6060# '
6161# ' # Example: Get MPAs for Australia and intersect with planning units.
62- # ' dat_mpas <- splnr_get_MPAs(PlanUnits = dat_PUs, Countries = "Australia")
62+ # ' dat_mpas <- splnr_get_MPAs(PlanUnits = dat_PUs, Countries = "Australia", force = TRUE )
6363# '
6464# ' # Example: Get MPAs for multiple countries with specific status and categories.
6565# ' dat_mpas_specific <- splnr_get_MPAs(
@@ -114,11 +114,14 @@ splnr_get_MPAs <- function(PlanUnits,
114114 # TODO Add a check for wdpar package
115115
116116
117- # Set a chromote timeout option to prevent issues with web scraping for WDPA data.
117+ # Set chromote timeout option to prevent issues with web scraping for WDPA data.
118118 options(chromote.timeout = 120 )
119119
120120 # Fetch WDPA data for the specified countries and then process it.
121- wdpa_data <- Countries %> %
121+ # Note: Chromote may produce benign "Unhandled promise error: Browser.close" messages
122+ # that can be safely ignored (see wdpar documentation and
123+ # https://github.com/rstudio/chromote/pull/111)
124+ wdpa_data <- suppressWarnings(Countries %> %
122125 # Use purrr::map to fetch WDPA data for each country in the 'Countries' vector.
123126 # 'wait = TRUE' ensures sequential downloads, and 'download_dir' specifies where to cache the data.
124127 purrr :: map(wdpar :: wdpa_fetch ,
@@ -127,8 +130,8 @@ splnr_get_MPAs <- function(PlanUnits,
127130 ... ) %> %
128131 # Bind all fetched data frames into a single data frame.
129132 dplyr :: bind_rows() %> %
130- # Filter for marine protected areas only (where MARINE attribute is greater than 0).
131- dplyr :: filter(.data $ MARINE > 0 ) %> %
133+ # Filter for marine and coastal protected areas only
134+ dplyr :: filter(.data $ REALM %in% c( " Coastal " , " Marine " ) ) %> %
132135 # Filter by the specified IUCN Protected Area Management Categories.
133136 dplyr :: filter(.data $ IUCN_CAT %in% Category ) %> %
134137 # Filter by the specified Designation Types.
@@ -144,7 +147,7 @@ splnr_get_MPAs <- function(PlanUnits,
144147 # Select only the 'geometry' column, discarding other attributes after dissolving.
145148 dplyr :: select(" geometry" ) %> %
146149 # Add a new column 'wdpa' and set its value to 1, indicating it's a WDPA area.
147- dplyr :: mutate(wdpa = 1 )
150+ dplyr :: mutate(wdpa = 1 ))
148151
149152 # Intersect the cleaned WDPA data with the provided planning units using spatialgridr::get_data_in_grid.
150153 # This function identifies which planning units overlap with the WDPA areas.
0 commit comments