Skip to content

Commit

Permalink
staticDownloadLink => not null
Browse files Browse the repository at this point in the history
  • Loading branch information
ptimoner committed Apr 23, 2024
1 parent d8b4b73 commit 3495e2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions R/geoboundaries_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
geoboundaries_query <- function (iso, adminLevel, type, validTypes) {
url <- paste0("https://www.geoboundaries.org/api/current/", type, "/", iso, "/ADM", adminLevel, "/")
jsonData <- tryCatch({jsonlite::fromJSON(url)}, error = function (e) NULL)
if (is.null(jsonData)) {
if (is.null(jsonData$staticDownloadLink)) {
message("Requested data not available. Searching for available data, please wait...")
avData <- data.frame()
for (typ in validTypes) {
for (lev in 0:3) {
url <- paste0("https://www.geoboundaries.org/api/current/", typ, "/", iso, "/ADM", lev, "/")
jsonData <- tryCatch({jsonlite::fromJSON(url)}, error = function (e) NULL)
if (is.null(jsonData)) {
if (is.null(jsonData$staticDownloadLink)) {
avData <- rbind(avData, data.frame(Type = typ, Level = lev, Availability = "NO"))
} else {
avData <- rbind(avData, data.frame(Type = typ, Level = lev, Availability = "YES"))
Expand Down
6 changes: 3 additions & 3 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ functions directly available. Remember that you must have a working internet con

### Initiate Project

With the `initiate_project` function, we can select the country and
With the `initiate_project` function, we can select a country (or a city) and
automatically, the ISO 3166-1 alpha-3 country code is stored in a
config.txt file and the directory main structure for the project is
created. This function also creates a log.txt file that will record and
Expand Down Expand Up @@ -85,8 +85,8 @@ name of the country folder, the boundary administrative level, the data
source, and a logical parameter (TRUE/FALSE) that indicates if the layer
should always be downloaded, even if it has already been downloaded.
Data source parameter (type) can be ‘gbOpen’ for geoBoundaries data,
‘gbHumanitarian’ for UN OCHA CODs data, or ‘gbAuthoritative’ for UN SALB
data (default). The ISO code used to download the shapefile is retrieved
‘gbHumanitarian’ (default) for UN OCHA CODs data, or ‘gbAuthoritative’ for UN SALB
data. The ISO code used to download the shapefile is retrieved
by the internal function. Another internal function will query the
geoBoundaries database (geoboundaries\_query) to check availability and
retrieve a json file that contains the download link.
Expand Down
4 changes: 2 additions & 2 deletions vignettes/Tutorial.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ library(inAccessMod)
```

### Initiate Project
With the `initiate_project` function, we can select the country and automatically, the ISO 3166-1 alpha-3 country code is stored in a config.txt file and the directory main structure for the project is created. This function also creates a log.txt file that will record and track the main operations related to the project. We will see that the final structure arises when downloading and processing the data with the corresponding functions, and it allows multiple ’raw’ inputs and multiple ’processed’ outputs for each input. This can be useful when performing different analyses for the same country (e.g. when we have updated data) or using different processing parameters. To initiate the project, the only parameter we need to provide is the path where the project, namely the country folder will be created. Let's run the function and select "Switzerland" for this tutorial.
With the `initiate_project` function, we can select a country (or a city) and automatically, the ISO 3166-1 alpha-3 country code is stored in a config.txt file and the directory main structure for the project is created. This function also creates a log.txt file that will record and track the main operations related to the project. We will see that the final structure arises when downloading and processing the data with the corresponding functions, and it allows multiple ’raw’ inputs and multiple ’processed’ outputs for each input. This can be useful when performing different analyses for the same country (e.g. when we have updated data) or using different processing parameters. To initiate the project, the only parameter we need to provide is the path where the project, namely the country folder will be created. Let's run the function and select "Switzerland" for this tutorial.

```{r initiate, eval=FALSE}
# Replace workDir with the actual path to your working directory
Expand Down Expand Up @@ -74,7 +74,7 @@ We are then asked to select the data we want to copy. In this case, as the folde

### Download the country boundaries

Let's say that we do not have any boundary shapefile. We can download it with the `download_boundaries` function. This layer will help to set the projected coordinate reference system and will be used for cropping, masking and clipping the other input layers. The function requires the name of the country folder, the boundary administrative level, the data source, and a logical parameter (TRUE/FALSE) that indicates if the layer should always be downloaded, even if it has already been downloaded. Data source parameter (type) can be 'gbOpen' for geoBoundaries data, 'gbHumanitarian' for UN OCHA CODs data, or 'gbAuthoritative' for UN SALB data (default). The ISO code used to download the shapefile is retrieved by the internal \code{get_param} function. Another internal function will query the geoBoundaries database (geoboundaries_query) to check availability and retrieve a json file that contains the download link.
Let's say that we do not have any boundary shapefile. We can download it with the `download_boundaries` function. This layer will help to set the projected coordinate reference system and will be used for cropping, masking and clipping the other input layers. The function requires the name of the country folder, the boundary administrative level, the data source, and a logical parameter (TRUE/FALSE) that indicates if the layer should always be downloaded, even if it has already been downloaded. Data source parameter (type) can be 'gbOpen' for geoBoundaries data, 'gbHumanitarian' (default) for UN OCHA CODs data, or 'gbAuthoritative' for UN SALB data. The ISO code used to download the shapefile is retrieved by the internal \code{get_param} function. Another internal function will query the geoBoundaries database (geoboundaries_query) to check availability and retrieve a json file that contains the download link.

```{r boundaries, eval=FALSE}
download_boundaries(mainPath, country, adminLevel = 1, type = "gbOpen", alwaysDownload = TRUE)
Expand Down

0 comments on commit 3495e2e

Please sign in to comment.