diff --git a/.Rbuildignore b/.Rbuildignore index 6c7aa0b0..e351e284 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -29,3 +29,14 @@ ^vignettes/mapSpain\.Rmd\.orig$ ^_pkgdown\.yaml$ ^CITATION\.cff$ +^tests/testthat/_snaps/esp_getTiles$ +^tests/testthat/_snaps/layer_spatraster$ +^.*\.pdf$ +^CRAN-SUBMISSION$ +^pkgdown\.yaml$ +^pkgdown\.yml$ +^\.imgbotconfig$ +^\.lintr$ +^CODE_OF_CONDUCT\.md$ +^CONTRIBUTING\.md$ +^Rplots\.pdf$ diff --git a/.gitattributes b/.gitattributes index 34e793c3..7a6fbd88 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ *.html linguist-detectable=false -*.js linguist-detectable=false \ No newline at end of file +*.js linguist-detectable=false diff --git a/.github/.gitignore b/.github/.gitignore index 0ce1091b..b550950b 100644 --- a/.github/.gitignore +++ b/.github/.gitignore @@ -1,3 +1,4 @@ *.html R-version depends.Rds +*.rds diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..03b62d6a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +# Basic set up for three package managers + +version: 2 +updates: + + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + diff --git a/.github/r-depends.rds b/.github/r-depends.rds deleted file mode 100644 index 477ac6ba..00000000 Binary files a/.github/r-depends.rds and /dev/null differ diff --git a/.github/workflows/cff-validator.yml b/.github/workflows/cff-validator.yml index a038ca46..5f3d872d 100644 --- a/.github/workflows/cff-validator.yml +++ b/.github/workflows/cff-validator.yml @@ -11,17 +11,11 @@ jobs: name: Validate CITATION.cff env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - RSPM: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - # This is needed for workflows running on - # ubuntu-20.04 or later - - name: Install V8 - if: runner.os == 'Linux' - run: | - sudo apt-get install -y libv8-dev - name: Validate CITATION.cff uses: dieghernan/cff-validator@main + diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml index 6de2d8b4..64c3f47b 100644 --- a/.github/workflows/check-full.yaml +++ b/.github/workflows/check-full.yaml @@ -10,7 +10,7 @@ on: pull_request: branches: [main, master] schedule: - - cron: '0 14 * * 2,5' + - cron: '0 14 * * 2,5' name: R-CMD-check @@ -24,51 +24,36 @@ jobs: fail-fast: false matrix: config: - - {os: windows-latest, r: 'devel'} + #- {os: windows-latest, r: 'devel'} - {os: windows-latest, r: 'release'} - {os: windows-latest, r: 'oldrel'} #- {os: macOS-latest, r: 'devel'} - {os: macOS-latest, r: 'release'} - {os: macOS-latest, r: 'oldrel'} - - {os: ubuntu-20.04, r: 'release'} - #- {os: ubuntu-20.04, r: 'devel'} - - {os: ubuntu-20.04, r: 'oldrel'} - - {os: ubuntu-20.04, r: '3.6'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + #- {os: ubuntu-latest, r: 'oldrel'} + env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: rcmdcheck - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + cache-version: 5 + extra-packages: any::rcmdcheck + needs: check - - name: Show testthat output - if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash + - uses: r-lib/actions/check-r-package@v2 - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check \ No newline at end of file diff --git a/.github/workflows/cran-status.yaml b/.github/workflows/cran-status.yaml new file mode 100644 index 00000000..82148555 --- /dev/null +++ b/.github/workflows/cran-status.yaml @@ -0,0 +1,24 @@ +name: CRAN Status Monitor + +on: + workflow_dispatch: + schedule: + - cron: '0 10 * * 1,3,5' + +jobs: + check: + runs-on: ubuntu-latest + permissions: write-all + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check + uses: dieghernan/cran-status-check@v1 + with: + fail-on-error: "true" + create-issue: "false" + diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 325eec31..b9b32f7f 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -1,29 +1,71 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples -# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# lintr provides static code analysis for R. +# It checks for adherence to a given style, +# identifying syntax errors and possible semantic issues, +# then reports them to you so you can take action. +# More details at https://lintr.r-lib.org/ + +name: lintr + on: push: - branches: [main, master] + branches: + - main + - master + workflow_dispatch: pull_request: - branches: [main, master] + # The branches below must be a subset of the branches above + branches: + - main + - master + schedule: + - cron: '56 11 * * 5' -name: lint +permissions: + contents: read jobs: - lint: + lintr: + name: Run lintr scanning runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: read # for checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v4 - - uses: r-lib/actions/setup-r@v1 + - name: Setup R + uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - name: Setup lintr + uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: | + local::. + any::lintr + + - name: Run lintr + run: | + # Lintr package + out <- lintr::lint_package() + # Create SARIF report + lintr::sarif_output(out, "lintr-results.sarif") + # Display + out + shell: Rscript {0} + continue-on-error: true + + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@v3 with: - extra-packages: lintr + sarif_file: lintr-results.sarif + wait-for-processing: true - - name: Lint - run: lintr::lint_package() - shell: Rscript {0} \ No newline at end of file diff --git a/.github/workflows/pkgcheck.yaml b/.github/workflows/pkgcheck.yaml new file mode 100644 index 00000000..e7a59842 --- /dev/null +++ b/.github/workflows/pkgcheck.yaml @@ -0,0 +1,21 @@ +name: pkgcheck + +# This will cancel running jobs once a new run is triggered +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref }} + cancel-in-progress: true + +on: + # Manually trigger the Action under Actions/pkgcheck + workflow_dispatch: + +jobs: + pkgcheck: + runs-on: ubuntu-latest + steps: + - uses: ropensci-review-tools/pkgcheck-action@main + with: + summary-only: false + post-to-issue: true + append-to-issue: true + diff --git a/.github/workflows/pkgdown-gh-pages-clean.yaml b/.github/workflows/pkgdown-gh-pages-clean.yaml deleted file mode 100644 index 46841ed1..00000000 --- a/.github/workflows/pkgdown-gh-pages-clean.yaml +++ /dev/null @@ -1,33 +0,0 @@ -on: - workflow_dispatch: - -name: Clean pkgdown manually - -jobs: - pkgdown-gh-pages-manual: - runs-on: ubuntu-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-pandoc@v1 - - - uses: r-lib/actions/setup-r@v1 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v1 - with: - extra-packages: | - pkgdown - remotes - devtools - ropenspain/rostemplate - needs: website - - - name: Deploy package - run: | - git config --local user.name "dieghernan" - git config --local user.email "dieghernan@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, clean = TRUE, run_dont_run = TRUE)' \ No newline at end of file diff --git a/.github/workflows/recheck.yaml b/.github/workflows/recheck.yaml new file mode 100644 index 00000000..83497ede --- /dev/null +++ b/.github/workflows/recheck.yaml @@ -0,0 +1,20 @@ +# Workflow derived from https://github.com/r-devel/recheck +on: + workflow_dispatch: + inputs: + which: + type: choice + description: Which dependents to check + options: + - strong + - most + +name: r-devel reverse dependency check + +jobs: + revdep_check: + name: Reverse check ${{ inputs.which }} dependents + uses: r-devel/recheck/.github/workflows/recheck.yml@v1 + with: + which: ${{ inputs.which }} + diff --git a/.github/workflows/revdepcheck.yaml b/.github/workflows/revdepcheck.yaml new file mode 100644 index 00000000..3c8f0538 --- /dev/null +++ b/.github/workflows/revdepcheck.yaml @@ -0,0 +1,55 @@ +on: + workflow_dispatch: + +name: revdepcheck + +jobs: + revdepcheck: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + #- {os: windows-latest, r: 'release'} + - {os: macOS-latest, r: 'release'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: | + local::. + dieghernan/pkgdev + r-lib/revdepcheck + needs: check + + - name: revdepcheck + run: | + revdepcheck::revdep_reset() + revdepcheck::revdep_check(num_workers = 4) + pkgdev::add_global_gitgnore() + + usethis::use_build_ignore("revdep") + + shell: Rscript {0} + + - name: Commit results + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m 'revdepcheck' || echo "No changes to commit" + git push origin || echo "No changes to commit" + diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml new file mode 100644 index 00000000..0db497f8 --- /dev/null +++ b/.github/workflows/rhub.yaml @@ -0,0 +1,96 @@ +# R-hub's generic GitHub Actions workflow file. It's canonical location is at +# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml +# You can update this file to a newer version using the rhub2 package: +# +# rhub::rhub_setup() +# +# It is unlikely that you need to modify this file manually. + +name: R-hub +run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" + +on: + workflow_dispatch: + inputs: + config: + description: 'A comma separated list of R-hub platforms to use.' + type: string + default: 'linux,windows,macos' + name: + description: 'Run name. You can leave this empty now.' + type: string + id: + description: 'Unique ID. You can leave this empty now.' + type: string + +jobs: + + setup: + runs-on: ubuntu-latest + outputs: + containers: ${{ steps.rhub-setup.outputs.containers }} + platforms: ${{ steps.rhub-setup.outputs.platforms }} + + steps: + # NO NEED TO CHECKOUT HERE + - uses: r-hub/actions/setup@v1 + with: + config: ${{ github.event.inputs.config }} + id: rhub-setup + + linux-containers: + needs: setup + if: ${{ needs.setup.outputs.containers != '[]' }} + runs-on: ubuntu-latest + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.containers) }} + container: + image: ${{ matrix.config.container }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/run-check@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + + other-platforms: + needs: setup + if: ${{ needs.setup.outputs.platforms != '[]' }} + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.platforms) }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/setup-r@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/run-check@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + diff --git a/.github/workflows/rostemplate-gh-pages.yaml b/.github/workflows/rostemplate-gh-pages.yaml index 23053e78..e86f5d56 100644 --- a/.github/workflows/rostemplate-gh-pages.yaml +++ b/.github/workflows/rostemplate-gh-pages.yaml @@ -1,35 +1,47 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: branches: [main, master] - tags: ['*'] + release: + types: [published] + workflow_dispatch: name: rostemplate-gh-pages jobs: rostemplate-gh-pages: - runs-on: ubuntu-latest + runs-on: windows-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true + install-r: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: | - pkgdown + extra-packages: + local::. + any::cli + any::rcmdcheck + any::pkgdown + any::reactable + any::rnaturalearth + any::tidyverse + dieghernan/pkgdev ropenspain/rostemplate + ropensci/rnaturalearthhires needs: website - name: Deploy package run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)' \ No newline at end of file + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)' + diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 3c0da1c9..7d3f5bea 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,30 +1,80 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: branches: [main, master] pull_request: - branches: [main, master] name: test-coverage +permissions: read-all + jobs: test-coverage: - runs-on: ubuntu-latest + runs-on: windows-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: covr + extra-packages: any::covr, any::xml2 + needs: coverage - name: Test coverage - run: covr::codecov() + run: | + cov <- covr::package_coverage( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + covr::to_cobertura(cov) + shell: Rscript {0} + + - name: Create Junit Report + if: always() + run: | + test_out <- path.expand(file.path(getwd(), "junit.xml")) + testthat::test_local(reporter = testthat::JunitReporter$new(test_out)) shell: Rscript {0} + + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + # Fail if error if not on PR, or if on PR and token is given + fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} + file: ./junit.xml + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload coverage report + uses: codecov/codecov-action@v5 + with: + # Fail if error if not on PR, or if on PR and token is given + fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} + files: ./cobertura.xml + plugins: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package + diff --git a/.github/workflows/update-citation-cff.yaml b/.github/workflows/update-citation-cff.yaml index 1beb3390..c8de00fb 100644 --- a/.github/workflows/update-citation-cff.yaml +++ b/.github/workflows/update-citation-cff.yaml @@ -1,6 +1,14 @@ # Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# The action runs when: +# - A new release is published +# - The DESCRIPTION or inst/CITATION are modified +# - Can be run manually +# For customizing the triggers, visit https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows on: + release: + types: [published] push: + branches: [master, main] paths: - DESCRIPTION - inst/CITATION @@ -10,33 +18,17 @@ name: Update CITATION.cff jobs: update-citation-cff: - runs-on: ubuntu-latest + runs-on: macos-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - with: - use-public-rspm: true - install-r: false - - # This is needed for workflows running on - # ubuntu-20.04 or later - - name: Install V8 - if: runner.os == 'Linux' - run: | - sudo apt-get install -y libv8-dev - - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: actions/checkout@v4 + - uses: r-lib/actions/setup-r@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: | - dieghernan/cffr - -# When on CRAN, use instead - # extra-packages: | - # cffr - + any::cffr + any::V8 - name: Update CITATION.cff run: | @@ -44,23 +36,22 @@ jobs: library(cffr) # Customize with your own code - # Mind the indentation! + # See https://docs.ropensci.org/cffr/articles/cffr.html - cff_write(keys = list( - message="To cite package 'mapSpain' in publications use:", - doi = "10.5281/zenodo.4318024" - ) - ) + # Write your own keys + mykeys <- list() + + # Create your CITATION.cff file + cff_write(keys = mykeys) shell: Rscript {0} - name: Commit results run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git add CITATION.cff git commit -m 'Update CITATION.cff' || echo "No changes to commit" git push origin || echo "No changes to commit" - diff --git a/.github/workflows/update-docs.yaml b/.github/workflows/update-docs.yaml index 499c67f5..8b5790a5 100644 --- a/.github/workflows/update-docs.yaml +++ b/.github/workflows/update-docs.yaml @@ -1,81 +1,60 @@ -on: - push: - branches: - - main - - master - workflow_dispatch: - -name: update-docs - -jobs: - update-docs: - runs-on: macos-latest - env: - GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-pandoc@v1 - - - uses: r-lib/actions/setup-r@v1 - with: - use-public-rspm: true - - - uses: r-lib/actions/setup-r-dependencies@v1 - with: - extra-packages: | - devtools - remotes - rcmdcheck - pkgdown - dieghernan/pkgdev - ropenspain/rostemplate - needs: website - - - name: Install package - run: | - devtools::install() - - shell: Rscript {0} - - - name: Update docs - run: | - - pkgdev::update_docs() - - shell: Rscript {0} - - - name: Commit results - run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - git add -A - git commit -m 'Update docs with pkgdev' || echo "No changes to commit" - git push origin || echo "No changes to commit" - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_: false - run: | - options(crayon.enabled = TRUE) - rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} - - - name: Show testthat output - if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash - - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main - with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check - - - name: Deploy package - run: | - git config --local user.name "$GITHUB_ACTOR" - git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" - Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)' - +on: + workflow_dispatch: + +name: update-docs + +jobs: + update-docs: + runs-on: macos-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + CURL_SSL_BACKEND: "openssl" + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + install-r: true + + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: | + local::. + any::cli + any::rcmdcheck + any::pkgdown + any::reactable + any::rnaturalearth + any::tidyverse + dieghernan/pkgdev + ropenspain/rostemplate + ropensci/rnaturalearthhires + needs: website + + - name: Update docs + run: | + + pkgdev::update_docs() + + shell: Rscript {0} + + - name: Commit results + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add -A + git commit -m 'Update docs with pkgdev' || echo "No changes to commit" + git push origin || echo "No changes to commit" + + - uses: r-lib/actions/check-r-package@v2 + + - name: Deploy package + run: | + git config --local user.name "github-actions[bot]" + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)' + diff --git a/.github/workflows/wipe-cache.yaml b/.github/workflows/wipe-cache.yaml new file mode 100644 index 00000000..fb707c50 --- /dev/null +++ b/.github/workflows/wipe-cache.yaml @@ -0,0 +1,12 @@ +name: Clear GHA caches manually +on: + workflow_dispatch: + schedule: + - cron: '0 18 15 * *' +jobs: + cache-clear: + runs-on: ubuntu-latest + + steps: + - uses: easimon/wipe-cache@main + diff --git a/.gitignore b/.gitignore index 22ca9c14..d3c2d042 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ mapSpain*.tgz Meta CRAN-RELEASE cran-comments.md -revdep dev doc docs @@ -30,3 +29,8 @@ vignettes/*.pdf *.knit.md .Renviron docs/ +/*.pdf +CRAN-SUBMISSION +.github/pkg.lock +.Rdata +Rplots.pdf diff --git a/.imgbotconfig b/.imgbotconfig new file mode 100644 index 00000000..378a7a6e --- /dev/null +++ b/.imgbotconfig @@ -0,0 +1,8 @@ +{ + "ignoredFiles": [ + "/tests/testthat/_snaps/*", + "/man/figures/lifecycle*" + ], + "compressWiki": "true", + "aggressiveCompression": "true" +} diff --git a/.lintr b/.lintr new file mode 100644 index 00000000..d4708be9 --- /dev/null +++ b/.lintr @@ -0,0 +1,3 @@ +linters: linters_with_defaults() # see vignette("lintr") +encoding: "UTF-8" +exclusions: list("data-raw") diff --git a/CITATION.cff b/CITATION.cff index ddc2d37d..72217795 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,21 +1,46 @@ +# -------------------------------------------- +# CITATION file created with {cffr} R package +# See also: https://docs.ropensci.org/cffr/ +# -------------------------------------------- + cff-version: 1.2.0 -message: 'To cite package ''mapSpain'' in publications use:' +message: 'To cite package "mapSpain" in publications use:' type: software license: GPL-3.0-only title: 'mapSpain: Administrative Boundaries of Spain' -version: 0.3.0.9000 -doi: 10.5281/zenodo.4318024 -abstract: Administrative Boundaries of Spain at several levels (CCAA, Provinces, Municipalities) - based on the GISCO Eurostat database and - 'CartoBase SIANE' from 'Instituto Geografico Nacional' . It - also provides a 'leaflet' plugin and the ability of downloading and processing static - tiles. +version: 0.10.0 +doi: 10.5281/zenodo.5366622 +identifiers: +- type: doi + value: 10.32614/CRAN.package.mapSpain +abstract: Administrative Boundaries of Spain at several levels (Autonomous Communities, + Provinces, Municipalities) based on the 'GISCO' 'Eurostat' database + and 'CartoBase SIANE' from 'Instituto Geografico Nacional' . + It also provides a 'leaflet' plugin and the ability of downloading and processing + static tiles. authors: - family-names: Hernangómez given-names: Diego email: diego.hernangomezherrero@gmail.com orcid: https://orcid.org/0000-0001-8457-4658 - affiliation: rOpenSpain +preferred-citation: + type: manual + title: 'mapSpain: Administrative Boundaries of Spain' + authors: + - family-names: Hernangómez + given-names: Diego + email: diego.hernangomezherrero@gmail.com + orcid: https://orcid.org/0000-0001-8457-4658 + year: '2024' + version: 0.10.0 + doi: 10.5281/zenodo.5366622 + url: https://ropenspain.github.io/mapSpain/ + abstract: Administrative Boundaries of Spain at several levels (Autonomous Communities, + Provinces, Municipalities) based on the GISCO Eurostat database + and CartoBase SIANE from Instituto Geografico Nacional . + It also provides a leaflet plugin and the ability of downloading and processing + static tiles. +repository: https://CRAN.R-project.org/package=mapSpain repository-code: https://github.com/rOpenSpain/mapSpain url: https://ropenspain.github.io/mapSpain/ contact: @@ -23,9 +48,8 @@ contact: given-names: Diego email: diego.hernangomezherrero@gmail.com orcid: https://orcid.org/0000-0001-8457-4658 - affiliation: rOpenSpain keywords: -- rOpenSpain +- ropenspain - tiles - r - maps @@ -33,10 +57,300 @@ keywords: - rstats - r-package - municipalities -- Spain +- spain - gisco - provinces - ign - administrative-boundaries - ccaa - static-tiles +- cran +- ggplot2 +- gis +references: +- type: software + title: 'R: A Language and Environment for Statistical Computing' + notes: Depends + url: https://www.R-project.org/ + authors: + - name: R Core Team + institution: + name: R Foundation for Statistical Computing + address: Vienna, Austria + year: '2024' + version: '>= 3.6.0' +- type: software + title: countrycode + abstract: 'countrycode: Convert Country Names and Country Codes' + notes: Imports + url: https://vincentarelbundock.github.io/countrycode/ + repository: https://CRAN.R-project.org/package=countrycode + authors: + - family-names: Arel-Bundock + given-names: Vincent + email: vincent.arel-bundock@umontreal.ca + orcid: https://orcid.org/0000-0003-2042-7063 + year: '2024' + doi: 10.32614/CRAN.package.countrycode + version: '>= 1.2.0' +- type: software + title: giscoR + abstract: 'giscoR: Download Map Data from GISCO API - Eurostat' + notes: Imports + url: https://ropengov.github.io/giscoR/ + repository: https://CRAN.R-project.org/package=giscoR + authors: + - family-names: Hernangómez + given-names: Diego + email: diego.hernangomezherrero@gmail.com + orcid: https://orcid.org/0000-0001-8457-4658 + affiliation: rOpenGov + year: '2024' + doi: 10.32614/CRAN.package.giscoR + version: '>= 0.2.4' +- type: software + title: rappdirs + abstract: 'rappdirs: Application Directories: Determine Where to Save Data, Caches, + and Logs' + notes: Imports + url: https://rappdirs.r-lib.org + repository: https://CRAN.R-project.org/package=rappdirs + authors: + - family-names: Ratnakumar + given-names: Sridhar + - family-names: Mick + given-names: Trent + - family-names: Davis + given-names: Trevor + year: '2024' + doi: 10.32614/CRAN.package.rappdirs + version: '>= 0.3.0' +- type: software + title: sf + abstract: 'sf: Simple Features for R' + notes: Imports + url: https://r-spatial.github.io/sf/ + repository: https://CRAN.R-project.org/package=sf + authors: + - family-names: Pebesma + given-names: Edzer + email: edzer.pebesma@uni-muenster.de + orcid: https://orcid.org/0000-0001-8049-7069 + year: '2024' + doi: 10.32614/CRAN.package.sf + version: '>= 0.9.0' +- type: software + title: utils + abstract: 'R: A Language and Environment for Statistical Computing' + notes: Imports + authors: + - name: R Core Team + institution: + name: R Foundation for Statistical Computing + address: Vienna, Austria + year: '2024' +- type: software + title: curl + abstract: 'curl: A Modern and Flexible Web Client for R' + notes: Suggests + url: https://jeroen.r-universe.dev/curl + repository: https://CRAN.R-project.org/package=curl + authors: + - family-names: Ooms + given-names: Jeroen + email: jeroenooms@gmail.com + orcid: https://orcid.org/0000-0002-4035-0289 + year: '2024' + doi: 10.32614/CRAN.package.curl +- type: software + title: ggplot2 + abstract: 'ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics' + notes: Suggests + url: https://ggplot2.tidyverse.org + repository: https://CRAN.R-project.org/package=ggplot2 + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + orcid: https://orcid.org/0000-0003-4757-117X + - family-names: Chang + given-names: Winston + orcid: https://orcid.org/0000-0002-1576-2126 + - family-names: Henry + given-names: Lionel + - family-names: Pedersen + given-names: Thomas Lin + email: thomas.pedersen@posit.co + orcid: https://orcid.org/0000-0002-5147-4711 + - family-names: Takahashi + given-names: Kohske + - family-names: Wilke + given-names: Claus + orcid: https://orcid.org/0000-0002-7470-9261 + - family-names: Woo + given-names: Kara + orcid: https://orcid.org/0000-0002-5125-4188 + - family-names: Yutani + given-names: Hiroaki + orcid: https://orcid.org/0000-0002-3385-7233 + - family-names: Dunnington + given-names: Dewey + orcid: https://orcid.org/0000-0002-9415-4582 + - family-names: Brand + given-names: Teun + name-particle: van den + orcid: https://orcid.org/0000-0002-9335-7468 + year: '2024' + doi: 10.32614/CRAN.package.ggplot2 + version: '>= 3.0.0' +- type: software + title: knitr + abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R' + notes: Suggests + url: https://yihui.org/knitr/ + repository: https://CRAN.R-project.org/package=knitr + authors: + - family-names: Xie + given-names: Yihui + email: xie@yihui.name + orcid: https://orcid.org/0000-0003-0645-5666 + year: '2024' + doi: 10.32614/CRAN.package.knitr +- type: software + title: leaflet + abstract: 'leaflet: Create Interactive Web Maps with the JavaScript ''Leaflet'' + Library' + notes: Suggests + url: https://rstudio.github.io/leaflet/ + repository: https://CRAN.R-project.org/package=leaflet + authors: + - family-names: Cheng + given-names: Joe + email: joe@posit.co + - family-names: Schloerke + given-names: Barret + email: barret@posit.co + orcid: https://orcid.org/0000-0001-9986-114X + - family-names: Karambelkar + given-names: Bhaskar + - family-names: Xie + given-names: Yihui + year: '2024' + doi: 10.32614/CRAN.package.leaflet + version: '>= 2.0.0' +- type: software + title: png + abstract: 'png: Read and write PNG images' + notes: Suggests + url: http://www.rforge.net/png/ + repository: https://CRAN.R-project.org/package=png + authors: + - family-names: Urbanek + given-names: Simon + email: Simon.Urbanek@r-project.org + year: '2024' + doi: 10.32614/CRAN.package.png + version: '>= 0.1-5' +- type: software + title: rmarkdown + abstract: 'rmarkdown: Dynamic Documents for R' + notes: Suggests + url: https://pkgs.rstudio.com/rmarkdown/ + repository: https://CRAN.R-project.org/package=rmarkdown + authors: + - family-names: Allaire + given-names: JJ + email: jj@posit.co + - family-names: Xie + given-names: Yihui + email: xie@yihui.name + orcid: https://orcid.org/0000-0003-0645-5666 + - family-names: Dervieux + given-names: Christophe + email: cderv@posit.co + orcid: https://orcid.org/0000-0003-4474-2498 + - family-names: McPherson + given-names: Jonathan + email: jonathan@posit.co + - family-names: Luraschi + given-names: Javier + - family-names: Ushey + given-names: Kevin + email: kevin@posit.co + - family-names: Atkins + given-names: Aron + email: aron@posit.co + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + - family-names: Cheng + given-names: Joe + email: joe@posit.co + - family-names: Chang + given-names: Winston + email: winston@posit.co + - family-names: Iannone + given-names: Richard + email: rich@posit.co + orcid: https://orcid.org/0000-0003-3925-190X + year: '2024' + doi: 10.32614/CRAN.package.rmarkdown +- type: software + title: slippymath + abstract: 'slippymath: Slippy Map Tile Tools' + notes: Suggests + url: https://www.github.com/milesmcbain/slippymath + repository: https://CRAN.R-project.org/package=slippymath + authors: + - family-names: McBain + given-names: Miles + email: miles.mcbain@gmail.com + orcid: https://orcid.org/0000-0003-2865-2548 + - family-names: Sumner + given-names: Michael + email: mdsumner@gmail.com + year: '2024' + doi: 10.32614/CRAN.package.slippymath + version: '>= 0.3.1' +- type: software + title: terra + abstract: 'terra: Spatial Data Analysis' + notes: Suggests + url: https://rspatial.org/ + repository: https://CRAN.R-project.org/package=terra + authors: + - family-names: Hijmans + given-names: Robert J. + email: r.hijmans@gmail.com + orcid: https://orcid.org/0000-0001-5872-2872 + year: '2024' + doi: 10.32614/CRAN.package.terra + version: '>= 1.1-4' +- type: software + title: testthat + abstract: 'testthat: Unit Testing for R' + notes: Suggests + url: https://testthat.r-lib.org + repository: https://CRAN.R-project.org/package=testthat + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + year: '2024' + doi: 10.32614/CRAN.package.testthat + version: '>= 3.0.0' +- type: software + title: tidyterra + abstract: 'tidyterra: ''tidyverse'' Methods and ''ggplot2'' Helpers for ''terra'' + Objects' + notes: Suggests + url: https://dieghernan.github.io/tidyterra/ + repository: https://CRAN.R-project.org/package=tidyterra + authors: + - family-names: Hernangómez + given-names: Diego + email: diego.hernangomezherrero@gmail.com + orcid: https://orcid.org/0000-0001-8457-4658 + year: '2024' + doi: 10.32614/CRAN.package.tidyterra + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..9f46a023 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,46 @@ +# CONTRIBUTING + +## Fixing typos + +Small typos or grammatical errors in documentation may be edited directly using +the GitHub web interface, so long as the changes are made in the *source* file. + +- YES ✔️: you edit a roxygen comment in a `.R` file below `R/`. +- NO ❌: you edit an `.Rd` file below `man/`. + +## Prerequisites + +Before you make a substantial pull request, you should always file an issue and +make sure someone from the team agrees that it's a problem. If you've found a +bug, create an associated issue and illustrate the bug with a minimal +[reprex](https://www.tidyverse.org/help/#reprex). + +## Pull request process + +- We recommend that you create a Git branch for each pull request (PR). +- Look at the `R-CMD-check` build status before. After making changes, run + `devtools::check()` and ensure no new Notes, Warnings or Errors are + appearing. +- We recommend the tidyverse [style guide](http://style.tidyverse.org). We + also use the [styler](https://CRAN.R-project.org/package=styler) package to + apply these styles, but please **don't restyle code that has nothing to do + with your PR**. +- We use [roxygen2](https://cran.r-project.org/package=roxygen2). +- We use [testthat](https://cran.r-project.org/package=testthat). + Contributions with test cases included are easier to accept. +- For user-facing changes, add a bullet to the top of `NEWS.md` below the + current development version header describing the changes made followed by + your GitHub username, and links to relevant issue(s)/PR(s). + +## Prefer to Email? + +Email the person listed as maintainer in the `DESCRIPTION` file of this repo. + +Though note that private discussions over email don't help others - of course +email is totally warranted if it's a sensitive problem of any kind. + +## Thanks for contributing! + +This contributing guide is adapted from the tidyverse contributing guide +available at + diff --git a/DESCRIPTION b/DESCRIPTION index 1b608f87..4da49f52 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,25 +1,16 @@ Type: Package Package: mapSpain Title: Administrative Boundaries of Spain -Version: 0.3.0.9000 +Version: 0.10.0 Authors@R: - c(person(given = "Diego", - family = "Hernangómez", - role = c("aut", "cre", "cph"), - email = "diego.hernangomezherrero@gmail.com", - comment = c(ORCID = "0000-0001-8457-4658", affiliation = "rOpenSpain")), - person(given = "EuroGeographics", - role = "cph", - comment = "for the administrative boundaries."), - person(given = "Instituto Geográfico Nacional", - role = "cph", - comment = "for the administrative boundaries.")) -Description: Administrative Boundaries of Spain at several levels (CCAA, - Provinces, Municipalities) based on the GISCO Eurostat database - and 'CartoBase SIANE' from - 'Instituto Geografico Nacional' . It also - provides a 'leaflet' plugin and the ability of downloading and - processing static tiles. + person("Diego", "Hernangómez", , "diego.hernangomezherrero@gmail.com", role = c("aut", "cre", "cph"), + comment = c(ORCID = "0000-0001-8457-4658")) +Description: Administrative Boundaries of Spain at several levels + (Autonomous Communities, Provinces, Municipalities) based on the + 'GISCO' 'Eurostat' database + and 'CartoBase SIANE' from 'Instituto Geografico Nacional' + . It also provides a 'leaflet' plugin and the + ability of downloading and processing static tiles. License: GPL-3 URL: https://ropenspain.github.io/mapSpain/, https://github.com/rOpenSpain/mapSpain @@ -29,29 +20,39 @@ Depends: Imports: countrycode (>= 1.2.0), giscoR (>= 0.2.4), - leaflet (>= 2.0.0), - png (>= 0.1-5), rappdirs (>= 0.3.0), - raster (>= 3.0), - sf (>= 0.9), - slippymath (>= 0.3.1), + sf (>= 0.9.0), utils Suggests: + curl, + ggplot2 (>= 3.0.0), knitr, - rgdal, + leaflet (>= 2.0.0), + png (>= 0.1-5), rmarkdown, + slippymath (>= 0.3.1), + terra (>= 1.1-4), testthat (>= 3.0.0), - tibble, - tmap (>= 3.0.0) + tidyterra VignetteBuilder: knitr +Config/Needs/check: curl +Config/Needs/coverage: covr +Config/Needs/website: ragg, reactable, rnaturalearth, tidyverse, devtools, + remotes, ropenspain/rostemplate, ropensci/rnaturalearthhires, + rspatial/geodata, sessioninfo, sfheaders, rapidjsonr, jsonify, + geometries Config/testthat/edition: 3 +Config/testthat/parallel: true +Copyright: © EuroGeographics for the administrative boundaries. Atlas + Nacional de España (ANE) CC BY 4.0 . INE + Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.3.2 X-schema.org-applicationCategory: cartography X-schema.org-isPartOf: https://ropenspain.es/ -X-schema.org-keywords: rOpenSpain, tiles, r, maps, spatial, rstats, - r-package, municipalities, Spain, gisco, provinces, ign, - administrative-boundaries, ccaa, static-tiles +X-schema.org-keywords: ropenspain, tiles, r, maps, spatial, rstats, + r-package, municipalities, spain, gisco, provinces, ign, + administrative-boundaries, ccaa, static-tiles, cran, ggplot2, gis diff --git a/LICENSE.md b/LICENSE.md index 25bd3641..8a7d85ca 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,595 +1,595 @@ -GNU General Public License -========================== - -_Version 3, 29 June 2007_ -_Copyright © 2007 Free Software Foundation, Inc. <>_ - -Everyone is permitted to copy and distribute verbatim copies of this license -document, but changing it is not allowed. - -## Preamble - -The GNU General Public License is a free, copyleft license for software and other -kinds of works. - -The licenses for most software and other practical works are designed to take away -your freedom to share and change the works. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change all versions of a -program--to make sure it remains free software for all its users. We, the Free -Software Foundation, use the GNU General Public License for most of our software; it -applies also to any other work released this way by its authors. You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our General -Public Licenses are designed to make sure that you have the freedom to distribute -copies of free software (and charge for them if you wish), that you receive source -code or can get it if you want it, that you can change the software or use pieces of -it in new free programs, and that you know you can do these things. - -To protect your rights, we need to prevent others from denying you these rights or -asking you to surrender the rights. Therefore, you have certain responsibilities if -you distribute copies of the software, or if you modify it: responsibilities to -respect the freedom of others. - -For example, if you distribute copies of such a program, whether gratis or for a fee, -you must pass on to the recipients the same freedoms that you received. You must make -sure that they, too, receive or can get the source code. And you must show them these -terms so they know their rights. - -Developers that use the GNU GPL protect your rights with two steps: **(1)** assert -copyright on the software, and **(2)** offer you this License giving you legal permission -to copy, distribute and/or modify it. - -For the developers' and authors' protection, the GPL clearly explains that there is -no warranty for this free software. For both users' and authors' sake, the GPL -requires that modified versions be marked as changed, so that their problems will not -be attributed erroneously to authors of previous versions. - -Some devices are designed to deny users access to install or run modified versions of -the software inside them, although the manufacturer can do so. This is fundamentally -incompatible with the aim of protecting users' freedom to change the software. The -systematic pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we have designed -this version of the GPL to prohibit the practice for those products. If such problems -arise substantially in other domains, we stand ready to extend this provision to -those domains in future versions of the GPL, as needed to protect the freedom of -users. - -Finally, every program is threatened constantly by software patents. States should -not allow patents to restrict development and use of software on general-purpose -computers, but in those that do, we wish to avoid the special danger that patents -applied to a free program could make it effectively proprietary. To prevent this, the -GPL assures that patents cannot be used to render the program non-free. - -The precise terms and conditions for copying, distribution and modification follow. - -## TERMS AND CONDITIONS - -### 0. Definitions - -“This License” refers to version 3 of the GNU General Public License. - -“Copyright” also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - -“The Program” refers to any copyrightable work licensed under this -License. Each licensee is addressed as “you”. “Licensees” and -“recipients” may be individuals or organizations. - -To “modify” a work means to copy from or adapt all or part of the work in -a fashion requiring copyright permission, other than the making of an exact copy. The -resulting work is called a “modified version” of the earlier work or a -work “based on” the earlier work. - -A “covered work” means either the unmodified Program or a work based on -the Program. - -To “propagate” a work means to do anything with it that, without -permission, would make you directly or secondarily liable for infringement under -applicable copyright law, except executing it on a computer or modifying a private -copy. Propagation includes copying, distribution (with or without modification), -making available to the public, and in some countries other activities as well. - -To “convey” a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through a computer -network, with no transfer of a copy, is not conveying. - -An interactive user interface displays “Appropriate Legal Notices” to the -extent that it includes a convenient and prominently visible feature that **(1)** -displays an appropriate copyright notice, and **(2)** tells the user that there is no -warranty for the work (except to the extent that warranties are provided), that -licensees may convey the work under this License, and how to view a copy of this -License. If the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - -### 1. Source Code - -The “source code” for a work means the preferred form of the work for -making modifications to it. “Object code” means any non-source form of a -work. - -A “Standard Interface” means an interface that either is an official -standard defined by a recognized standards body, or, in the case of interfaces -specified for a particular programming language, one that is widely used among -developers working in that language. - -The “System Libraries” of an executable work include anything, other than -the work as a whole, that **(a)** is included in the normal form of packaging a Major -Component, but which is not part of that Major Component, and **(b)** serves only to -enable use of the work with that Major Component, or to implement a Standard -Interface for which an implementation is available to the public in source code form. -A “Major Component”, in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system (if any) on which -the executable work runs, or a compiler used to produce the work, or an object code -interpreter used to run it. - -The “Corresponding Source” for a work in object code form means all the -source code needed to generate, install, and (for an executable work) run the object -code and to modify the work, including scripts to control those activities. However, -it does not include the work's System Libraries, or general-purpose tools or -generally available free programs which are used unmodified in performing those -activities but which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for the work, and -the source code for shared libraries and dynamically linked subprograms that the work -is specifically designed to require, such as by intimate data communication or -control flow between those subprograms and other parts of the work. - -The Corresponding Source need not include anything that users can regenerate -automatically from other parts of the Corresponding Source. - -The Corresponding Source for a work in source code form is that same work. - -### 2. Basic Permissions - -All rights granted under this License are granted for the term of copyright on the -Program, and are irrevocable provided the stated conditions are met. This License -explicitly affirms your unlimited permission to run the unmodified Program. The -output from running a covered work is covered by this License only if the output, -given its content, constitutes a covered work. This License acknowledges your rights -of fair use or other equivalent, as provided by copyright law. - -You may make, run and propagate covered works that you do not convey, without -conditions so long as your license otherwise remains in force. You may convey covered -works to others for the sole purpose of having them make modifications exclusively -for you, or provide you with facilities for running those works, provided that you -comply with the terms of this License in conveying all material for which you do not -control copyright. Those thus making or running the covered works for you must do so -exclusively on your behalf, under your direction and control, on terms that prohibit -them from making any copies of your copyrighted material outside their relationship -with you. - -Conveying under any other circumstances is permitted solely under the conditions -stated below. Sublicensing is not allowed; section 10 makes it unnecessary. - -### 3. Protecting Users' Legal Rights From Anti-Circumvention Law - -No covered work shall be deemed part of an effective technological measure under any -applicable law fulfilling obligations under article 11 of the WIPO copyright treaty -adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention -of such measures. - -When you convey a covered work, you waive any legal power to forbid circumvention of -technological measures to the extent such circumvention is effected by exercising -rights under this License with respect to the covered work, and you disclaim any -intention to limit operation or modification of the work as a means of enforcing, -against the work's users, your or third parties' legal rights to forbid circumvention -of technological measures. - -### 4. Conveying Verbatim Copies - -You may convey verbatim copies of the Program's source code as you receive it, in any -medium, provided that you conspicuously and appropriately publish on each copy an -appropriate copyright notice; keep intact all notices stating that this License and -any non-permissive terms added in accord with section 7 apply to the code; keep -intact all notices of the absence of any warranty; and give all recipients a copy of -this License along with the Program. - -You may charge any price or no price for each copy that you convey, and you may offer -support or warranty protection for a fee. - -### 5. Conveying Modified Source Versions - -You may convey a work based on the Program, or the modifications to produce it from -the Program, in the form of source code under the terms of section 4, provided that -you also meet all of these conditions: - -* **a)** The work must carry prominent notices stating that you modified it, and giving a -relevant date. -* **b)** The work must carry prominent notices stating that it is released under this -License and any conditions added under section 7. This requirement modifies the -requirement in section 4 to “keep intact all notices”. -* **c)** You must license the entire work, as a whole, under this License to anyone who -comes into possession of a copy. This License will therefore apply, along with any -applicable section 7 additional terms, to the whole of the work, and all its parts, -regardless of how they are packaged. This License gives no permission to license the -work in any other way, but it does not invalidate such permission if you have -separately received it. -* **d)** If the work has interactive user interfaces, each must display Appropriate Legal -Notices; however, if the Program has interactive interfaces that do not display -Appropriate Legal Notices, your work need not make them do so. - -A compilation of a covered work with other separate and independent works, which are -not by their nature extensions of the covered work, and which are not combined with -it such as to form a larger program, in or on a volume of a storage or distribution -medium, is called an “aggregate” if the compilation and its resulting -copyright are not used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work in an aggregate -does not cause this License to apply to the other parts of the aggregate. - -### 6. Conveying Non-Source Forms - -You may convey a covered work in object code form under the terms of sections 4 and -5, provided that you also convey the machine-readable Corresponding Source under the -terms of this License, in one of these ways: - -* **a)** Convey the object code in, or embodied in, a physical product (including a -physical distribution medium), accompanied by the Corresponding Source fixed on a -durable physical medium customarily used for software interchange. -* **b)** Convey the object code in, or embodied in, a physical product (including a -physical distribution medium), accompanied by a written offer, valid for at least -three years and valid for as long as you offer spare parts or customer support for -that product model, to give anyone who possesses the object code either **(1)** a copy of -the Corresponding Source for all the software in the product that is covered by this -License, on a durable physical medium customarily used for software interchange, for -a price no more than your reasonable cost of physically performing this conveying of -source, or **(2)** access to copy the Corresponding Source from a network server at no -charge. -* **c)** Convey individual copies of the object code with a copy of the written offer to -provide the Corresponding Source. This alternative is allowed only occasionally and -noncommercially, and only if you received the object code with such an offer, in -accord with subsection 6b. -* **d)** Convey the object code by offering access from a designated place (gratis or for -a charge), and offer equivalent access to the Corresponding Source in the same way -through the same place at no further charge. You need not require recipients to copy -the Corresponding Source along with the object code. If the place to copy the object -code is a network server, the Corresponding Source may be on a different server -(operated by you or a third party) that supports equivalent copying facilities, -provided you maintain clear directions next to the object code saying where to find -the Corresponding Source. Regardless of what server hosts the Corresponding Source, -you remain obligated to ensure that it is available for as long as needed to satisfy -these requirements. -* **e)** Convey the object code using peer-to-peer transmission, provided you inform -other peers where the object code and Corresponding Source of the work are being -offered to the general public at no charge under subsection 6d. - -A separable portion of the object code, whose source code is excluded from the -Corresponding Source as a System Library, need not be included in conveying the -object code work. - -A “User Product” is either **(1)** a “consumer product”, which -means any tangible personal property which is normally used for personal, family, or -household purposes, or **(2)** anything designed or sold for incorporation into a -dwelling. In determining whether a product is a consumer product, doubtful cases -shall be resolved in favor of coverage. For a particular product received by a -particular user, “normally used” refers to a typical or common use of -that class of product, regardless of the status of the particular user or of the way -in which the particular user actually uses, or expects or is expected to use, the -product. A product is a consumer product regardless of whether the product has -substantial commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - -“Installation Information” for a User Product means any methods, -procedures, authorization keys, or other information required to install and execute -modified versions of a covered work in that User Product from a modified version of -its Corresponding Source. The information must suffice to ensure that the continued -functioning of the modified object code is in no case prevented or interfered with -solely because modification has been made. - -If you convey an object code work under this section in, or with, or specifically for -use in, a User Product, and the conveying occurs as part of a transaction in which -the right of possession and use of the User Product is transferred to the recipient -in perpetuity or for a fixed term (regardless of how the transaction is -characterized), the Corresponding Source conveyed under this section must be -accompanied by the Installation Information. But this requirement does not apply if -neither you nor any third party retains the ability to install modified object code -on the User Product (for example, the work has been installed in ROM). - -The requirement to provide Installation Information does not include a requirement to -continue to provide support service, warranty, or updates for a work that has been -modified or installed by the recipient, or for the User Product in which it has been -modified or installed. Access to a network may be denied when the modification itself -materially and adversely affects the operation of the network or violates the rules -and protocols for communication across the network. - -Corresponding Source conveyed, and Installation Information provided, in accord with -this section must be in a format that is publicly documented (and with an -implementation available to the public in source code form), and must require no -special password or key for unpacking, reading or copying. - -### 7. Additional Terms - -“Additional permissions” are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. Additional -permissions that are applicable to the entire Program shall be treated as though they -were included in this License, to the extent that they are valid under applicable -law. If additional permissions apply only to part of the Program, that part may be -used separately under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - -When you convey a copy of a covered work, you may at your option remove any -additional permissions from that copy, or from any part of it. (Additional -permissions may be written to require their own removal in certain cases when you -modify the work.) You may place additional permissions on material, added by you to a -covered work, for which you have or can give appropriate copyright permission. - -Notwithstanding any other provision of this License, for material you add to a -covered work, you may (if authorized by the copyright holders of that material) -supplement the terms of this License with terms: - -* **a)** Disclaiming warranty or limiting liability differently from the terms of -sections 15 and 16 of this License; or -* **b)** Requiring preservation of specified reasonable legal notices or author -attributions in that material or in the Appropriate Legal Notices displayed by works -containing it; or -* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that -modified versions of such material be marked in reasonable ways as different from the -original version; or -* **d)** Limiting the use for publicity purposes of names of licensors or authors of the -material; or -* **e)** Declining to grant rights under trademark law for use of some trade names, -trademarks, or service marks; or -* **f)** Requiring indemnification of licensors and authors of that material by anyone -who conveys the material (or modified versions of it) with contractual assumptions of -liability to the recipient, for any liability that these contractual assumptions -directly impose on those licensors and authors. - -All other non-permissive additional terms are considered “further -restrictions” within the meaning of section 10. If the Program as you received -it, or any part of it, contains a notice stating that it is governed by this License -along with a term that is a further restriction, you may remove that term. If a -license document contains a further restriction but permits relicensing or conveying -under this License, you may add to a covered work material governed by the terms of -that license document, provided that the further restriction does not survive such -relicensing or conveying. - -If you add terms to a covered work in accord with this section, you must place, in -the relevant source files, a statement of the additional terms that apply to those -files, or a notice indicating where to find the applicable terms. - -Additional terms, permissive or non-permissive, may be stated in the form of a -separately written license, or stated as exceptions; the above requirements apply -either way. - -### 8. Termination - -You may not propagate or modify a covered work except as expressly provided under -this License. Any attempt otherwise to propagate or modify it is void, and will -automatically terminate your rights under this License (including any patent licenses -granted under the third paragraph of section 11). - -However, if you cease all violation of this License, then your license from a -particular copyright holder is reinstated **(a)** provisionally, unless and until the -copyright holder explicitly and finally terminates your license, and **(b)** permanently, -if the copyright holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - -Moreover, your license from a particular copyright holder is reinstated permanently -if the copyright holder notifies you of the violation by some reasonable means, this -is the first time you have received notice of violation of this License (for any -work) from that copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - -Termination of your rights under this section does not terminate the licenses of -parties who have received copies or rights from you under this License. If your -rights have been terminated and not permanently reinstated, you do not qualify to -receive new licenses for the same material under section 10. - -### 9. Acceptance Not Required for Having Copies - -You are not required to accept this License in order to receive or run a copy of the -Program. Ancillary propagation of a covered work occurring solely as a consequence of -using peer-to-peer transmission to receive a copy likewise does not require -acceptance. However, nothing other than this License grants you permission to -propagate or modify any covered work. These actions infringe copyright if you do not -accept this License. Therefore, by modifying or propagating a covered work, you -indicate your acceptance of this License to do so. - -### 10. Automatic Licensing of Downstream Recipients - -Each time you convey a covered work, the recipient automatically receives a license -from the original licensors, to run, modify and propagate that work, subject to this -License. You are not responsible for enforcing compliance by third parties with this -License. - -An “entity transaction” is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an organization, or -merging organizations. If propagation of a covered work results from an entity -transaction, each party to that transaction who receives a copy of the work also -receives whatever licenses to the work the party's predecessor in interest had or -could give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if the predecessor -has it or can get it with reasonable efforts. - -You may not impose any further restrictions on the exercise of the rights granted or -affirmed under this License. For example, you may not impose a license fee, royalty, -or other charge for exercise of rights granted under this License, and you may not -initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging -that any patent claim is infringed by making, using, selling, offering for sale, or -importing the Program or any portion of it. - -### 11. Patents - -A “contributor” is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The work thus -licensed is called the contributor's “contributor version”. - -A contributor's “essential patent claims” are all patent claims owned or -controlled by the contributor, whether already acquired or hereafter acquired, that -would be infringed by some manner, permitted by this License, of making, using, or -selling its contributor version, but do not include claims that would be infringed -only as a consequence of further modification of the contributor version. For -purposes of this definition, “control” includes the right to grant patent -sublicenses in a manner consistent with the requirements of this License. - -Each contributor grants you a non-exclusive, worldwide, royalty-free patent license -under the contributor's essential patent claims, to make, use, sell, offer for sale, -import and otherwise run, modify and propagate the contents of its contributor -version. - -In the following three paragraphs, a “patent license” is any express -agreement or commitment, however denominated, not to enforce a patent (such as an -express permission to practice a patent or covenant not to sue for patent -infringement). To “grant” such a patent license to a party means to make -such an agreement or commitment not to enforce a patent against the party. - -If you convey a covered work, knowingly relying on a patent license, and the -Corresponding Source of the work is not available for anyone to copy, free of charge -and under the terms of this License, through a publicly available network server or -other readily accessible means, then you must either **(1)** cause the Corresponding -Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the -patent license for this particular work, or **(3)** arrange, in a manner consistent with -the requirements of this License, to extend the patent license to downstream -recipients. “Knowingly relying” means you have actual knowledge that, but -for the patent license, your conveying the covered work in a country, or your -recipient's use of the covered work in a country, would infringe one or more -identifiable patents in that country that you have reason to believe are valid. - -If, pursuant to or in connection with a single transaction or arrangement, you -convey, or propagate by procuring conveyance of, a covered work, and grant a patent -license to some of the parties receiving the covered work authorizing them to use, -propagate, modify or convey a specific copy of the covered work, then the patent -license you grant is automatically extended to all recipients of the covered work and -works based on it. - -A patent license is “discriminatory” if it does not include within the -scope of its coverage, prohibits the exercise of, or is conditioned on the -non-exercise of one or more of the rights that are specifically granted under this -License. You may not convey a covered work if you are a party to an arrangement with -a third party that is in the business of distributing software, under which you make -payment to the third party based on the extent of your activity of conveying the -work, and under which the third party grants, to any of the parties who would receive -the covered work from you, a discriminatory patent license **(a)** in connection with -copies of the covered work conveyed by you (or copies made from those copies), or **(b)** -primarily for and in connection with specific products or compilations that contain -the covered work, unless you entered into that arrangement, or that patent license -was granted, prior to 28 March 2007. - -Nothing in this License shall be construed as excluding or limiting any implied -license or other defenses to infringement that may otherwise be available to you -under applicable patent law. - -### 12. No Surrender of Others' Freedom - -If conditions are imposed on you (whether by court order, agreement or otherwise) -that contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot convey a covered work so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not convey it at all. For example, if you -agree to terms that obligate you to collect a royalty for further conveying from -those to whom you convey the Program, the only way you could satisfy both those terms -and this License would be to refrain entirely from conveying the Program. - -### 13. Use with the GNU Affero General Public License - -Notwithstanding any other provision of this License, you have permission to link or -combine any covered work with a work licensed under version 3 of the GNU Affero -General Public License into a single combined work, and to convey the resulting work. -The terms of this License will continue to apply to the part which is the covered -work, but the special requirements of the GNU Affero General Public License, section -13, concerning interaction through a network will apply to the combination as such. - -### 14. Revised Versions of this License - -The Free Software Foundation may publish revised and/or new versions of the GNU -General Public License from time to time. Such new versions will be similar in spirit -to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program specifies that -a certain numbered version of the GNU General Public License “or any later -version” applies to it, you have the option of following the terms and -conditions either of that numbered version or of any later version published by the -Free Software Foundation. If the Program does not specify a version number of the GNU -General Public License, you may choose any version ever published by the Free -Software Foundation. - -If the Program specifies that a proxy can decide which future versions of the GNU -General Public License can be used, that proxy's public statement of acceptance of a -version permanently authorizes you to choose that version for the Program. - -Later license versions may give you additional or different permissions. However, no -additional obligations are imposed on any author or copyright holder as a result of -your choosing to follow a later version. - -### 15. Disclaimer of Warranty - -THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER -EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE -QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE -DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -### 16. Limitation of Liability - -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY -COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS -PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, -INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE -OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE -WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - -### 17. Interpretation of Sections 15 and 16 - -If the disclaimer of warranty and limitation of liability provided above cannot be -given local legal effect according to their terms, reviewing courts shall apply local -law that most closely approximates an absolute waiver of all civil liability in -connection with the Program, unless a warranty or assumption of liability accompanies -a copy of the Program in return for a fee. - -_END OF TERMS AND CONDITIONS_ - -## How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible use to -the public, the best way to achieve this is to make it free software which everyone -can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them -to the start of each source file to most effectively state the exclusion of warranty; -and each file should have at least the “copyright” line and a pointer to -where the full notice is found. - - Administrative Boundaries of Spain Including CCAA, Provinces and Municipalities - Copyright (C) 2020 Diego Hernangómez - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - -If the program does terminal interaction, make it output a short notice like this -when it starts in an interactive mode: - - mapSpain Copyright (C) 2020 Diego Hernangómez - This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type 'show c' for details. - -The hypothetical commands `show w` and `show c` should show the appropriate parts of -the General Public License. Of course, your program's commands might be different; -for a GUI interface, you would use an “about box”. - -You should also get your employer (if you work as a programmer) or school, if any, to -sign a “copyright disclaimer” for the program, if necessary. For more -information on this, and how to apply and follow the GNU GPL, see -<>. - -The GNU General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may consider it -more useful to permit linking proprietary applications with the library. If this is -what you want to do, use the GNU Lesser General Public License instead of this -License. But first, please read -<>. +GNU General Public License +========================== + +_Version 3, 29 June 2007_ +_Copyright © 2007 Free Software Foundation, Inc. <>_ + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +## Preamble + +The GNU General Public License is a free, copyleft license for software and other +kinds of works. + +The licenses for most software and other practical works are designed to take away +your freedom to share and change the works. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change all versions of a +program--to make sure it remains free software for all its users. We, the Free +Software Foundation, use the GNU General Public License for most of our software; it +applies also to any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General +Public Licenses are designed to make sure that you have the freedom to distribute +copies of free software (and charge for them if you wish), that you receive source +code or can get it if you want it, that you can change the software or use pieces of +it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or +asking you to surrender the rights. Therefore, you have certain responsibilities if +you distribute copies of the software, or if you modify it: responsibilities to +respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, +you must pass on to the recipients the same freedoms that you received. You must make +sure that they, too, receive or can get the source code. And you must show them these +terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: **(1)** assert +copyright on the software, and **(2)** offer you this License giving you legal permission +to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is +no warranty for this free software. For both users' and authors' sake, the GPL +requires that modified versions be marked as changed, so that their problems will not +be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of +the software inside them, although the manufacturer can do so. This is fundamentally +incompatible with the aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we have designed +this version of the GPL to prohibit the practice for those products. If such problems +arise substantially in other domains, we stand ready to extend this provision to +those domains in future versions of the GPL, as needed to protect the freedom of +users. + +Finally, every program is threatened constantly by software patents. States should +not allow patents to restrict development and use of software on general-purpose +computers, but in those that do, we wish to avoid the special danger that patents +applied to a free program could make it effectively proprietary. To prevent this, the +GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +## TERMS AND CONDITIONS + +### 0. Definitions + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this +License. Each licensee is addressed as “you”. “Licensees” and +“recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in +a fashion requiring copyright permission, other than the making of an exact copy. The +resulting work is called a “modified version” of the earlier work or a +work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on +the Program. + +To “propagate” a work means to do anything with it that, without +permission, would make you directly or secondarily liable for infringement under +applicable copyright law, except executing it on a computer or modifying a private +copy. Propagation includes copying, distribution (with or without modification), +making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer +network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the +extent that it includes a convenient and prominently visible feature that **(1)** +displays an appropriate copyright notice, and **(2)** tells the user that there is no +warranty for the work (except to the extent that warranties are provided), that +licensees may convey the work under this License, and how to view a copy of this +License. If the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +### 1. Source Code + +The “source code” for a work means the preferred form of the work for +making modifications to it. “Object code” means any non-source form of a +work. + +A “Standard Interface” means an interface that either is an official +standard defined by a recognized standards body, or, in the case of interfaces +specified for a particular programming language, one that is widely used among +developers working in that language. + +The “System Libraries” of an executable work include anything, other than +the work as a whole, that **(a)** is included in the normal form of packaging a Major +Component, but which is not part of that Major Component, and **(b)** serves only to +enable use of the work with that Major Component, or to implement a Standard +Interface for which an implementation is available to the public in source code form. +A “Major Component”, in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system (if any) on which +the executable work runs, or a compiler used to produce the work, or an object code +interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the +source code needed to generate, install, and (for an executable work) run the object +code and to modify the work, including scripts to control those activities. However, +it does not include the work's System Libraries, or general-purpose tools or +generally available free programs which are used unmodified in performing those +activities but which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for the work, and +the source code for shared libraries and dynamically linked subprograms that the work +is specifically designed to require, such as by intimate data communication or +control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate +automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +### 2. Basic Permissions + +All rights granted under this License are granted for the term of copyright on the +Program, and are irrevocable provided the stated conditions are met. This License +explicitly affirms your unlimited permission to run the unmodified Program. The +output from running a covered work is covered by this License only if the output, +given its content, constitutes a covered work. This License acknowledges your rights +of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without +conditions so long as your license otherwise remains in force. You may convey covered +works to others for the sole purpose of having them make modifications exclusively +for you, or provide you with facilities for running those works, provided that you +comply with the terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for you must do so +exclusively on your behalf, under your direction and control, on terms that prohibit +them from making any copies of your copyrighted material outside their relationship +with you. + +Conveying under any other circumstances is permitted solely under the conditions +stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +### 3. Protecting Users' Legal Rights From Anti-Circumvention Law + +No covered work shall be deemed part of an effective technological measure under any +applicable law fulfilling obligations under article 11 of the WIPO copyright treaty +adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention +of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of +technological measures to the extent such circumvention is effected by exercising +rights under this License with respect to the covered work, and you disclaim any +intention to limit operation or modification of the work as a means of enforcing, +against the work's users, your or third parties' legal rights to forbid circumvention +of technological measures. + +### 4. Conveying Verbatim Copies + +You may convey verbatim copies of the Program's source code as you receive it, in any +medium, provided that you conspicuously and appropriately publish on each copy an +appropriate copyright notice; keep intact all notices stating that this License and +any non-permissive terms added in accord with section 7 apply to the code; keep +intact all notices of the absence of any warranty; and give all recipients a copy of +this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer +support or warranty protection for a fee. + +### 5. Conveying Modified Source Versions + +You may convey a work based on the Program, or the modifications to produce it from +the Program, in the form of source code under the terms of section 4, provided that +you also meet all of these conditions: + +* **a)** The work must carry prominent notices stating that you modified it, and giving a +relevant date. +* **b)** The work must carry prominent notices stating that it is released under this +License and any conditions added under section 7. This requirement modifies the +requirement in section 4 to “keep intact all notices”. +* **c)** You must license the entire work, as a whole, under this License to anyone who +comes into possession of a copy. This License will therefore apply, along with any +applicable section 7 additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no permission to license the +work in any other way, but it does not invalidate such permission if you have +separately received it. +* **d)** If the work has interactive user interfaces, each must display Appropriate Legal +Notices; however, if the Program has interactive interfaces that do not display +Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are +not by their nature extensions of the covered work, and which are not combined with +it such as to form a larger program, in or on a volume of a storage or distribution +medium, is called an “aggregate” if the compilation and its resulting +copyright are not used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work in an aggregate +does not cause this License to apply to the other parts of the aggregate. + +### 6. Conveying Non-Source Forms + +You may convey a covered work in object code form under the terms of sections 4 and +5, provided that you also convey the machine-readable Corresponding Source under the +terms of this License, in one of these ways: + +* **a)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by the Corresponding Source fixed on a +durable physical medium customarily used for software interchange. +* **b)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by a written offer, valid for at least +three years and valid for as long as you offer spare parts or customer support for +that product model, to give anyone who possesses the object code either **(1)** a copy of +the Corresponding Source for all the software in the product that is covered by this +License, on a durable physical medium customarily used for software interchange, for +a price no more than your reasonable cost of physically performing this conveying of +source, or **(2)** access to copy the Corresponding Source from a network server at no +charge. +* **c)** Convey individual copies of the object code with a copy of the written offer to +provide the Corresponding Source. This alternative is allowed only occasionally and +noncommercially, and only if you received the object code with such an offer, in +accord with subsection 6b. +* **d)** Convey the object code by offering access from a designated place (gratis or for +a charge), and offer equivalent access to the Corresponding Source in the same way +through the same place at no further charge. You need not require recipients to copy +the Corresponding Source along with the object code. If the place to copy the object +code is a network server, the Corresponding Source may be on a different server +(operated by you or a third party) that supports equivalent copying facilities, +provided you maintain clear directions next to the object code saying where to find +the Corresponding Source. Regardless of what server hosts the Corresponding Source, +you remain obligated to ensure that it is available for as long as needed to satisfy +these requirements. +* **e)** Convey the object code using peer-to-peer transmission, provided you inform +other peers where the object code and Corresponding Source of the work are being +offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the +Corresponding Source as a System Library, need not be included in conveying the +object code work. + +A “User Product” is either **(1)** a “consumer product”, which +means any tangible personal property which is normally used for personal, family, or +household purposes, or **(2)** anything designed or sold for incorporation into a +dwelling. In determining whether a product is a consumer product, doubtful cases +shall be resolved in favor of coverage. For a particular product received by a +particular user, “normally used” refers to a typical or common use of +that class of product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected to use, the +product. A product is a consumer product regardless of whether the product has +substantial commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, +procedures, authorization keys, or other information required to install and execute +modified versions of a covered work in that User Product from a modified version of +its Corresponding Source. The information must suffice to ensure that the continued +functioning of the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for +use in, a User Product, and the conveying occurs as part of a transaction in which +the right of possession and use of the User Product is transferred to the recipient +in perpetuity or for a fixed term (regardless of how the transaction is +characterized), the Corresponding Source conveyed under this section must be +accompanied by the Installation Information. But this requirement does not apply if +neither you nor any third party retains the ability to install modified object code +on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to +continue to provide support service, warranty, or updates for a work that has been +modified or installed by the recipient, or for the User Product in which it has been +modified or installed. Access to a network may be denied when the modification itself +materially and adversely affects the operation of the network or violates the rules +and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with +this section must be in a format that is publicly documented (and with an +implementation available to the public in source code form), and must require no +special password or key for unpacking, reading or copying. + +### 7. Additional Terms + +“Additional permissions” are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. Additional +permissions that are applicable to the entire Program shall be treated as though they +were included in this License, to the extent that they are valid under applicable +law. If additional permissions apply only to part of the Program, that part may be +used separately under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any +additional permissions from that copy, or from any part of it. (Additional +permissions may be written to require their own removal in certain cases when you +modify the work.) You may place additional permissions on material, added by you to a +covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a +covered work, you may (if authorized by the copyright holders of that material) +supplement the terms of this License with terms: + +* **a)** Disclaiming warranty or limiting liability differently from the terms of +sections 15 and 16 of this License; or +* **b)** Requiring preservation of specified reasonable legal notices or author +attributions in that material or in the Appropriate Legal Notices displayed by works +containing it; or +* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that +modified versions of such material be marked in reasonable ways as different from the +original version; or +* **d)** Limiting the use for publicity purposes of names of licensors or authors of the +material; or +* **e)** Declining to grant rights under trademark law for use of some trade names, +trademarks, or service marks; or +* **f)** Requiring indemnification of licensors and authors of that material by anyone +who conveys the material (or modified versions of it) with contractual assumptions of +liability to the recipient, for any liability that these contractual assumptions +directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further +restrictions” within the meaning of section 10. If the Program as you received +it, or any part of it, contains a notice stating that it is governed by this License +along with a term that is a further restriction, you may remove that term. If a +license document contains a further restriction but permits relicensing or conveying +under this License, you may add to a covered work material governed by the terms of +that license document, provided that the further restriction does not survive such +relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in +the relevant source files, a statement of the additional terms that apply to those +files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a +separately written license, or stated as exceptions; the above requirements apply +either way. + +### 8. Termination + +You may not propagate or modify a covered work except as expressly provided under +this License. Any attempt otherwise to propagate or modify it is void, and will +automatically terminate your rights under this License (including any patent licenses +granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a +particular copyright holder is reinstated **(a)** provisionally, unless and until the +copyright holder explicitly and finally terminates your license, and **(b)** permanently, +if the copyright holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently +if the copyright holder notifies you of the violation by some reasonable means, this +is the first time you have received notice of violation of this License (for any +work) from that copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of +parties who have received copies or rights from you under this License. If your +rights have been terminated and not permanently reinstated, you do not qualify to +receive new licenses for the same material under section 10. + +### 9. Acceptance Not Required for Having Copies + +You are not required to accept this License in order to receive or run a copy of the +Program. Ancillary propagation of a covered work occurring solely as a consequence of +using peer-to-peer transmission to receive a copy likewise does not require +acceptance. However, nothing other than this License grants you permission to +propagate or modify any covered work. These actions infringe copyright if you do not +accept this License. Therefore, by modifying or propagating a covered work, you +indicate your acceptance of this License to do so. + +### 10. Automatic Licensing of Downstream Recipients + +Each time you convey a covered work, the recipient automatically receives a license +from the original licensors, to run, modify and propagate that work, subject to this +License. You are not responsible for enforcing compliance by third parties with this +License. + +An “entity transaction” is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an organization, or +merging organizations. If propagation of a covered work results from an entity +transaction, each party to that transaction who receives a copy of the work also +receives whatever licenses to the work the party's predecessor in interest had or +could give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if the predecessor +has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or +affirmed under this License. For example, you may not impose a license fee, royalty, +or other charge for exercise of rights granted under this License, and you may not +initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging +that any patent claim is infringed by making, using, selling, offering for sale, or +importing the Program or any portion of it. + +### 11. Patents + +A “contributor” is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus +licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or +controlled by the contributor, whether already acquired or hereafter acquired, that +would be infringed by some manner, permitted by this License, of making, using, or +selling its contributor version, but do not include claims that would be infringed +only as a consequence of further modification of the contributor version. For +purposes of this definition, “control” includes the right to grant patent +sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license +under the contributor's essential patent claims, to make, use, sell, offer for sale, +import and otherwise run, modify and propagate the contents of its contributor +version. + +In the following three paragraphs, a “patent license” is any express +agreement or commitment, however denominated, not to enforce a patent (such as an +express permission to practice a patent or covenant not to sue for patent +infringement). To “grant” such a patent license to a party means to make +such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the +Corresponding Source of the work is not available for anyone to copy, free of charge +and under the terms of this License, through a publicly available network server or +other readily accessible means, then you must either **(1)** cause the Corresponding +Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the +patent license for this particular work, or **(3)** arrange, in a manner consistent with +the requirements of this License, to extend the patent license to downstream +recipients. “Knowingly relying” means you have actual knowledge that, but +for the patent license, your conveying the covered work in a country, or your +recipient's use of the covered work in a country, would infringe one or more +identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you +convey, or propagate by procuring conveyance of, a covered work, and grant a patent +license to some of the parties receiving the covered work authorizing them to use, +propagate, modify or convey a specific copy of the covered work, then the patent +license you grant is automatically extended to all recipients of the covered work and +works based on it. + +A patent license is “discriminatory” if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on the +non-exercise of one or more of the rights that are specifically granted under this +License. You may not convey a covered work if you are a party to an arrangement with +a third party that is in the business of distributing software, under which you make +payment to the third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties who would receive +the covered work from you, a discriminatory patent license **(a)** in connection with +copies of the covered work conveyed by you (or copies made from those copies), or **(b)** +primarily for and in connection with specific products or compilations that contain +the covered work, unless you entered into that arrangement, or that patent license +was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied +license or other defenses to infringement that may otherwise be available to you +under applicable patent law. + +### 12. No Surrender of Others' Freedom + +If conditions are imposed on you (whether by court order, agreement or otherwise) +that contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot convey a covered work so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not convey it at all. For example, if you +agree to terms that obligate you to collect a royalty for further conveying from +those to whom you convey the Program, the only way you could satisfy both those terms +and this License would be to refrain entirely from conveying the Program. + +### 13. Use with the GNU Affero General Public License + +Notwithstanding any other provision of this License, you have permission to link or +combine any covered work with a work licensed under version 3 of the GNU Affero +General Public License into a single combined work, and to convey the resulting work. +The terms of this License will continue to apply to the part which is the covered +work, but the special requirements of the GNU Affero General Public License, section +13, concerning interaction through a network will apply to the combination as such. + +### 14. Revised Versions of this License + +The Free Software Foundation may publish revised and/or new versions of the GNU +General Public License from time to time. Such new versions will be similar in spirit +to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that +a certain numbered version of the GNU General Public License “or any later +version” applies to it, you have the option of following the terms and +conditions either of that numbered version or of any later version published by the +Free Software Foundation. If the Program does not specify a version number of the GNU +General Public License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU +General Public License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no +additional obligations are imposed on any author or copyright holder as a result of +your choosing to follow a later version. + +### 15. Disclaimer of Warranty + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +### 16. Limitation of Liability + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY +COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS +PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +### 17. Interpretation of Sections 15 and 16 + +If the disclaimer of warranty and limitation of liability provided above cannot be +given local legal effect according to their terms, reviewing courts shall apply local +law that most closely approximates an absolute waiver of all civil liability in +connection with the Program, unless a warranty or assumption of liability accompanies +a copy of the Program in return for a fee. + +_END OF TERMS AND CONDITIONS_ + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to +the public, the best way to achieve this is to make it free software which everyone +can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them +to the start of each source file to most effectively state the exclusion of warranty; +and each file should have at least the “copyright” line and a pointer to +where the full notice is found. + + Administrative Boundaries of Spain Including CCAA, Provinces and Municipalities + Copyright (C) 2020 Diego Hernangómez + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this +when it starts in an interactive mode: + + mapSpain Copyright (C) 2020 Diego Hernangómez + This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type 'show c' for details. + +The hypothetical commands `show w` and `show c` should show the appropriate parts of +the General Public License. Of course, your program's commands might be different; +for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to +sign a “copyright disclaimer” for the program, if necessary. For more +information on this, and how to apply and follow the GNU GPL, see +<>. + +The GNU General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may consider it +more useful to permit linking proprietary applications with the library. If this is +what you want to do, use the GNU Lesser General Public License instead of this +License. But first, please read +<>. diff --git a/NAMESPACE b/NAMESPACE index 1383f6e3..a0a94a29 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,9 @@ # Generated by roxygen2: do not edit by hand export(addProviderEspTiles) +export(esp_check_access) export(esp_clear_cache) +export(esp_detect_cache_dir) export(esp_dict_region_code) export(esp_dict_translate) export(esp_getTiles) @@ -10,7 +12,13 @@ export(esp_get_can_provinces) export(esp_get_capimun) export(esp_get_ccaa) export(esp_get_ccaa_siane) +export(esp_get_comarca) export(esp_get_country) +export(esp_get_grid_BDN) +export(esp_get_grid_BDN_ccaa) +export(esp_get_grid_EEA) +export(esp_get_grid_ESDAC) +export(esp_get_grid_MTN) export(esp_get_grid_ccaa) export(esp_get_grid_prov) export(esp_get_hex_ccaa) @@ -25,7 +33,13 @@ export(esp_get_prov_siane) export(esp_get_railway) export(esp_get_rivers) export(esp_get_roads) +export(esp_get_simpl_ccaa) +export(esp_get_simpl_prov) +export(esp_make_provider) +export(esp_move_can) export(esp_set_cache_dir) export(providerEspTileOptions) importFrom(sf,st_transform) importFrom(utils,download.file) +importFrom(utils,modifyList) +importFrom(utils,unzip) diff --git a/NEWS.md b/NEWS.md index 5fe43cbd..30f3076a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,48 +1,143 @@ -# mapSpain (development version) - -- Fix an error on CRAN related with the cache folder [#52](https://github.com/rOpenSpain/mapSpain/issues/52): - - Add `mapSpain::esp_clear_cache()` +# mapSpain 0.10.0 + +- Fix a bug on `esp_get_prov_siane()` when selecting columns #115. +- New argument `type` in `esp_get_comarca()`. Now it is possible to extract + different types of comarcas: Official (IGN), statistical (INE), agrarian or + livestock comarcas (MAPA). + +# mapSpain 0.9.2 + +- **SIANE 2024 Update**: Adapt functions to new databases. +- Improve dictionaries: `esp_dict_region_code()` and `esp_dict_translate()`. + +# mapSpain 0.9.1 + +- Update actions and docs. + +# mapSpain 0.9.0 + +- Changes on how to handle modifications on Canary Islands objects (#101): + - Add a helper function for displace stand-alone `sf` objects in Canary + Islands: `esp_move_can()`. + - `esp_move_can()` is used internally on all functions. +- Add a new function to show the current cache directory: + `esp_detect_cache_dir()`. +- `mapSpain::layer_spatraster()` removed (was deprecated in **mapSpain** + 0.6.2). + +# mapSpain 0.8.0 + +- Improve download of NUTS data from **giscoR**. +- Upgrade `esp_tiles_providers` to + v1.3.3. New providers + included: + - `IDErioja.Base` + - `IDErioja.Relieve` + - `IDErioja.Claro` + - `IDErioja.Oscuro` +- `esp_getTiles()` now supports non-OGC compliant WMTS providers, such as + Stamen or OpenStreetMaps (see examples). + +# mapSpain 0.7.0 + +- Upgrade `leaflet.providersESP.df` to + v1.3.2. +- Changes on how to package manages tiles providers: + - `leaflet.providersESP.df` is superseded in favor of + `esp_tiles_providers`. + - You can use a custom url with the `type` argument in `esp_getTiles()` + (#88). + - Add new function `esp_make_provider()` that helps to create custom + providers. + +# mapSpain 0.6.2 + +- Now `moveCAN` is a explicit parameter in the relevant functions. +- Deprecate `layer_spatraster().` Use `tidyterra::geom_spatraster_rgb()` + instead. +- Fix geometries on `esp_get_hex_prov()` and `esp_get_hex_ccaa()`. +- Add new function to get comarcas from INE: `esp_get_comarca()`. +- Add new functions to get simplified maps from INE: + - `esp_get_simpl_prov()`. + - `esp_get_simpl_ccaa()`. + +# mapSpain 0.6.1 + +- HOTFIX: Bug on `esp_getTiles()` when `mask = TRUE`. + +# mapSpain 0.6.0 + +- Upgrade `leaflet.providersESP.df` to + v1.3.0. New providers: + - `Catastro.BuildingPart` + - `Catastro.AdministrativeBoundary` + - `Catastro.AdministrativeUnit` +- Add new param `options` to `esp_getTiles()`. +- Improve regex search on municipalities: Now the casing of the word is + ignored. + +# mapSpain 0.5.0 + +- Rebuild coding database to avoid errors due to encoding. +- Fix translations on Galician. +- New grid functions (#61): + - `esp_get_grid_MTN()` + - `esp_get_grid_BDN()` + - `esp_get_grid_EEA()` + - `esp_get_grid_ESDAC()` + +# mapSpain 0.4.0 + +- Switch from **raster** to **terra**. +- Clean up dependencies. Imagery packages moved to 'Suggests'. +- Add `layer_spatraster()`. +- Move examples to **ggplot2**. + +# mapSpain 0.3.1 + +- Fix an error on **CRAN** related with the cache folder #52: + - Add `mapSpain::esp_clear_cache()` - Update docs with `@family` tag. # mapSpain 0.3.0 -- Caching improvements: new function `esp_set_cache_dir()` based on - `rappdirs::user_cache_dir()`. Now the cache_dir path is stored and it is - not necessary to set it up again on a new session. +- Caching improvements: new function `esp_set_cache_dir()` based on + `rappdirs::user_cache_dir()`. Now the cache_dir path is stored and it is not + necessary to set it up again on a new session. - Add a new parameter `zoommin` on `esp_getTiles()`. -- New tests with `testthat`. +- New tests with **testthat**. - Update on docs. New examples - Precompute vignette. - - # mapSpain 0.2.3 -- Move minimum version of `giscoR` to v0.2.4 -- Fix typos on `esp_dict_translate()` - [#36](https://github.com/rOpenSpain/mapSpain/issues/36) +- Move minimum version of **giscoR** to v0.2.4 +- Fix typos on `esp_dict_translate()` (#36). - Not run examples on tiles, as the server sometimes doesn't respond. -- Refactor `sysdata.rda`. -- CRAN fixes: +- Re factor `sysdata.rda`. +- **CRAN** fixes: - Removed broken link on `addProviderEspTiles()`. - - Vignette removed (CRAN warning). + - Vignette removed (**CRAN** warning). - Now the `cache` directory is created recursively. # mapSpain 0.2.2 -- Migrate examples, vignettes and README to `tmap`. +- Migrate examples, vignettes and README to **tmap**. - Add vignette to package. -- `esp_dict_region_code()` works with mixed casings (e.g: `esp_dict_region_code("aLbacEte", destination = "cpro")`). +- `esp_dict_region_code()` works with mixed casings (e.g: + `esp_dict_region_code("aLbacEte", destination = "cpro")`). # mapSpain 0.2.1 -- **QUICKFIX**: Fix a typo on documentation: `cache_dir` should be set as `options(mapSpain_cache_dir = "path/to/dir")`. +- **QUICKFIX**: Fix a typo on documentation: `cache_dir` should be set as + `options(mapSpain_cache_dir = "path/to/dir")`. # mapSpain 0.2.0 - Fix DOI -- Documentation ported to roxygen2/markdown. -- Include CartoBase ANE data : +- Documentation ported to **roxygen2**. +- Include CartoBase ANE data + : - `mapSpain::esp_get_munic_siane()` - `mapSpain::esp_get_prov_siane()` - `mapSpain::esp_get_ccaa_siane()` @@ -52,11 +147,11 @@ - `mapSpain::esp_get_capimun()` - `mapSpain::esp_get_roads()` - `mapSpain::esp_get_railway()` -- Mute warnings from `rgdal`. +- Mute warnings from **rgdal**. # mapSpain 0.1.2 -- Fix annoying warning if `sf` was not loaded first. +- Fix annoying warning if **sf** was not loaded first. - Include new `poly` option on `mapSpain::esp_get_can_box()`. - New grids created with `geogrid::calculate_grid()`. - Add more years on `mapSpain::esp_get_munic()`. @@ -64,7 +159,7 @@ # mapSpain 0.1.1 -- Fix CRAN submission. +- Fix **CRAN** submission. - Added `mapSpain::esp_get_grid_prov()` and `mapSpain::esp_get_grid_ccaa()`. # mapSpain 0.1.0 diff --git a/R/addProviderEspTiles.R b/R/addProviderEspTiles.R index 4c2364da..8e839d8e 100644 --- a/R/addProviderEspTiles.R +++ b/R/addProviderEspTiles.R @@ -1,175 +1,180 @@ -#' Include base tiles of Spanish public administrations on a **leaflet** map -#' -#' @description -#' Include tiles of public Spanish organisms to a -#' [leaflet::leaflet()] map. -#' -#' @family imagery utilities -#' @seealso [leaflet::leaflet()], [leaflet::addTiles()] -#' -#' @rdname addProviderEspTiles -#' @name addProviderEspTiles -#' -#' @source -#' leaflet plugin, -#' **v1.2.0**. -#' -#' @return A map object generated with [leaflet::leaflet()]. -#' -#' -#' -#' @export -#' -#' @param map A map widget created from [leaflet::leaflet()]. -#' @param group The name of the group the newly created layers should belong to -#' Human-friendly group names are permitted–they need not be short, -#' identifier-style names. Any number of layers and even different types of -#' layers (e.g. markers and polygons) can share the same group name. See -#' [leaflet::addTiles()]. -#' @param provider Name of the provider, see [leaflet.providersESP.df] for -#' values available. -#' -#' @inheritParams leaflet::addTiles -#' -#' @examples -#' library(leaflet) -#' PuertadelSol <- -#' leaflet() %>% -#' setView( -#' lat = 40.4166, -#' lng = -3.7038400, -#' zoom = 18 -#' ) %>% -#' addProviderEspTiles(provider = "IGNBase.Gris") %>% -#' addProviderEspTiles(provider = "RedTransporte.Carreteras") -#' -#' PuertadelSol -addProviderEspTiles <- function(map, - provider, - layerId = NULL, - group = NULL, - options = providerEspTileOptions()) { - # A. Check providers - providers_df <- - as.data.frame(mapSpain::leaflet.providersESP.df) - provs <- - providers_df[providers_df$provider == provider, ] - - if (nrow(provs) == 0) { - stop( - "No match for provider = '", - provider, - "' found. Available providers are:\n\n", - paste0("'", - unique(providers_df$provider), "'", - collapse = ", " - ) - ) - } - - # Get url - - templurl <- provs[provs$field == "url", "value"] - attribution <- provs[provs$field == "attribution", "value"] - - iswmts <- provs[provs$field == "type", "value"] == "WMTS" - - # Work with options - if (isFALSE(iswmts)) { - layers <- provs[provs$field == "layers", "value"] - } - - opts <- - provs[!( - provs$field %in% c( - "url", - "type", - "url_static", - "attribution", - "attribution_static", - "bounds", - "layers" - ) - ), c(2, 3)] - - - - # Clean if the option was already set - opts <- opts[!(opts$field %in% names(options)), ] - - # Pass to list - - opinit <- list() - - for (j in seq_len(nrow(opts))) { - name <- paste(opts[j, 1]) - value <- paste(opts[j, 2]) - - opinit[[name]] <- value - } - - options <- c(options, opinit) - rm(opts, provs, providers_df, opinit) - - # Replace on template - - optionend <- list() - - for (i in seq_len(length(options))) { - n <- names(options[i]) - v <- options[i][[1]] - - needreplace <- - grepl(paste0("{", n, "}"), templurl, fixed = TRUE) - - if (needreplace) { - templurl <- gsub(paste0("{", n, "}"), v, templurl, fixed = TRUE) - } else { - optionend <- c(optionend, options[i]) - } - } - - - - if (iswmts) { - optionend <- do.call(leaflet::tileOptions, optionend) - - leaflet::addTiles( - map, - urlTemplate = templurl, - attribution = attribution, - layerId = layerId, - group = group, - options = optionend - ) - } else { - optionend <- do.call(leaflet::WMSTileOptions, optionend) - - leaflet::addWMSTiles( - map, - baseUrl = templurl, - layers = layers, - attribution = attribution, - layerId = layerId, - group = group, - options = optionend - ) - } -} - -#' @rdname addProviderEspTiles -#' @name providerEspTileOptions -#' -#' @details -#' [providerEspTileOptions()] is a wrapper of -#' [leaflet::providerTileOptions()]. -#' -#' @inheritDotParams leaflet::providerTileOptions -#' -#' @seealso [leaflet::providerTileOptions()], [leaflet::tileOptions()] -#' -#' @export -providerEspTileOptions <- function(...) { - ops <- leaflet::providerTileOptions(...) - return(ops) -} +# Leaflet plugin version +leafletprovidersESP_v <- "v1.3.3" + + +#' Include base tiles of Spanish public administrations on a \CRANpkg{leaflet} +#' map +#' +#' @description +#' Include tiles of public Spanish organisms to a [leaflet::leaflet()] map. +#' +#' @family imagery utilities +#' @seealso [leaflet::leaflet()], [leaflet::addTiles()] +#' +#' @rdname addProviderEspTiles +#' @name addProviderEspTiles +#' +#' @source +#' leaflet plugin, +#' **`r leafletprovidersESP_v`**. +#' +#' @return A modified [leaflet::leaflet()] `map` object. +#' +#' @export +#' +#' @param provider Name of the provider, see [esp_tiles_providers] for +#' values available. +#' @inheritParams leaflet::addProviderTiles +#' @inheritParams leaflet::addTiles +#' +#' @examples +#' library(leaflet) +#' leafmap <- leaflet(width = "100%", height = "60vh") %>% +#' setView(lat = 40.4166, lng = -3.7038400, zoom = 10) %>% +#' addTiles(group = "Default (OSM)") %>% +#' addProviderEspTiles( +#' provider = "IDErioja.Claro", +#' group = "IDErioja Claro" +#' ) %>% +#' addProviderEspTiles( +#' provider = "RedTransporte.Carreteras", +#' group = "Carreteras" +#' ) %>% +#' addLayersControl( +#' baseGroups = c("IDErioja Claro", "Default (OSM)"), +#' overlayGroups = "Carreteras", +#' options = layersControlOptions(collapsed = FALSE) +#' ) +#' +#' leafmap +addProviderEspTiles <- function(map, provider, layerId = NULL, group = NULL, + options = providerEspTileOptions()) { + # A. Check providers + prov_list <- mapSpain::esp_tiles_providers + + allprovs <- names(prov_list) + + + if (!provider %in% allprovs) { + stop( + "No match for provider = '", provider, + "' found.\n\nCheck available providers in mapSpain::esp_tiles_providers." + ) + } + + # Check type of provider + thisprov <- prov_list[[provider]] + + # Get url + # Special case for IDErioja + if (grepl("rioja", provider, ignore.case = TRUE)) { + iswmts <- TRUE + } else { + type_prov <- tolower(thisprov$static$service) + iswmts <- type_prov == "wmts" + } + + # Prepare each provider + if (iswmts) { + # Build template + # Get requested options and merge with the current ones + def_opts <- thisprov$leaflet + + # Extract attribution + attribution <- def_opts$attribution + # Remove + def_opts <- modifyList(def_opts, list(attribution = NULL)) + + # Normalize names + names(def_opts) <- tolower(names(def_opts)) + names(options) <- tolower(names(options)) + + optionend <- modifyList(def_opts, options) + + # Build template url + temp_pieces <- thisprov$static + q <- temp_pieces$q + # Remove + rest <- modifyList(temp_pieces, list(attribution = NULL, q = NULL)) + + rest_temp <- paste0(names(rest), "=", rest, collapse = "&") + + templurl <- paste0(q, rest_temp) + + # Special case for IDErioja + if (grepl("rioja", provider, ignore.case = TRUE)) { + templurl <- q + } + + # Modify default leaflet::tileOptions() with our options + # Normalize names + tileops <- leaflet::tileOptions() + names(tileops) <- tolower(names(tileops)) + + optionend <- modifyList(tileops, optionend) + optionend <- do.call(leaflet::tileOptions, optionend) + + leaflet::addTiles(map, + urlTemplate = templurl, attribution = attribution, + layerId = layerId, group = group, options = optionend + ) + } else { + # Build template + # Get requested options and merge with the current ones + def_opts <- thisprov$leaflet + + # Extract attribution + attribution <- def_opts$attribution + # Remove + def_opts <- modifyList(def_opts, list(attribution = NULL)) + + # Get important params + temp_pieces <- thisprov$static + names(temp_pieces) <- tolower(names(temp_pieces)) + + templurl <- gsub("\\?$", "", temp_pieces$q) + layers <- temp_pieces$layers + + # Remove parameters only affecting static urls + todel <- names(temp_pieces) %in% c( + "attribution", "q", "service", "request", + "layers", "srs", "width", "height", + "bbox" + ) + + names(def_opts) <- tolower(names(def_opts)) + + def_opts <- modifyList(def_opts, temp_pieces[!todel]) + + # Add custom options + names(options) <- tolower(names(options)) + optionend <- modifyList(def_opts, options) + + # Modify default leaflet::WMSTileOptions() with our options + wmsopts <- leaflet::WMSTileOptions() + names(wmsopts) <- tolower(names(wmsopts)) + + optionend <- modifyList(wmsopts, optionend) + + leaflet::addWMSTiles(map, + baseUrl = templurl, layers = layers, + attribution = attribution, layerId = layerId, + group = group, options = optionend + ) + } +} + +#' @rdname addProviderEspTiles +#' @name providerEspTileOptions +#' +#' @details +#' [providerEspTileOptions()] is a wrapper of [leaflet::providerTileOptions()]. +#' +#' @param ... Arguments passed on to [leaflet::providerTileOptions()]. +#' @seealso [leaflet::providerTileOptions()], [leaflet::tileOptions()] +#' +#' @export +providerEspTileOptions <- function(...) { + ops <- leaflet::providerTileOptions(...) + return(ops) +} diff --git a/R/data.R b/R/data.R index 92fe3f40..b148f7e6 100644 --- a/R/data.R +++ b/R/data.R @@ -1,4 +1,4 @@ -#' Spanish Code Translation Data Frame +#' Database with codes and names of spanish regions #' #' @family datasets #' @family political @@ -9,67 +9,93 @@ #' @docType data #' #' @description -#' A data frame used internally for translating codes and names of the -#' different subdivisions of Spain. The data frame provides the hierarchy of -#' the subdivisions including NUTS1 level, Autonomous Communities -#' (equivalent to NUTS2), Provinces and NUTS3 level. See Note. +#' A `data.frame` object used internally for translating codes and names of the +#' different subdivisions of Spain. The `data.frame` provides the hierarchy of +#' the subdivisions including NUTS1 level, autonomous communities (equivalent +#' to NUTS2), provinces and NUTS3 level. See **Note**. #' #' @source -#' * **INE**: Instituto Nacional de Estadistica: -#' * **Eurostat (NUTS)**: -#' * **ISO**: -#' * **CLDR**: +#' - **INE**: Instituto Nacional de Estadistica: +#' - **Eurostat (NUTS)**: +#' - **ISO**: +#' - **CLDR**: #' #' @encoding UTF-8 #' #' @format -#' A data frame with `r nrow(mapSpain::esp_codelist)` rows -#' codes as columns -#' * **nuts+.code**: NUTS code of each subdivision. -#' * **nuts+.code**: NUTS name of each subdivision. -#' * **codauto**: INE code of each autonomous community. -#' * **iso2.+.code**: ISO2 code of each autonomous -#' community and province. -#' * **ine.+.name**: INE name of each autonomous community -#' and province. -#' * **iso2.+.name.(lang)**: ISO2 name of each autonomous community -#' and province. Several languages available. -#' * **cldr.+.name.(lang)**: CLDR name of each autonomous community and -#' province. Several languages available. -#' * **ccaa.short.+**: Short (common) name of each autonomous -#' community. Several languages available. -#' * **cpro**: INE code of each province. -#' * **prov.shortname.+**: Short (common) name of each province. -#' Several languages available. +#' A [`data.frame`][base::data.frame] with `r nrow(mapSpain::esp_codelist)` rows +#' codes and columns: +#' +#' \describe{ +#' \item{nuts1.code}{NUTS 1 code} +#' \item{nuts1.name}{NUTS 1 name} +#' \item{nuts1.name.alt}{NUTS 1 alternative name} +#' \item{nuts1.shortname.es}{NUTS1 1 short (common) name (Spanish)} +#' \item{codauto}{INE code of the autonomous community} +#' \item{iso2.ccaa.code}{ISO2 code of the autonomous community} +#' \item{nuts2.code}{NUTS 2 Code} +#' \item{ine.ccaa.name}{INE name of the autonomous community} +#' \item{iso2.ccaa.name.es}{ISO2 name of the autonomous community (Spanish)} +#' \item{iso2.ccaa.name.ca}{ISO2 name of the autonomous community (Catalan)} +#' \item{iso2.ccaa.name.gl}{ISO2 name of the autonomous community (Galician)} +#' \item{iso2.ccaa.name.eu}{ISO2 name of the autonomous community (Basque)} +#' \item{nuts2.name}{NUTS 2 name} +#' \item{cldr.ccaa.name.en}{CLDR name of the autonomous community (English)} +#' \item{cldr.ccaa.name.es}{CLDR name of the autonomous community (Spanish)} +#' \item{cldr.ccaa.name.ca}{CLDR name of the autonomous community (Catalan)} +#' \item{cldr.ccaa.name.ga}{CLDR name of the autonomous community (Galician)} +#' \item{cldr.ccaa.name.eu}{CLDR name of the autonomous community (Basque)} +#' \item{ccaa.shortname.en}{Short (common) name of the autonomous community +#' (English)} +#' \item{ccaa.shortname.es}{Short (common) name of the autonomous community +#' (Spanish)} +#' \item{ccaa.shortname.ca}{Short (common) name of the autonomous community +#' (Catalan)} +#' \item{ccaa.shortname.ga}{Short (common) name of the autonomous community +#' (Galician)} +#' \item{ccaa.shortname.eu}{Short (common) name of the autonomous community +#' (Basque)} +#' \item{cpro}{INE code of the province} +#' \item{iso2.prov.code}{ISO2 code of the province} +#' \item{nuts.prov.code}{NUTS code of the province} +#' \item{ine.prov.name}{INE name of the province} +#' \item{iso2.prov.name.es}{ISO2 name of the province (Spanish)} +#' \item{iso2.prov.name.ca}{ISO2 name of the province (Catalan)} +#' \item{iso2.prov.name.ga}{ISO2 name of the province (Galician)} +#' \item{iso2.prov.name.eu}{ISO2 name of the province (Basque)} +#' \item{cldr.prov.name.en}{CLDR name of the province (English)} +#' \item{cldr.prov.name.es}{CLDR name of the province (Spanish)} +#' \item{cldr.prov.name.ca}{CLDR name of the province (Catalan)} +#' \item{cldr.prov.name.ga}{CLDR name of the province (Galician)} +#' \item{cldr.prov.name.eu}{CLDR name of the province (Basque)} +#' \item{prov.shortname.en}{Short (common) name of the province (English)} +#' \item{prov.shortname.es}{Short (common) name of the province (Spanish)} +#' \item{prov.shortname.ca}{Short (common) name of the province (Catalan)} +#' \item{prov.shortname.ga}{Short (common) name of the province (Galician)} +#' \item{prov.shortname.eu}{Short (common) name of the province (Basque)} +#' \item{nuts3.code}{NUTS 3 code} +#' \item{nuts3.name}{NUTS 3 name} +#' \item{nuts3.shortname.es}{NUTS 3 short (common) name} +#' } #' #' @note -#' Languages available are: -#' * **"en"**: English -#' * **"es"**: Spanish -#' * **"ca"**: Catalan -#' * **"ga"**: Galician -#' * **"eu"**: Basque #' #' Although NUTS2 matches the first subdivision level of Spain #' (CCAA - Autonomous Communities), it should be noted that NUTS3 does not #' match the second subdivision level of Spain (Provinces). NUTS3 provides a -#' dedicated code for major islands whereas the Provinces doesn't. +#' dedicated code for major islands whereas the provinces doesn't. #' #' Ceuta and Melilla has an specific status (Autonomous Cities) but are -#' considered as communities with a single province (as Madrid, Asturias -#' or Murcia) on this dataset. +#' considered as autonomous communities with a single province (as Madrid, +#' Asturias or Murcia) on this database. #' #' @examples #' #' data("esp_codelist") -#' -#' library(tibble) -#' -#' glimpse(as_tibble(esp_codelist)) NULL -#' All NUTS `POLYGON` object of Spain +#' [`sf`][sf::st_sf] object with all the NUTS levels of Spain (2016) #' #' @family datasets #' @family nuts @@ -79,7 +105,7 @@ NULL #' @docType data #' #' @description -#' A `sf` object including all NUTS levels of Spain as provided by +#' A [`sf`][sf::st_sf] object including all NUTS levels of Spain as provided by #' GISCO (2016 version). #' #' @source @@ -90,60 +116,95 @@ NULL #' #' #' @format -#' A `POLYGON` data frame (resolution: 1:1million, EPSG:4258) object with -#' `r prettyNum(nrow(mapSpain::esp_nuts.sf), big.mark=",")` rows and fields: -#' * COAST_TYPE: COAST_TYPE -#' * FID: FID -#' * NUTS_NAME: NUTS name on local alphabet -#' * MOUNT_TYPE: MOUNT_TYPE -#' * NAME_LATN: Name on Latin characters -#' * CNTR_CODE: Eurostat Country code -#' * URBN_TYPE: URBN_TYPE -#' * NUTS_ID: NUTS identifier -#' * LEVL_CODE: NUTS level code (0,1,2,3) -#' * geometry: geometry field -#' +#' A [`sf`][sf::st_sf] object (resolution: 1:1million, EPSG:4258) with +#' `r prettyNum(nrow(mapSpain::esp_nuts.sf), big.mark=",")` rows and columns: +#' \describe{ +#' \item{LEVL_CODE}{NUTS level code (0,1,2,3)} +#' \item{NUTS_ID}{NUTS identifier} +#' \item{URBN_TYPE}{Urban Type, see Details} +#' \item{CNTR_CODE}{Eurostat Country code `ES`} +#' \item{NAME_LATN}{NUTS name on Latin characters} +#' \item{NUTS_NAME}{NUTS name on local alphabet} +#' \item{MOUNT_TYPE}{Mount Type, see Details} +#' \item{COAST_TYPE}{Coast Type, see Details} +#' \item{FID}{FID} +#' \item{geometry}{geometry field} +#' } #' @example inst/examples/esp_nuts_sf.R +#' +#' @details +#' +#' **MOUNT_TYPE**: Mountain typology: +#' - 1: More than 50 % of the surface is covered by topographic mountain areas. +#' - 2: More than 50 % of the regional population lives in topographic +#' mountain areas. +#' - 3: More than 50 % of the surface is covered by topographic mountain areas +#' and where more than 50 % of the regional population lives in these +#' mountain areas. +#' - 4: Non-mountain region / other regions. +#' - 0: No classification provided +#' +#' **URBN_TYPE**: Urban-rural typology: +#' - 1: Predominantly urban region. +#' - 2: Intermediate region. +#' - 3: Predominantly rural region. +#' - 0: No classification provided +#' +#' **COAST_TYPE**: Coastal typology: +#' - 1: Coastal (on coast). +#' - 2: Coastal (less than 50% of population living within 50 km. of the +#' coastline). +#' - 3: Non-coastal region. +#' - 0: No classification provided +#' NULL -#' All Municipalities `POLYGON` object of Spain (2019) -#' +#' [`sf`][sf::st_sf] object with all the municipalities of Spain (2019) #' @family datasets #' @family municipalities #' #' @name esp_munic.sf #' #' @description -#' A `sf` object including all municipalities of Spain as provided by GISCO -#' (2019 version). +#' A [`sf`][sf::st_sf] object including all municipalities of Spain as provided +#' by GISCO (2019 version). #' #' @docType data #' #' @source -#' , LAU 2019 -#' data. +#' +#' ```{r, echo=FALSE, results='asis'} +#' +#' cat(paste0(", ")) +#' +#' +#' ``` +#' LAU 2019 data. #' #' @encoding UTF-8 #' #' @seealso [esp_get_munic()]. #' @format -#' A `POLYGON` data frame (resolution: 1:1million, EPSG:4258) object with -#' `r prettyNum(nrow(mapSpain::esp_munic.sf), big.mark=",")` rows and fields: -#' * **codauto**: INE code of each autonomous community. -#' * **ine.ccaa.name**: INE name of each autonomous community. -#' * **cpro**: INE code of each province. -#' * **ine.prov.name**: INE name of each province. -#' * **cmun**: INE code of each municipality. -#' * **name**: Name of the municipality. -#' * **LAU_CODE**: LAU Code (GISCO) of the municipality. This is a -#' combination of **cpro** and **cmun**, aligned with INE coding scheme. -#' * **geometry**: geometry field. -#' +#' A [`sf`][sf::st_sf] object (resolution: 1:1 million, EPSG:4258) object with +#' `r prettyNum(nrow(mapSpain::esp_munic.sf), big.mark=",")` rows and columns: +#' \describe{ +#' \item{codauto}{INE code of the autonomous community.} +#' \item{ine.ccaa.name}{INE name of the autonomous community.} +#' \item{cpro}{INE code of the province.} +#' \item{ine.prov.name}{INE name of the province.} +#' \item{cmun}{INE code of the municipality.} +#' \item{name}{Name of the municipality.} +#' \item{LAU_CODE}{LAU Code (GISCO) of the municipality. This is a +#' combination of **cpro** and **cmun** fields, aligned with INE coding +#' scheme.} +#' \item{geometry}{geometry field.} +#' } #' @example inst/examples/esp_munic_sf.R NULL -#' @title Population by municipality (2019) +#' Database with the population of Spain by municipality (2019) #' #' @family datasets #' @@ -151,69 +212,118 @@ NULL #' #' @docType data #' -#' @description -#' A data frame with `r prettyNum(nrow(mapSpain::pobmun19), big.mark=",")` -#' rows containing the population data by municipality in Spain (2019). +#' @format +#' An example `data.frame` object with +#' `r prettyNum(nrow(mapSpain::pobmun19), big.mark=",")` rows containing the +#' population data by municipality in Spain (2019). +#' +#' \describe{ +#' \item{cpro}{INE code of the province.} +#' \item{provincia}{name of the province.} +#' \item{cmun}{INE code of the municipality.} +#' \item{name}{Name of the municipality.} +#' \item{pob19}{Overall population (2019)} +#' \item{men}{Men population (2019)} +#' \item{women}{Women population (2019)} +#' } #' #' @source INE: Instituto Nacional de Estadistica #' #' @examples #' data("pobmun19") -#' -#' library(tibble) -#' -#' as_tibble(pobmun19) NULL -#' @title Public WMS and WMTS of Spain +#' (Superseded) Database of public WMS and WMTS of Spain #' -#' @family datasets -#' @family imagery utilities +#' @keywords internal #' #' @name leaflet.providersESP.df #' #' @description -#' A data frame containing information of different public WMS and WMTS +#' `r lifecycle::badge('superseded')` +#' +#' This `data.frame` is not longer in use by \CRANpkg{mapSpain}. See +#' [esp_tiles_providers] instead. +#' +#' A `data.frame` containing information of different public WMS and WMTS #' providers of Spain #' -#' This function is a implementation of the javascript plugin -#' [leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/) -#' **v1.2.0**. #' #' @docType data #' #' @source #' leaflet plugin, -#' **v1.2.0**. +#' **`r leafletprovidersESP_v`**. #' #' @encoding UTF-8 #' #' @format -#' A data frame object with a list of the required parameters for calling +#' A `data.frame` object with a list of the required parameters for calling #' the service: -#' * **provider**: Provider name. -#' * **field**: Description of `value`. -#' * **value**: INE code of each province. +#' \describe{ +#' \item{provider}{Provider name}. +#' \item{field}{Description of `value`}. +#' \item{value}{INE code of each province}. +#' } #' +#' @examples +#' data("leaflet.providersESP.df") +NULL + +#' Database of public WMS and WMTS of Spain +#' +#' @family datasets +#' @family imagery utilities +#' +#' @name esp_tiles_providers +#' +#' @description +#' A named [`list`][base::list] of length `r length(esp_tiles_providers)` +#' containing the parameters of the url information of different public WMS and +#' WMTSproviders of Spain. +#' +#' Implementation of javascript plugin +#' [leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/) +#' **`r leafletprovidersESP_v`**. +#' +#' @docType data +#' +#' @source +#' leaflet plugin, +#' **`r leafletprovidersESP_v`**. +#' +#' @encoding UTF-8 +#' +#' @format +#' A named `list` of the providers available with the following structure: +#' - Each item of the list is named with the provider alias. +#' - Each element of the list contains two nested named lists: +#' - `static` with the parameters to get static tiles plus an additional item +#' named `attribution`. +#' - `leaflet` with additional parameters to be passed onto +#' [addProviderEspTiles()]. #' #' @details #' Providers available to be passed to `type` on [esp_getTiles()] are: #' -#' ```{r, echo=FALSE} +#' ```{r, echo=FALSE, comment="", results="asis"} +#' +#' t <- names(mapSpain::esp_tiles_providers) +#' t <- paste0('\n - `"', t, '"`') #' -#' t <- mapSpain::leaflet.providersESP.df -#' t <- paste0("'", unique(t$provider), "'") -#' t <- data.frame(provider=t) #' -#' knitr::kable(t) +#' cat(t) #' #' #' ``` #' @examples -#' data("leaflet.providersESP.df") +#' data("esp_tiles_providers") +#' # Get a single provider +#' +#' single <- esp_tiles_providers[["IGNBase.Todo"]] +#' single$static #' -#' library(tibble) +#' single$leaflet #' -#' as_tibble(leaflet.providersESP.df) NULL diff --git a/R/esp_cache.R b/R/esp_cache.R index 0e5c5ff7..7e0d8d6f 100644 --- a/R/esp_cache.R +++ b/R/esp_cache.R @@ -1,9 +1,11 @@ -#' Set your **mapSpain** cache dir +#' Set your \CRANpkg{mapSpain} cache dir #' #' @family cache utilities #' @seealso [rappdirs::user_config_dir()] #' -#' @return An (invisible) character with the path to your `cache_dir`. +#' @return +#' An (invisible) character with the path to your `cache_dir`. +#' #' @description #' This function will store your `cache_dir` path on your local machine and #' would load it for future sessions. Type `Sys.getenv("MAPSPAIN_CACHE_DIR")` to @@ -11,24 +13,23 @@ #' #' Alternatively, you can store the `cache_dir` manually with the following #' options: -#' * Run `Sys.setenv(MAPSPAIN_CACHE_DIR = "cache_dir")`. You would need to -#' run this command on each session (Similar to `install = FALSE`). -#' * Set `options(mapSpain_cache_dir = "cache_dir")`. Similar to the previous -#' option. This is **not recommended any more**, and it is provided for -#' backwards compatibility purposes. -#' * Write this line on your .Renviron file: -#' `MAPSPAIN_CACHE_DIR = "value_for_cache_dir"` (same behavior than -#' `install = TRUE`). This would store your `cache_dir` permanently. +#' - Run `Sys.setenv(MAPSPAIN_CACHE_DIR = "cache_dir")`. You would need to +#' run this command on each session (Similar to `install = FALSE`). +#' - Set `options(mapSpain_cache_dir = "cache_dir")`. Similar to the previous +#' option. This is **not recommended any more**, and it is provided for +#' backwards compatibility purposes. +#' - Write this line on your .Renviron file: +#' `MAPSPAIN_CACHE_DIR = "value_for_cache_dir"` (same behavior than +#' `install = TRUE`). This would store your `cache_dir` permanently. #' #' @inheritParams esp_get_nuts #' @param cache_dir A path to a cache directory. On missing value the function #' would store the cached files on a temporary dir (See [base::tempdir()]). -#' @param install if `TRUE`, will install the key in your local machine for -#' use in future sessions. Defaults to `FALSE.` If `cache_dir` is `FALSE` -#' this parameter is set to `FALSE` automatically. -#' @param overwrite If this is set to `TRUE`, it will overwrite an existing -#' `MAPSPAIN_CACHE_DIR` that you already have in local machine. -#' +#' @param install Logical. If `TRUE`, will install the key in your local +#' machine for use in future sessions. Defaults to `FALSE.` If `cache_dir` +#' is `FALSE` this parameter is set to `FALSE` automatically. +#' @param overwrite Logical. If this is set to `TRUE`, it will overwrite an +#' existing `MAPSPAIN_CACHE_DIR` that you already have in local machine. #' #' @examples #' @@ -39,13 +40,8 @@ #' #' Sys.getenv("MAPSPAIN_CACHE_DIR") #' @export -esp_set_cache_dir <- function(cache_dir, - overwrite = FALSE, - install = FALSE, +esp_set_cache_dir <- function(cache_dir, overwrite = FALSE, install = FALSE, verbose = TRUE) { - - # nocov start - # Default if not provided if (missing(cache_dir) || cache_dir == "") { if (verbose) { @@ -64,12 +60,10 @@ esp_set_cache_dir <- function(cache_dir, # Validate - stopifnot( - is.character(cache_dir), - is.logical(overwrite), - is.logical(install) - ) + stopifnot(is.character(cache_dir), is.logical(overwrite), is.logical(install)) + # Expand + cache_dir <- path.expand(cache_dir) # Create cache dir if it doesn't exists if (!dir.exists(cache_dir)) { @@ -77,14 +71,11 @@ esp_set_cache_dir <- function(cache_dir, } if (verbose) { - message( - "mapSpain cache dir is: ", - cache_dir - ) + message("mapSpain cache dir is: ", cache_dir) } - # Install path on environ var. + # nocov start if (install) { config_dir <- rappdirs::user_config_dir("mapSpain", "R") @@ -105,6 +96,7 @@ esp_set_cache_dir <- function(cache_dir, call. = FALSE ) } + # nocov end } else { if (verbose && !is_temp) { message( @@ -116,11 +108,9 @@ esp_set_cache_dir <- function(cache_dir, Sys.setenv(MAPSPAIN_CACHE_DIR = cache_dir) return(invisible(cache_dir)) - # nocov end } -esp_clear_cache <- function(config = TRUE, - cached_data = TRUE, +esp_clear_cache <- function(config = TRUE, cached_data = TRUE, verbose = FALSE) { config_dir <- rappdirs::user_config_dir("mapSpain", "R") data_dir <- esp_hlp_detect_cache_dir() @@ -144,22 +134,20 @@ esp_clear_cache <- function(config = TRUE, #' #' @noRd esp_hlp_detect_cache_dir <- function() { - # Try from getenv getvar <- Sys.getenv("MAPSPAIN_CACHE_DIR") # 1. Get from option - This is from backwards compatibility only - # nocov start + from_option <- getOption("mapSpain_cache_dir", NULL) + # nocov start if (!is.null(from_option) && (is.null(getvar) || getvar == "")) { cache_dir <- esp_set_cache_dir(from_option, install = FALSE) return(cache_dir) } - - - + # nocov end if (is.null(getvar) || is.na(getvar) || getvar == "") { # Not set - tries to retrieve from cache @@ -168,35 +156,29 @@ esp_hlp_detect_cache_dir <- function() { "mapSpain_cache_dir" ) + # nocov start if (file.exists(cache_config)) { cached_path <- readLines(cache_config) # Case on empty cached path - would default - if (is.null(cached_path) || - is.na(cached_path) || cached_path == "") { - cache_dir <- esp_set_cache_dir( - overwrite = TRUE, - verbose = FALSE - ) + if (any(is.null(cached_path), is.na(cached_path), cached_path == "")) { + cache_dir <- esp_set_cache_dir(overwrite = TRUE, verbose = FALSE) return(cache_dir) } # 3. Return from cached path Sys.setenv(MAPSPAIN_CACHE_DIR = cached_path) return(cached_path) + # nocov end } else { # 4. Default cache location - cache_dir <- esp_set_cache_dir( - overwrite = TRUE, - verbose = FALSE - ) + cache_dir <- esp_set_cache_dir(overwrite = TRUE, verbose = FALSE) return(cache_dir) } } else { return(getvar) } - # nocov end } #' Creates `cache_dir` @@ -210,14 +192,35 @@ esp_hlp_cachedir <- function(cache_dir = NULL) { cache_dir <- esp_hlp_detect_cache_dir() } - # Reevaluate - if (is.null(cache_dir)) { - cache_dir <- file.path(tempdir(), "mapSpain") - } - # Create cache dir if needed if (isFALSE(dir.exists(cache_dir))) { dir.create(cache_dir, recursive = TRUE) } return(cache_dir) } + +#' Detect cache dir for \CRANpkg{mapSpain} +#' +#' @description +#' +#' Helper function to detect the current cache folder. See +#' [esp_set_cache_dir()]. +#' +#' +#' @param x Ignored. +#' +#' @return A character with the path to your `cache_dir`. +#' +#' @export +#' +#' @rdname esp_detect_cache_dir +#' @family cache utilities +#' @examples +#' esp_detect_cache_dir() +#' +esp_detect_cache_dir <- function(x = NULL) { + # Cheat linters + cd <- x + cd <- esp_hlp_detect_cache_dir() + cd +} diff --git a/R/esp_cache_clear.R b/R/esp_cache_clear.R index 40cf6421..df361253 100644 --- a/R/esp_cache_clear.R +++ b/R/esp_cache_clear.R @@ -1,6 +1,5 @@ -#' Clear your **mapSpain** cache dir +#' Clear your \CRANpkg{mapSpain} cache dir #' -#' @name esp_clear_cache #' @family cache utilities #' #' @return Invisible. This function is called for its side effects. @@ -9,21 +8,21 @@ #' **Use this function with caution**. This function would clear your cached #' data and configuration, specifically: #' -#' * Deletes the **mapSpain** config directory +#' - Deletes the \CRANpkg{mapSpain} config directory #' (`rappdirs::user_config_dir("mapSpain", "R")`). -#' * Deletes the `cache_dir` directory. -#' * Deletes the values on stored on `Sys.getenv("MAPSPAIN_CACHE_DIR")` and +#' - Deletes the `cache_dir` directory. +#' - Deletes the values on stored on `Sys.getenv("MAPSPAIN_CACHE_DIR")` and #' `options(mapSpain_cache_dir)`. #' -#' @param config if `TRUE`, will delete the configuration folder of -#' **mapSpain**. -#' @param cached_data If this is set to `TRUE`, it will delete your -#' `cache_dir` and all its content. +#' @param config Logical. If `TRUE`, will delete the configuration folder of +#' \CRANpkg{mapSpain}. +#' @param cached_data Logical. If `TRUE`, it will delete your `cache_dir` and +#' all its content. #' @inheritParams esp_set_cache_dir #' #' @details #' This is an overkill function that is intended to reset your status -#' as it you would never have installed and/or used **mapSpain**. +#' as it you would never have installed and/or used \CRANpkg{mapSpain}. #' #' @examples #' @@ -34,27 +33,27 @@ #' #' Sys.getenv("MAPSPAIN_CACHE_DIR") #' @export -esp_clear_cache <- function(config = TRUE, - cached_data = TRUE, +esp_clear_cache <- function(config = FALSE, cached_data = TRUE, verbose = FALSE) { - # nocov start config_dir <- rappdirs::user_config_dir("mapSpain", "R") data_dir <- esp_hlp_detect_cache_dir() + + # nocov start if (config && dir.exists(config_dir)) { unlink(config_dir, recursive = TRUE, force = TRUE) + if (verbose) message("mapSpain cache config deleted") } + # nocov end if (cached_data && dir.exists(data_dir)) { unlink(data_dir, recursive = TRUE, force = TRUE) if (verbose) message("mapSpain cached data deleted: ", data_dir) } - Sys.setenv(MAPSPAIN_CACHE_DIR = "") options(mapSpain_cache_dir = NULL) # Reset cache dir return(invisible()) - # nocov end } diff --git a/R/esp_check_access.R b/R/esp_check_access.R new file mode 100644 index 00000000..d73a5e9f --- /dev/null +++ b/R/esp_check_access.R @@ -0,0 +1,69 @@ +#' Check access to SIANE data +#' +#' @family helper +#' +#' @description +#' Check if R has access to resources at +#' . +#' +#' @return a logical. +#' +#' @seealso [giscoR::gisco_check_access()] +#' +#' @examples +#' +#' esp_check_access() +#' @export +esp_check_access <- function() { + url <- paste0( + "https://github.com/rOpenSpain/mapSpain/raw/sianedata/", + "dist/se89_3_admin_ccaa_a_y.gpkg" + ) + + # nocov start + access <- + tryCatch( + download.file(url, destfile = tempfile(), quiet = TRUE), + warning = function(e) { + return(FALSE) + }, + error = function(e) { + return(FALSE) + } + ) + + if (isFALSE(access)) { + return(FALSE) + } else { + return(TRUE) + } + # nocov end +} + + +skip_if_siane_offline <- function() { + # nocov start + if (esp_check_access()) { + return(invisible(TRUE)) + } + + if (requireNamespace("testthat", quietly = TRUE)) { + testthat::skip("SIANE API not reachable") + } + return(invisible()) + # nocov end +} + + +skip_if_gisco_offline <- function() { + # nocov start + if (giscoR::gisco_check_access()) { + return(invisible(TRUE)) + } + + if (requireNamespace("testthat", quietly = TRUE)) { + testthat::skip("GISCO API not reachable") + } + return(invisible()) + # nocov end +} diff --git a/R/esp_dict.R b/R/esp_dict.R index 15d76b98..6933cd99 100644 --- a/R/esp_dict.R +++ b/R/esp_dict.R @@ -1,5 +1,6 @@ -#' Convert and translate Subdivision Names +#' Convert and translate subdivision names #' +#' @description #' Converts long subdivision names into different coding schemes and languages. #' #' @family dictionary @@ -15,8 +16,8 @@ #' #' @param sourcevar Vector which contains the subdivision names to be converted. #' -#' @param origin,destination One of `"text"`, `"nuts"`, `"iso2"`, -#' `"codauto"` and `"cpro"`. +#' @param origin,destination One of `"text"`, `"nuts"`, `"iso2"`, `"codauto"` +#' and `"cpro"`. #' #' @details #' If no match is found for any value, the function displays a warning and @@ -58,28 +59,35 @@ #' esp_dict_region_code(valsmix, destination = "iso2") #' } #' -esp_dict_region_code <- function(sourcevar, - origin = "text", +esp_dict_region_code <- function(sourcevar, origin = "text", destination = "text") { + # Manually replace + sourcevar <- gsub("Ciudad de ceuta", "Ceuta", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("Ciudad de melilla", "Melilla", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta. cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + initsourcevar <- sourcevar validvars <- c("text", "nuts", "iso2", "codauto", "cpro") if (!(origin %in% validvars)) { - stop( - "origin should be ", - paste0("'", validvars, "'", collapse = ", ") - ) + stop("origin should be ", paste0("'", validvars, "'", collapse = ", ")) } if (!(destination %in% validvars)) { - stop( - "destination should be ", - paste0("'", validvars, "'", collapse = ", ") - ) + stop("destination should be ", paste0("'", validvars, "'", collapse = ", ")) } - if (origin == destination & origin == "text") { + if (origin == destination && origin == "text") { message("No conversion - origin equal to destination") return(initsourcevar) } @@ -87,17 +95,14 @@ esp_dict_region_code <- function(sourcevar, # Create dict dict <- names_full - names_dict <- - unique(names_full[ - grep("name", dict$variable), - c("key", "value") - ]) + names_dict <- unique( + names_full[grep("name", dict$variable), c("key", "value")] + ) # If text convert to nuts if (origin == "text") { - sourcevar <- countrycode::countrycode( - tolower(sourcevar), + sourcevar <- countrycode::countrycode(tolower(sourcevar), origin = "value", destination = "key", custom_dict = names_dict, @@ -105,8 +110,7 @@ esp_dict_region_code <- function(sourcevar, ) # Translate to nuts - sourcevar <- countrycode::countrycode( - sourcevar, + sourcevar <- countrycode::countrycode(sourcevar, origin = "key", destination = "nuts", custom_dict = names2nuts, @@ -114,8 +118,7 @@ esp_dict_region_code <- function(sourcevar, ) # Replace NOMATCH - sourcevar[sourcevar == "NOMATCH"] <- - initsourcevar[sourcevar == "NOMATCH"] + sourcevar[sourcevar == "NOMATCH"] <- initsourcevar[sourcevar == "NOMATCH"] origin <- "nuts" # By name, perform some replacements @@ -139,27 +142,19 @@ esp_dict_region_code <- function(sourcevar, } } - - # Destination if (destination == "text") { - sourcevar <- - countrycode::countrycode(sourcevar, - origin, - "nuts", - custom_dict = code2code, - nomatch = "NOMATCH" - ) + sourcevar <- countrycode::countrycode(sourcevar, origin, "nuts", + custom_dict = code2code, + nomatch = "NOMATCH" + ) dict_nutsall <- sf::st_drop_geometry(mapSpain::esp_nuts.sf) - out <- - countrycode::countrycode(sourcevar, - "NUTS_ID", - "NUTS_NAME", - custom_dict = dict_nutsall, - nomatch = "NOMATCH" - ) + out <- countrycode::countrycode(sourcevar, "NUTS_ID", "NUTS_NAME", + custom_dict = dict_nutsall, + nomatch = "NOMATCH" + ) } else { # Solve problems if (origin == "nuts") { @@ -178,22 +173,16 @@ esp_dict_region_code <- function(sourcevar, sourcevar[sourcevar == "ES630"] <- "ES63" } - - - out <- - countrycode::countrycode(sourcevar, - origin, - destination, - custom_dict = code2code, - nomatch = "NOMATCH" - ) + out <- countrycode::countrycode(sourcevar, origin, destination, + custom_dict = code2code, nomatch = "NOMATCH" + ) # Baleares if (destination == "cpro") { out[sourcevar == "ES530"] <- "07" } # Ceuta - if (origin == "iso2" & destination == "codauto") { + if (origin == "iso2" && destination == "codauto") { out[sourcevar == "ES-CE"] <- "18" out[sourcevar == "ES-ML"] <- "19" } @@ -203,15 +192,12 @@ esp_dict_region_code <- function(sourcevar, # Sanitize if (length(out[!(out == "NOMATCH")]) != length(sourcevar)) { warning( - "No match on ", - destination, - " found for ", + "No match on ", destination, " found for ", paste0(initsourcevar[out == "NOMATCH"], collapse = ", ") ) } out[out == "NOMATCH"] <- NA - return(out) } @@ -221,28 +207,27 @@ esp_dict_region_code <- function(sourcevar, #' #' @name esp_dict_translate #' -#' @return [esp_dict_translate()] returns a character vector or a named -#' list with each of the possible names of each `sourcevar` on the required -#' language `lang`. +#' @return +#' [esp_dict_translate()] returns a `character` vector or a named `list` with +#' each of the possible names of each `sourcevar` on the required language +#' `lang`. #' #' @export #' #' @param lang Language of translation. Available languages are: -#' * `"es"`: Spanish -#' * `"en"`: English -#' * `"ca"`: Catalan -#' * `"ga"`: Galician -#' * `"eu"`: Basque +#' - `"es"`: Spanish +#' - `"en"`: English +#' - `"ca"`: Catalan +#' - `"ga"`: Galician +#' - `"eu"`: Basque #' #' @param all Logical. Should the function return all names or not? #' On `FALSE` it returns a character vector. See **Value**. #' #' @examples #' -#' vals <- c( -#' "La Rioja", "Sevilla", "Madrid", -#' "Jaen", "Orense", "Baleares" -#' ) +#' vals <- c("La Rioja", "Sevilla", "Madrid", "Jaen", "Orense", "Baleares") +#' #' esp_dict_translate(vals) #' esp_dict_translate(vals, lang = "es") #' esp_dict_translate(vals, lang = "ca") @@ -250,80 +235,86 @@ esp_dict_region_code <- function(sourcevar, #' esp_dict_translate(vals, lang = "ga") #' #' esp_dict_translate(vals, lang = "ga", all = TRUE) -esp_dict_translate <- - function(sourcevar, - lang = "en", - all = FALSE) { - avlang <- c("es", "en", "ca", "ga", "eu") - if (!(lang %in% avlang)) { - stop("lang sould be one of ", paste0("'", avlang, - "'", - collapse = ", " - )) - } - - # Create dict - dict <- names_full - - # Arrange prelation for results: - # - First: prov (a_prov) - # - Second: ccaa (b_ccaa) - # - Last: nuts (c_nuts) - dict$variable <- gsub("prov", "a_prov", dict$variable) # Upgrade provs - dict$variable <- gsub("ccaa", "b_ccaa", dict$variable) # Upgrade nuts - dict$variable <- gsub("nuts", "c_nuts", dict$variable) # Upgrade nuts - - names_dict <- - unique(names_full[grep("name", dict$variable), c("key", "value")]) - - tokeys <- countrycode::countrycode( - sourcevar, - origin = "value", - destination = "key", - custom_dict = names_dict, - nomatch = "NOMATCH" +esp_dict_translate <- function(sourcevar, lang = "en", all = FALSE) { + avlang <- c("es", "en", "ca", "ga", "eu") + if (!(lang %in% avlang)) { + stop( + "lang sould be one of ", + paste0("'", avlang, "'", collapse = ", ") ) + } - # Create lang dict - dict_tolang <- - unique(dict[grep( - paste0("name.", lang), - dict$variable - ), ]) - - # Order using short - - shrt <- grep("short", dict_tolang$variable) - - dict_tolang[shrt, ]$variable <- - paste0("aa", dict_tolang[shrt, ]$variable) - - dict_tolang <- - unique(dict_tolang[order(dict_tolang$variable), c("key", "value")]) - - - namestrans <- - lapply(seq(1, length(tokeys)), function(x) { - dict_tolang[dict_tolang$key == tokeys[x], "value"] - }) - - namestrans[tokeys == "NOMATCH"] <- NA - - if (isTRUE(all)) { - names(namestrans) <- sourcevar - } + # Create dict + dict <- names_full - if (isFALSE(all)) { - namestrans <- - unlist(lapply(namestrans, `[[`, 1)) - } + # Arrange prelation for results: + # - First: prov (a_prov) + # - Second: ccaa (b_ccaa) + # - Last: nuts (c_nuts) + dict$variable <- gsub("prov", "a_prov", dict$variable) # Upgrade provs + dict$variable <- gsub("ccaa", "b_ccaa", dict$variable) # Upgrade nuts + dict$variable <- gsub("nuts", "c_nuts", dict$variable) # Upgrade nuts + + names_dict <- unique( + names_full[grep("name", dict$variable), c("key", "value")] + ) + + # Manually replace + sourcevar <- gsub("Ciudad de ceuta", "Ceuta", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("Ciudad de melilla", "Melilla", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta. cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + sourcevar <- gsub("sta cruz", "Santa Cruz", sourcevar, + ignore.case = TRUE + ) + + tokeys <- countrycode::countrycode(sourcevar, + origin = "value", + destination = "key", + custom_dict = names_dict, + nomatch = "NOMATCH" + ) + + # Create lang dict + dict_tolang <- unique( + dict[grep(paste0("name.", lang), dict$variable), ] + ) + + # Order using short + shrt <- grep("short", dict_tolang$variable) + + dict_tolang[shrt, ]$variable <- paste0("aa", dict_tolang[shrt, ]$variable) + + dict_tolang <- unique( + dict_tolang[order(dict_tolang$variable), c("key", "value")] + ) + + + namestrans <- lapply(seq(1, length(tokeys)), function(x) { + dict_tolang[dict_tolang$key == tokeys[x], "value"] + }) + + namestrans[tokeys == "NOMATCH"] <- NA + + if (isTRUE(all)) { + names(namestrans) <- sourcevar + } - if (any(tokeys == "NOMATCH")) { - warning( - "No match found for ", - paste0(sourcevar[tokeys == "NOMATCH"], collapse = ", ") - ) - } + if (isFALSE(all)) { + namestrans <- unlist(lapply(namestrans, `[[`, 1)) + } - return(namestrans) + if (any(tokeys == "NOMATCH")) { + warning( + "No match found for ", + paste0(sourcevar[tokeys == "NOMATCH"], collapse = ", ") + ) } + + return(namestrans) +} diff --git a/R/esp_getTiles.R b/R/esp_getTiles.R index 5d84c591..da5c0ae4 100644 --- a/R/esp_getTiles.R +++ b/R/esp_getTiles.R @@ -1,4 +1,4 @@ -#' Get static tiles from public administrations of Spanish. +#' Get static tiles from public administrations of Spain #' #' @description #' Get static map tiles based on a spatial object. Maps can be fetched from @@ -6,28 +6,28 @@ #' #' This function is a implementation of the javascript plugin #' [leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/) -#' **v1.2.0**. +#' **`r leafletprovidersESP_v`**. #' #' @family imagery utilities -#' @seealso [raster::brick()]. +#' @seealso [terra::rast()]. #' #' @return -#' A `RasterBrick` is returned, with 3 (RGB) or 4 (RGBA) layers, depending on -#' the provider. See [raster::brick()]. +#' A `SpatRaster` is returned, with 3 (RGB) or 4 (RGBA) layers, depending on +#' the provider. See [terra::rast()]. #' . #' @source #' leaflet plugin, -#' **v1.2.0**. -#' -#' -#' -#' For plotting, you can use [raster::plotRGB()], [tmap::tm_rgb()]. +#' **`r leafletprovidersESP_v`**. #' #' @export #' -#' @param x An `sf` object. +#' @param x An [`sf`][sf::st_sf] or [`sfc`][sf::st_sfc] object. #' -#' @param type Name of the provider. See [leaflet.providersESP.df]. +#' @param type This parameter could be either: +#' - The name of one of the pre-defined providers +#' (see [esp_tiles_providers()]). +#' - A list with two named elements `id` and `q` with your own parameters. +#' See [esp_make_provider()] and examples. #' @param zoom Zoom level. If `NULL`, it is determined automatically. If set, #' it overrides `zoommin`. Only valid for WMTS tiles. On a single point it #' applies a buffer to the point and on `zoom = NULL` the function set a zoom @@ -36,14 +36,16 @@ #' download fewer tiles than you probably want. Use `1` or `2` to #' increase the resolution. #' @param crop `TRUE` if results should be cropped to the specified `x` extent, -#' `FALSE` otherwise. If `x` is an `sf` object with one `POINT`, crop is set -#' to `FALSE`. +#' `FALSE` otherwise. If `x` is an [`sf`][sf::st_sf] object with one `POINT`, +#' `crop` is set to `FALSE`. #' @param res Resolution (in pixels) of the final tile. Only valid for WMS. #' @param bbox_expand A numeric value that indicates the expansion percentage #' of the bounding box of `x`. #' @param transparent Logical. Provides transparent background, if supported. #' Depends on the selected provider on `type`. #' @param mask `TRUE` if the result should be masked to `x`. +#' @param options A named list containing additional options to pass to the +#' query. #' #' @inheritParams esp_get_nuts #' @@ -55,25 +57,32 @@ #' #' ```{r, echo=FALSE} #' -#' t <- tibble::tribble( -#' ~zoom, ~"area to represent", -#' 0, "whole world", -#' 3, "large country", -#' 5, "state", -#' 8, "county", -#' 10, "metropolitan area", -#' 11, "city", -#' 13, "village or suburb", -#' 16, "streets", -#' 18, "some buildings, trees" -#' ) #' -#' knitr::kable(t) +#' df <- data.frame( +#' zoom = c(0, 3, 5, 8, 10, 11, 13, 16, 18), +#' represents = c( +#' "whole world", +#' "large country", +#' "state", +#' "county", +#' "metropolitan area", +#' "city", +#' "village or suburb", +#' "streets", +#' "some buildings, trees" +#' ) +#' ) +#' +#' +#' knitr::kable(df, +#' col.names = c("zoom", +#' "area to represent") +#' ) #' #' #' ``` #' -#' For a complete list of providers see [leaflet.providersESP.df]. +#' For a complete list of providers see [esp_tiles_providers]. #' #' #' Most WMS/WMTS providers provide tiles on "EPSG:3857". In case that the tile @@ -81,57 +90,86 @@ #' #' `x <- sf::st_transform(x, 3857)` #' +#' #' @examples #' \dontrun{ #' # This script downloads tiles to your local machine #' # Run only if you are online #' -#' Murcia <- esp_get_ccaa_siane("Murcia", epsg = 3857) -#' Tile <- esp_getTiles(Murcia) +#' segovia <- esp_get_prov_siane("segovia", epsg = 3857) +#' tile <- esp_getTiles(segovia, "IGNBase.Todo") +#' +#' library(ggplot2) +#' library(tidyterra) +#' +#' ggplot(segovia) + +#' geom_spatraster_rgb(data = tile, maxcell = Inf) + +#' geom_sf(fill = NA) +#' +#' # Another provider +#' +#' tile2 <- esp_getTiles(segovia, type = "MDT") +#' +#' ggplot(segovia) + +#' geom_spatraster_rgb(data = tile2, maxcell = Inf) + +#' geom_sf(fill = NA) +#' +#' # A custom WMS provided +#' +#' custom_wms <- esp_make_provider( +#' id = "an_id_for_caching", +#' q = "https://idecyl.jcyl.es/geoserver/ge/wms?", +#' service = "WMS", +#' version = "1.3.0", +#' format = "image/png", +#' layers = "geolog_cyl_litologia" +#' ) +#' +#' custom_wms_tile <- esp_getTiles(segovia, custom_wms) +#' +#' autoplot(custom_wms_tile, maxcell = Inf) + +#' geom_sf(data = segovia, fill = NA, color = "red") #' -#' library(tmap) +#' # A custom WMTS provider #' -#' tm_shape(Tile, raster.downsample = FALSE) + -#' tm_rgb(interpolate = FALSE) + -#' tm_shape(Murcia) + -#' tm_borders() +#' custom_wmts <- esp_make_provider( +#' id = "cyl_wmts", +#' q = "https://www.ign.es/wmts/pnoa-ma?", +#' service = "WMTS", +#' layer = "OI.OrthoimageCoverage" +#' ) +#' +#' custom_wmts_tile <- esp_getTiles(segovia, custom_wmts) +#' +#' autoplot(custom_wmts_tile, maxcell = Inf) + +#' geom_sf(data = segovia, fill = NA, color = "white", linewidth = 2) +#' +#' # Example from https://leaflet-extras.github.io/leaflet-providers/preview/ +#' cartodb_voyager <- list( +#' id = "CartoDB_Voyager", +#' q = "https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png" +#' ) +#' cartodb <- esp_getTiles(segovia, cartodb_voyager, zoommin = 1) +#' +#' autoplot(cartodb, maxcell = Inf) + +#' geom_sf(data = segovia, fill = NA, color = "black", linewidth = 1) #' } -esp_getTiles <- function(x, - type = "IDErioja", - zoom = NULL, - zoommin = 0, - crop = TRUE, - res = 512, - bbox_expand = 0.05, - transparent = TRUE, - mask = FALSE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE) { - # nocov start - if (isFALSE(requireNamespace("rgdal", quietly = TRUE))) { - stop("`rgdal` package required for esp_getTiles()") - } - +esp_getTiles <- function(x, type = "IDErioja", zoom = NULL, zoommin = 0, + crop = TRUE, res = 512, bbox_expand = 0.05, + transparent = TRUE, mask = FALSE, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE, options = NULL) { + # Only sf and sfc objects allowed - # Disable warnings related with crs - oldw <- getOption("warn") - options(warn = -1) + if (!inherits(x, "sf") && !inherits(x, "sfc")) { + stop("Only sf and sfc objects allowed") + } - # A. Check providers - leafletProvidersESP <- mapSpain::leaflet.providersESP.df - provs <- - leafletProvidersESP[leafletProvidersESP$provider == type, ] - - if (nrow(provs) == 0) { - stop( - "No match for type = '", - type, - "' found. Available providers are:\n\n", - paste0("'", unique(leafletProvidersESP$provider), "'", collapse = ", ") - ) + # If sfc convert to sf + if (inherits(x, "sfc")) { + x <- sf::st_as_sf(data.frame(x = 1), x) } + # Some transformations res <- as.numeric(res) @@ -139,99 +177,274 @@ esp_getTiles <- function(x, xinit <- x x <- sf::st_geometry(x) - # Transform to 3857 as it is native for tiles - x <- sf::st_transform(x, 3857) + # A. Check providers + if (is.list(type)) { + # Custom query - # Buffer if single point - if (length(x) & "POINT" %in% sf::st_geometry_type(x)) { - x <- sf::st_buffer(sf::st_geometry(x), 50) - crop <- FALSE - # Auto zoom = 18 if not set - if (is.null(zoom)) { - zoom <- 18 - if (verbose) message("Auto zoom on point set to 18") + url_pieces <- type$q + type <- type$id + + if (any(is.null(url_pieces), is.null(type))) { + stop( + "Custom provider should be a named list with an 'id' ", + "and a 'q' field" + ) + } + + url_pieces <- esp_hlp_split_url(url_pieces) + extra_opts <- NULL + } else { + provs <- mapSpain::esp_tiles_providers + + if (!type %in% names(provs)) { + stop( + "No match for type = '", + type, + "' found. Check providers available in mapSpain::esp_tiles_providers" + ) } - } + # Split url + url_pieces <- provs[[type]]$static + # And get extra optios + extra_opts <- provs[[type]]$leaflet + + names(url_pieces) <- tolower(names(url_pieces)) + names(extra_opts) <- tolower(names(extra_opts)) + } # Create cache dir cache_dir <- esp_hlp_cachedir(cache_dir) cache_dir <- esp_hlp_cachedir(paste0(cache_dir, "/", type)) - if (provs[provs$field == "type", "value"] == "WMS") { - rout <- - getwms( - x, - provs, - update_cache, - cache_dir, - verbose, - res, - transparent, - bbox_expand - ) + # Attribution + attr <- url_pieces$attribution + + url_pieces <- modifyList(url_pieces, list(attribution = NULL)) + + # Get type of service + if (is.null(url_pieces$service)) { + # On null we assume WMTS, case of non INSPIRE serves OSM) + typeprov <- "WMTS" } else { - rout <- - getwmts( - x, - provs, - update_cache, - cache_dir, - verbose, - res, - zoom, - zoommin, - type, - transparent - ) + typeprov <- toupper(url_pieces$service) + } + # Add options + if (is.list(options)) { + names(options) <- tolower(names(options)) + + if (typeprov == "WMS" && "version" %in% names(options)) { + # Exception: need to change names depending on the version of WMS + + v_wms <- unlist(modifyList( + list(v = url_pieces$version), + list(v = options$version) + )) + + + # Assess version + v_wms <- unlist(strsplit(v_wms, ".", fixed = TRUE)) + + + if (v_wms[1] >= "1" && v_wms[2] >= "3") { + names(url_pieces) <- gsub("srs", "crs", names(url_pieces)) + } else { + names(url_pieces) <- gsub("crs", "srs", names(url_pieces)) + } + } + + # Ignore TileMatrix fields in WMTS + if (typeprov == "WMTS") { + ig <- !grepl("tilematrix", names(options), ignore.case = TRUE) + options <- options[ig] + } + + url_pieces <- modifyList(url_pieces, options) + # Create new cache dir + + # Modify cache dir + newdir <- paste0(names(options), "=", options, collapse = "&") + newdir <- esp_get_md5(newdir) + + cache_dir <- file.path(cache_dir, newdir) + cache_dir <- esp_hlp_cachedir(cache_dir) + } + + # Get CRS of Tile + crs <- unlist( + url_pieces[names(url_pieces) %in% c("crs", "srs", "tilematrixset")] + ) + # Caso some WMTS + if (is.null(crs)) crs <- "epsg:3857" + + if (tolower(crs) == tolower("GoogleMapsCompatible")) crs <- "epsg:3857" + + crs_sf <- sf::st_crs(crs) + + + # Transform to crs of tile + + x <- sf::st_transform(x, crs_sf) + + # Buffer if single point + if (length(x) == 1 && "POINT" %in% sf::st_geometry_type(x)) { + xmod <- sf::st_transform(sf::st_geometry(x), 3857) + xmod <- sf::st_buffer(xmod, 50) + x <- sf::st_transform(xmod, sf::st_crs(x)) + crop <- FALSE + # Auto zoom = 15 if not set + if (is.null(zoom)) { + zoom <- 15 + if (verbose) message("Auto zoom on point set to 15") + } + } + + newbbox <- esp_hlp_get_bbox(x, bbox_expand, typeprov) + + if (typeprov == "WMS") { + rout <- getwms( + newbbox, url_pieces, update_cache, cache_dir, verbose, + res, transparent + ) + } else { + rout <- getwmts( + newbbox, type, url_pieces, update_cache, cache_dir, verbose, + zoom, zoommin, transparent, extra_opts + ) } # Regenerate # Display attributions - if (verbose) { - message( - "\nData and map tiles sources:\n", - provs[provs$field == "attribution_static", "value"] - ) + if (verbose && !is.null(attr)) { + message("\nData and map tiles sources:\n", attr) } x <- xinit + x_terra <- terra::vect(x) - # reproject rout + # reproject rout if needed + if (!sf::st_crs(x) == sf::st_crs(rout)) { + # Sometimes it gets an error - rout <- - raster::projectRaster(from = rout, crs = sf::st_crs(x)$proj4string) + rout_end <- try(terra::project(rout, terra::crs(x_terra)), silent = TRUE) - rout <- raster::clamp(rout, - lower = 0, - upper = 255, - useValues = TRUE - ) + if (inherits(rout_end, "try-error")) { + if (verbose) message("Tile not reprojected.") + rout <- rout + } else { + rout <- rout_end + } + } + + rout <- terra::clamp(rout, lower = 0, upper = 255, values = TRUE) # crop management if (crop == TRUE) { - cb <- sf::st_bbox(x) + newbbox <- sf::st_transform(newbbox, sf::st_crs(x)) + cb <- sf::st_bbox(newbbox) - k <- - min(c(bbox_expand * (cb[4] - cb[2]), bbox_expand * (cb[3] - cb[1]))) - cb <- cb + c(-k, -k, k, k) - rout <- raster::crop(rout, cb[c(1, 3, 2, 4)]) + rout <- terra::crop(rout, cb[c(1, 3, 2, 4)]) } # Mask - if (mask & class(x)[1] != "RasterBrick") { - rout <- raster::mask(rout, x) + if (mask) { + rout <- terra::mask(rout, x_terra) + } + + # Manage transparency + + if (!transparent && terra::nlyr(rout) == 4) { + rout <- terra::subset(rout, 1:3) + } + + # Manage RGB + if (isFALSE(terra::has.RGB(rout))) { + terra::RGB(rout) <- seq_len(terra::nlyr(rout)) } - # Restore warnings - options(warn = oldw) - on.exit(options(warn = oldw)) # Result return(rout) - # nocov end +} + +#' Helper to get bboxes +#' @noRd +esp_hlp_get_bbox <- function(x, bbox_expand = 0.05, typeprov = "WMS") { + bbox <- as.double(sf::st_bbox(x)) + dimx <- (bbox[3] - bbox[1]) + dimy <- (bbox[4] - bbox[2]) + center <- c(bbox[1] + dimx / 2, bbox[2] + dimy / 2) + + bbox_expand <- 1 + bbox_expand + + + if (typeprov == "WMS") { + maxdist <- max(dimx, dimy) + dimy <- maxdist + dimx <- dimy + } + + newbbox <- c( + center[1] - bbox_expand * dimx / 2, + center[2] - bbox_expand * dimy / 2, + center[1] + bbox_expand * dimx / 2, + center[2] + bbox_expand * dimy / 2 + ) + + class(newbbox) <- "bbox" + + newbbox <- sf::st_as_sfc(newbbox) + + sf::st_crs(newbbox) <- sf::st_crs(x) + + return(newbbox) +} + +# Helper to split urls +esp_hlp_split_url <- function(url_static) { + split <- unlist(strsplit(url_static, "?", fixed = TRUE)) + + if (length(split) == 1) { + return(list(q = split)) + } + + urlsplit <- list() + urlsplit$q <- paste0(split[1], "?") + + opts <- unlist(strsplit(split[2], "&")) + + names_opts <- vapply(opts, function(x) { + n <- strsplit(x, "=", fixed = TRUE) + return(unlist(n)[1]) + }, FUN.VALUE = character(1)) + + values_opts <- vapply(opts, function(x) { + n <- strsplit(x, "=", fixed = TRUE) + + unl <- unlist(n) + if (length(unl) == 2) { + return(unl[2]) + } + return("") + }, FUN.VALUE = character(1)) + + + names(values_opts) <- tolower(names_opts) + + urlsplit <- modifyList(urlsplit, as.list(values_opts)) + + return(urlsplit) +} + +esp_get_md5 <- function(x) { + tmp <- tempfile(fileext = ".txt") + writeLines(x, tmp) + + md5 <- unname(tools::md5sum(tmp)) + + return(md5) } diff --git a/R/esp_get_can_box.R b/R/esp_get_can_box.R index 7d5594ef..a7e5402b 100644 --- a/R/esp_get_can_box.R +++ b/R/esp_get_can_box.R @@ -1,4 +1,4 @@ -#' Get `sf` lines and polygons for insetting the Canary Islands +#' Get [`sf`][sf::st_sf] lines and polygons for insetting the Canary Islands #' #' @description #' When plotting Spain, it is usual to represent the Canary Islands as an inset @@ -6,17 +6,18 @@ #' lines and polygons to be used when the Canary Islands are displayed #' as an inset. #' -#' * [esp_get_can_box()] is used to draw lines around the displaced Canary +#' - [esp_get_can_box()] is used to draw lines around the displaced Canary #' Islands. #' #' @family political +#' @family Canary Islands #' #' @rdname esp_get_can_box #' #' @name esp_get_can_box #' -#' @return A `sf` polygon or line depending of `style` parameter. -#' +#' @return A [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` depending of `style` +#' parameter. #' #' @export #' @@ -34,31 +35,31 @@ #' Line <- esp_get_can_provinces() #' #' # Plot +#' library(ggplot2) #' -#' library(tmap) -#' -#' -#' tm_shape(Provs) + -#' tm_polygons() + -#' tm_shape(Box) + -#' tm_lines() + -#' tm_shape(Line) + -#' tm_lines() +#' ggplot(Provs) + +#' geom_sf() + +#' geom_sf(data = Box) + +#' geom_sf(data = Line) + +#' theme_linedraw() #' \donttest{ #' # Displacing Canary #' -#' Provs_D <- esp_get_prov(moveCAN = c(15, 0)) +#' # By same factor +#' +#' displace <- c(15, 0) #' -#' Box_D <- esp_get_can_box(style = "left", moveCAN = c(15, 0)) +#' Provs_D <- esp_get_prov(moveCAN = displace) #' -#' Line_D <- esp_get_can_provinces(moveCAN = c(15, 0)) +#' Box_D <- esp_get_can_box(style = "left", moveCAN = displace) #' -#' tm_shape(Provs_D) + -#' tm_polygons() + -#' tm_shape(Box_D) + -#' tm_lines() + -#' tm_shape(Line_D) + -#' tm_lines() +#' Line_D <- esp_get_can_provinces(moveCAN = displace) +#' +#' ggplot(Provs_D) + +#' geom_sf() + +#' geom_sf(data = Box_D) + +#' geom_sf(data = Line_D) + +#' theme_linedraw() #' #' #' # Example with poly option @@ -91,42 +92,36 @@ #' #' # Plot #' -#' tm_shape(Countries, bbox = c(-10, 34.6, 4.3, 44)) + -#' tm_polygons(col = "#DFDFDF") + -#' tm_shape(CANbox) + -#' tm_polygons(col = "#C7E7FB") + -#' tm_shape(CANbox) + -#' tm_borders(lwd = 2) + -#' tm_shape(CCAA) + -#' tm_polygons("#FDFBEA") + -#' tm_graticules(lines = FALSE) + -#' tm_layout( -#' bg.color = "#C7E7FB", -#' frame.double.line = TRUE +#' ggplot(Countries) + +#' geom_sf(fill = "#DFDFDF") + +#' geom_sf(data = CANbox, fill = "#C7E7FB", linewidth = 1) + +#' geom_sf(data = CCAA, fill = "#FDFBEA") + +#' coord_sf( +#' xlim = c(-10, 4.3), +#' ylim = c(34.6, 44) +#' ) + +#' theme( +#' panel.background = element_rect(fill = "#C7E7FB"), +#' panel.grid = element_blank() #' ) #' } -esp_get_can_box <- function(style = "right", - moveCAN = TRUE, - epsg = "4258") { +esp_get_can_box <- function(style = "right", moveCAN = TRUE, epsg = "4258") { # checks if (!style %in% c("left", "right", "box", "poly")) { stop("style should be one of 'right','left','box'") } - epsg <- as.character(epsg) if (!epsg %in% c("4258", "4326", "3035", "3857")) { stop("epsg should be one of '4258','4326','3035', '3857'") } - can <- esp_get_ccaa("Canarias", epsg = "4326", moveCAN = FALSE) - bbox <- sf::st_bbox(can) - if (style == "box" | style == "poly") { + if (style == "box" || style == "poly") { bbox <- bbox + c(-0.5, -0.3, 0.5, 0.3) lall <- sf::st_as_sfc(bbox, crs = sf::st_crs(can)) @@ -162,20 +157,7 @@ esp_get_can_box <- function(style = "right", moving <- isTRUE(moveCAN) | length(moveCAN) > 1 if (moving) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - can <- sf::st_transform(lall, 3857) + offset - can <- sf::st_sfc(can, crs = 3857) - can <- sf::st_transform(can, sf::st_crs(lall)) - lall <- can + lall <- esp_move_can(lall, moveCAN = moveCAN) } # Transform @@ -189,8 +171,11 @@ esp_get_can_box <- function(style = "right", #' #' #' @description -#' * [esp_get_can_provinces()] is used to draw a separator line between the two -#' provinces of the Canary Islands. +#' - [esp_get_can_provinces()] is used to draw a separator line between the two +#' provinces of the Canary Islands. +#' +#' See also [esp_move_can()] to displace stand-alone objects on the Canary +#' Islands. #' #' @return `esp_get_can_provinces` returns a `LINESTRING` object. #' @@ -199,8 +184,7 @@ esp_get_can_box <- function(style = "right", #' `se89_mult_admin_provcan_l.shp` file. #' #' @export -esp_get_can_provinces <- function(moveCAN = TRUE, - epsg = "4258") { +esp_get_can_provinces <- function(moveCAN = TRUE, epsg = "4258") { epsg <- as.character(epsg) if (!epsg %in% c("4258", "4326", "3035", "3857")) { @@ -220,20 +204,7 @@ esp_get_can_provinces <- function(moveCAN = TRUE, moving <- isTRUE(moveCAN) | length(moveCAN) > 1 if (moving) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - can <- sf::st_transform(lall, 3857) + offset - can <- sf::st_sfc(can, crs = 3857) - can <- sf::st_transform(can, sf::st_crs(lall)) - lall <- can + lall <- esp_move_can(lall, moveCAN = moveCAN) } # Transform diff --git a/R/esp_get_capimun.R b/R/esp_get_capimun.R index a83a8d5d..2951ac60 100644 --- a/R/esp_get_capimun.R +++ b/R/esp_get_capimun.R @@ -1,7 +1,7 @@ -#' Get `sf` points of the municipalities of Spain +#' Get [`sf`][sf::st_sf] `POINT` of the municipalities of Spain #' #' @description -#' Get a `sf` point with the location of the political powers for +#' Get a [`sf`][sf::st_sf] `POINT` with the location of the political powers for #' each municipality (possibly the center of the municipality). #' #' Note that this differs of the centroid of the boundaries of the @@ -10,7 +10,7 @@ #' @family political #' @family municipalities #' -#' @return A `sf` point object. +#' @return A [`sf`][sf::st_sf] `POINT` object. #' #' @source IGN data via a custom CDN (see #' ). @@ -28,16 +28,16 @@ #' @inheritSection esp_get_nuts Displacing the Canary Islands #' #' @details -#' `year` could be passed as a single year ("YYYY" format, as end of year) or -#' as a specific date ("YYYY-MM-DD" format). Historical information starts as +#' `year` could be passed as a single year (`YYYY` format, as end of year) or +#' as a specific date (`YYYY-MM-DD` format). Historical information starts as #' of 2005. #' #' When using `region` you can use and mix names and NUTS codes (levels 1, -#' 2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro". See +#' 2 or 3), ISO codes (corresponding to level 2 or 3) or `cpro`. See #' [esp_codelist] #' -#' When calling a superior level (Province, Autonomous Community or NUTS1) , -#' all the municipalities of that level would be added. +#' When calling a higher level (province, CCAA or NUTS1), all the municipalities +#' of that level would be added. #' #' @export #' @@ -63,7 +63,7 @@ #' capimun$type <- "Capimun" #' #' # Get a tile to check -#' tile <- esp_getTiles(area, zoommin = 2) +#' tile <- esp_getTiles(area, "IGNBase.Todo", zoommin = 2) #' #' # Join both point geometries #' points <- rbind( @@ -71,32 +71,23 @@ #' capimun[, "type"] #' ) #' +#' #' # Check on plot -#' library(tmap) -#' -#' tm_shape(tile, raster.downsample = FALSE) + -#' tm_rgb() + -#' tm_shape(area) + -#' tm_borders(col = "grey40") + -#' tm_shape(points) + -#' tm_symbols(col = "type", alpha = 0.8, pal = "RdBu") + -#' tm_layout( -#' main.title = "Centroid vs. capimun", -#' legend.outside = TRUE, -#' legend.outside.size = 0.3, -#' legend.text.size = 1 -#' ) +#' library(ggplot2) +#' library(tidyterra) +#' +#' ggplot(points) + +#' geom_spatraster_rgb(data = tile, maxcell = Inf) + +#' geom_sf(data = area, fill = NA, color = "blue") + +#' geom_sf(data = points, aes(fill = type), size = 5, shape = 21) + +#' scale_fill_manual(values = c("green", "red")) + +#' theme_void() + +#' labs(title = "Centroid vs. capimun") #' } -esp_get_capimun <- function(year = Sys.Date(), - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - region = NULL, - munic = NULL, - moveCAN = TRUE, - rawcols = FALSE) { +esp_get_capimun <- function(year = Sys.Date(), epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, region = NULL, munic = NULL, + moveCAN = TRUE, rawcols = FALSE) { init_epsg <- as.character(epsg) year <- as.character(year) @@ -106,13 +97,8 @@ esp_get_capimun <- function(year = Sys.Date(), # Get Data from SIANE data_sf <- esp_hlp_get_siane( - "capimun", - 3, - cache, - cache_dir, - update_cache, - verbose, - year + "capimun", 3, cache, cache_dir, + update_cache, verbose, year ) colnames_init <- colnames(sf::st_drop_geometry(data_sf)) @@ -129,25 +115,20 @@ esp_get_capimun <- function(year = Sys.Date(), NA ) - cod <- - unique(mapSpain::esp_codelist[, c( - "codauto", - "ine.ccaa.name", - "cpro", "ine.prov.name" - )]) - - df2 <- merge(df, - cod, - by = "cpro", - all.x = TRUE, - no.dups = TRUE + cod <- unique( + mapSpain::esp_codelist[ + , + c("codauto", "ine.ccaa.name", "cpro", "ine.prov.name") + ] ) + df2 <- merge(df, cod, by = "cpro", all.x = TRUE, no.dups = TRUE) + data_sf <- df2 if (!is.null(munic)) { munic <- paste(munic, collapse = "|") - data_sf <- data_sf[grep(munic, data_sf$name), ] + data_sf <- data_sf[grep(munic, data_sf$name, ignore.case = TRUE), ] } if (!is.null(region)) { @@ -160,10 +141,7 @@ esp_get_capimun <- function(year = Sys.Date(), } if (nrow(data_sf) == 0) { - stop( - "The combination of region and/or munic does ", - "not return any result" - ) + stop("The combination of region and/or munic does not return any result") } # Move CAN @@ -173,26 +151,10 @@ esp_get_capimun <- function(year = Sys.Date(), if (moving) { if (length(grep("05", data_sf$codauto)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) penin <- data_sf[-grep("05", data_sf$codauto), ] can <- data_sf[grep("05", data_sf$codauto), ] - # Move CAN - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) + can <- esp_move_can(can, moveCAN = moveCAN) # Regenerate if (nrow(penin) > 0) { @@ -204,19 +166,13 @@ esp_get_capimun <- function(year = Sys.Date(), } data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) - data_sf <- - data_sf[order(data_sf$codauto, data_sf$cpro, data_sf$cmun), ] + data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro, data_sf$cmun), ] namesend <- unique(c( colnames_init, c( - "codauto", - "ine.ccaa.name", - "cpro", - "ine.prov.name", - "cmun", - "name", - "LAU_CODE" + "codauto", "ine.ccaa.name", "cpro", "ine.prov.name", + "cmun", "name", "LAU_CODE" ), colnames(data_sf) )) @@ -225,13 +181,8 @@ esp_get_capimun <- function(year = Sys.Date(), if (isFALSE(rawcols)) { data_sf <- data_sf[, c( - "codauto", - "ine.ccaa.name", - "cpro", - "ine.prov.name", - "cmun", - "name", - "LAU_CODE" + "codauto", "ine.ccaa.name", "cpro", + "ine.prov.name", "cmun", "name", "LAU_CODE" )] } return(data_sf) diff --git a/R/esp_get_ccaa.R b/R/esp_get_ccaa.R index d7da2d93..89d10593 100644 --- a/R/esp_get_ccaa.R +++ b/R/esp_get_ccaa.R @@ -1,11 +1,12 @@ -#' Get Autonomous Communities of Spain as `sf` polygons and points +#' Get Autonomous Communities of Spain as [`sf`][sf::st_sf] `POLYGON` or `POINT` #' #' @description #' Returns -#' [Autonomous Communities of Spain](https://en.wikipedia.org/wiki/Autonomous_communities_of_Spain) -#' as polygons and points at a specified scale. +#' [Autonomous Communities of +#' Spain](https://en.wikipedia.org/wiki/Autonomous_communities_of_Spain) as +#' `sf` `POLYGON` or `POINT` at a specified scale. #' -#' * [esp_get_ccaa()] uses GISCO (Eurostat) as source. Please use +#' - [esp_get_ccaa()] uses GISCO (Eurostat) as source. Please use #' [giscoR::gisco_attributions()] #' #' @family political @@ -14,7 +15,7 @@ #' #' @name esp_get_ccaa #' -#' @return A `sf` object specified by `spatialtype`. +#' @return A [`sf`][sf::st_sf] object specified by `spatialtype`. #' #' #' @export @@ -26,7 +27,7 @@ #' #' @details #' When using `ccaa` you can use and mix names and NUTS codes (levels 1 or 2), -#' ISO codes (corresponding to level 2) or "codauto" (see [esp_codelist]). +#' ISO codes (corresponding to level 2) or `codauto` (see [esp_codelist]). #' Ceuta and Melilla are considered as Autonomous Communities on this function. #' #' When calling a NUTS1 level, all the Autonomous Communities of that level @@ -39,9 +40,10 @@ #' @examples #' ccaa <- esp_get_ccaa() #' -#' library(tmap) +#' library(ggplot2) #' -#' qtm(ccaa) +#' ggplot(ccaa) + +#' geom_sf() #' #' # Random CCAA #' Random <- esp_get_ccaa(ccaa = c( @@ -54,21 +56,17 @@ #' )) #' #' -#' tm_shape(Random) + -#' tm_polygons(col = "codauto", legend.show = FALSE) + -#' tm_shape(Random, point.per = "feature") + -#' tm_text("codauto", -#' auto.placement = TRUE, -#' shadow = TRUE -#' ) -#' +#' ggplot(Random) + +#' geom_sf(aes(fill = codauto), show.legend = FALSE) + +#' geom_sf_label(aes(label = codauto), alpha = 0.3) #' #' # All CCAA of a Zone plus an addition #' #' Mix <- #' esp_get_ccaa(ccaa = c("La Rioja", "Noroeste")) #' -#' qtm(Mix) +#' ggplot(Mix) + +#' geom_sf() #' #' # Combine with giscoR to get countries #' \donttest{ @@ -85,14 +83,16 @@ #' europe <- st_transform(europe, 3035) #' ccaa <- st_transform(ccaa, 3035) #' -#' tm_shape(europe, bbox = c(23, 14, 74, 55) * 10e4) + -#' tm_graticules() + -#' tm_polygons("#DFDFDF", border.col = "#656565") + -#' tm_shape(ccaa) + -#' tm_polygons("#FDFBEA", border.col = "#656565") + -#' tm_layout(bg.color = "#C7E7FB") +#' ggplot(europe) + +#' geom_sf(fill = "#DFDFDF", color = "#656565") + +#' geom_sf(data = ccaa, fill = "#FDFBEA", color = "#656565") + +#' coord_sf( +#' xlim = c(23, 74) * 10e4, +#' ylim = c(14, 55) * 10e4 +#' ) + +#' theme(panel.background = element_rect(fill = "#C7E7FB")) #' } -esp_get_ccaa <- function(ccaa = NULL, ...) { +esp_get_ccaa <- function(ccaa = NULL, moveCAN = TRUE, ...) { params <- list(...) # Get region id @@ -107,17 +107,11 @@ esp_get_ccaa <- function(ccaa = NULL, ...) { nuts_id <- esp_hlp_all2ccaa(region) nuts_id <- unique(nuts_id) - if (length(nuts_id) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } } params$region <- nuts_id params$nuts_level <- 2 + params$moveCAN <- moveCAN data_sf <- do.call(mapSpain::esp_get_nuts, params) @@ -135,8 +129,7 @@ esp_get_ccaa <- function(ccaa = NULL, ...) { # Paste nuts1 dfnuts <- mapSpain::esp_codelist - dfnuts <- - unique(dfnuts[, c("nuts2.code", "nuts1.code", "nuts1.name")]) + dfnuts <- unique(dfnuts[, c("nuts2.code", "nuts1.code", "nuts1.name")]) data_sf <- merge(data_sf, dfnuts, all.x = TRUE) @@ -154,7 +147,7 @@ esp_get_ccaa <- function(ccaa = NULL, ...) { #' @name esp_get_ccaa_siane #' #' @description -#' * [esp_get_ccaa_siane()] uses CartoBase ANE as source, provided by +#' - [esp_get_ccaa_siane()] uses CartoBase ANE as source, provided by #' Instituto Geografico Nacional (IGN), . #' Years available are 2005 up to today. #' @@ -165,30 +158,24 @@ esp_get_ccaa <- function(ccaa = NULL, ...) { #' @export #' #' @param year Release year. See [esp_get_nuts()] for [esp_get_ccaa()] and -#' **Details** for [esp_get_ccaa_siane()] +#' **Details** for [esp_get_ccaa_siane()]. #' -#' @param resolution Resolution of the polygon. Values available are -#' "3", "6.5" or "10". +#' @param resolution Resolution of the `POLYGON`. Values available are +#' `3`, `6.5` or `10`. #' #' @param rawcols Logical. Setting this to `TRUE` would add the raw columns of -#' the dataset provided by IGN. +#' the resulting object as provided by IGN. #' #' @inheritParams esp_get_nuts #' #' @details -#' On [esp_get_ccaa_siane()], `year` could be passed as a single year ("YYYY" -#' format, as end of year) or as a specific date ("YYYY-MM-DD" format). +#' On [esp_get_ccaa_siane()], `year` could be passed as a single year (`YYYY` +#' format, as end of year) or as a specific date (`YYYY-MM-DD` format). #' Historical information starts as of 2005. - -esp_get_ccaa_siane <- function(ccaa = NULL, - year = Sys.Date(), - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = "3", - moveCAN = TRUE, +esp_get_ccaa_siane <- function(ccaa = NULL, year = Sys.Date(), epsg = "4258", + cache = TRUE, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE, + resolution = "3", moveCAN = TRUE, rawcols = FALSE) { init_epsg <- as.character(epsg) year <- as.character(year) @@ -200,26 +187,19 @@ esp_get_ccaa_siane <- function(ccaa = NULL, # Get Data from SIANE data_sf <- esp_hlp_get_siane( - "ccaa", - resolution, - cache, - cache_dir, - update_cache, - verbose, - year + "ccaa", resolution, cache, cache_dir, + update_cache, verbose, year ) initcols <- colnames(sf::st_drop_geometry(data_sf)) # Add codauto - data_sf$lab <- data_sf$nombres_f + data_sf$lab <- data_sf$rotulo data_sf$lab <- gsub("Ciudad de ", "", data_sf$lab, fixed = TRUE) data_sf$lab <- gsub("/Catalunya", "", data_sf$lab) data_sf$lab <- gsub("/Euskadi", "", data_sf$lab) - data_sf$codauto <- esp_dict_region_code(data_sf$lab, - destination = "codauto" - ) + data_sf$codauto <- esp_dict_region_code(data_sf$lab, destination = "codauto") # Filter CCAA @@ -229,13 +209,6 @@ esp_get_ccaa_siane <- function(ccaa = NULL, } else { nuts_id <- esp_hlp_all2ccaa(region) nuts_id <- unique(nuts_id) - if (length(nuts_id) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } # Get df df <- mapSpain::esp_codelist @@ -258,8 +231,7 @@ esp_get_ccaa_siane <- function(ccaa = NULL, # Paste nuts1 dfnuts <- mapSpain::esp_codelist - dfnuts <- - unique(dfnuts[, c("nuts2.code", "nuts1.code", "nuts1.name")]) + dfnuts <- unique(dfnuts[, c("nuts2.code", "nuts1.code", "nuts1.name")]) data_sf <- merge(data_sf, dfnuts, all.x = TRUE) # Move CAN @@ -270,26 +242,11 @@ esp_get_ccaa_siane <- function(ccaa = NULL, if (moving) { if (length(grep("05", data_sf$codauto)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) penin <- data_sf[-grep("05", data_sf$codauto), ] can <- data_sf[grep("05", data_sf$codauto), ] # Move CAN - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) + can <- esp_move_can(can, moveCAN = moveCAN) # Regenerate if (nrow(penin) > 0) { @@ -309,11 +266,15 @@ esp_get_ccaa_siane <- function(ccaa = NULL, # Select columns if (rawcols) { - data_sf <- - data_sf[, unique(c(initcols, colnames(df), "nuts1.code", "nuts1.name"))] + data_sf <- data_sf[ + , + unique(c( + initcols, colnames(df), "nuts1.code", + "nuts1.name" + )) + ] } else { - data_sf <- - data_sf[, unique(c(colnames(df), "nuts1.code", "nuts1.name"))] + data_sf <- data_sf[, unique(c(colnames(df), "nuts1.code", "nuts1.name"))] } return(data_sf) diff --git a/R/esp_get_comarca.R b/R/esp_get_comarca.R new file mode 100644 index 00000000..8eb03a57 --- /dev/null +++ b/R/esp_get_comarca.R @@ -0,0 +1,188 @@ +#' Get 'comarcas' of Spain as [`sf`][sf::st_sf] `POLYGON` +#' +#' @description +#' Returns 'comarcas' of Spain as `sf` `POLYGON` objects. +#' +#' @source +#' INE: PC_Axis files, IGN, Ministry of Agriculture, Fisheries and Food (MAPA). +#' +#' @return A [`sf`][sf::st_sf] polygon object. +#' +#' @family political +#' +#' @param region A vector of names and/or codes for provinces or `NULL` to get +#' all the comarcas. See **Details**. +#' +#' @param comarca A name or [`regex`][base::grep()] expression with the names of +#' the required comarcas. `NULL` would return all the possible comarcas. +#' +#' @param type One of `"INE"`, `"IGN"`, `"AGR"`, `"LIV"`. Type of comarca to +#' return, see **Details**. +#' +#' @inheritParams esp_get_munic +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @inheritSection esp_get_nuts Displacing the Canary Islands +#' +#' @export +#' +#' @details +#' +#' ## About comarcas +#' 'Comarcas' (English equivalent: district, county, area or zone) does not +#' always have a formal legal status. They correspond mainly to natural areas +#' (valleys, river basins etc.) or even to historical regions or ancient +#' kingdoms. +#' +#' In the case of Spain, comarcas only have an administrative character legally +#' recognized in Catalonia, the Basque Country, Navarra (named merindades +#' instead), in the region of El Bierzo (Castilla y Leon) and Aragon. Galicia, +#' the Principality of Asturias, and Andalusia have functional comarcas. +#' +#' ## Types +#' +#' `esp_get_comarca()` can retrieve several types of comarcas, each one +#' provided under different classification criteria. +#' +#' - `"INE"`: Comarcas as defined by the National Statistics Institute (INE). +#' - `"IGN"`: Official comarcas, only available on some Autonomous Communities, +#' provided by the National Geographic Institute. +#' - `"AGR"`: Agrarian comarcas defined by the Ministry of Agriculture, +#' Fisheries and Food (MAPA). +#' +#' - `"LIV"`: Livestock comarcas defined by the Ministry of Agriculture, +#' Fisheries and Food (MAPA). +#' +#' ## Misc +#' +#' When using `region` you can use and mix names and NUTS codes +#' (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or +#' "cpro" (see [esp_codelist]). +#' +#' When calling a higher level (Province, Autonomous Community or NUTS1), +#' all the comarcas of that level would be added. +#' +#' ## Legal Notice +#' +#' The use of the information contained on the +#' [INE website](https://www.ine.es/en/index.htm) may be carried out by users or +#' re-use agents, at their own risk, and they will be the sole liable parties +#' in the case of having to answer to third parties due to damages arising +#' from such use. +#' +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' comarcas <- esp_get_comarca(moveCAN = FALSE) +#' +#' library(ggplot2) +#' +#' ggplot(comarcas) + +#' geom_sf() +#' +#' # IGN provides recognized comarcas +#' +#' rec <- esp_get_comarca(type = "IGN") +#' +#' ggplot(rec) + +#' geom_sf(aes(fill = t_comarca)) +#' +#' # Legal Comarcas of Catalunya +#' +#' comarcas_cat <- esp_get_comarca("Catalunya", type = "IGN") +#' +#' ggplot(comarcas_cat) + +#' geom_sf(aes(fill = ine.prov.name)) + +#' labs(fill = "Province") +#' } +#' +esp_get_comarca <- function(region = NULL, comarca = NULL, moveCAN = TRUE, + type = c("INE", "IGN", "AGR", "LIV"), + epsg = "4258", update_cache = FALSE, + cache_dir = NULL, verbose = FALSE) { + init_epsg <- as.character(epsg) + type <- match.arg(type) + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + # Url + api_entry <- switch(type, + "INE" = "https://github.com/rOpenSpain/mapSpain/raw/sianedata/INE/", + "IGN" = "https://github.com/rOpenSpain/mapSpain/raw/sianedata/IGNComarcas/", + "AGR" = "https://github.com/rOpenSpain/mapSpain/raw/sianedata/MITECO/dist/", + "LIV" = "https://github.com/rOpenSpain/mapSpain/raw/sianedata/MITECO/dist/", + ) + + + filename <- switch(type, + "INE" = "esp_com_99.gpkg", + "IGN" = "comarcas_ign.gpkg", + "AGR" = "comarcas_agrarias.gpkg", + "LIV" = "comarcas_ganaderas.gpkg" + ) + + + + data_sf <- esp_hlp_dwnload_sianedata( + api_entry = api_entry, + filename = filename, + cache_dir = cache_dir, + verbose = verbose, + update_cache = update_cache, + cache = TRUE + ) + + if (!is.null(comarca)) { + comarca <- paste(comarca, collapse = "|") + data_sf <- data_sf[grep(comarca, data_sf$name, ignore.case = TRUE), ] + } + + if (!is.null(region)) { + tonuts <- esp_hlp_all2prov(region) + + # toprov + df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) + df <- df[df$nuts3.code %in% tonuts, "cpro"] + toprov <- unique(df) + + data_sf <- data_sf[data_sf$cpro %in% toprov, ] + } + + if (nrow(data_sf) == 0) { + stop( + "The combination of region and/or comarca does ", + "not return any result" + ) + } + + # Move CAN + + # Checks + + moving <- FALSE + moving <- isTRUE(moveCAN) | length(moveCAN) > 1 + + + if (moving) { + if (length(grep("05", data_sf$codauto)) > 0) { + penin <- data_sf[-grep("05", data_sf$codauto), ] + can <- data_sf[grep("05", data_sf$codauto), ] + + # Move CAN + can <- esp_move_can(can, moveCAN = moveCAN) + + # Regenerate + if (nrow(penin) > 0) { + data_sf <- rbind(penin, can) + } else { + data_sf <- can + } + } + } + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) + + return(data_sf) +} diff --git a/R/esp_get_country.R b/R/esp_get_country.R index 91eefcf1..b55c296b 100644 --- a/R/esp_get_country.R +++ b/R/esp_get_country.R @@ -1,71 +1,81 @@ -#' Get the borders of Spain as a `sf` polygon -#' -#' @description -#' Returns the boundaries of Spain as a single `sf` polygon at a -#' specified scale. -#' -#' @family political -#' -#' @return A `sf` polygon object. -#' -#' -#' @export -#' -#' @inheritDotParams esp_get_nuts -nuts_level -region -spatialtype -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @inheritSection esp_get_nuts Displacing the Canary Islands -#' -#' @examples -#' -#' OriginalCan <- esp_get_country(moveCAN = FALSE) -#' -#' # One row only -#' -#' nrow(OriginalCan) -#' -#' library(tmap) -#' qtm(OriginalCan, fill = "grey70") -#' -#' # Less resolution -#' -#' MovedCan <- esp_get_country(moveCAN = TRUE, resolution = "20") -#' -#' qtm(MovedCan, fill = "grey70") -esp_get_country <- function(...) { - params <- list(...) - params$nuts_level <- 1 - params$region <- NULL - data_sf <- do.call(mapSpain::esp_get_nuts, params) - - # Extract geom column - names <- names(data_sf) - - which.geom <- - which(vapply(data_sf, function(f) { - inherits(f, "sfc") - }, TRUE)) - - nm <- names(which.geom) - - # Join all - init <- sf::st_crs(data_sf) - data_sf <- sf::st_transform(data_sf, 3035) - g <- sf::st_union(data_sf) - g <- sf::st_transform(g, init) - - - # Get df - df <- sf::st_drop_geometry(esp_get_nuts(nuts_level = 0)) - - # Generate sf object - data_sf <- sf::st_as_sf(df, g) - # Rename geometry to original value - newnames <- names(data_sf) - newnames[newnames == "g"] <- nm - colnames(data_sf) <- newnames - data_sf <- sf::st_set_geometry(data_sf, nm) - - return(data_sf) -} +#' Get [`sf`][sf::st_sf] `POLYGON` representing Spain +#' +#' @description +#' Returns the boundaries of Spain as a single [`sf`][sf::st_sf] `POLYGON` at a +#' specified scale. +#' +#' @family political +#' +#' @return A [`sf`][sf::st_sf] `POLYGON` object. +#' +#' +#' @export +#' +#' @inheritParams esp_get_nuts +#' @inheritDotParams esp_get_nuts -nuts_level -region -spatialtype +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @inheritSection esp_get_nuts Displacing the Canary Islands +#' +#' @examples +#' +#' OriginalCan <- esp_get_country(moveCAN = FALSE) +#' +#' # One row only +#' +#' nrow(OriginalCan) +#' +#' library(ggplot2) +#' +#' ggplot(OriginalCan) + +#' geom_sf(fill = "grey70") +#' +#' +#' # Less resolution +#' +#' MovedCan <- esp_get_country(moveCAN = TRUE, resolution = "20") +#' +#' library(ggplot2) +#' +#' ggplot(MovedCan) + +#' geom_sf(fill = "grey70") +esp_get_country <- function(moveCAN = TRUE, ...) { + params <- list(...) + params$nuts_level <- 1 + params$region <- NULL + params$moveCAN <- moveCAN + + data_sf <- do.call(mapSpain::esp_get_nuts, params) + + # Extract geom column + names <- names(data_sf) + + which_geom <- which( + vapply(data_sf, function(f) { + inherits(f, "sfc") + }, TRUE) + ) + + nm <- names(which_geom) + + # Join all + init <- sf::st_crs(data_sf) + data_sf <- sf::st_transform(data_sf, 3035) + g <- sf::st_union(data_sf) + g <- sf::st_transform(g, init) + + + # Get df + df <- sf::st_drop_geometry(esp_get_nuts(nuts_level = 0)) + + # Generate sf object + data_sf <- sf::st_as_sf(df, g) + # Rename geometry to original value + newnames <- names(data_sf) + newnames[newnames == "g"] <- nm + colnames(data_sf) <- newnames + data_sf <- sf::st_set_geometry(data_sf, nm) + + return(data_sf) +} diff --git a/R/esp_get_grid_BDN.R b/R/esp_get_grid_BDN.R new file mode 100644 index 00000000..fbdb1234 --- /dev/null +++ b/R/esp_get_grid_BDN.R @@ -0,0 +1,137 @@ +#' Get [`sf`][sf::st_sf] `POLYGON` with the national geographic grids from BDN +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `POLYGON` with the geographic grids of Spain as +#' provided on the Banco de Datos de la Naturaleza (Nature Data Bank), by the +#' Ministry of Environment (MITECO): +#' - [esp_get_grid_BDN()] extracts country-wide grids with resolutions +#' 5x5 or 10x10 kms. +#' - [esp_get_grid_BDN_ccaa()] extracts grids by Autonomous Community with +#' resolution 1x1 km. +#' +#' @family grids +#' +#' @return A [`sf`][sf::st_sf] `POLYGON`. +#' +#' +#' @source +#' BDN data via a custom CDN (see +#' ). +#' +#' See original metadata and source on +#' +#' +#' @export +#' +#' @param resolution Resolution of the grid in kms. Could be `5` or `10`. +#' @param type The scope of the grid. It could be mainland Spain (`"main"`) or +#' the Canary Islands (`"canary"`). +#' +#' @inheritParams esp_get_nuts +#' +#' @inheritSection esp_get_nuts About caching +#' @examplesIf esp_check_access() +#' \donttest{ +#' grid <- esp_get_grid_BDN(resolution = "10", type = "main") +#' +#' library(ggplot2) +#' +#' ggplot(grid) + +#' geom_sf() + +#' theme_light() + +#' labs(title = "BDN Grid for Spain") +#' } +esp_get_grid_BDN <- function(resolution = 10, type = "main", + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE) { + # Check grid + res <- as.numeric(resolution) + + if (!res %in% c(5, 10)) { + stop("resolution should be one of 5, 10") + } + + if (!type %in% c("main", "canary")) { + stop("type should be one of 'main', 'canary'") + } + + # Url + api_entry <- paste0( + "https://github.com/rOpenSpain/mapSpain/raw/", + "sianedata/MITECO/dist/" + ) + + # Filename + if (res == 10) { + filename <- switch(type, + "main" = "Malla10x10_Ter_p.gpkg", + "Malla10x10_Ter_c.gpkg" + ) + } else { + filename <- switch(type, + "main" = "Malla_5x5_tierra_p.gpkg", + "Malla_5x5_tierra_c.gpkg" + ) + } + result <- esp_hlp_dwnload_sianedata( + api_entry = api_entry, + filename = filename, + cache_dir = cache_dir, + verbose = verbose, + update_cache = update_cache, + cache = TRUE + ) + + return(result) +} + +#' @rdname esp_get_grid_BDN +#' @export +#' @param ccaa A vector of names and/or codes for autonomous communities. +#' See **Details** on [esp_get_ccaa()]. +#' @seealso [esp_get_ccaa()] + +esp_get_grid_BDN_ccaa <- function(ccaa, update_cache = FALSE, cache_dir = NULL, + verbose = FALSE) { + # Get region id + + ccaa <- ccaa[!is.na(ccaa)] + + region <- ccaa + if (is.null(region)) { + stop("ccaa can't be null") + } else { + nuts_id <- esp_hlp_all2ccaa(region) + + nuts_id <- unique(nuts_id) + } + + # Check if it is a valid NUTS, if not throws an error + + data <- mapSpain::esp_codelist + + if (!nuts_id %in% data$nuts2.code) stop(ccaa, " is not a CCAA") + + + # Switch name. The ids are the same than the NUTS code removing the "ES" part + id <- gsub("ES", "", nuts_id) + + + api_entry <- paste0( + "https://github.com/rOpenSpain/mapSpain/", + "raw/sianedata/MITECO/dist/" + ) + filename <- paste0("malla1x1_", id, ".gpkg") + + result <- esp_hlp_dwnload_sianedata( + api_entry = api_entry, + filename = filename, + cache_dir = cache_dir, + verbose = verbose, + update_cache = update_cache, + cache = TRUE + ) + + + return(result) +} diff --git a/R/esp_get_grid_EEA.R b/R/esp_get_grid_EEA.R new file mode 100644 index 00000000..abdccfd9 --- /dev/null +++ b/R/esp_get_grid_EEA.R @@ -0,0 +1,145 @@ +#' Get [`sf`][sf::st_sf] `POLYGON` of the national geographic grids from EEA +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `POLYGON` with the geographic grids of Spain as +#' provided by the European Environment Agency (EEA). +#' +#' @family grids +#' +#' @return A [`sf`][sf::st_sf] `POLYGON`. +#' +#' +#' @source +#' [EEA reference +#' grid](https://www.eea.europa.eu/en/datahub/datahubitem-view/3c362237-daa4-45e2-8c16-aaadfb1a003b). +#' +#' @export +#' @param resolution Resolution of the grid in kms. Could be `1`, `10` or `100`. +#' +#' @inheritParams esp_get_grid_BDN +#' +#' @inheritSection esp_get_nuts About caching +#' @examplesIf esp_check_access() +#' \dontrun{ +#' +#' grid <- esp_get_grid_EEA(type = "main", resolution = 100) +#' grid_can <- esp_get_grid_EEA(type = "canary", resolution = 100) +#' esp <- esp_get_country(moveCAN = FALSE) +#' +#' library(ggplot2) +#' +#' ggplot(grid) + +#' geom_sf() + +#' geom_sf(data = grid_can) + +#' geom_sf(data = esp, fill = NA) + +#' theme_light() + +#' labs(title = "EEA Grid for Spain") +#' } +esp_get_grid_EEA <- function(resolution = 100, type = "main", + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE) { + # Check grid + res <- as.numeric(resolution) + + if (!res %in% c(1, 10, 100)) { + stop("resolution should be one of 1, 10 or 100") + } + + if (!type %in% c("main", "canary")) { + stop("type should be one of 'main', 'canary'") + } + + newtype <- switch(type, + "main" = "es", + "ic" + ) + + # Url + url <- paste0( + "https://www.eea.europa.eu/data-and-maps/data/", + "eea-reference-grids-2/gis-files/spain-shapefile/at_download/file" + ) + cache_dir <- esp_hlp_cachedir(cache_dir) + + # Create filepath + filename <- "Spain_shapefile.zip" + + filepath <- file.path(cache_dir, filename) + + init_grid <- paste0(newtype, "_", resolution, "km.shp") + + init_grid <- file.path(cache_dir, init_grid) + + localfile <- file.exists(init_grid) + + if (verbose) message("Cache dir is ", cache_dir) + + if (update_cache || isFALSE(localfile)) { + dwnload <- TRUE + if (verbose) { + message("Downloading file from ", url) + } + if (verbose && update_cache) { + message("\nUpdating cache") + } + } else { + dwnload <- FALSE + if (verbose && isFALSE(update_cache)) { + message("File already available on ", filepath) + } + } + + # Downloading + if (dwnload) { + err_dwnload <- try( + download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), + silent = TRUE + ) + # nocov start + if (inherits(err_dwnload, "try-error")) { + if (verbose) message("Retrying query") + err_dwnload <- try( + download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), + silent = TRUE + ) + } + + # If not then message + + + if (inherits(err_dwnload, "try-error")) { + message( + "Download failed", + "\n\nurl \n ", + url, + " not reachable.\n\nPlease try with another options. ", + "If you think this ", + "is a bug please consider opening an issue on:", + "\nhttps://github.com/rOpenSpain/mapSpain/issues" + ) + stop("\nExecution halted") + # nocov end + } else if (verbose) { + message("Download succesful") + } + + if (verbose) message("Unzipping ", filepath, " on ", cache_dir) + unzip(filepath, exdir = cache_dir, overwrite = TRUE) + } + + err_onload <- try( + sf::st_read(init_grid, quiet = isFALSE(verbose), stringsAsFactors = FALSE), + silent = TRUE + ) + # nocov start + if (inherits(err_onload, "try-error")) { + message( + "File may be corrupt. Please try again using cache = TRUE ", + "and update_cache = TRUE" + ) + stop("\nExecution halted") + } + # nocov end + if (verbose) message("File loaded") + return(err_onload) +} diff --git a/R/esp_get_grid_ESDAC.R b/R/esp_get_grid_ESDAC.R new file mode 100644 index 00000000..ce293225 --- /dev/null +++ b/R/esp_get_grid_ESDAC.R @@ -0,0 +1,154 @@ +#' Get [`sf`][sf::st_sf] `POLYGON` of the national geographic grids from ESDAC +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `POLYGON` with the geographic grids of Spain as +#' provided by the European Soil Data Centre (ESDAC). +#' +#' @family grids +#' +#' @return A [`sf`][sf::st_sf] `POLYGON`. +#' +#' +#' @source +#' [EEA reference +#' grid](https://esdac.jrc.ec.europa.eu/content/european-reference-grids). +#' +#' @references +#' - Panagos P., Van Liedekerke M., Jones A., Montanarella L., "European Soil +#' Data Centre: Response to European policy support and public data +#' requirements"; (2012) _Land Use Policy_, 29 (2), pp. 329-338. +#' \doi{10.1016/j.landusepol.2011.07.003} +#' - European Soil Data Centre (ESDAC), esdac.jrc.ec.europa.eu, European +#' Commission, Joint Research Centre. +#' +#' @export +#' @param resolution Resolution of the grid in kms. Could be `1` or `10`. +#' +#' @inheritParams esp_get_grid_EEA +#' +#' @inheritSection esp_get_nuts About caching +#' @examplesIf esp_check_access() +#' \dontrun{ +#' grid <- esp_get_grid_ESDAC() +#' esp <- esp_get_country(moveCAN = FALSE) +#' +#' library(ggplot2) +#' +#' ggplot(grid) + +#' geom_sf() + +#' geom_sf(data = esp, color = "grey50", fill = NA) + +#' theme_light() + +#' labs(title = "ESDAC Grid for Spain") +#' } +#' +esp_get_grid_ESDAC <- function(resolution = 10, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE) { + # Check grid + res <- as.numeric(resolution) + + if (!res %in% c(1, 10)) { + stop( + "resolution should be one of 1, 10" + ) + } + + cache_dir <- esp_hlp_cachedir(cache_dir) + + + # Url + if (res == 10) { + url <- paste0( + "https://esdac.jrc.ec.europa.eu/Library/Reference_Grids/", + "Grids/grids_for_single_eu25_countries_etrs_laea_10k.zip" + ) + filename <- "grids_for_single_eu25_countries_etrs_laea_10k.zip" + init_grid <- "grid_spain_etrs_laea_10k.shp" + } else { + # nocov start + url <- paste0( + "https://esdac.jrc.ec.europa.eu/Library/Reference_Grids/", + "Grids/grid_spain_etrs_laea_1k.zip" + ) + filename <- "grid_spain_etrs_laea_1k.zip" + init_grid <- "grid_spain_etrs_laea_1k.shp" + # nocov end + } + + + filepath <- file.path(cache_dir, filename) + + init_grid <- file.path(cache_dir, init_grid) + + localfile <- file.exists(init_grid) + + if (verbose) message("Cache dir is ", cache_dir) + + if (update_cache || isFALSE(localfile)) { + dwnload <- TRUE + if (verbose) { + message("Downloading file from ", url) + } + if (verbose && update_cache) { + message("\nUpdating cache") + } + } else { + dwnload <- FALSE + if (verbose && isFALSE(update_cache)) { + message("File already available on ", filepath) + } + } + + # Downloading + if (dwnload) { + err_dwnload <- try( + download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), + silent = TRUE + ) + # nocov start + if (inherits(err_dwnload, "try-error")) { + if (verbose) message("Retrying query") + err_dwnload <- try( + download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), + silent = TRUE + ) + } + + # If not then message + + + if (inherits(err_dwnload, "try-error")) { + message( + "Download failed", + "\n\nurl \n ", + url, + " not reachable.\n\nPlease try with another options. ", + "If you think this ", + "is a bug please consider opening an issue on:", + "\nhttps://github.com/rOpenSpain/mapSpain/issues" + ) + stop("\nExecution halted") + # nocov end + } else if (verbose) { + message("Download succesful") + } + + if (verbose) message("Unzipping ", filepath, " on ", cache_dir) + unzip(filepath, exdir = cache_dir, overwrite = TRUE) + } + + err_onload <- try( + sf::st_read(init_grid, quiet = isFALSE(verbose), stringsAsFactors = FALSE), + silent = TRUE + ) + # nocov start + if (inherits(err_onload, "try-error")) { + message( + "File may be corrupt. Please try again using cache = TRUE ", + "and update_cache = TRUE" + ) + stop("\nExecution halted") + } + # nocov end + if (verbose) message("File loaded") + return(err_onload) +} diff --git a/R/esp_get_grid_MTN.R b/R/esp_get_grid_MTN.R new file mode 100644 index 00000000..480734c6 --- /dev/null +++ b/R/esp_get_grid_MTN.R @@ -0,0 +1,227 @@ +#' Get [`sf`][sf::st_sf] `POLYGON` of the national geographic grids from IGN +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `POLYGON` with the geographic grids of Spain. +#' +#' @family grids +#' +#' @return A [`sf`][sf::st_sf] `POLYGON`. +#' +#' +#' @source IGN data via a custom CDN (see +#' ). +#' +#' @export +#' +#' @param grid Name of the grid to be loaded. See **Details**. +#' +#' @inheritParams esp_get_nuts +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @details +#' Metadata available on +#' . +#' +#' Possible values of `grid` are: +#' +#' ```{r, echo=FALSE} +#' +#' +#' df <- data.frame(grid_name = c( +#' "MTN25_ED50_Peninsula_Baleares", +#' "MTN25_ETRS89_ceuta_melilla_alboran", +#' "MTN25_ETRS89_Peninsula_Baleares_Canarias", +#' "MTN25_RegCan95_Canarias", +#' "MTN50_ED50_Peninsula_Baleares", +#' "MTN50_ETRS89_Peninsula_Baleares_Canarias", +#' "MTN50_RegCan95_Canarias" +#' )) +#' +#' +#' knitr::kable(df, +#' col.names = "**grid_name**") +#' +#' +#' +#' ``` +#' +#' ## MTN Grids +#' +#' A description of the MTN (Mapa Topografico Nacional) grids available: +#' +#' +#' **MTN25_ED50_Peninsula_Baleares** +#' +#' MTN25 grid corresponding to the Peninsula and Balearic Islands, in ED50 and +#' geographical coordinates (longitude, latitude) This is the real MTN25 grid, +#' that is, the one that divides the current printed series of the map, taking +#' into account special sheets and irregularities. +#' +#' **MTN50_ED50_Peninsula_Baleares** +#' +#' MTN50 grid corresponding to the Peninsula and Balearic Islands, in ED50 and +#' geographical coordinates (longitude, latitude) This is the real MTN50 grid, +#' that is, the one that divides the current printed series of the map, taking +#' into account special sheets and irregularities. +#' +#' **MTN25_ETRS89_ceuta_melilla_alboran** +#' +#' MTN25 grid corresponding to Ceuta, Melilla, Alboran and Spanish territories +#' in North Africa, adjusted to the new official geodetic reference system +#' ETRS89, in geographical coordinates (longitude, latitude). +#' +#' **MTN25_ETRS89_Peninsula_Baleares_Canarias** +#' +#' MTN25 real grid corresponding to the Peninsula, the Balearic Islands and the +#' Canary Islands, adjusted to the new ETRS89 official reference geodetic +#' system, in geographical coordinates (longitude, latitude). +#' +#' **MTN50_ETRS89_Peninsula_Baleares_Canarias** +#' +#' MTN50 real grid corresponding to the Peninsula, the Balearic Islands and the +#' Canary Islands, adjusted to the new ETRS89 official reference geodetic +#' system, in geographical coordinates (longitude, latitude). +#' +#' **MTN25_RegCan95_Canarias** +#' +#' MTN25 grid corresponding to the Canary Islands, in REGCAN95 (WGS84 +#' compatible) and geographic coordinates (longitude, latitude). It is the real +#' MTN25 grid, that is, the one that divides the current printed series of the +#' map, taking into account the special distribution of the Canary Islands +#' sheets. +#' +#' **MTN50_RegCan95_Canarias** +#' +#' MTN50 grid corresponding to the Canary Islands, in REGCAN95 (WGS84 +#' compatible) and geographic coordinates (longitude, latitude). This is the +#' real grid of the MTN50, that is, the one that divides the current printed +#' series of the map, taking into account the special distribution of the +#' Canary Islands sheets. +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' grid <- esp_get_grid_MTN(grid = "MTN50_ETRS89_Peninsula_Baleares_Canarias") +#' +#' library(ggplot2) +#' +#' ggplot(grid) + +#' geom_sf() + +#' theme_light() + +#' labs(title = "MTN50 Grid for Spain") +#' } +esp_get_grid_MTN <- function(grid = "MTN25_ETRS89_Peninsula_Baleares_Canarias", + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE) { + # Check grid + init_grid <- grid + valid_grid <- c( + "MTN25_ED50_Peninsula_Baleares", + "MTN25_ETRS89_ceuta_melilla_alboran", + "MTN25_ETRS89_Peninsula_Baleares_Canarias", + "MTN25_RegCan95_Canarias", + "MTN50_ED50_Peninsula_Baleares", + "MTN50_ETRS89_Peninsula_Baleares_Canarias", + "MTN50_RegCan95_Canarias" + ) + + if (!init_grid %in% valid_grid) { + stop( + "grid should be one of '", + paste0(valid_grid, collapse = "', "), + "'" + ) + } + + # Url + url <- paste0( + "https://github.com/rOpenSpain/mapSpain/raw/sianedata/", + "MTN/dist/MTN_grids.zip" + ) + + cache_dir <- esp_hlp_cachedir(cache_dir) + + # Create filepath + filename <- "MTN_grids.zip" + + filepath <- file.path(cache_dir, filename) + + gpkgpath <- file.path(cache_dir, paste0(init_grid, ".gpkg")) + localfile <- file.exists(gpkgpath) + + if (verbose) message("Cache dir is ", cache_dir) + + if (update_cache || isFALSE(localfile)) { + dwnload <- TRUE + if (verbose) { + message( + "Downloading file from ", + url, + "\n\nSee https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN ", + "for more info" + ) + } + if (verbose && update_cache) { + message("\nUpdating cache") + } + } else { + dwnload <- FALSE + if (verbose && isFALSE(update_cache)) { + message("File already available on ", filepath) + } + } + + # Downloading + if (dwnload) { + err_dwnload <- try( + download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), + silent = TRUE + ) + # nocov start + if (inherits(err_dwnload, "try-error")) { + if (verbose) message("Retrying query") + err_dwnload <- try( + download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), + silent = TRUE + ) + } + + # If not then message + + + if (inherits(err_dwnload, "try-error")) { + message( + "Download failed", + "\n\nurl \n ", + url, + " not reachable.\n\nPlease try with another options. ", + "If you think this ", + "is a bug please consider opening an issue on:", + "\nhttps://github.com/rOpenSpain/mapSpain/issues" + ) + stop("\nExecution halted") + # nocov end + } else if (verbose) { + message("Download succesful") + } + + if (verbose) message("Unzipping ", filepath, " on ", cache_dir) + unzip(filepath, exdir = cache_dir, overwrite = TRUE) + } + + err_onload <- try( + sf::st_read(gpkgpath, quiet = isFALSE(verbose), stringsAsFactors = FALSE), + silent = TRUE + ) + # nocov start + if (inherits(err_onload, "try-error")) { + message( + "File may be corrupt. Please try again using cache = TRUE ", + "and update_cache = TRUE" + ) + stop("\nExecution halted") + } + # nocov end + if (verbose) message("File loaded") + return(err_onload) +} diff --git a/R/esp_get_gridmap.R b/R/esp_get_gridmap.R index 8e0be1bf..80b5a809 100644 --- a/R/esp_get_gridmap.R +++ b/R/esp_get_gridmap.R @@ -1,175 +1,168 @@ -#' Get a `sf` hexbin or squared polygon of Spain -#' -#' @description -#' Loads a hexbin map (`sf` object) or a map of squares with the boundaries of -#' the provinces or autonomous communities of Spain. -#' -#' @rdname esp_get_gridmap -#' @name esp_get_gridmap -#' -#' @family political -#' -#' @return A `sf` POLYGON object. -#' -#' -#' @export -#' -#' @inheritParams esp_get_prov -#' -#' @inheritParams esp_get_ccaa -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @inheritSection esp_get_nuts Displacing the Canary Islands -#' -#' @details -#' -#' Hexbin or grid map has an advantage over usual choropleth maps. -#' In choropleths, a large polygon data looks more emphasized just because -#' of its size, what introduces a bias. Here with hexbin, each region is -#' represented equally dismissing the bias. -#' -#' You can use and mix names, ISO codes, "codauto"/"cpro" codes (see -#' [esp_codelist]) and NUTS codes of different levels. -#' -#' When using a code corresponding of a higher level (e.g. -#' `esp_get_prov("Andalucia")`) all the corresponding units of that level are -#' provided (in this case , all the provinces of Andalucia). -#' -#' -#' Results are provided in **EPSG:4258**, use [sf::st_transform()] -#' to change the projection. -#' -#' -#' @example inst/examples/esp_get_gridmap.R -#' -esp_get_hex_prov <- function(prov = NULL) { - region <- prov - data_sf <- esp_hexbin_prov - - region <- unique(region) - - if (!is.null(region)) { - region <- esp_hlp_all2prov(region) - - region <- unique(region) - if (length(region) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } - - dfcpro <- mapSpain::esp_codelist - dfcpro <- unique(dfcpro[, c("nuts3.code", "cpro")]) - cprocodes <- - unique(dfcpro[dfcpro$nuts3.code %in% region, ]$cpro) - - data_sf <- data_sf[data_sf$cpro %in% cprocodes, ] - } - - # Order - data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] - - return(data_sf) -} - -#' @rdname esp_get_gridmap -#' -#' @export -esp_get_hex_ccaa <- function(ccaa = NULL) { - region <- ccaa - - data_sf <- esp_hexbin_ccaa - - region <- unique(region) - - - if (!is.null(region)) { - nuts_id <- esp_hlp_all2ccaa(region) - - nuts_id <- unique(nuts_id) - if (length(nuts_id) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } - - data_sf <- data_sf[data_sf$nuts2.code %in% nuts_id, ] - } - - # Order - data_sf <- data_sf[order(data_sf$codauto), ] - - return(data_sf) -} - -#' @rdname esp_get_gridmap -#' -#' @export -esp_get_grid_prov <- function(prov = NULL) { - region <- prov - data_sf <- esp_grid_prov - - region <- unique(region) - - if (!is.null(region)) { - region <- esp_hlp_all2prov(region) - - region <- unique(region) - if (length(region) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } - - dfcpro <- mapSpain::esp_codelist - dfcpro <- unique(dfcpro[, c("nuts3.code", "cpro")]) - cprocodes <- - unique(dfcpro[dfcpro$nuts3.code %in% region, ]$cpro) - - data_sf <- data_sf[data_sf$cpro %in% cprocodes, ] - } - - # Order - data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] - - return(data_sf) -} - -#' @rdname esp_get_gridmap -#' -#' @export -esp_get_grid_ccaa <- function(ccaa = NULL) { - region <- ccaa - - data_sf <- esp_grid_ccaa - - region <- unique(region) - - - if (!is.null(region)) { - nuts_id <- esp_hlp_all2ccaa(region) - - nuts_id <- unique(nuts_id) - if (length(nuts_id) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } - - data_sf <- data_sf[data_sf$nuts2.code %in% nuts_id, ] - } - - # Order - data_sf <- data_sf[order(data_sf$codauto), ] - - return(data_sf) -} +#' Get a [`sf`][sf::st_sf] hexbin or squared `POLYGON` of Spain +#' +#' @description +#' Loads a hexbin map ([`sf`][sf::st_sf] object) or a map of squares with the +#' boundaries of the provinces or autonomous communities of Spain. +#' +#' @rdname esp_get_gridmap +#' @name esp_get_gridmap +#' +#' @family political +#' +#' @return A [`sf`][sf::st_sf] `POLYGON` object. +#' +#' +#' @export +#' +#' @inheritParams esp_get_prov +#' +#' @inheritParams esp_get_ccaa +#' +#' @details +#' +#' Hexbin or grid map has an advantage over usual choropleth maps. +#' In choropleths, a large polygon data looks more emphasized just because +#' of its size, what introduces a bias. Here with hexbin, each region is +#' represented equally dismissing the bias. +#' +#' You can use and mix names, ISO codes, `"codauto"/ "cpro"` codes (see +#' [esp_codelist]) and NUTS codes of different levels. +#' +#' When using a code corresponding of a higher level (e.g. +#' `esp_get_prov("Andalucia")`) all the corresponding units of that level are +#' provided (in this case , all the provinces of Andalusia). +#' +#' +#' Results are provided in **EPSG:4258**, use [sf::st_transform()] +#' to change the projection. +#' +#' +#' @example inst/examples/esp_get_gridmap.R +#' +esp_get_hex_prov <- function(prov = NULL) { + region <- prov + data_sf <- esp_hexbin_prov + + region <- unique(region) + + if (!is.null(region)) { + region <- esp_hlp_all2prov(region) + + region <- unique(region) + if (length(region) == 0) { + stop( + "region ", + paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + + dfcpro <- mapSpain::esp_codelist + dfcpro <- unique(dfcpro[, c("nuts3.code", "cpro")]) + cprocodes <- unique(dfcpro[dfcpro$nuts3.code %in% region, ]$cpro) + + data_sf <- data_sf[data_sf$cpro %in% cprocodes, ] + } + + # Order + data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] + + return(data_sf) +} + +#' @rdname esp_get_gridmap +#' +#' @export +esp_get_hex_ccaa <- function(ccaa = NULL) { + region <- ccaa + + data_sf <- esp_hexbin_ccaa + + region <- unique(region) + + + if (!is.null(region)) { + nuts_id <- esp_hlp_all2ccaa(region) + + nuts_id <- unique(nuts_id) + if (length(nuts_id) == 0) { + stop( + "region ", + paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + + data_sf <- data_sf[data_sf$nuts2.code %in% nuts_id, ] + } + + # Order + data_sf <- data_sf[order(data_sf$codauto), ] + + return(data_sf) +} + +#' @rdname esp_get_gridmap +#' +#' @export +esp_get_grid_prov <- function(prov = NULL) { + region <- prov + data_sf <- esp_grid_prov + + region <- unique(region) + + if (!is.null(region)) { + region <- esp_hlp_all2prov(region) + + region <- unique(region) + if (length(region) == 0) { + stop( + "region ", + paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + + dfcpro <- mapSpain::esp_codelist + dfcpro <- unique(dfcpro[, c("nuts3.code", "cpro")]) + cprocodes <- unique(dfcpro[dfcpro$nuts3.code %in% region, ]$cpro) + + data_sf <- data_sf[data_sf$cpro %in% cprocodes, ] + } + + # Order + data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] + + return(data_sf) +} + +#' @rdname esp_get_gridmap +#' +#' @export +esp_get_grid_ccaa <- function(ccaa = NULL) { + region <- ccaa + + data_sf <- esp_grid_ccaa + + region <- unique(region) + + + if (!is.null(region)) { + nuts_id <- esp_hlp_all2ccaa(region) + + nuts_id <- unique(nuts_id) + if (length(nuts_id) == 0) { + stop( + "region ", paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + + data_sf <- data_sf[data_sf$nuts2.code %in% nuts_id, ] + } + + # Order + data_sf <- data_sf[order(data_sf$codauto), ] + + return(data_sf) +} diff --git a/R/esp_get_hydrobasin.R b/R/esp_get_hydrobasin.R index 36920929..6fe6373b 100644 --- a/R/esp_get_hydrobasin.R +++ b/R/esp_get_hydrobasin.R @@ -1,94 +1,84 @@ -#' Get `sf` polygons of the drainage basin demarcations of Spain -#' -#' @description -#' Loads a `sf` polygon object containing areas with the required -#' hydrographic elements of Spain. -#' -#' @family natural -#' -#' @return A `sf` polygon object. -#' -#' @source IGN data via a custom CDN (see -#' ). -#' -#' @export -#' -#' @param domain Possible values are `"land"`, that includes only -#' the ground part or the ground or `"landsea"`, that includes both the ground -#' and the related sea waters of the basin -#' -#' @inheritParams esp_get_rivers -#' -#' @inheritParams esp_get_nuts -#' -#' @inheritSection esp_get_nuts About caching -#' -#' -#' @details -#' Metadata available on -#' . -#' -#' @examples -#' \donttest{ -#' all <- esp_get_prov(moveCAN = FALSE) -#' hydroland <- esp_get_hydrobasin(domain = "land") -#' hydrolandsea <- esp_get_hydrobasin(domain = "landsea") -#' -#' library(tmap) -#' -#' tm_shape(hydrolandsea, bbox = c(-9.5, 35, 4.5, 44)) + -#' tm_fill("skyblue4") + -#' tm_shape(all) + -#' tm_polygons("grey90") + -#' tm_shape(hydroland) + -#' tm_polygons("skyblue", alpha = 0.5, border.col = "blue") + -#' tm_text( -#' text = "rotulo", -#' remove.overlap = TRUE, -#' size = 0.5, -#' fontface = "bold", -#' shadow = TRUE -#' ) + -#' tm_layout(bg.color = "grey95") -#' } -esp_get_hydrobasin <- function(epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = "3", - domain = "land") { - # Check epsg - init_epsg <- as.character(epsg) - if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { - stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") - } - - # Valid spatialtype - validdomain <- c("land", "landsea") - - if (!domain %in% validdomain) { - stop( - "domain should be one of '", - paste0(validdomain, collapse = "', "), - "'" - ) - } - - type <- paste0("basin", domain) - basin_sf <- - esp_hlp_get_siane( - type, - resolution, - cache, - cache_dir, - update_cache, - verbose, - Sys.Date() - ) - - basin_sf <- - sf::st_transform(basin_sf, as.double(init_epsg)) - - return(basin_sf) -} +#' Get [`sf`][sf::st_sf] `POLYGON` of the drainage basin demarcations of Spain +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `POLYGON` object containing areas with the required +#' hydrographic elements of Spain. +#' +#' @family natural +#' +#' @return A [`sf`][sf::st_sf] `POLYGON` object. +#' +#' @source +#' IGN data via a custom CDN (see +#' ). +#' +#' @export +#' +#' @param domain Possible values are `"land"`, that includes only +#' the ground part or the ground or `"landsea"`, that includes both the ground +#' and the related sea waters of the basin. +#' +#' @inheritParams esp_get_rivers +#' +#' @inheritParams esp_get_nuts +#' +#' @inheritSection esp_get_nuts About caching +#' +#' +#' @details +#' Metadata available on +#' . +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' hydroland <- esp_get_hydrobasin(domain = "land") +#' hydrolandsea <- esp_get_hydrobasin(domain = "landsea") +#' +#' library(ggplot2) +#' +#' +#' ggplot(hydroland) + +#' geom_sf(data = hydrolandsea, fill = "skyblue4", alpha = .4) + +#' geom_sf(fill = "skyblue", alpha = .5) + +#' geom_sf_text(aes(label = rotulo), +#' size = 3, check_overlap = TRUE, +#' fontface = "bold", +#' family = "serif" +#' ) + +#' coord_sf( +#' xlim = c(-9.5, 4.5), +#' ylim = c(35, 44) +#' ) + +#' theme_void() +#' } +esp_get_hydrobasin <- function(epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, resolution = "3", + domain = "land") { + # Check epsg + init_epsg <- as.character(epsg) + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + # Valid spatialtype + validdomain <- c("land", "landsea") + + if (!domain %in% validdomain) { + stop( + "domain should be one of '", + paste0(validdomain, collapse = "', "), + "'" + ) + } + + type <- paste0("basin", domain) + basin_sf <- esp_hlp_get_siane( + type, resolution, cache, cache_dir, + update_cache, verbose, Sys.Date() + ) + + basin_sf <- sf::st_transform(basin_sf, as.double(init_epsg)) + + return(basin_sf) +} diff --git a/R/esp_get_hypsobath.R b/R/esp_get_hypsobath.R index 9cc250fc..9defbde6 100644 --- a/R/esp_get_hypsobath.R +++ b/R/esp_get_hypsobath.R @@ -1,147 +1,158 @@ -#' Get `sf` polygons and lines with the hypsometry and bathymetry of Spain -#' -#' @description -#' Loads a `sf` polygon or line object representing the hypsometry and -#' bathymetry of Spain. -#' -#' * **Hypsometry** represents the the elevation and depth of features of the -#' Earth's surface relative to mean sea level. -#' * **Bathymetry** is the measurement of the depth of water in oceans, rivers, -#' or lakes. -#' -#' @family natural -#' -#' @return A `sf` polygon or line object. -#' -#' @source IGN data via a custom CDN (see -#' ). -#' -#' @export -#' -#' @param resolution Resolution of the shape. Values available -#' are `"3"` or `"6.5"`. -#' -#' @param spatialtype Spatial type of the output. Use `"area"` for polygons or -#' `"line"` for lines. -#' -#' @inheritParams esp_get_nuts -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @details -#' Metadata available on -#' . -#' -#' @examples -#' \donttest{ -#' # This code would produce a nice plot - It will take a few seconds to run -#' library(tmap) -#' -#' hypsobath <- esp_get_hypsobath() -#' -#' # Tints from Wikipedia -#' # https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Maps/Conventions/Topographic_maps -#' -#' bath_tints <- colorRampPalette( -#' rev( -#' c( -#' "#D8F2FE", "#C6ECFF", "#B9E3FF", -#' "#ACDBFB", "#A1D2F7", "#96C9F0", -#' "#8DC1EA", "#84B9E3", "#79B2DE", -#' "#71ABD8" -#' ) -#' ) -#' ) -#' -#' hyps_tints <- colorRampPalette( -#' rev( -#' c( -#' "#F5F4F2", "#E0DED8", "#CAC3B8", "#BAAE9A", -#' "#AC9A7C", "#AA8753", "#B9985A", "#C3A76B", -#' "#CAB982", "#D3CA9D", "#DED6A3", "#E8E1B6", -#' "#EFEBC0", "#E1E4B5", "#D1D7AB", "#BDCC96", -#' "#A8C68F", "#94BF8B", "#ACD0A5" -#' ) -#' ) -#' ) -#' -#' levels <- sort(unique(hypsobath$val_inf)) -#' -#' # Create palette -#' br_bath <- length(levels[levels < 0]) -#' br_terrain <- length(levels) - br_bath -#' -#' bath_tints(br_bath) -#' -#' pal <- c(bath_tints((br_bath)), hyps_tints((br_terrain))) -#' -#' -#' # Plot Canary Islands -#' tm_shape(hypsobath, bbox = c(-18.6, 27, -13, 29.5)) + -#' tm_fill("val_inf", -#' style = "cat", -#' palette = pal, -#' title = "Elevation", -#' legend.reverse = TRUE -#' ) + -#' tm_layout( -#' legend.outside = TRUE -#' ) -#' -#' -#' # Plot Mainland -#' tm_shape(hypsobath, bbox = c(-9.5, 35.8, 4.4, 44)) + -#' tm_fill("val_inf", -#' style = "cat", -#' palette = pal, -#' title = "Elevation", -#' legend.reverse = TRUE -#' ) + -#' tm_layout(legend.outside = TRUE) -#' } -esp_get_hypsobath <- function(epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = "3", - spatialtype = "area") { - init_epsg <- as.character(epsg) - if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { - stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") - } - - # Valid res - validres <- c("3", "6.5") - - if (!resolution %in% validres) { - stop( - "resolution should be one of '", - paste0(validres, collapse = "', "), - "'" - ) - } - - # Valid spatialtype - validspatialtype <- c("area", "line") - - if (!spatialtype %in% validspatialtype) { - stop( - "spatialtype should be one of '", - paste0(validspatialtype, collapse = "', "), - "'" - ) - } - - type <- paste0("orog", spatialtype) - - data_sf <- esp_hlp_get_siane(type, - resolution, - cache, - cache_dir, - update_cache, - verbose, - year = Sys.Date() - ) - data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) -} +#' Get [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` with hypsometry and +#' bathymetry of Spain +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` object representing the +#' hypsometry and bathymetry of Spain. +#' +#' - **Hypsometry** represents the the elevation and depth of features of the +#' Earth's surface relative to mean sea level. +#' - **Bathymetry** is the measurement of the depth of water in oceans, rivers, +#' or lakes. +#' +#' @family natural +#' +#' @return A [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` object. +#' +#' @source +#' IGN data via a custom CDN (see +#' ). +#' +#' @export +#' +#' @param resolution Resolution of the shape. Values available +#' are `"3"` or `"6.5"`. +#' +#' @param spatialtype Spatial type of the output. Use `"area"` for `POLYGON` or +#' `"line"` for `LINESTRING`. +#' +#' @inheritParams esp_get_nuts +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @details +#' Metadata available on +#' . +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' # This code would produce a nice plot - It will take a few seconds to run +#' library(ggplot2) +#' +#' hypsobath <- esp_get_hypsobath() +#' +#' # Error on the data provided - There is an empty shape +#' # Remove: +#' +#' hypsobath <- hypsobath[!sf::st_is_empty(hypsobath), ] +#' +#' # Tints from Wikipedia +#' # https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Maps/Conventions/ +#' # Topographic_maps +#' +#' bath_tints <- colorRampPalette( +#' rev( +#' c( +#' "#D8F2FE", "#C6ECFF", "#B9E3FF", +#' "#ACDBFB", "#A1D2F7", "#96C9F0", +#' "#8DC1EA", "#84B9E3", "#79B2DE", +#' "#71ABD8" +#' ) +#' ) +#' ) +#' +#' hyps_tints <- colorRampPalette( +#' rev( +#' c( +#' "#F5F4F2", "#E0DED8", "#CAC3B8", "#BAAE9A", +#' "#AC9A7C", "#AA8753", "#B9985A", "#C3A76B", +#' "#CAB982", "#D3CA9D", "#DED6A3", "#E8E1B6", +#' "#EFEBC0", "#E1E4B5", "#D1D7AB", "#BDCC96", +#' "#A8C68F", "#94BF8B", "#ACD0A5" +#' ) +#' ) +#' ) +#' +#' levels <- sort(unique(hypsobath$val_inf)) +#' +#' # Create palette +#' br_bath <- length(levels[levels < 0]) +#' br_terrain <- length(levels) - br_bath +#' +#' pal <- c(bath_tints((br_bath)), hyps_tints((br_terrain))) +#' +#' +#' # Plot Canary Islands +#' ggplot(hypsobath) + +#' geom_sf(aes(fill = as.factor(val_inf)), +#' color = NA +#' ) + +#' coord_sf( +#' xlim = c(-18.6, -13), +#' ylim = c(27, 29.5) +#' ) + +#' scale_fill_manual(values = pal) + +#' guides(fill = guide_legend( +#' title = "Elevation", +#' direction = "horizontal", +#' label.position = "bottom", +#' title.position = "top", +#' nrow = 1 +#' )) + +#' theme(legend.position = "bottom") +#' +#' +#' # Plot Mainland +#' ggplot(hypsobath) + +#' geom_sf(aes(fill = as.factor(val_inf)), +#' color = NA +#' ) + +#' coord_sf( +#' xlim = c(-9.5, 4.4), +#' ylim = c(35.8, 44) +#' ) + +#' scale_fill_manual(values = pal) + +#' guides(fill = guide_legend( +#' title = "Elevation", +#' reverse = TRUE, +#' keyheight = .8 +#' )) +#' } +esp_get_hypsobath <- function(epsg = "4258", cache = TRUE, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE, + resolution = "3", spatialtype = "area") { + init_epsg <- as.character(epsg) + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + # Valid res + validres <- c("3", "6.5") + + if (!resolution %in% validres) { + stop( + "resolution should be one of '", paste0(validres, collapse = "', "), + "'" + ) + } + + # Valid spatialtype + validspatialtype <- c("area", "line") + + if (!spatialtype %in% validspatialtype) { + stop( + "spatialtype should be one of '", + paste0(validspatialtype, collapse = "', "), "'" + ) + } + + type <- paste0("orog", spatialtype) + + data_sf <- esp_hlp_get_siane(type, resolution, cache, cache_dir, update_cache, + verbose, + year = Sys.Date() + ) + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) + data_sf +} diff --git a/R/esp_get_munic.R b/R/esp_get_munic.R index 8f34d4c4..4af47402 100644 --- a/R/esp_get_munic.R +++ b/R/esp_get_munic.R @@ -1,486 +1,389 @@ -#' Get municipalities of Spain as `sf` polygons -#' -#' @description -#' Returns municipalities of Spain as polygons at a specified scale. -#' -#' * [esp_get_munic()] uses GISCO (Eurostat) as source. Please use -#' [giscoR::gisco_attributions()] -#' -#' @family political -#' @family municipalities -#' @seealso [giscoR::gisco_get_lau()], [base::regex()]. -#' -#' @return A `sf` polygon -#' -#' @export -#' -#' @source [GISCO API](https://gisco-services.ec.europa.eu/distribution/v2/) -#' -#' -#' -#' -#' @param year Release year. See **Details** for years available. - -#' @param region A vector of names and/or codes for provinces -#' or `NULL` to get all the municipalities. See **Details**. -#' -#' @param munic A name or [`regex`][base::grep()] expression with the names of the -#' required municipalities. `NULL` would not produce any filtering. -#' -#' @inheritParams esp_get_nuts -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @inheritSection esp_get_nuts Displacing the Canary Islands -#' -#' @details -#' -#' The years available are: -#' * [esp_get_munic()]: `year` could be one of "2001", "2004", "2006", "2008", -#' "2010", "2013" and any year between 2016 and 2019. -#' See [giscoR::gisco_get_lau()], [giscoR::gisco_get_communes()]. -#' -#' * [esp_get_munic_siane()]: `year` could be passed as a single year ("YYYY" -#' format, as end of year) or as a specific date ("YYYY-MM-DD" format). -#' Historical information starts as of 2005. -#' -#' When using `region` you can use and mix names and NUTS codes -#' (levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or -#' "cpro" (see [esp_codelist]). -#' -#' When calling a superior level (Province, Autonomous Community or NUTS1) , -#' all the municipalities of that level would be added. -#' -#' @examples -#' # Get munics -#' Base <- esp_get_munic(year = "2019", region = "Castilla y Leon") -#' -#' # Provs for delimiting -#' provs <- esp_get_prov(prov = "Castilla y Leon") -#' -#' # Load population data -#' data("pobmun19") -#' -#' # Arrange and create breaks -#' -#' Base_pop <- merge(Base, pobmun19, -#' by = c("cpro", "cmun"), -#' all.x = TRUE -#' ) -#' -#' br <- sort(c( -#' 0, 50, 100, 200, 500, -#' 1000, 5000, 50000, 100000, -#' max(Base_pop$pob19) -#' )) -#' -#' # Plot -#' library(tmap) -#' tm_shape(Base_pop) + -#' tm_fill( -#' col = "pob19", palette = "cividis", -#' breaks = br, -#' title = "Persons" -#' ) + -#' tm_shape(provs) + -#' tm_borders(col = "white", alpha = 0.25) + -#' tm_layout( -#' legend.outside = TRUE, -#' legend.position = c("right", "center"), -#' main.title = "Population in Castilla y Leon (2019)", -#' frame = FALSE -#' ) -esp_get_munic <- function(year = "2019", - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - region = NULL, - munic = NULL, - moveCAN = TRUE) { - init_epsg <- as.character(epsg) - year <- as.character(year) - - yearsav <- - c( - "2001", - "2004", - "2006", - "2008", - "2010", - "2013", - "2016", - "2017", - "2018", - "2019" - ) - - if (!year %in% yearsav) { - stop( - "year ", - year, - " not available, try ", - paste0("'", yearsav, "'", collapse = ", ") - ) - } - - cache_dir <- esp_hlp_cachedir(cache_dir) - - if (init_epsg == "4258") { - epsg <- "4326" - } - - dwnload <- TRUE - - - if (year == "2019" & - epsg == "4326" & - isFALSE(update_cache)) { - if (verbose) { - message("Reading from esp_munic.sf") - } - data_sf <- mapSpain::esp_munic.sf - - - dwnload <- FALSE - } - - # nocov start - - if (dwnload) { - if (year >= "2016") { - data_sf <- giscoR::gisco_get_lau( - year = year, - epsg = epsg, - cache = cache, - update_cache = update_cache, - cache_dir = cache_dir, - verbose = verbose, - country = "ES" - ) - } else { - data_sf <- giscoR::gisco_get_communes( - year = year, - epsg = epsg, - cache = cache, - update_cache = update_cache, - cache_dir = cache_dir, - verbose = verbose, - country = "ES", - spatialtype = "RG" - ) - } - - # Create dataframe - - df <- data_sf - - # Names management - - if ("LAU_ID" %in% colnames(df)) { - df$LAU_CODE <- df$LAU_ID - } - - if ("NSI_CODE" %in% colnames(df)) { - df$LAU_CODE <- df$NSI_CODE - } - - if ("LAU_NAME" %in% colnames(df)) { - df$name <- df$LAU_NAME - } - - if ("COMM_NAME" %in% colnames(df)) { - df$name <- df$COMM_NAME - } - - if ("SABE_NAME" %in% colnames(df)) { - df$name <- df$SABE_NAME - } - - df <- df[, c("LAU_CODE", "name")] - - - df$LAU_CODE <- gsub("ES", "", df$LAU_CODE) - - df$cpro <- substr(df$LAU_CODE, 1, 2) - df$cmun <- substr(df$LAU_CODE, 3, 8) - - df <- df[, c("cpro", "cmun", "name", "LAU_CODE")] - - cod <- - unique(mapSpain::esp_codelist[, c( - "codauto", - "ine.ccaa.name", - "cpro", "ine.prov.name" - )]) - - df2 <- merge(df, - cod, - by = "cpro", - all.x = TRUE, - no.dups = TRUE - ) - - - df2 <- - df2[, c( - "codauto", - "ine.ccaa.name", - "cpro", - "ine.prov.name", - "cmun", - "name", - "LAU_CODE" - )] - - - data_sf <- df2 - } - - # nocov end - - if (!is.null(munic)) { - munic <- paste(munic, collapse = "|") - data_sf <- data_sf[grep(munic, data_sf$name), ] - } - - - - if (!is.null(region)) { - tonuts <- esp_hlp_all2prov(region) - - # toprov - df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) - df <- df[df$nuts3.code %in% tonuts, "cpro"] - toprov <- unique(df) - - data_sf <- data_sf[data_sf$cpro %in% toprov, ] - } - - if (nrow(data_sf) == 0) { - stop( - "The combination of region and/or munic does ", - "not return any result" - ) - } - - - - # Move CAN - - # Checks - - moving <- FALSE - moving <- isTRUE(moveCAN) | length(moveCAN) > 1 - - - if (moving) { - if (length(grep("05", data_sf$codauto)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) - penin <- data_sf[-grep("05", data_sf$codauto), ] - can <- data_sf[grep("05", data_sf$codauto), ] - - # Move CAN - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) - - # Regenerate - if (nrow(penin) > 0) { - data_sf <- rbind(penin, can) - } else { - data_sf <- can - } - } - } - - data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) - data_sf <- - data_sf[order(data_sf$codauto, data_sf$cpro, data_sf$cmun), ] - - return(data_sf) -} - - -#' @rdname esp_get_munic -#' -#' -#' @description -#' * [esp_get_munic_siane()] uses CartoBase ANE as source, provided by -#' Instituto Geografico Nacional (IGN), . -#' Years available are 2005 up to today. -#' -#' @source -#' IGN data via a custom CDN (see -#' ). -#' -#' @param resolution Resolution of the polygon. Values available are -#' `"3"`, `"6.5"` or `"10"`. -#' -#' @inheritParams esp_get_ccaa_siane -#' -#' -#' @export -esp_get_munic_siane <- function(year = Sys.Date(), - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = 3, - region = NULL, - munic = NULL, - moveCAN = TRUE, - rawcols = FALSE) { - init_epsg <- as.character(epsg) - year <- as.character(year) - - if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { - stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") - } - - # Get Data from SIANE - data_sf <- esp_hlp_get_siane( - "munic", - resolution, - cache, - cache_dir, - update_cache, - verbose, - year - ) - - colnames_init <- colnames(sf::st_drop_geometry(data_sf)) - df <- data_sf - - # Name management - df$LAU_CODE <- df$id_ine - df$name <- df$rotulo - df$cpro <- df$id_prov - - idprov <- sort(unique(mapSpain::esp_codelist$cpro)) - df$cmun <- ifelse(substr(df$LAU_CODE, 1, 2) %in% idprov, - substr(df$LAU_CODE, 3, 8), - NA - ) - - cod <- - unique(mapSpain::esp_codelist[, c( - "codauto", - "ine.ccaa.name", - "cpro", "ine.prov.name" - )]) - - df2 <- merge(df, - cod, - by = "cpro", - all.x = TRUE, - no.dups = TRUE - ) - - data_sf <- df2 - - if (!is.null(munic)) { - munic <- paste(munic, collapse = "|") - data_sf <- data_sf[grep(munic, data_sf$name), ] - } - - if (!is.null(region)) { - tonuts <- esp_hlp_all2prov(region) - # toprov - df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) - df <- df[df$nuts3.code %in% tonuts, "cpro"] - toprov <- unique(df) - data_sf <- data_sf[data_sf$cpro %in% toprov, ] - } - - if (nrow(data_sf) == 0) { - stop( - "The combination of region and/or munic does ", - "not return any result" - ) - } - # Move CAN - - # Checks - moving <- FALSE - moving <- isTRUE(moveCAN) | length(moveCAN) > 1 - - if (moving) { - if (length(grep("05", data_sf$codauto)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) - penin <- data_sf[-grep("05", data_sf$codauto), ] - can <- data_sf[grep("05", data_sf$codauto), ] - - # Move CAN - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) - - # Regenerate - if (nrow(penin) > 0) { - data_sf <- rbind(penin, can) - } else { - data_sf <- can - } - } - } - - data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) - data_sf <- - data_sf[order(data_sf$codauto, data_sf$cpro, data_sf$cmun), ] - - namesend <- unique(c( - colnames_init, - c( - "codauto", - "ine.ccaa.name", - "cpro", - "ine.prov.name", - "cmun", - "name", - "LAU_CODE" - ), - colnames(data_sf) - )) - - data_sf <- data_sf[, namesend] - - if (isFALSE(rawcols)) { - data_sf <- data_sf[, c( - "codauto", - "ine.ccaa.name", - "cpro", - "ine.prov.name", - "cmun", - "name", - "LAU_CODE" - )] - } - return(data_sf) -} +#' Get municipalities of Spain as [`sf`][sf::st_sf] `POLYGON` +#' +#' @description +#' Returns municipalities of Spain `sf` POLYGON` at a specified scale. +#' +#' - [esp_get_munic()] uses GISCO (Eurostat) as source. Please use +#' [giscoR::gisco_attributions()]. +#' +#' @family political +#' @family municipalities +#' @seealso [giscoR::gisco_get_lau()], [base::regex()]. +#' +#' @return A [`sf`][sf::st_sf] `POLYGON`. +#' +#' @export +#' +#' @source +#' [GISCO API](https://gisco-services.ec.europa.eu/distribution/v2/) +#' +#' @param year Release year. See **Details** for years available. +#' @param region A vector of names and/or codes for provinces +#' or `NULL` to get all the municipalities. See **Details**. +#' +#' @param munic A name or [`regex`][base::grep()] expression with the names of +#' the required municipalities. `NULL` would return all municipalities. +#' +#' @inheritParams esp_get_nuts +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @inheritSection esp_get_nuts Displacing the Canary Islands +#' +#' @details +#' +#' The years available are: +#' - [esp_get_munic()]: `year` could be one of "2001", "2004", "2006", "2008", +#' "2010", "2013" and any year between 2016 and 2019. +#' See [giscoR::gisco_get_lau()], [giscoR::gisco_get_communes()]. +#' - [esp_get_munic_siane()]: `year` could be passed as a single year ("YYYY" +#' format, as end of year) or as a specific date ("YYYY-MM-DD" format). +#' Historical information starts as of 2005. +#' +#' When using `region` you can use and mix names and NUTS codes (levels 1, 2 or +#' 3), ISO codes (corresponding to level 2 or 3) or `"cpro"` +#' (see [esp_codelist]). +#' +#' When calling a higher level (Province, Autonomous Community or NUTS1), all +#' the municipalities of that level would be added. +#' +#' @examples +#' \donttest{ +#' # Get munics +#' Base <- esp_get_munic(year = "2019", region = "Castilla y Leon") +#' +#' # Provs for delimiting +#' provs <- esp_get_prov(prov = "Castilla y Leon") +#' +#' # Load population data +#' data("pobmun19") +#' +#' # Arrange and create breaks +#' +#' Base_pop <- merge(Base, pobmun19, +#' by = c("cpro", "cmun"), +#' all.x = TRUE +#' ) +#' +#' br <- sort(c( +#' 0, 50, 100, 200, 500, +#' 1000, 5000, 50000, 100000, +#' Inf +#' )) +#' +#' Base_pop$cuts <- cut(Base_pop$pob19, br, dig.lab = 20) +#' +#' # Plot +#' library(ggplot2) +#' +#' +#' ggplot(Base_pop) + +#' geom_sf(aes(fill = cuts), color = NA) + +#' geom_sf(data = provs, fill = NA, color = "grey70") + +#' scale_fill_manual(values = hcl.colors(length(br), "cividis")) + +#' labs( +#' title = "Population in Castilla y Leon", +#' subtitle = "INE, 2019", +#' fill = "Persons" +#' ) + +#' theme_void() +#' } +esp_get_munic <- function(year = "2019", epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, region = NULL, munic = NULL, + moveCAN = TRUE) { + init_epsg <- as.character(epsg) + year <- as.character(year) + + yearsav <- c( + "2001", "2004", "2006", "2008", "2010", "2013", "2016", "2017", + "2018", "2019" + ) + + if (!year %in% yearsav) { + stop( + "year ", year, " not available, try ", + paste0("'", yearsav, "'", collapse = ", ") + ) + } + + cache_dir <- esp_hlp_cachedir(cache_dir) + + if (init_epsg == "4258") epsg <- "4326" + + dwnload <- TRUE + + + if (all(year == "2019", epsg == "4326", isFALSE(update_cache))) { + if (verbose) { + message("Reading from esp_munic.sf") + } + data_sf <- mapSpain::esp_munic.sf + + + dwnload <- FALSE + } + + if (dwnload) { + if (year >= "2016") { + data_sf <- giscoR::gisco_get_lau( + year = year, epsg = epsg, + cache = cache, + update_cache = update_cache, + cache_dir = cache_dir, + verbose = verbose, country = "ES" + ) + } else { + data_sf <- giscoR::gisco_get_communes( + year = year, epsg = epsg, + cache = cache, + update_cache = update_cache, + cache_dir = cache_dir, + verbose = verbose, + country = "ES", + spatialtype = "RG" + ) + } + + # Create dataframe + + df <- data_sf + + # Names management + + if ("LAU_ID" %in% colnames(df)) { + df$LAU_CODE <- df$LAU_ID + } + + if ("NSI_CODE" %in% colnames(df)) { + df$LAU_CODE <- df$NSI_CODE + } + + if ("LAU_NAME" %in% colnames(df)) { + df$name <- df$LAU_NAME + } + + if ("COMM_NAME" %in% colnames(df)) { + df$name <- df$COMM_NAME + } + + if ("SABE_NAME" %in% colnames(df)) { + df$name <- df$SABE_NAME + } + + df <- df[, c("LAU_CODE", "name")] + + + df$LAU_CODE <- gsub("ES", "", df$LAU_CODE) + + df$cpro <- substr(df$LAU_CODE, 1, 2) + df$cmun <- substr(df$LAU_CODE, 3, 8) + + df <- df[, c("cpro", "cmun", "name", "LAU_CODE")] + + cod <- unique(mapSpain::esp_codelist[, c( + "codauto", + "ine.ccaa.name", + "cpro", "ine.prov.name" + )]) + + df2 <- merge(df, cod, by = "cpro", all.x = TRUE, no.dups = TRUE) + + + df2 <- df2[, c( + "codauto", "ine.ccaa.name", "cpro", "ine.prov.name", + "cmun", "name", "LAU_CODE" + )] + + + data_sf <- df2 + } + + if (!is.null(munic)) { + munic <- paste(munic, collapse = "|") + data_sf <- data_sf[grep(munic, data_sf$name, ignore.case = TRUE), ] + } + + + + if (!is.null(region)) { + tonuts <- esp_hlp_all2prov(region) + + # toprov + df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) + df <- df[df$nuts3.code %in% tonuts, "cpro"] + toprov <- unique(df) + + data_sf <- data_sf[data_sf$cpro %in% toprov, ] + } + + if (nrow(data_sf) == 0) { + stop( + "The combination of region and/or munic does ", + "not return any result" + ) + } + + + + # Move CAN + + # Checks + + moving <- FALSE + moving <- isTRUE(moveCAN) | length(moveCAN) > 1 + + + if (moving) { + if (length(grep("05", data_sf$codauto)) > 0) { + penin <- data_sf[-grep("05", data_sf$codauto), ] + can <- data_sf[grep("05", data_sf$codauto), ] + + # Move CAN + can <- esp_move_can(can, moveCAN = moveCAN) + + # Regenerate + if (nrow(penin) > 0) { + data_sf <- rbind(penin, can) + } else { + data_sf <- can + } + } + } + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) + data_sf <- + data_sf[order(data_sf$codauto, data_sf$cpro, data_sf$cmun), ] + + return(data_sf) +} + + +#' @rdname esp_get_munic +#' +#' +#' @description +#' - [esp_get_munic_siane()] uses CartoBase ANE as source, provided by +#' Instituto Geografico Nacional (IGN), . +#' Years available are 2005 up to today. +#' +#' @source +#' IGN data via a custom CDN (see +#' ). +#' +#' @param resolution Resolution of the polygon. Values available are +#' `"3"`, `"6.5"` or `"10"`. +#' +#' @inheritParams esp_get_ccaa_siane +#' +#' +#' @export +esp_get_munic_siane <- function(year = Sys.Date(), epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, resolution = 3, region = NULL, + munic = NULL, moveCAN = TRUE, rawcols = FALSE) { + init_epsg <- as.character(epsg) + year <- as.character(year) + + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + # Get Data from SIANE + data_sf <- esp_hlp_get_siane( + "munic", resolution, cache, cache_dir, + update_cache, verbose, year + ) + + colnames_init <- colnames(sf::st_drop_geometry(data_sf)) + df <- data_sf + + # Name management + df$LAU_CODE <- df$id_ine + df$name <- df$rotulo + df$cpro <- df$id_prov + + idprov <- sort(unique(mapSpain::esp_codelist$cpro)) + df$cmun <- ifelse(substr(df$LAU_CODE, 1, 2) %in% idprov, + substr(df$LAU_CODE, 3, 8), + NA + ) + + cod <- unique(mapSpain::esp_codelist[, c( + "codauto", + "ine.ccaa.name", + "cpro", "ine.prov.name" + )]) + + df2 <- merge(df, cod, by = "cpro", all.x = TRUE, no.dups = TRUE) + + data_sf <- df2 + + if (!is.null(munic)) { + munic <- paste(munic, collapse = "|") + data_sf <- data_sf[grep(munic, data_sf$name, ignore.case = TRUE), ] + } + + if (!is.null(region)) { + tonuts <- esp_hlp_all2prov(region) + # toprov + df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) + df <- df[df$nuts3.code %in% tonuts, "cpro"] + toprov <- unique(df) + data_sf <- data_sf[data_sf$cpro %in% toprov, ] + } + + if (nrow(data_sf) == 0) { + stop( + "The combination of region and/or munic does ", + "not return any result" + ) + } + # Move CAN + + # Checks + moving <- FALSE + moving <- isTRUE(moveCAN) | length(moveCAN) > 1 + + if (moving) { + if (length(grep("05", data_sf$codauto)) > 0) { + penin <- data_sf[-grep("05", data_sf$codauto), ] + can <- data_sf[grep("05", data_sf$codauto), ] + + # Move CAN + can <- esp_move_can(can, moveCAN = moveCAN) + # Regenerate + if (nrow(penin) > 0) { + data_sf <- rbind(penin, can) + } else { + data_sf <- can + } + } + } + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) + data_sf <- + data_sf[order(data_sf$codauto, data_sf$cpro, data_sf$cmun), ] + + namesend <- unique(c( + colnames_init, + c( + "codauto", "ine.ccaa.name", "cpro", "ine.prov.name", "cmun", "name", + "LAU_CODE" + ), + colnames(data_sf) + )) + + data_sf <- data_sf[, namesend] + + if (isFALSE(rawcols)) { + data_sf <- data_sf[ + , + c( + "codauto", "ine.ccaa.name", "cpro", "ine.prov.name", + "cmun", "name", "LAU_CODE" + ) + ] + } + return(data_sf) +} diff --git a/R/esp_get_nuts.R b/R/esp_get_nuts.R index 89faa208..7f1372fc 100644 --- a/R/esp_get_nuts.R +++ b/R/esp_get_nuts.R @@ -1,18 +1,18 @@ -#' Get NUTS of Spain as `sf` polygons and points +#' Get NUTS of Spain as [`sf`][sf::st_sf] `POLYGON` or `POINT` #' #' @description -#' Returns -#' [NUTS regions of Spain](https://en.wikipedia.org/wiki/NUTS_statistical_regions_of_Spain) -#' as polygons and points at a specified scale, as provided by +#' Returns [NUTS regions of +#' Spain](https://en.wikipedia.org/wiki/NUTS_statistical_regions_of_Spain) +#' as `POLYGON` or `POINT` at a specified scale, as provided by #' [GISCO](https://ec.europa.eu/eurostat/web/gisco) #' (Geographic Information System of the Commission, depending of Eurostat). #' #' NUTS are provided at three different levels: -#' * **"0"**: Country level -#' * **"1"**: Groups of autonomous communities -#' * **"2"**: Autonomous communities -#' * **"3"**: Roughly matches the provinces, but providing specific individual -#' objects for each major island +#' - **"0"**: Country level. +#' - **"1"**: Groups of autonomous communities. +#' - **"2"**: Autonomous communities (CCAA). +#' - **"3"**: Roughly matches the provinces, but providing specific individual +#' objects for each major island. #' #' @export #' @@ -20,24 +20,24 @@ #' @family nuts #' @seealso [giscoR::gisco_get_nuts()], [esp_dict_region_code()]. #' -#' @return A `sf` object specified by `spatialtype`. +#' @return A [`sf`][sf::st_sf] object specified by `spatialtype`. #' #' @note #' Please check the download and usage provisions on #' [giscoR::gisco_attributions()] #' -#' @source [GISCO API](https://gisco-services.ec.europa.eu/distribution/v2/) +#' @source +#' [GISCO API](https://gisco-services.ec.europa.eu/distribution/v2/) #' #' #' @param year Release year of the file. One of `"2003"`, `"2006"`, #' `"2010"`, `"2013"`, `"2016"` or `"2021"`. -#' #' @param epsg projection of the map: 4-digit [EPSG code](https://epsg.io/). #' One of: -#' * `"4258"`: ETRS89 -#' * `"4326"`: WGS84 -#' * `"3035"`: ETRS89 / ETRS-LAEA -#' * `"3857"`: Pseudo-Mercator +#' - `"4258"`: ETRS89. +#' - `"4326"`: WGS84. +#' - `"3035"`: ETRS89 / ETRS-LAEA. +#' - `"3857"`: Pseudo-Mercator. #' #' @param cache A logical whether to do caching. Default is `TRUE`. See #' **About caching**. @@ -51,21 +51,21 @@ #' default is `FALSE`. #' #' @param resolution Resolution of the geospatial data. One of -#' * "60": 1:60million -#' * "20": 1:20million -#' * "10": 1:10million -#' * "03": 1:3million -#' * "01": 1:1million +#' - `"60"`: 1:60million +#' - `"20"`: 1:20million +#' - `"10"`: 1:10million +#' - `"03"`: 1:3million +#' - `"01"`: 1:1million #' #' @param spatialtype Type of geometry to be returned: -#' * `"LB"`: Labels - point object. -#' * `"RG"`: Regions - polygon object. +#' - `"LB"`: Labels - `POINT` object. +#' - `"RG"`: Regions - `POLYGON` object. #' #' @param region Optional. A vector of region names, NUTS or ISO codes #' (see [esp_dict_region_code()]). #' -#' @param nuts_level NUTS level. One of "0" (Country-level), "1", "2" or "3". -#' See **Description**. +#' @param nuts_level NUTS level. One of `"0"` (Country-level), `"1"`, `"2"` or +#' `"3"`. See **Description**. #' #' @param moveCAN A logical `TRUE/FALSE` or a vector of coordinates #' `c(lat, lon)`. It places the Canary Islands close to Spain's mainland. @@ -84,92 +84,80 @@ #' corresponding .geojson file by any other method and save it on your #' `cache_dir`. Use the option `verbose = TRUE` for debugging the API query. #' -#' #' # Displacing the Canary Islands #' #' While `moveCAN` is useful for visualization, it would alter the actual #' geographic position of the Canary Islands. When using the output for #' spatial analysis or using tiles (e.g. with [esp_getTiles()] or #' [addProviderEspTiles()]) this option should be set to `FALSE` in order to -#' get the actual coordinates, instead of the modified ones. +#' get the actual coordinates, instead of the modified ones. See also +#' [esp_move_can()] for displacing stand-alone [`sf`][sf::st_sf] objects. #' #' @examples #' #' NUTS1 <- esp_get_nuts(nuts_level = 1, moveCAN = TRUE) #' +#' library(ggplot2) #' -#' library(tmap) -#' -#' tm_shape(NUTS1) + -#' tm_graticules() + -#' tm_polygons() + -#' tm_credits(giscoR::gisco_attributions(), -#' fontface = "italic", -#' size = 0.7 -#' ) + -#' tm_layout( -#' main.title = "NUTS1: Displacing Canary Islands", -#' main.title.size = 0.9, -#' main.title.fontface = "bold", -#' attr.outside = TRUE +#' ggplot(NUTS1) + +#' geom_sf() + +#' labs( +#' title = "NUTS1: Displacing Canary Islands", +#' caption = giscoR::gisco_attributions() #' ) #' +#' #' NUTS1_alt <- esp_get_nuts(nuts_level = 1, moveCAN = c(15, 0)) #' -#' tm_shape(NUTS1_alt) + -#' tm_graticules() + -#' tm_polygons() + -#' tm_credits(giscoR::gisco_attributions(), -#' fontface = "italic", -#' size = 0.7 -#' ) + -#' tm_layout( -#' main.title = "NUTS1: Displacing Canary Islands to the right", -#' main.title.size = 0.9, -#' main.title.fontface = "bold", -#' attr.outside = TRUE +#' +#' ggplot(NUTS1_alt) + +#' geom_sf() + +#' labs( +#' title = "NUTS1: Displacing Canary Islands", +#' subtitle = "to the right", +#' caption = giscoR::gisco_attributions() #' ) #' +#' #' NUTS1_orig <- esp_get_nuts(nuts_level = 1, moveCAN = FALSE) #' -#' tm_shape(NUTS1_orig) + -#' tm_graticules() + -#' tm_polygons() + -#' tm_credits(giscoR::gisco_attributions(), -#' fontface = "italic", -#' size = 0.7 -#' ) + -#' tm_layout( -#' main.title = "NUTS1: Canary Islands on the true location", -#' main.title.size = 0.9, -#' main.title.fontface = "bold", -#' attr.outside = TRUE +#' ggplot(NUTS1_orig) + +#' geom_sf() + +#' labs( +#' title = "NUTS1", +#' subtitle = "Canary Islands on the true location", +#' caption = giscoR::gisco_attributions() #' ) #' #' -#' AndOriental <- -#' esp_get_nuts(region = c("Almeria", "Granada", "Jaen", "Malaga")) +#' AndOriental <- esp_get_nuts(region = c( +#' "Almeria", "Granada", +#' "Jaen", "Malaga" +#' )) #' -#' qtm(AndOriental, main.title = "Andalucia Oriental") +#' +#' ggplot(AndOriental) + +#' geom_sf() #' #' #' #' RandomRegions <- esp_get_nuts(region = c("ES1", "ES300", "ES51")) -#' qtm(RandomRegions, main.title = "Random regions") +#' +#' ggplot(RandomRegions) + +#' geom_sf() + +#' labs(title = "Random Regions") +#' #' #' MixingCodes <- esp_get_nuts(region = c("ES4", "ES-PV", "Valencia")) -#' qtm(MixingCodes, main.title = "Mixing codes") -esp_get_nuts <- function(year = "2016", - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = "01", - spatialtype = "RG", - region = NULL, - nuts_level = "all", - moveCAN = TRUE) { +#' +#' +#' ggplot(MixingCodes) + +#' geom_sf() + +#' labs(title = "Mixing Codes") +esp_get_nuts <- function(year = "2016", epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, resolution = "01", spatialtype = "RG", + region = NULL, nuts_level = "all", moveCAN = TRUE) { init_epsg <- as.character(epsg) year <- as.character(year) resolution <- as.character(resolution) @@ -200,9 +188,16 @@ esp_get_nuts <- function(year = "2016", } # Get region id - if (is.null(region)) { - nuts_id <- NULL + # Get codes from cached data + # This overcome the issue on giscoR + # https://github.com/rOpenGov/giscoR/issues/57 + getids <- sf::st_drop_geometry(mapSpain::esp_nuts.sf) + + if (nuts_level != "all") { + getids <- getids[getids$LEVL_CODE == nuts_level, ] + } + nuts_id <- as.character(getids$NUTS_ID) } else { nuts_id <- esp_hlp_all2nuts(region) @@ -211,20 +206,18 @@ esp_get_nuts <- function(year = "2016", if (length(nuts_id) == 0) { stop( - "region ", - paste0("'", region, "'", collapse = ", "), + "region ", paste0("'", region, "'", collapse = ", "), " is not a valid name" ) } } - dwnload <- TRUE - if (year == "2016" & - resolution == "01" & - epsg == "4326" & - spatialtype == "RG" & isFALSE(update_cache)) { + if (all( + year == "2016", resolution == "01", epsg == "4326", spatialtype == "RG", + isFALSE(update_cache) + )) { if (verbose) { message("Reading from esp_nuts.sf") } @@ -244,16 +237,13 @@ esp_get_nuts <- function(year = "2016", if (dwnload) { data_sf <- giscoR::gisco_get_nuts( - resolution = resolution, - year = year, - epsg = epsg, - nuts_level = nuts_level, + resolution = resolution, year = year, + epsg = epsg, nuts_level = nuts_level, cache = cache, update_cache = update_cache, cache_dir = cache_dir, spatialtype = spatialtype, - nuts_id = nuts_id, - country = "ES", + nuts_id = nuts_id, country = "ES", verbose = verbose ) } @@ -266,26 +256,11 @@ esp_get_nuts <- function(year = "2016", if (moving) { if (length(grep("ES7", data_sf$NUTS_ID)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) penin <- data_sf[-grep("ES7", data_sf$NUTS_ID), ] can <- data_sf[grep("ES7", data_sf$NUTS_ID), ] # Move can - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) + can <- esp_move_can(can, moveCAN = moveCAN) # Regenerate if (nrow(penin) > 0) { diff --git a/R/esp_get_prov.R b/R/esp_get_prov.R index c1eba00c..2957ab97 100644 --- a/R/esp_get_prov.R +++ b/R/esp_get_prov.R @@ -1,382 +1,367 @@ -#' Get Provinces of Spain as `sf` polygons and points -#' -#' @description -#' Returns -#' [provinces of Spain](https://en.wikipedia.org/wiki/Provinces_of_Spain) -#' as polygons and points at a specified scale. -#' -#' * [esp_get_prov()] uses GISCO (Eurostat) as source. Please use -#' [giscoR::gisco_attributions()] -#' -#' -#' @family political -#' -#' @rdname esp_get_prov -#' @name esp_get_prov -#' -#' @return A `sf` object specified by `spatialtype`. -#' -#' -#' @export -#' -#' @param prov A vector of names and/or codes for provinces -#' or `NULL` to get all the provinces. See **Details**. -#' -#' @inheritDotParams esp_get_nuts -nuts_level -region -#' -#' @details -#' When using `prov` you can use and mix names and NUTS codes (levels 1, 2 or -#' 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see -#' [esp_codelist]). -#' -#' Ceuta and Melilla are considered as provinces on this dataset. -#' -#' When calling a superior level (Autonomous Community or NUTS1) , -#' all the provinces of that level would be added. -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @inheritSection esp_get_nuts Displacing the Canary Islands -#' -#' @examples -#' prov <- esp_get_prov() -#' -#' library(tmap) -#' -#' qtm(prov) -#' -#' # Random Provinces -#' -#' Random <- -#' esp_get_prov(prov = c( -#' "Zamora", -#' "Palencia", -#' "ES-GR", -#' "ES521", -#' "01" -#' )) -#' -#' tm_shape(Random) + -#' tm_polygons(col = "codauto", legend.show = FALSE, palette = "Spectral") -#' -#' -#' -#' # All Provinces of a Zone plus an addition -#' -#' Mix <- esp_get_prov(prov = c( -#' "Noroeste", -#' "Castilla y Leon", "La Rioja" -#' )) -#' -#' qtm(Mix) -#' -#' # ISO codes available -#' -#' allprovs <- esp_get_prov() -#' -#' -#' tm_shape(allprovs, point.per = "feature") + -#' tm_polygons() + -#' tm_text("iso2.prov.code", -#' remove.overlap = TRUE, -#' shadow = TRUE -#' ) -esp_get_prov <- function(prov = NULL, ...) { - params <- list(...) - - # Get region id - - prov <- prov[!is.na(prov)] - - - region <- prov - if (is.null(region)) { - nuts_id <- NULL - } else { - nuts_id <- esp_hlp_all2prov(region) - - nuts_id <- unique(nuts_id) - if (length(nuts_id) == 0) { - stop( - "region ", - paste0("'", region, "'", collapse = ", "), - " is not a valid name" - ) - } - } - - params$region <- nuts_id - params$nuts_level <- 3 - - - data_sf <- do.call(mapSpain::esp_get_nuts, params) - - # Avoid warning on union - initcrs <- sf::st_crs(data_sf) - data_sf <- sf::st_transform(data_sf, 3035) - - - data_sf$nuts3.code <- data_sf$NUTS_ID - data_sf <- data_sf[, "nuts3.code"] - - # Get cpro - - df <- mapSpain::esp_codelist - df <- unique(df[, c("nuts3.code", "cpro")]) - data_sf <- merge(data_sf, df, all.x = TRUE) - data_sf <- data_sf[, "cpro"] - - # Merge Islands - - # Extract geom column - names <- names(data_sf) - - which.geom <- - which(vapply(data_sf, function(f) { - inherits(f, "sfc") - }, TRUE)) - - nm <- names(which.geom) - - # Baleares - - if (any(data_sf$cpro %in% "07")) { - clean <- data_sf[data_sf$cpro != "07", ] - island <- data_sf[data_sf$cpro == "07", ] - g <- sf::st_union(island) - df <- unique(sf::st_drop_geometry(island)) - # Generate sf object - new <- sf::st_as_sf(df, g) - # Rename geometry to original value - newnames <- names(new) - newnames[newnames == "g"] <- nm - colnames(new) <- newnames - new <- sf::st_set_geometry(new, nm) - data_sf <- rbind(clean, new) - } - - # Las Palmas - - if (any(data_sf$cpro %in% "35")) { - clean <- data_sf[data_sf$cpro != "35", ] - island <- data_sf[data_sf$cpro == "35", ] - g <- sf::st_union(island) - df <- unique(sf::st_drop_geometry(island)) - # Generate sf object - new <- sf::st_as_sf(df, g) - # Rename geometry to original value - newnames <- names(new) - newnames[newnames == "g"] <- nm - colnames(new) <- newnames - new <- sf::st_set_geometry(new, nm) - data_sf <- rbind(clean, new) - } - - # Sta Cruz Tfe - if (any(data_sf$cpro %in% "38")) { - clean <- data_sf[data_sf$cpro != "38", ] - island <- data_sf[data_sf$cpro == "38", ] - g <- sf::st_union(island) - df <- unique(sf::st_drop_geometry(island)) - # Generate sf object - new <- sf::st_as_sf(df, g) - # Rename geometry to original value - newnames <- names(new) - newnames[newnames == "g"] <- nm - colnames(new) <- newnames - new <- sf::st_set_geometry(new, nm) - data_sf <- rbind(clean, new) - } - - - - # Get df - df <- dict_prov - df <- df[, names(df) != "key"] - - data_sf <- merge(data_sf, df, all.x = TRUE) - - # Paste nuts2 - dfnuts <- mapSpain::esp_codelist - dfnuts <- - unique(dfnuts[, c( - "cpro", - "nuts2.code", - "nuts2.name", - "nuts1.code", - "nuts1.name" - )]) - data_sf <- merge(data_sf, dfnuts, all.x = TRUE) - data_sf <- - data_sf[, c( - colnames(df), - "nuts2.code", - "nuts2.name", - "nuts1.code", - "nuts1.name" - )] - - # Order - data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] - - # Transform - - data_sf <- sf::st_transform(data_sf, initcrs) - - return(data_sf) -} - - -#' @rdname esp_get_prov -#' @name esp_get_prov_siane -#' -#' -#' @description -#' * [esp_get_prov_siane()] uses CartoBase ANE as source, provided by Instituto -#' Geografico Nacional (IGN), . Years -#' available are 2005 up to today. -#' -#' @source -#' IGN data via a custom CDN (see -#' ). -#' -#' @export -#' -#' @param year Release year. See [esp_get_nuts()] for [esp_get_prov()] and -#' **Details** for [esp_get_prov_siane()] -#' -#' @inheritParams esp_get_ccaa -#' -#' @details -#' On [esp_get_prov_siane()], `year` could be passed as a single year ("YYYY" -#' format, as end of year) or as a specific date ("YYYY-MM-DD" format). -#' Historical information starts as of 2005. -esp_get_prov_siane <- function(prov = NULL, - year = Sys.Date(), - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = "3", - moveCAN = TRUE, - rawcols = FALSE) { - init_epsg <- as.character(epsg) - year <- as.character(year) - - - if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { - stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") - } - - # Get Data from SIANE - data_sf <- esp_hlp_get_siane( - "prov", - resolution, - cache, - cache_dir, - update_cache, - verbose, - year - ) - - - colnames_init <- colnames(sf::st_drop_geometry(data_sf)) - - - data_sf$cpro <- data_sf$id_prov - - if (!is.null(prov)) { - tonuts <- esp_hlp_all2prov(prov) - # toprov - df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) - df <- df[df$nuts3.code %in% tonuts, "cpro"] - toprov <- unique(df) - data_sf <- data_sf[data_sf$cpro %in% toprov, ] - } - - if (nrow(data_sf) == 0) { - stop( - "provs '", - paste0(prov, collapse = "', "), - "' does not return any result" - ) - } - - # Get df - df <- dict_prov - df <- df[, names(df) != "key"] - - data_sf <- merge(data_sf, df, all.x = TRUE) - - # Paste nuts2 - dfnuts <- mapSpain::esp_codelist - dfnuts <- - unique(dfnuts[, c( - "cpro", - "nuts2.code", - "nuts2.name", - "nuts1.code", - "nuts1.name" - )]) - data_sf <- merge(data_sf, dfnuts, all.x = TRUE) - - - # Move can - - # Checks - moving <- FALSE - moving <- isTRUE(moveCAN) | length(moveCAN) > 1 - - if (moving) { - if (length(grep("05", data_sf$codauto)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) - penin <- data_sf[-grep("05", data_sf$codauto), ] - can <- data_sf[grep("05", data_sf$codauto), ] - - # Move can - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) - - # Regenerate - if (nrow(penin) > 0) { - data_sf <- rbind(penin, can) - } else { - data_sf <- can - } - } - } - - data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) - - - # Order - data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] - - namesend <- unique(c( - colnames_init, - colnames(esp_get_prov()) - )) - - data_sf <- data_sf[, namesend] - - - if (isFALSE(rawcols)) { - data_sf <- data_sf[, colnames(esp_get_prov())] - } - - return(data_sf) -} +#' Get Provinces of Spain as [`sf`][sf::st_sf] `POLYGON` or `POINT` +#' +#' @description +#' Returns +#' [provinces of Spain](https://en.wikipedia.org/wiki/Provinces_of_Spain) +#' as `POLYGON` or `POINT` at a specified scale. +#' +#' - [esp_get_prov()] uses GISCO (Eurostat) as source. Please use +#' [giscoR::gisco_attributions()] +#' +#' +#' @family political +#' +#' @rdname esp_get_prov +#' @name esp_get_prov +#' +#' @return A [`sf`][sf::st_sf] object specified by `spatialtype`. +#' +#' +#' @export +#' +#' @param prov A vector of names and/or codes for provinces or `NULL` to get all +#' the provinces. See **Details**. +#' +#' @inheritDotParams esp_get_nuts -nuts_level -region +#' +#' @details +#' When using `prov` you can use and mix names and NUTS codes (levels 1, 2 or +#' 3), ISO codes (corresponding to level 2 or 3) or "cpro" (see +#' [esp_codelist]). +#' +#' Ceuta and Melilla are considered as provinces on this dataset. +#' +#' When calling a higher level (Autonomous Community or NUTS1), all the +#' provinces of that level would be added. +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @inheritSection esp_get_nuts Displacing the Canary Islands +#' +#' @examples +#' prov <- esp_get_prov() +#' +#' library(ggplot2) +#' +#' ggplot(prov) + +#' geom_sf() + +#' theme_void() +#' +#' \donttest{ +#' # Random Provinces +#' +#' Random <- esp_get_prov(prov = c( +#' "Zamora", "Palencia", "ES-GR", +#' "ES521", "01" +#' )) +#' +#' +#' ggplot(Random) + +#' geom_sf(aes(fill = codauto), show.legend = FALSE, alpha = 0.5) + +#' scale_fill_manual(values = hcl.colors( +#' nrow(Random), "Spectral" +#' )) + +#' theme_minimal() +#' +#' +#' # All Provinces of a Zone plus an addition +#' +#' Mix <- esp_get_prov(prov = c( +#' "Noroeste", +#' "Castilla y Leon", "La Rioja" +#' )) +#' +#' Mix$CCAA <- esp_dict_region_code( +#' Mix$codauto, +#' origin = "codauto" +#' ) +#' +#' ggplot(Mix) + +#' geom_sf(aes(fill = CCAA), alpha = 0.5) + +#' scale_fill_discrete(type = hcl.colors(5, "Temps")) + +#' theme_classic() +#' +#' # ISO codes available +#' +#' allprovs <- esp_get_prov() +#' +#' ggplot(allprovs) + +#' geom_sf(fill = NA) + +#' geom_sf_text(aes(label = iso2.prov.code), +#' check_overlap = TRUE, +#' fontface = "bold" +#' ) + +#' theme_void() +#' } +esp_get_prov <- function(prov = NULL, moveCAN = TRUE, ...) { + params <- list(...) + + # Get region id + + prov <- prov[!is.na(prov)] + + + region <- prov + if (is.null(region)) { + nuts_id <- NULL + } else { + nuts_id <- esp_hlp_all2prov(region) + + nuts_id <- unique(nuts_id) + if (length(nuts_id) == 0) { + stop( + "region ", + paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + } + + params$region <- nuts_id + params$nuts_level <- 3 + params$moveCAN <- moveCAN + + data_sf <- do.call(mapSpain::esp_get_nuts, params) + + # Avoid warning on union + initcrs <- sf::st_crs(data_sf) + data_sf <- sf::st_transform(data_sf, 3035) + + + data_sf$nuts3.code <- data_sf$NUTS_ID + data_sf <- data_sf[, "nuts3.code"] + + # Get cpro + + df <- mapSpain::esp_codelist + df <- unique(df[, c("nuts3.code", "cpro")]) + data_sf <- merge(data_sf, df, all.x = TRUE) + data_sf <- data_sf[, "cpro"] + + # Merge Islands + + # Extract geom column + names <- names(data_sf) + + which.geom <- + which(vapply(data_sf, function(f) { + inherits(f, "sfc") + }, TRUE)) + + nm <- names(which.geom) + + # Baleares + + if (any(data_sf$cpro %in% "07")) { + clean <- data_sf[data_sf$cpro != "07", ] + island <- data_sf[data_sf$cpro == "07", ] + g <- sf::st_union(island) + df <- unique(sf::st_drop_geometry(island)) + # Generate sf object + new <- sf::st_as_sf(df, g) + # Rename geometry to original value + newnames <- names(new) + newnames[newnames == "g"] <- nm + colnames(new) <- newnames + new <- sf::st_set_geometry(new, nm) + data_sf <- rbind(clean, new) + } + + # Las Palmas + + if (any(data_sf$cpro %in% "35")) { + clean <- data_sf[data_sf$cpro != "35", ] + island <- data_sf[data_sf$cpro == "35", ] + g <- sf::st_union(island) + df <- unique(sf::st_drop_geometry(island)) + # Generate sf object + new <- sf::st_as_sf(df, g) + # Rename geometry to original value + newnames <- names(new) + newnames[newnames == "g"] <- nm + colnames(new) <- newnames + new <- sf::st_set_geometry(new, nm) + data_sf <- rbind(clean, new) + } + + # Sta Cruz Tfe + if (any(data_sf$cpro %in% "38")) { + clean <- data_sf[data_sf$cpro != "38", ] + island <- data_sf[data_sf$cpro == "38", ] + g <- sf::st_union(island) + df <- unique(sf::st_drop_geometry(island)) + # Generate sf object + new <- sf::st_as_sf(df, g) + # Rename geometry to original value + newnames <- names(new) + newnames[newnames == "g"] <- nm + colnames(new) <- newnames + new <- sf::st_set_geometry(new, nm) + data_sf <- rbind(clean, new) + } + + + + # Get df + df <- dict_prov + df <- df[, names(df) != "key"] + + data_sf <- merge(data_sf, df, all.x = TRUE) + + # Paste nuts2 + dfnuts <- mapSpain::esp_codelist + dfnuts <- + unique(dfnuts[, c( + "cpro", + "nuts2.code", + "nuts2.name", + "nuts1.code", + "nuts1.name" + )]) + data_sf <- merge(data_sf, dfnuts, all.x = TRUE) + data_sf <- data_sf[, c( + colnames(df), "nuts2.code", "nuts2.name", + "nuts1.code", "nuts1.name" + )] + + # Order + data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] + + # Transform + + data_sf <- sf::st_transform(data_sf, initcrs) + + return(data_sf) +} + + +#' @rdname esp_get_prov +#' @name esp_get_prov_siane +#' +#' +#' @description +#' - [esp_get_prov_siane()] uses CartoBase ANE as source, provided by Instituto +#' Geografico Nacional (IGN), . Years +#' available are 2005 up to today. +#' +#' @source +#' IGN data via a custom CDN (see +#' ). +#' +#' @export +#' +#' @param year Release year. See [esp_get_nuts()] for [esp_get_prov()] and +#' **Details** for [esp_get_prov_siane()]. +#' +#' @inheritParams esp_get_ccaa +#' +#' @details +#' On [esp_get_prov_siane()], `year` could be passed as a single year ("YYYY" +#' format, as end of year) or as a specific date ("YYYY-MM-DD" format). +#' Historical information starts as of 2005. +esp_get_prov_siane <- function(prov = NULL, year = Sys.Date(), epsg = "4258", + cache = TRUE, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE, + resolution = "3", moveCAN = TRUE, + rawcols = FALSE) { + init_epsg <- as.character(epsg) + year <- as.character(year) + + + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + # Get Data from SIANE + data_sf <- esp_hlp_get_siane( + "prov", resolution, cache, cache_dir, + update_cache, verbose, year + ) + + + colnames_init <- colnames(sf::st_drop_geometry(data_sf)) + + + data_sf$cpro <- data_sf$id_prov + + if (!is.null(prov)) { + tonuts <- esp_hlp_all2prov(prov) + # toprov + df <- unique(mapSpain::esp_codelist[, c("nuts3.code", "cpro")]) + df <- df[df$nuts3.code %in% tonuts, "cpro"] + toprov <- unique(df) + data_sf <- data_sf[data_sf$cpro %in% toprov, ] + } + + if (nrow(data_sf) == 0) { + stop( + "provs '", + paste0(prov, collapse = "', "), + "' does not return any result" + ) + } + + # Get df + df <- dict_prov + df <- df[, names(df) != "key"] + + data_sf <- merge(data_sf, df, all.x = TRUE) + + # Paste nuts2 + dfnuts <- mapSpain::esp_codelist + dfnuts <- unique(dfnuts[, c( + "cpro", "nuts2.code", "nuts2.name", "nuts1.code", + "nuts1.name" + )]) + data_sf <- merge(data_sf, dfnuts, all.x = TRUE) + + + # Move can + + # Checks + moving <- FALSE + moving <- isTRUE(moveCAN) | length(moveCAN) > 1 + + if (moving) { + if (length(grep("05", data_sf$codauto)) > 0) { + penin <- data_sf[-grep("05", data_sf$codauto), ] + can <- data_sf[grep("05", data_sf$codauto), ] + + can <- esp_move_can(can, moveCAN = moveCAN) + + # Regenerate + if (nrow(penin) > 0) { + data_sf <- rbind(penin, can) + } else { + data_sf <- can + } + } + } + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) + + + # Order + data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] + + namesend <- unique(c( + colnames_init, + colnames(esp_get_prov()) + )) + + # Review this error, can't fully reproduce + + namesend <- namesend[namesend %in% names(data_sf)] + + data_sf <- data_sf[, namesend] + + + if (isFALSE(rawcols)) { + nm <- colnames(esp_get_prov()) + nm <- nm[nm %in% colnames(data_sf)] + + data_sf <- data_sf[, nm] + } + + return(data_sf) +} diff --git a/R/esp_get_railway.R b/R/esp_get_railway.R index 62250f34..537f01a7 100644 --- a/R/esp_get_railway.R +++ b/R/esp_get_railway.R @@ -1,93 +1,93 @@ -#' Get `sf` lines and points with the railways of Spain -#' -#' @description -#' Loads a `sf` lines or point object representing the nodes and railway -#' lines of Spain. -#' -#' @family infrastructure -#' -#' @return A `sf` line or point object. -#' -#' @source IGN data via a custom CDN (see -#' ). -#' -#' @export -#' -#' @param year Release year. -#' -#' @param spatialtype Spatial type of the output. Use `"line"` -#' for extracting the railway as lines and `"point"` for extracting -#' stations. -#' -#' @inheritParams esp_get_roads -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @examples -#' \donttest{ -#' -#' provs <- esp_get_prov() -#' ccaa <- esp_get_ccaa() -#' -#' # Railways -#' rails <- esp_get_railway() -#' -#' # Stations -#' stations <- esp_get_railway(spatialtype = "point") -#' -#' # Map -#' -#' library(tmap) -#' -#' tm_shape(provs, bbox = c(-7.5, 38, -2.5, 41)) + -#' tm_polygons(col = "grey99", border.col = "grey50") + -#' tm_shape(ccaa) + -#' tm_borders("black") + -#' tm_shape(rails) + -#' tm_lines("tipo", -#' legend.col.show = FALSE, lwd = 3, -#' palette = "viridis" -#' ) + -#' tm_shape(stations) + -#' tm_symbols("red", size = .3, alpha = 0.5, shape = 19) -#' } -esp_get_railway <- function(year = Sys.Date(), - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - spatialtype = "line") { - init_epsg <- as.character(epsg) - year <- as.character(year) - - if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { - stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") - } - - - # Valid spatialtype - validspatialtype <- c("line", "point") - - if (!spatialtype %in% validspatialtype) { - stop( - "spatialtype should be one of '", - paste0(validspatialtype, collapse = "', "), - "'" - ) - } - - type <- paste0("ffcc", spatialtype) - - - data_sf <- esp_hlp_get_siane(type, - "3", - cache, - cache_dir, - update_cache, - verbose, - year = Sys.Date() - ) - - data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) -} +#' Get [`sf`][sf::st_sf] `LINESTRING` or `POINT` with the railways of Spain +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `LINESTRING` or `POINT` object representing the +#' nodes and railway lines of Spain. +#' +#' @family infrastructure +#' +#' @return A [`sf`][sf::st_sf] `LINESTRING` or `POINT` object. +#' +#' @source IGN data via a custom CDN (see +#' ). +#' +#' @export +#' +#' @param year Release year. +#' +#' @param spatialtype Spatial type of the output. Use `"line"` +#' for extracting the railway as lines and `"point"` for extracting +#' stations. +#' +#' @inheritParams esp_get_roads +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' +#' provs <- esp_get_prov() +#' ccaa <- esp_get_ccaa() +#' +#' # Railways +#' rails <- esp_get_railway() +#' +#' # Stations +#' stations <- esp_get_railway(spatialtype = "point") +#' +#' # Map +#' +#' library(ggplot2) +#' +#' ggplot(provs) + +#' geom_sf(fill = "grey99", color = "grey50") + +#' geom_sf(data = ccaa, fill = NA) + +#' geom_sf( +#' data = rails, aes(color = tipo), +#' show.legend = FALSE, linewidth = 1.5 +#' ) + +#' geom_sf( +#' data = stations, +#' color = "red", alpha = 0.5 +#' ) + +#' coord_sf( +#' xlim = c(-7.5, -2.5), +#' ylim = c(38, 41) +#' ) + +#' scale_color_manual(values = hcl.colors( +#' length(unique(rails$tipo)), "viridis" +#' )) + +#' theme_minimal() +#' } +esp_get_railway <- function(year = Sys.Date(), epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, spatialtype = "line") { + init_epsg <- as.character(epsg) + year <- as.character(year) + + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + + # Valid spatialtype + validspatialtype <- c("line", "point") + + if (!spatialtype %in% validspatialtype) { + stop( + "spatialtype should be one of '", + paste0(validspatialtype, collapse = "', "), + "'" + ) + } + + type <- paste0("ffcc", spatialtype) + + + data_sf <- esp_hlp_get_siane(type, "3", cache, cache_dir, update_cache, + verbose, + year = Sys.Date() + ) + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) +} diff --git a/R/esp_get_rivers.R b/R/esp_get_rivers.R index 09c52e24..f987cb8d 100644 --- a/R/esp_get_rivers.R +++ b/R/esp_get_rivers.R @@ -1,12 +1,13 @@ -#' Get `sf` polygon and lines of rivers, channels and other wetlands of Spain +#' Get [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` of rivers, channels and other +#' wetlands of Spain #' #' @description -#' Loads a `sf` polygon or line object representing rivers, channels, -#' reservoirs and other wetlands of Spain +#' Loads a [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` object representing +#' rivers, channels, reservoirs and other wetlands of Spain. #' #' @family natural #' -#' @return A `sf` polygon or line object. +#' @return A [`sf`][sf::st_sf] `POLYGON` or `LINESTRING` object. #' #' #' @source IGN data via a custom CDN (see @@ -14,7 +15,7 @@ #' #' @export #' -#' @param resolution Resolution of the polygon. Values available are +#' @param resolution Resolution of the `POLYGON`. Values available are #' `"3"`, `"6.5"` or `"10"`. #' #' @inheritParams esp_get_hypsobath @@ -26,7 +27,7 @@ #' Metadata available on #' . #' -#' @examples +#' @examplesIf esp_check_access() #' \donttest{ #' # Use of regex #' @@ -45,33 +46,38 @@ #' MainRivers <- #' esp_get_rivers(name = "Tajo$|Ebro$|Ebre$|Duero|Guadiana$|Guadalquivir") #' +#' sf::st_bbox(MainRivers) +#' library(ggplot2) #' -#' library(tmap) -#' -#' tm_shape(shapeEsp, bbox = MainRivers) + -#' tm_borders() + -#' tm_shape(MainRivers) + -#' tm_lines(col = "skyblue", lwd = 3) +#' ggplot(shapeEsp) + +#' geom_sf() + +#' geom_sf(data = MainRivers, color = "skyblue", linewidth = 2) + +#' coord_sf( +#' xlim = c(-7.5, 1), +#' ylim = c(36.8, 43) +#' ) + +#' theme_void() #' #' #' # Wetlands in South-West Andalucia #' and <- esp_get_prov(c("Huelva", "Sevilla", "Cadiz")) #' Wetlands <- esp_get_rivers(spatialtype = "area") #' -#' -#' tm_shape(and) + -#' tm_polygons() + -#' tm_shape(Wetlands) + -#' tm_polygons(col = "skyblue", alpha = 0.5, border.col = "skyblue", lwd = 2) +#' ggplot(and) + +#' geom_sf() + +#' geom_sf( +#' data = Wetlands, fill = "skyblue", +#' color = "skyblue", alpha = 0.5 +#' ) + +#' coord_sf( +#' xlim = c(-7.5, -4.5), +#' ylim = c(36, 38.5) +#' ) + +#' theme_void() #' } -esp_get_rivers <- function(epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - resolution = "3", - spatialtype = "line", - name = NULL) { +esp_get_rivers <- function(epsg = "4258", cache = TRUE, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE, resolution = "3", + spatialtype = "line", name = NULL) { # Check epsg init_epsg <- as.character(epsg) if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { @@ -92,39 +98,22 @@ esp_get_rivers <- function(epsg = "4258", type <- paste0("river", spatialtype) # Get shape - rivers_sf <- - esp_hlp_get_siane( - type, - resolution, - cache, - cache_dir, - update_cache, - verbose, - Sys.Date() - ) + rivers_sf <- esp_hlp_get_siane( + type, resolution, cache, cache_dir, + update_cache, verbose, Sys.Date() + ) # Get river names - rivernames <- - esp_hlp_get_siane( - "rivernames", - resolution, - cache, - cache_dir, - update_cache, - verbose, - Sys.Date() - ) - - + rivernames <- esp_hlp_get_siane( + "rivernames", resolution, cache, cache_dir, + update_cache, verbose, Sys.Date() + ) # Merge names rivernames$id_rio <- rivernames$PFAFRIO rivernames <- rivernames[, c("id_rio", "NOM_RIO")] - rivers_sf_merge <- merge(rivers_sf, - rivernames, - all.x = TRUE - ) + rivers_sf_merge <- merge(rivers_sf, rivernames, all.x = TRUE) if (!is.null(name)) { getrows1 <- grep(name, rivers_sf_merge$rotulo) @@ -134,22 +123,19 @@ esp_get_rivers <- function(epsg = "4258", if (nrow(rivers_sf_merge) == 0) { stop( - "Your value '", - name, - "' for name does not produce any result ", - "for spatialtype = '", - spatialtype, - "'" + "Your value '", name, "' for name does not produce any result ", + "for spatialtype = '", spatialtype, "'" ) } } if (spatialtype == "area") { - rivers_sf_merge <- - rivers_sf_merge[, -match("NOM_RIO", colnames(rivers_sf_merge))] + rivers_sf_merge <- rivers_sf_merge[, -match( + "NOM_RIO", + colnames(rivers_sf_merge) + )] } - rivers_sf_merge <- - sf::st_transform(rivers_sf_merge, as.double(init_epsg)) + rivers_sf_merge <- sf::st_transform(rivers_sf_merge, as.double(init_epsg)) return(rivers_sf_merge) } diff --git a/R/esp_get_roads.R b/R/esp_get_roads.R index 5477ae73..40f49a4b 100644 --- a/R/esp_get_roads.R +++ b/R/esp_get_roads.R @@ -1,132 +1,114 @@ -#' Get `sf` lines of the roads of Spain -#' -#' @description -#' Loads a `sf` line object representing the main roads of Spain. -#' -#' @family infrastructure -#' -#' @return A `sf` line object. -#' -#' @source IGN data via a custom CDN (see -#' ). -#' -#' -#' @param year Release year. See **Details** for years available. -#' @inheritParams esp_get_nuts -#' -#' @inheritSection esp_get_nuts About caching -#' -#' @inheritSection esp_get_nuts Displacing the Canary Islands -#' -#' @export -#' @details -#' `year` could be passed as a single year ("YYYY" format, as end of year) or -#' as a specific date ("YYYY-MM-DD" format). -#' -#' -#' @examples -#' \donttest{ -#' #' -#' country <- esp_get_country() -#' Roads <- esp_get_roads() -#' -#' -#' library(tmap) -#' -#' tm_shape(country) + -#' tm_fill(col = "grey90") + -#' tm_shape(Roads) + -#' tm_lines("tipo", -#' palette = c("#003399", "#003399", "#ff0000", "#ffff00") -#' ) + -#' tm_layout( -#' legend.outside = TRUE, -#' legend.outside.position = "bottom" -#' ) -#' } -esp_get_roads <- function(year = Sys.Date(), - epsg = "4258", - cache = TRUE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE, - moveCAN = TRUE) { - init_epsg <- as.character(epsg) - year <- as.character(year) - - if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { - stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") - } - - # Get Data from SIANE - data_sf <- esp_hlp_get_siane( - "roads", - 3, - cache, - cache_dir, - update_cache, - verbose, - year - ) - - - colnames_init <- colnames(sf::st_drop_geometry(data_sf)) - - # Buffer around Canary Island to identify roads - data_sf2 <- sf::st_transform(data_sf, 3857) - canbuff <- sf::st_transform(esp_get_ccaa("Canarias", moveCAN = FALSE), 3857) - canbuff <- sf::st_buffer(sf::st_union(canbuff), 20000) - - can_logic <- sf::st_intersects(data_sf2, canbuff, sparse = FALSE) - data_sf$codauto <- "XX" - data_sf[can_logic, ]$codauto <- "05" - - - - - # Move can - # Checks - moving <- FALSE - moving <- isTRUE(moveCAN) | length(moveCAN) > 1 - - if (moving) { - if (length(grep("05", data_sf$codauto)) > 0) { - offset <- c(550000, 920000) - - if (length(moveCAN) > 1) { - coords <- sf::st_point(moveCAN) - coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) - coords <- sf::st_transform(coords, 3857) - coords <- sf::st_coordinates(coords) - offset <- offset + as.double(coords) - } - - data_sf <- sf::st_transform(data_sf, 3857) - penin <- data_sf[-grep("05", data_sf$codauto), ] - can <- data_sf[grep("05", data_sf$codauto), ] - - # Change geometry name on penin - penin <- sf::st_sf( - sf::st_drop_geometry(penin), - geometry = sf::st_geometry(penin), - crs = sf::st_crs(penin) - ) - - # Move can - can <- sf::st_sf( - sf::st_drop_geometry(can), - geometry = sf::st_geometry(can) + offset, - crs = sf::st_crs(can) - ) - - # Regenerate - data_sf <- rbind(penin, can) - } - } - - data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) - - data_sf <- data_sf[, colnames_init] - - return(data_sf) -} +#' Get [`sf`][sf::st_sf] `LINESTRING` of the roads of Spain +#' +#' @description +#' Loads a [`sf`][sf::st_sf] `LINESTRING` object representing the main roads of +#' Spain. +#' +#' @family infrastructure +#' +#' @return A [`sf`][sf::st_sf] `LINESTRING` object. +#' +#' @source IGN data via a custom CDN (see +#' ). +#' +#' +#' @param year Release year. See **Details** for years available. +#' @inheritParams esp_get_nuts +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @inheritSection esp_get_nuts Displacing the Canary Islands +#' +#' @export +#' @details +#' `year` could be passed as a single year ("YYYY" format, as end of year) or +#' as a specific date ("YYYY-MM-DD" format). +#' +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' +#' country <- esp_get_country() +#' Roads <- esp_get_roads() +#' +#' library(ggplot2) +#' +#' ggplot(country) + +#' geom_sf(fill = "grey90") + +#' geom_sf(data = Roads, aes(color = tipo), show.legend = "line") + +#' scale_color_manual( +#' values = c("#003399", "#003399", "#ff0000", "#ffff00") +#' ) + +#' guides(color = guide_legend(direction = "vertical")) + +#' theme_minimal() + +#' labs(color = "Road type") + +#' theme(legend.position = "bottom") +#' } +esp_get_roads <- function(year = Sys.Date(), epsg = "4258", cache = TRUE, + update_cache = FALSE, cache_dir = NULL, + verbose = FALSE, moveCAN = TRUE) { + init_epsg <- as.character(epsg) + year <- as.character(year) + + if (!init_epsg %in% c("4326", "4258", "3035", "3857")) { + stop("epsg value not valid. It should be one of 4326, 4258, 3035 or 3857") + } + + # Get Data from SIANE + data_sf <- esp_hlp_get_siane( + "roads", 3, cache, cache_dir, update_cache, + verbose, year + ) + + + colnames_init <- colnames(sf::st_drop_geometry(data_sf)) + + # Buffer around Canary Island to identify roads + data_sf2 <- sf::st_transform(data_sf, 3857) + canbuff <- sf::st_transform(esp_get_ccaa("Canarias", moveCAN = FALSE), 3857) + canbuff <- sf::st_buffer(sf::st_union(canbuff), 20000) + + can_logic <- sf::st_intersects(data_sf2, canbuff, sparse = FALSE) + data_sf$codauto <- "XX" + data_sf[can_logic, ]$codauto <- "05" + + + + + # Move can + # Checks + moving <- FALSE + moving <- isTRUE(moveCAN) | length(moveCAN) > 1 + + if (moving) { + if (length(grep("05", data_sf$codauto)) > 0) { + data_sf <- sf::st_transform(data_sf, 3857) + penin <- data_sf[-grep("05", data_sf$codauto), ] + can <- data_sf[grep("05", data_sf$codauto), ] + + # Change geometry name on penin + penin <- sf::st_sf( + sf::st_drop_geometry(penin), + geometry = sf::st_geometry(penin), + crs = sf::st_crs(penin) + ) + + # Move can + can <- sf::st_sf(sf::st_drop_geometry(can), + geometry = sf::st_geometry(can), crs = sf::st_crs(can) + ) + + can <- esp_move_can(can, moveCAN = moveCAN) + + + # Regenerate + data_sf <- rbind(penin, can) + } + } + + data_sf <- sf::st_transform(data_sf, as.double(init_epsg)) + + data_sf <- data_sf[, colnames_init] + + return(data_sf) +} diff --git a/R/esp_get_simplified.R b/R/esp_get_simplified.R new file mode 100644 index 00000000..06b418bb --- /dev/null +++ b/R/esp_get_simplified.R @@ -0,0 +1,162 @@ +#' Get a simplified map of provinces and autonomous communities of Spain +#' +#' @description +#' Loads a simplified map ([`sf`][sf::st_sf] object) with the boundaries of the +#' provinces or autonomous communities of Spain, as provided by the **INE** +#' (Instituto Nacional de Estadistica). +#' +#' @rdname esp_get_simplified +#' +#' @export +#' +#' @family political +#' +#' @return A [`sf`][sf::st_sf] `POLYGON` object. +#' +#' @inheritParams esp_get_prov +#' +#' @inheritParams esp_get_ccaa +#' +#' @inheritSection esp_get_nuts About caching +#' +#' @seealso [esp_get_hex_prov()], [esp_get_hex_ccaa()] +#' +#' @source INE: PC_Axis files +#' +#' @details +#' +#' Results are provided **without CRS**, as provided on source. +#' +#' You can use and mix names, ISO codes, `"codauto"/"cpro"` codes (see +#' [esp_codelist]) and NUTS codes of different levels. +#' +#' When using a code corresponding of a higher level (e.g. +#' `esp_get_simpl_prov("Andalucia")`) all the corresponding units of that level +#' are provided (in this case , all the provinces of Andalusia). +#' +#' @examplesIf esp_check_access() +#' \donttest{ +#' prov_simp <- esp_get_simpl_prov() +#' +#' library(ggplot2) +#' +#' ggplot(prov_simp) + +#' geom_sf(aes(fill = ine.ccaa.name)) + +#' labs(fill = "CCAA") +#' +#' # Provs of Single CCAA +#' +#' and_simple <- esp_get_simpl_prov("Andalucia") +#' +#' ggplot(and_simple) + +#' geom_sf() +#' +#' # CCAAs +#' +#' ccaa_simp <- esp_get_simpl_ccaa() +#' +#' ggplot(ccaa_simp) + +#' geom_sf() + +#' geom_sf_text(aes(label = ine.ccaa.name), check_overlap = TRUE) +#' } +esp_get_simpl_prov <- function(prov = NULL, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE) { + region <- prov + + # Url + api_entry <- "https://github.com/rOpenSpain/mapSpain/raw/sianedata/INE/" + filename <- "ine_prov_simplified.gpkg" + + + data_sf <- esp_hlp_dwnload_sianedata( + api_entry = api_entry, + filename = filename, + cache_dir = cache_dir, verbose = verbose, + update_cache = update_cache, + cache = TRUE + ) + + region <- unique(region) + + + if (!is.null(region)) { + region <- esp_hlp_all2prov(region) + + region <- unique(region) + if (length(region) == 0) { + stop( + "region ", + paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + + dfcpro <- mapSpain::esp_codelist + dfcpro <- unique(dfcpro[, c("nuts3.code", "cpro")]) + cprocodes <- unique(dfcpro[dfcpro$nuts3.code %in% region, ]$cpro) + + data_sf <- data_sf[data_sf$cpro %in% cprocodes, ] + } + + # Order + data_sf <- data_sf[order(data_sf$codauto, data_sf$cpro), ] + + sf::st_crs(data_sf) <- NA + + + return(data_sf) +} + +#' @rdname esp_get_simplified +#' +#' @export +esp_get_simpl_ccaa <- function(ccaa = NULL, update_cache = FALSE, + cache_dir = NULL, verbose = FALSE) { + region <- ccaa + + # Url + api_entry <- "https://github.com/rOpenSpain/mapSpain/raw/sianedata/INE/" + filename <- "ine_ccaa_simplified.gpkg" + + + data_sf <- esp_hlp_dwnload_sianedata( + api_entry = api_entry, + filename = filename, + cache_dir = cache_dir, verbose = verbose, + update_cache = update_cache, + cache = TRUE + ) + + + + region <- unique(region) + + + if (!is.null(region)) { + nuts_id <- esp_hlp_all2ccaa(region) + # to codauto + codauto <- esp_dict_region_code(nuts_id, + origin = "nuts", + destination = "codauto" + ) + + + codauto <- unique(codauto) + codauto <- codauto[!is.na(codauto)] + if (length(codauto) == 0) { + stop( + "region ", paste0("'", region, "'", collapse = ", "), + " is not a valid name" + ) + } + + data_sf <- data_sf[data_sf$codauto %in% codauto, ] + } + + # Order + data_sf <- data_sf[order(data_sf$codauto), ] + + sf::st_crs(data_sf) <- NA + + return(data_sf) +} diff --git a/R/esp_make_provider.R b/R/esp_make_provider.R new file mode 100644 index 00000000..c78cd89d --- /dev/null +++ b/R/esp_make_provider.R @@ -0,0 +1,112 @@ +#' Create a custom tile provider +#' +#' @description +#' Helper function for [esp_getTiles()] that helps to create a custom provider. +#' +#' @family imagery utilities +#' @seealso [esp_getTiles()]. +#' +#' For a list of potential providers from Spain check +#' [IDEE Directory](https://www.idee.es/segun-tipo-de-servicio). +#' +#' +#' @return +#' A named list with two elements `id` and `q`. +#' +#' @export +#' +#' @param id An identifier for the user. Would be used also for identifying +#' cached tiles. +#' +#' @param q The base url of the service. +#' +#' @param service The type of tile service, either `"WMS"` or `"WMTS"`. +#' +#' @param layers The name of the layer to retrieve. +#' +#' @param ... Additional parameters to the query, like `version`, `format`, +#' `crs/srs`, `style`, ... depending on the capabilities of the service. +#' +#' @details +#' This function is meant to work with services provided as of the +#' [OGC +#' Standard](http://opengeospatial.github.io/e-learning/wms/text/operations.html#getmap). +#' +#' Note that: +#' - \CRANpkg{mapSpain} would not provide advice on the parameter `q` to be +#' provided. +#' - Currently, on **WMTS** requests only services with +#' `tilematrixset=GoogleMapsCompatible` are supported. +#' +#' @examples +#' \dontrun{ +#' # This script downloads tiles to your local machine +#' # Run only if you are online +#' +#' custom_wms <- esp_make_provider( +#' id = "an_id_for_caching", +#' q = "https://idecyl.jcyl.es/geoserver/ge/wms?", +#' service = "WMS", +#' version = "1.3.0", +#' layers = "geolog_cyl_litologia" +#' ) +#' +#' x <- esp_get_ccaa("Castilla y León", epsg = 3857) +#' +#' mytile <- esp_getTiles(x, type = custom_wms) +#' +#' tidyterra::autoplot(mytile) + +#' ggplot2::geom_sf(data = x, fill = NA) +#' } +esp_make_provider <- function(id, q, service, layers, ...) { + dots <- list(...) + names(dots) <- tolower(names(dots)) + + # Ignore tilematrixset + dots <- dots[names(dots) != "tilematrixset"] + + # Minimal for WMS + + if (toupper(service) == "WMS") { + def_params <- list( + q = q, request = "GetMap", service = "WMS", + format = "image/png", layers = layers, styles = "" + ) + } else { + def_params <- list( + q = q, request = "GetTile", service = "WMTS", + version = "1.0.0", format = "image/png", layer = layers, + style = "", tilematrixset = "GoogleMapsCompatible" + ) + } + + # Modify + end <- modifyList(def_params, dots) + + + # Here adjust crs values + + if (end$service == "WMS") { + if (all(!is.null(end$version), end$version < "1.3.0")) { + names(end) <- gsub("crs", "srs", names(end)) + end$srs <- ifelse(is.null(end$srs), "EPSG:3857", end$srs) + } else { + names(end) <- gsub("srs", "crs", names(end)) + end$crs <- ifelse(is.null(end$crs), "EPSG:3857", end$crs) + } + } + + + # Create final list + final <- list(id = id) + + # Create query + q <- gsub("\\?\\?$", "?", paste0(end$q, "?")) + rest <- end[names(end) != "q"] + q_end <- paste0(q, paste0(names(rest), "=", rest, collapse = "&")) + + final$q <- q_end + + + return(final) +} diff --git a/R/esp_move_can.R b/R/esp_move_can.R new file mode 100644 index 00000000..ac004a79 --- /dev/null +++ b/R/esp_move_can.R @@ -0,0 +1,116 @@ +#' Displace a [`sf`][sf::st_sf] object located in the Canary Islands +#' +#' @description +#' Helper function to displace an external [`sf`][sf::st_sf] object (potentially +#' representing a location in the Canary Islands) to align it with the objects +#' provided by [`sf`][sf::st_sf] with the option `moveCAN = TRUE`. +#' +#' +#' @param x An [`sf`][sf::st_sf] object. It may be `sf` or `sfc` object. +#' @param moveCAN A logical `TRUE/FALSE` or a vector of coordinates +#' `c(lat, lon)`. +#' +#' @return A [`sf`][sf::st_sf] object of the same class and same CRS than `x` +#' but displaced accordingly. +#' +#' @details +#' This is a helper function that intends to ease the representation of objects +#' located in the Canary Islands that have been obtained from other sources +#' rather than the package \CRANpkg{mapSpain}. +#' +#' @family helper +#' @family Canary Islands +#' +#' +#' @export +#' +#' @examples +#' library(sf) +#' teide <- data.frame( +#' name = "Teide Peak", +#' lon = -16.6437593, +#' lat = 28.2722883 +#' ) +#' +#' teide_sf <- st_as_sf(teide, coords = c("lon", "lat"), crs = 4326) +#' +#' # If we use any mapSpain produced object with moveCAN = TRUE... +#' +#' esp <- esp_get_country(moveCAN = c(13, 0)) +#' +#' library(ggplot2) +#' +#' +#' ggplot(esp) + +#' geom_sf() + +#' geom_sf(data = teide_sf, color = "red") + +#' labs( +#' title = "Canary Islands displaced", +#' subtitle = "But not the external Teide object" +#' ) +#' +#' +#' +#' # But we can +#' +#' teide_sf_disp <- esp_move_can(teide_sf, moveCAN = c(13, 0)) +#' +#' ggplot(esp) + +#' geom_sf() + +#' geom_sf(data = teide_sf_disp, color = "red") + +#' labs( +#' title = "Canary Islands displaced", +#' subtitle = "And also the external Teide object" +#' ) +#' +esp_move_can <- function(x, moveCAN = TRUE) { + if (!any(inherits(x, "sf"), inherits(x, "sfc"))) { + stop("`x` should be an `sf` or `sfc` object") + } + + is_sfc <- inherits(x, "sfc") + + # If no object then return the same + g <- sf::st_geometry(x) + + if (length(g) == 0) { + return(x) + } + + moving <- FALSE + moving <- isTRUE(moveCAN) | length(moveCAN) > 1 + + if (moving) { + offset <- c(550000, 920000) + + if (length(moveCAN) > 1) { + coords <- sf::st_point(moveCAN) + coords <- sf::st_sfc(coords, crs = sf::st_crs(4326)) + coords <- sf::st_transform(coords, 3857) + coords <- sf::st_coordinates(coords) + offset <- offset + as.double(coords) + } + + data_3857 <- sf::st_transform(x, 3857) + if (is_sfc) data_3857 <- sf::st_sf(x = 1, geometry = data_3857) + + # Move can + geom_mov <- sf::st_geometry(data_3857) + offset + df <- sf::st_drop_geometry(data_3857) + can <- sf::st_sf(df, geometry = geom_mov, crs = 3857) + + # Regenerate CRS + x_out <- sf::st_transform(can, sf::st_crs(x)) + + + if (is_sfc) { + x_out <- sf::st_geometry(x_out) + } else { + # Rename sf col + sf::st_geometry(x_out) <- attr(x, "sf_column") + } + } else { + x_out <- x + } + x_out +} diff --git a/R/mapSpain-package.R b/R/mapSpain-package.R index ef56f10e..faf5c3da 100644 --- a/R/mapSpain-package.R +++ b/R/mapSpain-package.R @@ -1,79 +1,7 @@ -#' mapSpain package -#' -#' @name mapSpain-package -#' -#' @aliases mapSpain -#' -#' @docType package -#' -#' @details -#' -#' | | | -#' | :--- | :-- | -#' | **Package** | mapSpain | -#' | **Type** | Package | -#' | **Version** | `r packageVersion("mapSpain")` | -#' | **Date** | `r format(Sys.Date(), "%Y")` | -#' | **License** | GPL-3 | -#' | **LazyLoad** | yes | -# - -#' @description \if{html}{\figure{logo.png}{options: width=120 alt="mapSpain logo" align='right'}} -#' This package provides Administrative Boundaries of Spain based on -#' the GISCO (Geographic Information System of the Commission) Eurostat -#' database and CartoBase SIANE from -#' Instituto Geográfico Nacional. -#' -#' -#' @source -#' [GISCO webpage](https://ec.europa.eu/eurostat/web/gisco/geodata) -#' -#' @references See `citation("mapSpain")`. -#' -#' @seealso -#' Useful links: -#' * -#' * -#' * Report bugs at -#' -#' @keywords package -#' -#' @details -#' -#' # COPYRIGHT NOTICE (IGN) -#' -#' This package uses data from CartoBase SIANE, provided by Instituto -#' Geografico Nacional (IGN): -#' -#' Atlas Nacional de España (ANE) -#' [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/deed.en) -#' [ign.es](https://www.ign.es/) -#' -#' # COPYRIGHT NOTICE (GISCO) -#' -#' When data downloaded from GISCO -#' is used in any printed or electronic publication, -#' in addition to any other provisions -#' applicable to the whole Eurostat website, -#' data source will have to be acknowledged -#' in the legend of the map and -#' in the introductory page of the publication -#' with the following copyright notice: -#' * EN: (C) EuroGeographics for the administrative boundaries -#' * FR: (C) EuroGeographics pour les limites administratives -#' * DE: (C) EuroGeographics bezüglich der Verwaltungsgrenzen -#' -#' For publications in languages other than -#' English, French or German, -#' the translation of the copyright notice -#' in the language of the publication shall be used. -#' -#' If you intend to use the data commercially, -#' please contact EuroGeographics for -#' information regarding their license agreements. -NULL +#' @keywords internal +"_PACKAGE" # import stuffs -#' @importFrom utils download.file +#' @importFrom utils download.file unzip modifyList #' @importFrom sf st_transform NULL diff --git a/R/sysdata.rda b/R/sysdata.rda index 09d4a9ab..f96e8098 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/R/utils_download_sianedata.R b/R/utils_download_sianedata.R new file mode 100644 index 00000000..74534cb2 --- /dev/null +++ b/R/utils_download_sianedata.R @@ -0,0 +1,108 @@ +esp_hlp_dwnload_sianedata <- function(api_entry, filename, cache_dir, + verbose, update_cache, cache) { + url <- file.path(api_entry, filename) + + cache_dir <- esp_hlp_cachedir(cache_dir) + + if (verbose) message("Cache dir is ", cache_dir) + + # Create filepath + filepath <- file.path(cache_dir, filename) + localfile <- file.exists(filepath) + + if (isFALSE(cache)) { + dwnload <- FALSE + filepath <- url + if (verbose) { + message("Try loading from ", filepath) + } + } else if (update_cache || isFALSE(localfile)) { + dwnload <- TRUE + if (verbose) { + message( + "Downloading file from ", + url, + "\n\nSee https://github.com/rOpenSpain/mapSpain/tree/sianedata/ ", + "for more info" + ) + } + if (verbose && update_cache) { + message("\nUpdating cache") + } + } else if (localfile) { + dwnload <- FALSE + if (verbose && isFALSE(update_cache)) { + message("File already available on ", filepath) + } + } + + # Downloading + if (dwnload) { + err_dwnload <- try( + download.file(url, filepath, + quiet = isFALSE(verbose), + mode = "wb" + ), + silent = TRUE + ) + # nocov start + if (inherits(err_dwnload, "try-error")) { + if (verbose) message("Retrying query") + err_dwnload <- try( + download.file(url, filepath, + quiet = isFALSE(verbose), + mode = "wb" + ), + silent = TRUE + ) + } + + # If not then message + if (inherits(err_dwnload, "try-error")) { + message( + "Download failed", + "\n\nurl \n ", + url, + " not reachable.\n\nPlease try with another options. ", + "If you think this ", + "is a bug please consider opening an issue on:", + "\nhttps://github.com/rOpenSpain/mapSpain/issues" + ) + stop("\nExecution halted") + } else if (verbose) { + message("Download succesful") + } + } + + # nocov end + if (verbose && isTRUE(cache)) { + message("Reading from local file ", filepath) + size <- file.size(filepath) + class(size) <- "object_size" + message(format(size, units = "auto")) + } + + # Load + + err_onload <- try( + sf::st_read( + filepath, + quiet = isFALSE(verbose), + stringsAsFactors = FALSE + ), + silent = TRUE + ) + + # nocov start + if (inherits(err_onload, "try-error")) { + message( + "File may be corrupt. Please try again using cache = TRUE ", + "and update_cache = TRUE" + ) + stop("\nExecution halted") + } + # nocov end + + if (verbose) message("File loaded") + return(err_onload) +} diff --git a/R/utils_names.R b/R/utils_names.R index 5f322bef..af7b676f 100644 --- a/R/utils_names.R +++ b/R/utils_names.R @@ -1,267 +1,267 @@ -#' Transform region to NUTS code -#' -#' @param region A name or code of a Spanish region -#' -#' @noRd -esp_hlp_all2nuts <- function(region) { - region <- unique(region[!is.na(region)]) - - iso <- grep("^ES-", region) - nuts <- grep("^ES[[:digit:]]", region) - collectcode <- c(iso, nuts) - key <- seq_len(length(region)) - - if (length(collectcode) > 0) { - key <- key[-collectcode] - } - nuts_id <- region - if (length(iso) > 0) { - isoname <- esp_dict_region_code(region[iso], "iso2", "nuts") - nuts_id[iso] <- isoname - } - - if (length(nuts) > 0) { - # # Validate - nutstoval <- nuts_id[nuts] - out <- nutstoval - - # Validate nuts - dfnuts <- sf::st_drop_geometry(esp_get_nuts()) - validnuts <- dfnuts$NUTS_ID - check <- nutstoval %in% validnuts - - out[check == FALSE] <- NA - - nuts_id[nuts] <- out - - if (any(is.na(out))) { - warning( - paste0(nutstoval[is.na(out)], collapse = ", "), - " are not valid nuts codes" - ) - } - } - - if (length(key) > 0) { - keyname <- esp_dict_region_code(region[key], "text", "nuts") - nuts_id[key] <- keyname - } - - - return(nuts_id) -} - - -#' Transform region to CCAA -#' -#' @inheritParams esp_hlp_all2nuts -#' -#' @noRd -esp_hlp_all2ccaa <- function(region) { - dfall <- mapSpain::esp_codelist - - region <- unique(region) - - nuts_init <- region - - codauto <- grep("^[[:digit:]]", region) - - key <- seq_len(length(region)) - - if (length(codauto) > 0) { - key <- key[-codauto] - } - - if (length(codauto > 0)) { - codautoname <- - esp_dict_region_code(region[codauto], "codauto", "nuts") - nuts_init[codauto] <- codautoname - } - - if (length(key) > 0) { - keyname <- - esp_hlp_all2nuts(region[key]) - nuts_init[key] <- keyname - } - - # Fix Ceuta and Melilla - nuts_init[grep("ES640", nuts_init)] <- "ES64" - nuts_init[grep("ES630", nuts_init)] <- "ES63" - - novalid <- nchar(nuts_init) > 4 - - if (any(novalid)) { - warning( - paste0(region[novalid], collapse = ", "), - " does not return a Autonomous Community" - ) - } - - # Get NUTS2 from NUTS1 - lev1 <- nchar(nuts_init) == 3 - - - if (any(lev1)) { - nutslev1 <- - dfall[dfall$nuts1.code %in% nuts_init[lev1], ]$nuts2.code - nuts_init <- nuts_init[lev1 == FALSE] - nuts_init <- unique(c(nuts_init, nutslev1)) - } - - return(nuts_init) -} - -#' Transform region to province -#' -#' @inheritParams esp_hlp_all2nuts -#' -#' @noRd -esp_hlp_all2prov <- function(region) { - cod2cod <- code2code - cod2cod <- cod2cod[!is.na(cod2cod$cpro), ] - - region <- unique(region) - # Replace - - region[region == "ES-GC"] <- "35" - region[region == "ES-TF"] <- "38" - region[region == "ES-PM"] <- "07" - - # Separate between types of codes - cpro <- grep("^[[:digit:]]", region) - nuts <- grep("^ES[[:digit:]]", region) - iso <- grep("^ES-", region) - collectcode <- c(cpro, nuts, iso) - key <- seq_len(length(region)) - - if (length(collectcode) > 0) { - key <- key[-collectcode] - } - if (length(key) > 0) { - # Get names - key2names <- esp_dict_translate(region[key], "es") - - # See if Canary Islands are here - ngc <- key[key2names == "Las Palmas"] - ntf <- key[key2names == "Santa Cruz de Tenerife"] - - if (length(ngc) > 0) { - region[ngc] <- "35" - } - - if (length(ntf) > 0) { - region[ntf] <- "38" - } - } - - # Reassess after modification - cpro <- grep("^[[:digit:]]", region) - nuts <- grep("^ES[[:digit:]]", region) - iso <- grep("^ES-", region) - collectcode <- c(cpro, nuts, iso) - key <- seq_len(length(region)) - - if (length(collectcode) > 0) { - key <- key[-collectcode] - } - - nuts_init <- region - - # Get iso - if (length(cpro > 0)) { - cproname <- countrycode::countrycode( - region[cpro], - origin = "cpro", - destination = "cpro", - custom_dict = cod2cod, - nomatch = "NOMATCH" - ) - nuts_init[cpro] <- cproname - } - - - if (length(iso) > 0) { - isoname <- esp_dict_region_code(region[iso], "iso2", "nuts") - nuts_init[iso] <- isoname - } - - # Join - newkey <- c(nuts, key) - - if (length(newkey) > 0) { - newkeyname <- esp_hlp_all2nuts(region[newkey]) - nuts_init[newkey] <- newkeyname - } - - - # So far all are cpro or NUTS - arenuts <- grep("^ES[[:digit:]]", nuts_init) - - dfall <- mapSpain::esp_codelist - - - if (length(arenuts) > 0) { - nutsend <- nuts_init[grep("^ES[[:digit:]]", nuts_init)] - cproend <- nuts_init[-grep("^ES[[:digit:]]", nuts_init)] - - originalnames <- region[grep("^ES[[:digit:]]", nuts_init)] - - # Modify NUTS - - noprovs <- - dfall[c( - grep("ES53", dfall$nuts3.code), - grep("ES7", dfall$nuts3.code) - ), ]$nuts3.code - - novalid <- nutsend %in% noprovs - - - if (any(novalid)) { - warning( - paste0(originalnames[novalid], collapse = ", "), - " does not return a province" - ) - } - - nutsend <- nutsend[!novalid] - - # Get NUTS3 from NUTS1 - lev1 <- nchar(nutsend) == 3 - - - if (any(lev1)) { - nutslev1 <- - dfall[dfall$nuts1.code %in% nutsend[lev1], ]$nuts3.code - nutsend <- nutsend[lev1 == FALSE] - nutsend <- unique(c(nutsend, nutslev1)) - } - - # Get NUTS3 from NUTS2 - lev2 <- nchar(nutsend) == 4 - - - if (any(lev2)) { - nutslev2 <- - dfall[dfall$nuts2.code %in% nutsend[lev2], ]$nuts3.code - nutsend <- nutsend[lev2 == FALSE] - nutsend <- unique(c(nutsend, nutslev2)) - } - - final <- unique(c(nutsend, cproend)) - } else { - final <- nuts_init - } - - # Pass now cpro to NUTS - arecpro <- grep("^[[:digit:]]", final) - - if (length(arecpro) > 0) { - cpro <- final[arecpro] - - nutscpro <- dfall[dfall$cpro %in% cpro, ]$nuts3.code - - final <- unique(c(final[-arecpro], nutscpro)) - } - return(final) -} +#' Transform region to NUTS code +#' +#' @param region A name or code of a Spanish region +#' +#' @noRd +esp_hlp_all2nuts <- function(region) { + region <- unique(region[!is.na(region)]) + + iso <- grep("^ES-", region) + nuts <- grep("^ES[[:digit:]]", region) + collectcode <- c(iso, nuts) + key <- seq_len(length(region)) + + if (length(collectcode) > 0) { + key <- key[-collectcode] + } + nuts_id <- region + if (length(iso) > 0) { + isoname <- esp_dict_region_code(region[iso], "iso2", "nuts") + nuts_id[iso] <- isoname + } + + if (length(nuts) > 0) { + # # Validate + nutstoval <- nuts_id[nuts] + out <- nutstoval + + # Validate nuts + dfnuts <- sf::st_drop_geometry(esp_get_nuts()) + validnuts <- dfnuts$NUTS_ID + check <- nutstoval %in% validnuts + + out[check == FALSE] <- NA + + nuts_id[nuts] <- out + + if (any(is.na(out))) { + warning( + paste0(nutstoval[is.na(out)], collapse = ", "), + " are not valid nuts codes" + ) + } + } + + if (length(key) > 0) { + keyname <- esp_dict_region_code(region[key], "text", "nuts") + nuts_id[key] <- keyname + } + + + return(nuts_id) +} + + +#' Transform region to CCAA +#' +#' @inheritParams esp_hlp_all2nuts +#' +#' @noRd +esp_hlp_all2ccaa <- function(region) { + dfall <- mapSpain::esp_codelist + + region <- unique(region) + + nuts_init <- region + + codauto <- grep("^[[:digit:]]", region) + + key <- seq_len(length(region)) + + if (length(codauto) > 0) { + key <- key[-codauto] + } + + if (length(codauto > 0)) { + codautoname <- + esp_dict_region_code(region[codauto], "codauto", "nuts") + nuts_init[codauto] <- codautoname + } + + if (length(key) > 0) { + keyname <- + esp_hlp_all2nuts(region[key]) + nuts_init[key] <- keyname + } + + # Fix Ceuta and Melilla + nuts_init[grep("ES640", nuts_init)] <- "ES64" + nuts_init[grep("ES630", nuts_init)] <- "ES63" + + novalid <- nchar(nuts_init) > 4 + + if (any(novalid)) { + warning( + paste0(region[novalid], collapse = ", "), + " does not return a Autonomous Community" + ) + } + + # Get NUTS2 from NUTS1 + lev1 <- nchar(nuts_init) == 3 + + + if (any(lev1)) { + nutslev1 <- + dfall[dfall$nuts1.code %in% nuts_init[lev1], ]$nuts2.code + nuts_init <- nuts_init[lev1 == FALSE] + nuts_init <- unique(c(nuts_init, nutslev1)) + } + + return(nuts_init) +} + +#' Transform region to province +#' +#' @inheritParams esp_hlp_all2nuts +#' +#' @noRd +esp_hlp_all2prov <- function(region) { + cod2cod <- code2code + cod2cod <- cod2cod[!is.na(cod2cod$cpro), ] + + region <- unique(region) + # Replace + + region[region == "ES-GC"] <- "35" + region[region == "ES-TF"] <- "38" + region[region == "ES-PM"] <- "07" + + # Separate between types of codes + cpro <- grep("^[[:digit:]]", region) + nuts <- grep("^ES[[:digit:]]", region) + iso <- grep("^ES-", region) + collectcode <- c(cpro, nuts, iso) + key <- seq_len(length(region)) + + if (length(collectcode) > 0) { + key <- key[-collectcode] + } + if (length(key) > 0) { + # Get names + key2names <- esp_dict_translate(region[key], "es") + + # See if Canary Islands are here + ngc <- key[key2names == "Las Palmas"] + ntf <- key[key2names == "Santa Cruz de Tenerife"] + + if (length(ngc) > 0) { + region[ngc] <- "35" + } + + if (length(ntf) > 0) { + region[ntf] <- "38" + } + } + + # Reassess after modification + cpro <- grep("^[[:digit:]]", region) + nuts <- grep("^ES[[:digit:]]", region) + iso <- grep("^ES-", region) + collectcode <- c(cpro, nuts, iso) + key <- seq_len(length(region)) + + if (length(collectcode) > 0) { + key <- key[-collectcode] + } + + nuts_init <- region + + # Get iso + if (length(cpro > 0)) { + cproname <- countrycode::countrycode( + region[cpro], + origin = "cpro", + destination = "cpro", + custom_dict = cod2cod, + nomatch = "NOMATCH" + ) + nuts_init[cpro] <- cproname + } + + + if (length(iso) > 0) { + isoname <- esp_dict_region_code(region[iso], "iso2", "nuts") + nuts_init[iso] <- isoname + } + + # Join + newkey <- c(nuts, key) + + if (length(newkey) > 0) { + newkeyname <- esp_hlp_all2nuts(region[newkey]) + nuts_init[newkey] <- newkeyname + } + + + # So far all are cpro or NUTS + arenuts <- grep("^ES[[:digit:]]", nuts_init) + + dfall <- mapSpain::esp_codelist + + + if (length(arenuts) > 0) { + nutsend <- nuts_init[grep("^ES[[:digit:]]", nuts_init)] + cproend <- nuts_init[-grep("^ES[[:digit:]]", nuts_init)] + + originalnames <- region[grep("^ES[[:digit:]]", nuts_init)] + + # Modify NUTS + + noprovs <- + dfall[c( + grep("ES53", dfall$nuts3.code), + grep("ES7", dfall$nuts3.code) + ), ]$nuts3.code + + novalid <- nutsend %in% noprovs + + + if (any(novalid)) { + warning( + paste0(originalnames[novalid], collapse = ", "), + " does not return a province" + ) + } + + nutsend <- nutsend[!novalid] + + # Get NUTS3 from NUTS1 + lev1 <- nchar(nutsend) == 3 + + + if (any(lev1)) { + nutslev1 <- + dfall[dfall$nuts1.code %in% nutsend[lev1], ]$nuts3.code + nutsend <- nutsend[lev1 == FALSE] + nutsend <- unique(c(nutsend, nutslev1)) + } + + # Get NUTS3 from NUTS2 + lev2 <- nchar(nutsend) == 4 + + + if (any(lev2)) { + nutslev2 <- + dfall[dfall$nuts2.code %in% nutsend[lev2], ]$nuts3.code + nutsend <- nutsend[lev2 == FALSE] + nutsend <- unique(c(nutsend, nutslev2)) + } + + final <- unique(c(nutsend, cproend)) + } else { + final <- nuts_init + } + + # Pass now cpro to NUTS + arecpro <- grep("^[[:digit:]]", final) + + if (length(arecpro) > 0) { + cpro <- final[arecpro] + + nutscpro <- dfall[dfall$cpro %in% cpro, ]$nuts3.code + + final <- unique(c(final[-arecpro], nutscpro)) + } + return(final) +} diff --git a/R/utils_siane.R b/R/utils_siane.R index 6d8f9466..a90bdac7 100644 --- a/R/utils_siane.R +++ b/R/utils_siane.R @@ -1,308 +1,312 @@ -#' Download data from SIANE -#' -#' @param sub Call to mainland Spain ("x") or Canary Island ("y") -#' -#' @inheritParams esp_hlp_get_siane -#' -#' @noRd -esp_hlp_download_siane <- function(type, - resolution, - cache, - cache_dir, - update_cache, - verbose, - sub) { - resolution <- as.character(resolution) - # Valid res - validres <- c("3", "6.5", "10") - - if (!resolution %in% validres) { - stop( - "resolution should be one of '", - paste0(validres, collapse = "', "), - "'" - ) - } - resolution <- gsub("6.5", "6m5", resolution) - # Create url - api_entry <- - "https://github.com/rOpenSpain/mapSpain/raw/sianedata/dist" - - if (type == "munic") { - filename <- - paste0("se89_", resolution, "_admin_muni_a_", sub, ".gpkg") - } else if (type == "prov") { - filename <- - paste0("se89_", resolution, "_admin_prov_a_", sub, ".gpkg") - } else if (type == "ccaa") { - filename <- - paste0("se89_", resolution, "_admin_ccaa_a_", sub, ".gpkg") - } else if (type == "orogarea") { - filename <- - paste0("se89_", resolution, "_orog_hipso_a_", sub, ".gpkg") - } else if (type == "orogline") { - filename <- - paste0("se89_", resolution, "_orog_hipso_l_", sub, ".gpkg") - } else if (type == "riverline") { - filename <- - paste0("se89_", resolution, "_hidro_rio_l_", sub, ".gpkg") - } else if (type == "riverarea") { - filename <- - paste0("se89_", resolution, "_hidro_rio_a_", sub, ".gpkg") - } else if (type == "rivernames") { - filename <- "rivernames.rda" - api_entry <- - "https://github.com/rOpenSpain/mapSpain/raw/sianedata/data-raw" - } else if (type == "basinland") { - filename <- - paste0("se89_", resolution, "_hidro_demt_a_", sub, ".gpkg") - } else if (type == "basinlandsea") { - filename <- - paste0("se89_", resolution, "_hidro_demc_a_", sub, ".gpkg") - } else if (type == "capimun") { - filename <- - paste0("se89_3_urban_capimuni_p_", sub, ".gpkg") - } else if (type == "roads") { - filename <- - paste0("se89_3_vias_ctra_l_", sub, ".gpkg") - } else if (type == "ffccline") { - filename <- - paste0("se89_3_vias_ffcc_l_", sub, ".gpkg") - } else if (type == "ffccpoint") { - filename <- - paste0("se89_3_vias_ffcc_p_", sub, ".gpkg") - } else { - # This should never be activated, as it is an internal function - stop("Type not recognized") - } - - url <- file.path(api_entry, filename) - - cache_dir <- esp_hlp_cachedir(cache_dir) - - if (verbose) { - message("Cache dir is ", cache_dir) - } - - # Create filepath - filepath <- file.path(cache_dir, filename) - localfile <- file.exists(filepath) - - # nocov start - - if (isFALSE(cache)) { - dwnload <- FALSE - filepath <- url - if (verbose) { - message("Try loading from ", filepath) - } - } else if (update_cache | isFALSE(localfile)) { - dwnload <- TRUE - if (verbose) { - message( - "Downloading file from ", - url, - "\n\nSee https://github.com/rOpenSpain/mapSpain/tree/sianedata/ for more info" - ) - } - if (verbose & update_cache) { - message("\nUpdating cache") - } - } else if (localfile) { - dwnload <- FALSE - if (verbose & isFALSE(update_cache)) { - message("File already available on ", filepath) - } - } - - # Downloading - file_avail <- TRUE - - if (dwnload) { - err_dwnload <- tryCatch( - download.file(url, filepath, quiet = isFALSE(verbose), mode = "wb"), - warning = function(e) { - message( - "Download failed", - "\n\nurl \n ", - url, - " not reachable.\n\nPlease try with another options. If you think this is a bug please consider opening an issue on https://github.com/rOpenSpain/mapSpain/issues" - ) - return(TRUE) - } - ) - if (isTRUE(err_dwnload)) { - file_avail <- FALSE - } else if (verbose) { - message("Download succesful") - } - } - - loaded <- FALSE - - if (file_avail) { - if (verbose & isTRUE(cache)) { - message("Reading from local file ", filepath) - size <- file.size(filepath) - class(size) <- "object_size" - message(format(size, units = "auto")) - } - if (type == "rivernames") { - data <- readRDS(filepath) - return(data) - } - err_onload <- tryCatch( - data_sf <- sf::st_read( - filepath, - quiet = isFALSE(verbose), - stringsAsFactors = FALSE - ), - warning = function(e) { - message( - "\n\nFile couldn't be loaded from \n\n", - filepath, - "\n\n Please try cache = TRUE" - ) - return(TRUE) - }, - error = function(e) { - message("File may be corrupt. Please try again using cache = TRUE and update_cache = TRUE") - return(TRUE) - } - ) - if (isTRUE(err_onload)) { - loaded <- FALSE - } else { - loaded <- TRUE - if (verbose) { - message("File loaded") - } - } - } - if (loaded) { - return(data_sf) - } else { - stop("\nExecution halted") - } - # nocov end -} - -#' Return data from SIANE -#' -#' @param type Type of data to be requestes -#' -#' @inheritParams esp_get_capimun -#' -#' @inheritParams esp_get_ccaa_siane -#' -#' @noRd -esp_hlp_get_siane <- function(type, - resolution, - cache, - cache_dir, - update_cache, - verbose, - year) { - # Rivers names - if (type == "rivernames") { - df <- - esp_hlp_download_siane( - type, 3, cache, cache_dir, update_cache, - verbose, "x" - ) - return(df) - } - - # Mainland - data_sf1 <- - esp_hlp_download_siane( - type, resolution, cache, cache_dir, update_cache, - verbose, "x" - ) - # Canary Islands - if (type == "riverline" & as.character(resolution) != "3") { - # Nothing - } else if (type == "riverarea") { - # Nothing - } else if (type %in% c("ffccline", "ffccpoint")) { - # Nothing - } else { - data_sf2 <- - esp_hlp_download_siane( - type, - resolution, - cache, - cache_dir, - update_cache, - verbose, - "y" - ) - } - # CCAA - if (type == "ccaa") { - data_sf1$x_cap2 <- NA - data_sf1$y_cap2 <- NA - data_sf1 <- data_sf1[, colnames(data_sf2)] - } - - if (exists("data_sf2")) { - # Transform and bind - data_sf2 <- sf::st_transform(data_sf2, sf::st_crs(data_sf1)) - - data_sf <- rbind(data_sf1, data_sf2) - } else { - if (verbose) { - message("Shape not provided for Canary Islands") - } - data_sf <- data_sf1 - } - # Date management - mindate <- min(data_sf$fecha_alta) - maxdate <- Sys.Date() - year <- as.character(year) - - if (nchar(year) != 10) { - selDate <- paste(year, "12", "31", sep = "-") - } else { - selDate <- year - } - - if (nchar(selDate) != 10) { - stop( - "Date '", - selDate, - "' doesn't seem to be valid, use YYYY or YYYY-MM-DD format" - ) - } - - selDate <- as.Date(selDate) - - # Check range - checkDateRange <- mindate <= selDate & selDate <= maxdate - - if (isFALSE(checkDateRange)) { - stop( - "year not available. Select a year/date between '", - mindate, - "' and '", - maxdate, - "'" - ) - } - - # Filter - df <- data_sf - # By date - df$fecha_bajamod <- as.character(df$fecha_baja) - df$fecha_bajamod <- - as.Date(ifelse( - is.na(df$fecha_bajamod), - as.character(Sys.Date()), - df$fecha_bajamod - )) - df <- - df[df$fecha_alta <= selDate & - selDate <= df$fecha_bajamod, colnames(data_sf)] - - return(df) -} +#' Download data from SIANE +#' +#' @param sub Call to mainland Spain ("x") or Canary Island ("y") +#' +#' @inheritParams esp_hlp_get_siane +#' +#' @noRd +esp_hlp_download_siane <- function(type, + resolution, + cache, + cache_dir, + update_cache, + verbose, + sub) { + resolution <- as.character(resolution) + # Valid res + validres <- c("3", "6.5", "10") + + if (!resolution %in% validres) { + stop( + "resolution should be one of '", + paste0(validres, collapse = "', "), + "'" + ) + } + resolution <- gsub("6.5", "6m5", resolution) + # Create url + api_entry <- + "https://github.com/rOpenSpain/mapSpain/raw/sianedata/dist" + + + # If requesting riversname need to change api entry + + if (type == "rivernames") { + api_entry <- + "https://github.com/rOpenSpain/mapSpain/raw/sianedata/data-raw" + } + + # Switch name + + filename <- switch(type, + "munic" = paste0( + "se89_", resolution, + "_admin_muni_a_", sub, ".gpkg" + ), + "prov" = paste0("se89_", resolution, "_admin_prov_a_", sub, ".gpkg"), + "ccaa" = paste0("se89_", resolution, "_admin_ccaa_a_", sub, ".gpkg"), + "orogarea" = paste0("se89_", resolution, "_orog_hipso_a_", sub, ".gpkg"), + "orogline" = paste0("se89_", resolution, "_orog_hipso_l_", sub, ".gpkg"), + "riverline" = paste0("se89_", resolution, "_hidro_rio_l_", sub, ".gpkg"), + "riverarea" = paste0("se89_", resolution, "_hidro_rio_a_", sub, ".gpkg"), + "rivernames" = "rivernames.rda", + "basinland" = paste0("se89_", resolution, "_hidro_demt_a_", sub, ".gpkg"), + "basinlandsea" = paste0( + "se89_", resolution, + "_hidro_demc_a_", sub, ".gpkg" + ), + "capimun" = paste0("se89_3_urban_capimuni_p_", sub, ".gpkg"), + "roads" = paste0("se89_3_vias_ctra_l_", sub, ".gpkg"), + "ffccline" = paste0("se89_3_vias_ffcc_l_", sub, ".gpkg"), + "ffccpoint" = paste0("se89_3_vias_ffcc_p_", sub, ".gpkg"), + # This should never be activated, as it is an internal function + stop("Type not recognized") + ) + + url <- file.path(api_entry, filename) + + cache_dir <- esp_hlp_cachedir(cache_dir) + + if (verbose) message("Cache dir is ", cache_dir) + + # Create filepath + filepath <- file.path(cache_dir, filename) + localfile <- file.exists(filepath) + + if (isFALSE(cache)) { + dwnload <- FALSE + filepath <- url + if (verbose) { + message("Try loading from ", filepath) + } + } else if (update_cache || isFALSE(localfile)) { + dwnload <- TRUE + if (verbose) { + message( + "Downloading file from ", + url, + "\n\nSee https://github.com/rOpenSpain/mapSpain/tree/sianedata/ ", + "for more info" + ) + } + if (verbose && update_cache) { + message("\nUpdating cache") + } + } else if (localfile) { + dwnload <- FALSE + if (verbose && isFALSE(update_cache)) { + message("File already available on ", filepath) + } + } + + # Downloading + if (dwnload) { + err_dwnload <- try( + download.file(url, filepath, + quiet = isFALSE(verbose), + mode = "wb" + ), + silent = TRUE + ) + + if (inherits(err_dwnload, "try-error")) { + if (verbose) message("Retrying query") + err_dwnload <- try( + download.file(url, filepath, + quiet = isFALSE(verbose), + mode = "wb" + ), + silent = TRUE + ) + } + + # If not then message + if (inherits(err_dwnload, "try-error")) { + message( + "Download failed", + "\n\nurl \n ", + url, + " not reachable.\n\nPlease try with another options. ", + "If you think this ", + "is a bug please consider opening an issue on:", + "\nhttps://github.com/rOpenSpain/mapSpain/issues" + ) + stop("\nExecution halted") + } else if (verbose) { + message("Download succesful") + } + } + + # Rivernames is special cas + if (type == "rivernames") { + data <- readRDS(filepath) + return(data) + } + + if (verbose && isTRUE(cache)) { + message("Reading from local file ", filepath) + size <- file.size(filepath) + class(size) <- "object_size" + message(format(size, units = "auto")) + } + + # Load + + err_onload <- try( + sf::st_read( + filepath, + quiet = isFALSE(verbose), + stringsAsFactors = FALSE + ), + silent = TRUE + ) + + if (inherits(err_onload, "try-error")) { + message( + "File may be corrupt. Please try again using cache = TRUE ", + "and update_cache = TRUE" + ) + stop("\nExecution halted") + } + + if (verbose) message("File loaded") + return(err_onload) +} + +#' Return data from SIANE +#' +#' @param type Type of data to be requestes +#' +#' @inheritParams esp_get_capimun +#' +#' @inheritParams esp_get_ccaa_siane +#' +#' @noRd +esp_hlp_get_siane <- function(type, + resolution, + cache, + cache_dir, + update_cache, + verbose, + year) { + # Rivers names + if (type == "rivernames") { + df <- + esp_hlp_download_siane( + type, 3, cache, cache_dir, update_cache, + verbose, "x" + ) + return(df) + } + + # Mainland + data_sf1 <- + esp_hlp_download_siane( + type, resolution, cache, cache_dir, update_cache, + verbose, "x" + ) + # Canary Islands + if (type == "riverline" && as.character(resolution) != "3") { + # Nothing + } else if (type == "riverarea") { + # Nothing + } else if (type %in% c("ffccline", "ffccpoint")) { + # Nothing + } else { + data_sf2 <- + esp_hlp_download_siane( + type, + resolution, + cache, + cache_dir, + update_cache, + verbose, + "y" + ) + } + # CCAA + if (type == "ccaa") { + data_sf1$x_cap2 <- NA + data_sf1$y_cap2 <- NA + data_sf1 <- data_sf1[, colnames(data_sf2)] + } + + if (exists("data_sf2")) { + # Transform and bind + data_sf2 <- sf::st_transform(data_sf2, sf::st_crs(data_sf1)) + + if (ncol(data_sf1) != ncol(data_sf2)) { + data_sf2[, setdiff(names(data_sf1), names(data_sf2))] <- NA + } + + + data_sf <- rbind(data_sf1, data_sf2) + } else { + if (verbose) { + message("Shape not provided for Canary Islands") + } + data_sf <- data_sf1 + } + # Date management + # Need to adjust on 2024 dist + if (type %in% c( + "roads", "riverline", "riverarea", + "orogarea", "orogline" + )) { + data_sf$fecha_baja <- NA + } + + mindate <- min(data_sf$fecha_alta) + maxdate <- Sys.Date() + year <- as.character(year) + + if (nchar(year) != 10) { + selDate <- paste(year, "12", "31", sep = "-") + } else { + selDate <- year + } + + if (nchar(selDate) != 10) { + stop( + "Date '", + selDate, + "' doesn't seem to be valid, use YYYY or YYYY-MM-DD format" + ) + } + + selDate <- as.Date(selDate) + + # Check range + checkDateRange <- mindate <= selDate & selDate <= maxdate + + if (isFALSE(checkDateRange)) { + stop( + "year not available. Select a year/date between '", + mindate, + "' and '", + maxdate, + "'" + ) + } + + # Filter + if (type %in% c("ffccline", "ffccpoint")) { + return(data_sf) + } + + df <- data_sf + # By date + df$fecha_bajamod <- as.character(df$fecha_baja) + df$fecha_bajamod <- + as.Date(ifelse( + is.na(df$fecha_bajamod), + as.character(Sys.Date()), + df$fecha_bajamod + )) + df <- df[ + df$fecha_alta <= selDate & selDate <= df$fecha_bajamod, + colnames(data_sf) + ] + + return(df) +} diff --git a/R/utils_tiles.R b/R/utils_tiles.R index cc8342e5..73ca0dd0 100644 --- a/R/utils_tiles.R +++ b/R/utils_tiles.R @@ -1,305 +1,329 @@ -#' Get tiles from WMS -#' -#' @param transparent Transparency -#' -#' @param bbox_expand Expansion of the bbox -#' -#' @param provs Provider -#' -#' @inheritParams esp_getTiles -#' -#' @noRd -getwms <- function(x, - provs, - update_cache, - cache_dir, - verbose, - res, - transparent, - bbox_expand) { # nocov start - - bbox_expand <- max(1 + bbox_expand, 1.1) - - # Get squared bbox - bbox <- as.double(sf::st_bbox(x)) - dimx <- (bbox[3] - bbox[1]) - dimy <- (bbox[4] - bbox[2]) - maxdist <- max(dimx, dimy) * bbox_expand # Expand bbox - center <- c(bbox[1] + dimx / 2, bbox[2] + dimy / 2) - - bboxsquare <- c( - center[1] - maxdist / 2, - center[2] - maxdist / 2, - center[1] + maxdist / 2, - center[2] + maxdist / 2 - ) - - - class(bboxsquare) <- "bbox" - - - # Compose params - q <- provs[provs$field == "url_static", "value"] - q <- - gsub("{bbox}", paste0(bboxsquare, collapse = ","), q, fixed = TRUE) - - q <- gsub("512", as.character(res), q) - src <- unique(provs$provider) - - - ext <- "jpeg" - if (length(grep("png", q)) > 0) { - ext <- "png" - } else if (length(grep("jpg", q)) > 0) { - ext <- "jpg" - } - - filename <- - paste0( - src, - "_bbox3857_res", - res, - "_", - paste0(bboxsquare, collapse = "_"), - ".", - ext - ) - - filename <- file.path(cache_dir, filename) - - if (isFALSE(file.exists(filename)) | isTRUE(update_cache)) { - if (verbose) { - message("Downloading from \n", q, "\n to cache dir \n", cache_dir) - } - - - download.file( - url = q, - destfile = filename, - mode = "wb", - quiet = !verbose - ) - } else { - if (verbose) { - message("Requested tile already cached on \n", cache_dir) - } - } - - # Read png and geotag - - # Only png - - img <- png::readPNG(filename) * 255 - # Give transparency if available - if (dim(img)[3] == 4 & transparent) { - nrow <- dim(img)[1] - - for (i in seq_len(nrow)) { - row <- img[i, , ] - alpha <- row[, 4] == 0 - row[alpha, ] <- NA - img[i, , ] <- row - } - } - - - # compose brick raster - rout <- - raster::brick(img, crs = sf::st_crs(3857)$proj4string) - - raster::extent(rout) <- - raster::extent(bboxsquare[c(1, 3, 2, 4)]) - - # End WMS - - return(rout) - # nocov end -} - -#' Get tiles from WMTS -#' -#' @inheritParams esp_getTiles -#' -#' @inheritParams getWMS -#' -#' @noRd -getwmts <- function(x, - provs, - update_cache, - cache_dir, - verbose, - res, - zoom, - zoommin, - type, - transparent) { - # nocov start - # New fun - - x <- sf::st_transform(x, 4326) - bbx <- sf::st_bbox(x) - - # select a default zoom level - if (is.null(zoom)) { - gz <- slippymath::bbox_tile_query(bbx) - zoom <- min(gz[gz$total_tiles %in% 4:10, "zoom"]) + zoommin - - if (verbose) { - message("Auto zoom level: ", zoom) - } - } - - # Check zoom - if ("minZoom" %in% provs$field) { - minZoom <- as.numeric(provs[provs$field == "minZoom", "value"]) - - if (zoom < minZoom) { - zoom <- max(zoom, minZoom) - if (verbose) { - message( - "\nSwitching. Minimum zoom for this provider is ", - zoom, - "\n" - ) - } - } - } - - # get tile list - tile_grid <- - slippymath::bbox_to_tile_grid(bbox = bbx, zoom = zoom) - - # Compose params - q <- provs[provs$field == "url_static", "value"] - ext <- "jpeg" - if (length(grep("png", q)) > 0) { - ext <- "png" - } else if (length(grep("jpg", q)) > 0) { - ext <- "jpg" - } - - if (verbose) { - message("Caching tiles on ", cache_dir) - } - - # download images - images <- apply( - X = tile_grid$tiles, - MARGIN = 1, - FUN = dl_t, - z = tile_grid$zoom, - ext = ext, - src = type, - q = q, - verbose = verbose, - cache_dir = cache_dir, - update_cache = update_cache - ) - - rout <- compose_tile_grid(tile_grid, ext, images, transparent) - return(rout) - # nocov end -} - - -#' @name compose_tile_grid -#' @noRd -compose_tile_grid <- function(tile_grid, ext, images, transparent) { - # nocov start - bricks <- vector("list", nrow(tile_grid$tiles)) - for (i in seq_along(bricks)) { - bbox <- - slippymath::tile_bbox( - tile_grid$tiles$x[i], tile_grid$tiles$y[i], - tile_grid$zoom - ) - img <- images[i] - # special for png tiles - if (ext == "png") { - img <- png::readPNG(img) * 255 - - if (dim(img)[3] == 4 & transparent) { - nrow <- dim(img)[1] - - for (j in seq_len(nrow)) { - row <- img[j, , ] - alpha <- row[, 4] == 0 - row[alpha, ] <- NA - img[j, , ] <- row - } - } - } - - # compose brick raster - r_img <- - raster::brick(img, crs = sf::st_crs(3857)$proj4string) - raster::extent(r_img) <- - raster::extent(bbox[c( - "xmin", "xmax", - "ymin", "ymax" - )]) - bricks[[i]] <- r_img - } - # if only one tile is needed - if (length(bricks) == 1) { - return(bricks[[1]]) - } - # all tiles together - rout <- do.call(raster::merge, bricks) - return(rout) - # nocov end -} - - -#' @name dl_t -#' @noRd -dl_t <- - function(x, - z, - ext, - src, - q, - verbose, - cache_dir, - update_cache) { - # nocov start - outfile <- - paste0(cache_dir, "/", src, "_", z, "_", x[1], "_", x[2], ".", ext) - - if (!file.exists(outfile) | - isTRUE(update_cache)) { - q <- - gsub( - pattern = "{x}", - replacement = x[1], - x = q, - fixed = TRUE - ) - q <- - gsub( - pattern = "{y}", - replacement = x[2], - x = q, - fixed = TRUE - ) - q <- gsub( - pattern = "{z}", - replacement = z, - x = q, - fixed = TRUE - ) - if (verbose) { - message("Downloading ", q, "\n") - } - download.file( - url = q, - destfile = outfile, - quiet = TRUE, - mode = "wb" - ) - } else if (verbose) { - message("Tile cached on ", outfile) - } - return(outfile) - # nocov end - } +#' Get tiles from WMS +#' +#' @param transparent Transparency +#' +#' @param bbox_expand Expansion of the bbox +#' +#' @param url_pieces Provider +#' +#' @inheritParams esp_getTiles +#' +#' @noRd +getwms <- function(newbbox, + url_pieces, + update_cache, + cache_dir, + verbose, + res, + transparent) { + # Get squared bbox + bbox <- as.double(sf::st_bbox(newbbox)) + dimx <- (bbox[3] - bbox[1]) + dimy <- (bbox[4] - bbox[2]) + maxdist <- max(dimx, dimy) + center <- c(bbox[1] + dimx / 2, bbox[2] + dimy / 2) + + bboxsquare <- c( + center[1] - maxdist / 2, + center[2] - maxdist / 2, + center[1] + maxdist / 2, + center[2] + maxdist / 2 + ) + + + + + class(bboxsquare) <- "bbox" + + # Compose params + url_pieces$bbox <- paste0(bboxsquare, collapse = ",") + url_pieces$width <- as.character(res) + url_pieces$height <- as.character(res) + + # Compose + ext <- tolower(gsub("image/", "", url_pieces$format)) + if (!ext %in% c( + "png", "jpeg", "jpg", "tiff", + "geotiff" + )) { + stop( + "Can't handle ", ext, + " files" + ) + } + + q <- url_pieces$q + rest <- url_pieces[names(url_pieces) != "q"] + q <- paste0(q, paste0(names(rest), "=", rest, collapse = "&")) + + crs <- unlist( + url_pieces[names(url_pieces) %in% c("crs", "srs", "tilematrixset")] + ) + + filename <- + paste0( + "tile_", + "_bbox_", crs, + "_res", + res, + "_", + paste0(bboxsquare, collapse = "_"), + ".", + ext + ) + + filename <- paste0(esp_get_md5(filename), ".", ext) + filename <- file.path(cache_dir, filename) + + if (isFALSE(file.exists(filename)) || isTRUE(update_cache)) { + if (verbose) { + message("Downloading from \n", q, "\n to cache dir \n", cache_dir) + } + + + download.file( + url = q, + destfile = filename, + mode = "wb", + quiet = !verbose + ) + } else { + if (verbose) { + message("Requested tile already cached on \n", cache_dir) + } + } + + # Read png and geotag + + # Only png + if (ext == "png") { + img <- png::readPNG(filename) * 255 + } else { + img <- filename + } + + + # compose brick raster + r_img <- suppressWarnings(terra::rast(img)) + + # Provide transparency if available + if (terra::nlyr(r_img) == 4 && transparent) { + tomask <- terra::subset(r_img, 4) + tomask[tomask == 0] <- NA + + r_img <- terra::mask(r_img, tomask) + } + + # Check if need extent, some tiffs dont + if (all(as.vector(terra::ext(r_img)) == c(0, res, 0, res))) { + terra::ext(r_img) <- terra::ext(bboxsquare[c(1, 3, 2, 4)]) + } + + # Check if need a CRS + if (terra::crs(r_img) == "") { + terra::crs(r_img) <- crs + } + # End WMS + + return(r_img) +} + +#' Get tiles from WMTS +#' +#' @inheritParams esp_getTiles +#' +#' @inheritParams getWMS +#' +#' @noRd +getwmts <- function(newbbox, + type, + url_pieces, + update_cache, + cache_dir, + verbose, + zoom, + zoommin, + transparent, + extra_opts) { + newbbox <- sf::st_transform(newbbox, 4326) + bbx <- sf::st_bbox(newbbox) + + # select a default zoom level + + if (is.null(zoom)) { + gz <- slippymath::bbox_tile_query(bbx) + zoom <- min(gz[gz$total_tiles %in% 4:10, "zoom"]) + zoommin + + if (verbose) { + message("Auto zoom level: ", zoom) + } + } + + + # Check zoom + if ("minzoom" %in% names(extra_opts)) { + minzoom <- as.double(extra_opts$minzoom) + + if (zoom < minzoom) { + zoom <- max(zoom, minzoom) + if (verbose) { + message( + "\nSwitching. Minimum zoom for this provider is ", + zoom, + "\n" + ) + } + } + } + + # get tile list + tile_grid <- slippymath::bbox_to_tile_grid( + bbox = bbx, + zoom = as.numeric(zoom) + ) + + # Compose + # Special case for non INSPIRE serves + if (is.null(url_pieces$format)) { + ext <- tools::file_ext(url_pieces$q) + } else { + ext <- tolower(gsub("image/", "", url_pieces$format)) + } + + + + if (!ext %in% c( + "png", "jpeg", "jpg", "tiff", + "geotiff" + )) { + stop( + "Can't handle ", ext, + " files" + ) + } + + url_pieces$tilematrixset <- "GoogleMapsCompatible" + url_pieces$tilematrix <- "{z}" + url_pieces$tilerow <- "{y}" + url_pieces$tilecol <- "{x}" + + q <- url_pieces$q + rest <- url_pieces[names(url_pieces) != "q"] + + # Special case WMTS + if (isFALSE(grepl("?", url_pieces$q, fixed = TRUE))) { + q <- url_pieces$q + } else { + q <- paste0(q, paste0(names(rest), "=", rest, collapse = "&")) + } + + if (verbose) { + message("Caching tiles on ", cache_dir) + } + + # download images + images <- apply( + X = tile_grid$tiles, + MARGIN = 1, + FUN = dl_t, + z = tile_grid$zoom, + ext = ext, + src = type, + q = q, + verbose = verbose, + cache_dir = cache_dir, + update_cache = update_cache + ) + + rout <- compose_tile_grid(tile_grid, ext, images, transparent, "epsg:3857") + return(rout) +} + + +#' @name compose_tile_grid +#' @noRd +compose_tile_grid <- function(tile_grid, ext, images, transparent, crs) { + # Based on https://github.com/riatelab/maptiles/blob/main/R/get_tiles.R + + bricks <- vector("list", nrow(tile_grid$tiles)) + + + for (i in seq_along(bricks)) { + bbox <- slippymath::tile_bbox( + tile_grid$tiles$x[i], tile_grid$tiles$y[i], + tile_grid$zoom + ) + img <- images[i] + + # Read png and geotag + + # Only png + if (ext == "png") { + img <- png::readPNG(img) * 255 + } + + + # compose brick raster + r_img <- suppressWarnings(terra::rast(img)) + + # Provide transparency if available + if (terra::nlyr(r_img) == 4 && transparent) { + tomask <- terra::subset(r_img, 4) + tomask[tomask == 0] <- NA + + r_img <- terra::mask(r_img, tomask) + } + + terra::ext(r_img) <- terra::ext(bbox[c( + "xmin", "xmax", + "ymin", "ymax" + )]) + + # Check if need a CRS + if (terra::crs(r_img) == "") { + terra::crs(r_img) <- crs + } + + + bricks[[i]] <- r_img + } + + # if only one tile is needed + if (length(bricks) == 1) { + rout <- bricks[[1]] + rout <- terra::merge(rout, rout) + } else { + # all tiles together + rout <- do.call(terra::merge, bricks) + } + + return(rout) +} + + +#' @name dl_t +#' @noRd +dl_t <- function(x, z, ext, src, q, verbose, cache_dir, update_cache) { + outfile <- paste0( + cache_dir, "/", src, "_", z, "_", x[1], "_", x[2], ".", + ext + ) + + if (!file.exists(outfile) || isTRUE(update_cache)) { + q <- gsub(pattern = "{x}", replacement = x[1], x = q, fixed = TRUE) + q <- gsub(pattern = "{y}", replacement = x[2], x = q, fixed = TRUE) + q <- gsub(pattern = "{z}", replacement = z, x = q, fixed = TRUE) + if (verbose) { + message("Downloading ", q, "\n") + } + download.file( + url = q, + destfile = outfile, + quiet = TRUE, + mode = "wb" + ) + } else if (verbose) { + message("Tile cached on ", outfile) + } + return(outfile) +} diff --git a/README.Rmd b/README.Rmd index c6e99bb5..93fe3747 100644 --- a/README.Rmd +++ b/README.Rmd @@ -9,7 +9,7 @@ editor_options: ```{r, include = FALSE} knitr::opts_knit$set( progress = TRUE, - base.url = "https://raw.githubusercontent.com/ropenspain/mapSpain/master/" + base.url = "https://raw.githubusercontent.com/ropenspain/mapSpain/main/" ) knitr::opts_chunk$set( @@ -31,22 +31,24 @@ knitr::opts_chunk$set( [![rOS-badge](https://ropenspain.github.io/rostemplate/reference/figures/ropenspain-badge.svg)](https://ropenspain.es/) [![CRAN-status](https://www.r-pkg.org/badges/version/mapSpain)](https://CRAN.R-project.org/package=mapSpain) -[![CRAN-results](https://cranchecks.info/badges/worst/mapSpain)](https://cran.r-project.org/web/checks/check_results_mapSpain.html) +[![CRAN-results](https://badges.cranchecks.info/worst/mapSpain.svg)](https://cran.r-project.org/web/checks/check_results_mapSpain.html) [![Downloads](https://cranlogs.r-pkg.org/badges/mapSpain)](https://CRAN.R-project.org/package=mapSpain) -[![r-universe](https://ropenspain.r-universe.dev/badges/mapSpain)](https://ropenspain.r-universe.dev/) -[![R-CMD-check](https://github.com/rOpenSpain/mapSpain/workflows/R-CMD-check/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions?query=workflow%3AR-CMD-check) -[![codecov](https://codecov.io/gh/rOpenSpain/mapSpain/branch/master/graph/badge.svg?token=6L01BKLL85)](https://codecov.io/gh/rOpenSpain/mapSpain) -[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.4318024-blue)](https://doi.org/10.5281/zenodo.4318024) +[![r-universe](https://ropenspain.r-universe.dev/badges/mapSpain)](https://ropenspain.r-universe.dev/mapSpain) +[![R-CMD-check](https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml) +[![R-hub](https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml) +[![codecov](https://codecov.io/gh/rOpenSpain/mapSpain/branch/main/graph/badge.svg?token=6L01BKLL85)](https://app.codecov.io/gh/rOpenSpain/mapSpain) +[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5366622-blue)](https://doi.org/10.5281/zenodo.5366622) [![Project-Status:Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![status](https://tinyverse.netlify.app/badge/mapSpain)](https://CRAN.R-project.org/package=mapSpain) [**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package that -provides spatial `sf` objects of the administrative boundaries of Spain, +provides spatial **sf** objects of the administrative boundaries of Spain, including CCAA, provinces and municipalities. -**mapSpain** also provides a leaflet plugin to be used with the [`leaflet` -package](https://rstudio.github.io/leaflet/), that loads several basemaps of +**mapSpain** also provides a leaflet plugin to be used with the [**leaflet** +package](https://rstudio.github.io/leaflet/), that loads several base maps of public institutions of Spain, and the ability of downloading and processing static tiles. @@ -59,27 +61,27 @@ Install **mapSpain** from [**CRAN**](https://CRAN.R-project.org/package=mapSpain): ```{r, eval = FALSE} -install.packages("mapSpain") +install.packages("mapSpain", dependencies = TRUE) ``` You can install the developing version of **mapSpain** using the -[r-universe](https://ropenspain.r-universe.dev/ui#builds): +[r-universe](https://ropenspain.r-universe.dev/mapSpain): ```{r, eval = FALSE} -# Enable this universe -options(repos = c( - ropenspain = "https://ropenspain.r-universe.dev", - CRAN = "https://cloud.r-project.org" -)) - -install.packages("mapSpain") +# Install mapSpain in R: +install.packages("mapSpain", + repos = c( + "https://ropenspain.r-universe.dev", + "https://cloud.r-project.org" + ), + dependencies = TRUE +) ``` Alternatively, you can install the developing version of **mapSpain** with: ```{r, eval = FALSE} -library(remotes) -install_github("rOpenSpain/mapSpain") +remotes::install_github("rOpenSpain/mapSpain", dependencies = TRUE) ``` ## Usage @@ -87,160 +89,140 @@ install_github("rOpenSpain/mapSpain") This script highlights some features of **mapSpain** : ```{r static} - library(mapSpain) - +library(sf) +library(dplyr) census <- mapSpain::pobmun19 # Extract CCAA from base dataset -codelist <- mapSpain::esp_codelist +codelist <- mapSpain::esp_codelist %>% + select(cpro, codauto) %>% + distinct() + +census_ccaa <- census %>% + left_join(codelist) %>% + # Summarize by CCAA + group_by(codauto) %>% + summarise(pob19 = sum(pob19), men = sum(men), women = sum(women)) %>% + mutate( + porc_women = women / pob19, + porc_women_lab = paste0(round(100 * porc_women, 2), "%") + ) -census <- - unique(merge(census, codelist[, c("cpro", "codauto")], all.x = TRUE)) -# Summarize by CCAA -census_ccaa <- - aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum) +# Merge into spatial data -census_ccaa$porc_women <- census_ccaa$women / census_ccaa$pob19 -census_ccaa$porc_women_lab <- - paste0(round(100 * census_ccaa$porc_women, 2), "%") +ccaa_sf <- esp_get_ccaa() %>% + left_join(census_ccaa) +can <- esp_get_can_box() -# Merge into spatial data -CCAA_sf <- esp_get_ccaa() -CCAA_sf <- merge(CCAA_sf, census_ccaa) -Can <- esp_get_can_box() - - -# Plot with tmap -library(tmap) - -tm_shape(CCAA_sf) + - tm_polygons( - "porc_women", - border.col = "grey70", - title = "Porc. women", - palette = "Blues", - alpha = 0.7, - legend.format = list( - fun = function(x) { - sprintf("%1.1f%%", 100 * x) - } - ) +# Plot with ggplot +library(ggplot2) + + +ggplot(ccaa_sf) + + geom_sf(aes(fill = porc_women), color = "grey70", linewidth = .3) + + geom_sf(data = can, color = "grey70") + + geom_sf_label(aes(label = porc_women_lab), + fill = "white", alpha = 0.5, + size = 3, label.size = 0 ) + - tm_shape(CCAA_sf, point.per = "feature") + - tm_text("porc_women_lab", remove.overlap = TRUE, shadow = TRUE) + - tm_shape(Can) + - tm_lines(col = "grey70") + - tm_layout(legend.position = c("LEFT", "center")) + scale_fill_gradientn( + colors = hcl.colors(10, "Blues", rev = TRUE), + n.breaks = 10, labels = scales::label_percent(), + guide = guide_legend(title = "Porc. women", position = "inside") + ) + + theme_void() + + theme(legend.position.inside = c(0.1, 0.6)) ``` You can combine `sf` objects with static tiles -```{r tile, fig.width=5, fig.height=5.1} - +```{r tile} # Get census -census <- mapSpain::pobmun19 -census$porc_women <- census$women / census$pob19 +census <- mapSpain::pobmun19 %>% + mutate(porc_women = women / pob19) %>% + select(cpro, cmun, porc_women) # Get shapes shape <- esp_get_munic_siane(region = "Segovia", epsg = 3857) provs <- esp_get_prov_siane(epsg = 3857) -shape_pop <- merge(shape, - census, - by = c("cpro", "cmun"), - all.x = TRUE -) +shape_pop <- shape %>% left_join(census) -tile <- - esp_getTiles(shape_pop, - type = "IGNBase.Todo", - zoom = 10, - bbox_expand = 0.1 - ) +tile <- esp_getTiles(shape_pop, type = "IDErioja.Relieve", zoommin = 1) # Plot - -library(tmap) - -tm_shape(tile, raster.downsample = FALSE) + - tm_rgb() + - tm_shape(shape_pop) + - tm_fill("porc_women", - palette = "RdYlBu", - title = "", - n = 8, - alpha = 0.6, - showNA = FALSE, - legend.format = list( - fun = function(x) { - sprintf("%1.0f%%", 100 * x) - }, - text.separator = "-" - ) +library(ggplot2) +library(tidyterra) + +lims <- as.vector(terra::ext(tile)) + +ggplot(remove_missing(shape_pop, na.rm = TRUE)) + + geom_spatraster_rgb(data = tile, maxcell = 10e6) + + geom_sf(aes(fill = porc_women), color = NA) + + geom_sf(data = provs, fill = NA) + + scale_fill_gradientn( + colours = hcl.colors(10, "RdYlBu", alpha = .5), + n.breaks = 8, + labels = function(x) { + sprintf("%1.0f%%", 100 * x) + }, + guide = guide_legend(title = "", ) + ) + + coord_sf( + xlim = lims[c(1, 2)], + ylim = lims[c(3, 4)], + expand = FALSE ) + - tm_shape(provs) + - tm_credits("Source: INE", - fontface = "bold", - position = c("left", "bottom") + labs( + title = "Share of women in Segovia by town (2019)", + caption = "Source: INE, CC BY 4.0 www.iderioja.org" ) + - tm_borders(alpha = 0.5) + - tm_layout( - frame = FALSE, - main.title = "Share of women in Segovia by town (2019)", - main.title.fontface = "bold", - main.title.size = 0.8, - legend.position = c("right", "bottom"), - legend.bg.color = "white", - legend.bg.alpha = 0.7 + theme_void() + + theme( + title = element_text(face = "bold") ) ``` ## mapSpain and giscoR If you need to plot Spain along with another countries, consider using -[**giscoR**](https://dieghernan.github.io/giscoR/) package, that is installed as a +[**giscoR**](https://ropengov.github.io/giscoR/) package, that is installed as a dependency when you installed **mapSpain**. A basic example: ```{r giscoR, fig.asp=1} - library(giscoR) # Set the same resolution for a perfect fit -res <- "03" +res <- "20" -# Same crs -target_crs <- 3035 +all_countries <- gisco_get_countries(resolution = res) %>% + st_transform(3035) -all_countries <- gisco_get_countries( - resolution = res, - epsg = target_crs -) -eu_countries <- gisco_get_countries( - resolution = res, region = "EU", - epsg = target_crs -) -ccaa <- esp_get_ccaa( - moveCAN = FALSE, resolution = res, - epsg = target_crs -) +eu_countries <- gisco_get_countries(resolution = res, region = "EU") %>% + st_transform(3035) -# Plot -library(tmap) - -tm_shape(all_countries, bbox = c(23, 14, 67, 54) * 10e4) + - tm_graticules(col = "#DFDFDF", alpha = 0.7) + - tm_fill("#DFDFDF") + - tm_shape(eu_countries) + - tm_polygons("#FDFBEA", border.col = "#656565") + - tm_shape(ccaa) + - tm_polygons("#C12838", border.col = "grey80", lwd = 0.1) +ccaa <- esp_get_ccaa(moveCAN = FALSE, resolution = res) %>% + st_transform(3035) + +library(ggplot2) + +ggplot(all_countries) + + geom_sf(fill = "#DFDFDF", color = "#656565") + + geom_sf(data = eu_countries, fill = "#FDFBEA", color = "#656565") + + geom_sf(data = ccaa, fill = "#C12838", color = "grey80", linewidth = .1) + + # Center in Europe: EPSG 3035 + coord_sf(xlim = c(2377294, 7453440), ylim = c(1313597, 5628510)) + + theme( + panel.background = element_blank(), + panel.grid = element_line(colour = "#DFDFDF", linetype = "dotted") + ) ``` ## A note on caching @@ -263,24 +245,25 @@ Some packages recommended for visualization are: - [**tmap**](https://github.com/r-tmap/tmap) - [**mapsf**](https://riatelab.github.io/mapsf/) - [**ggplot2**](https://github.com/tidyverse/ggplot2) + - [**ggspatial**](https://github.com/paleolimbot/ggspatial) + [**tidyterra**](https://github.com/dieghernan/tidyterra). - [**leaflet**](https://rstudio.github.io/leaflet/) ## Citation -Please use the following when citing **mapSpain**: - -```{r citation} - -citation("mapSpain") +```{r echo=FALSE, results='asis'} +print(citation("mapSpain"), style = "html") ``` +A BibTeX entry for LaTeX users is: +```{r echo=FALSE, comment=''} +toBibtex(citation("mapSpain")) +``` ## Contribute -Check the GitHub page for -[source code](https://github.com/ropenspain/mapSpain/). +Check the GitHub page for [source +code](https://github.com/ropenspain/mapSpain/). ## Copyright notice @@ -294,7 +277,7 @@ Nacional: See This package uses data from **GISCO**. GISCO -[(FAQ)](https://ec.europa.eu/eurostat/web/gisco/faq) is a geospatial open data +[(FAQ)](https://ec.europa.eu/eurostat/web/gisco) is a geospatial open data repository including several data sets at several resolution levels. *From GISCO \> Geodata \> Reference data \> Administrative Units / Statistical diff --git a/README.md b/README.md index 32ae7a89..11acdae3 100644 --- a/README.md +++ b/README.md @@ -5,23 +5,25 @@ [![rOS-badge](https://ropenspain.github.io/rostemplate/reference/figures/ropenspain-badge.svg)](https://ropenspain.es/) [![CRAN-status](https://www.r-pkg.org/badges/version/mapSpain)](https://CRAN.R-project.org/package=mapSpain) -[![CRAN-results](https://cranchecks.info/badges/worst/mapSpain)](https://cran.r-project.org/web/checks/check_results_mapSpain.html) +[![CRAN-results](https://badges.cranchecks.info/worst/mapSpain.svg)](https://cran.r-project.org/web/checks/check_results_mapSpain.html) [![Downloads](https://cranlogs.r-pkg.org/badges/mapSpain)](https://CRAN.R-project.org/package=mapSpain) -[![r-universe](https://ropenspain.r-universe.dev/badges/mapSpain)](https://ropenspain.r-universe.dev/) -[![R-CMD-check](https://github.com/rOpenSpain/mapSpain/workflows/R-CMD-check/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions?query=workflow%3AR-CMD-check) -[![codecov](https://codecov.io/gh/rOpenSpain/mapSpain/branch/master/graph/badge.svg?token=6L01BKLL85)](https://codecov.io/gh/rOpenSpain/mapSpain) -[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.4318024-blue)](https://doi.org/10.5281/zenodo.4318024) +[![r-universe](https://ropenspain.r-universe.dev/badges/mapSpain)](https://ropenspain.r-universe.dev/mapSpain) +[![R-CMD-check](https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml) +[![R-hub](https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml/badge.svg)](https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml) +[![codecov](https://codecov.io/gh/rOpenSpain/mapSpain/branch/main/graph/badge.svg?token=6L01BKLL85)](https://app.codecov.io/gh/rOpenSpain/mapSpain) +[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5366622-blue)](https://doi.org/10.5281/zenodo.5366622) [![Project-Status:Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![status](https://tinyverse.netlify.app/badge/mapSpain)](https://CRAN.R-project.org/package=mapSpain) [**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package that -provides spatial `sf` objects of the administrative boundaries of Spain, -including CCAA, provinces and municipalities. +provides spatial **sf** objects of the administrative boundaries of +Spain, including CCAA, provinces and municipalities. **mapSpain** also provides a leaflet plugin to be used with the -[`leaflet` package](https://rstudio.github.io/leaflet/), that loads -several basemaps of public institutions of Spain, and the ability of +[**leaflet** package](https://rstudio.github.io/leaflet/), that loads +several base maps of public institutions of Spain, and the ability of downloading and processing static tiles. Full site with examples and vignettes on @@ -33,28 +35,28 @@ Install **mapSpain** from [**CRAN**](https://CRAN.R-project.org/package=mapSpain): ``` r -install.packages("mapSpain") +install.packages("mapSpain", dependencies = TRUE) ``` You can install the developing version of **mapSpain** using the -[r-universe](https://ropenspain.r-universe.dev/ui#builds): +[r-universe](https://ropenspain.r-universe.dev/mapSpain): ``` r -# Enable this universe -options(repos = c( - ropenspain = "https://ropenspain.r-universe.dev", - CRAN = "https://cloud.r-project.org" -)) - -install.packages("mapSpain") +# Install mapSpain in R: +install.packages("mapSpain", + repos = c( + "https://ropenspain.r-universe.dev", + "https://cloud.r-project.org" + ), + dependencies = TRUE +) ``` Alternatively, you can install the developing version of **mapSpain** with: ``` r -library(remotes) -install_github("rOpenSpain/mapSpain") +remotes::install_github("rOpenSpain/mapSpain", dependencies = TRUE) ``` ## Usage @@ -63,125 +65,113 @@ This script highlights some features of **mapSpain** : ``` r library(mapSpain) - +library(sf) +library(dplyr) census <- mapSpain::pobmun19 # Extract CCAA from base dataset -codelist <- mapSpain::esp_codelist +codelist <- mapSpain::esp_codelist %>% + select(cpro, codauto) %>% + distinct() + +census_ccaa <- census %>% + left_join(codelist) %>% + # Summarize by CCAA + group_by(codauto) %>% + summarise(pob19 = sum(pob19), men = sum(men), women = sum(women)) %>% + mutate( + porc_women = women / pob19, + porc_women_lab = paste0(round(100 * porc_women, 2), "%") + ) -census <- - unique(merge(census, codelist[, c("cpro", "codauto")], all.x = TRUE)) -# Summarize by CCAA -census_ccaa <- - aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum) +# Merge into spatial data -census_ccaa$porc_women <- census_ccaa$women / census_ccaa$pob19 -census_ccaa$porc_women_lab <- - paste0(round(100 * census_ccaa$porc_women, 2), "%") +ccaa_sf <- esp_get_ccaa() %>% + left_join(census_ccaa) +can <- esp_get_can_box() -# Merge into spatial data -CCAA_sf <- esp_get_ccaa() -CCAA_sf <- merge(CCAA_sf, census_ccaa) -Can <- esp_get_can_box() - - -# Plot with tmap -library(tmap) - -tm_shape(CCAA_sf) + - tm_polygons( - "porc_women", - border.col = "grey70", - title = "Porc. women", - palette = "Blues", - alpha = 0.7, - legend.format = list( - fun = function(x) { - sprintf("%1.1f%%", 100 * x) - } - ) +# Plot with ggplot +library(ggplot2) + + +ggplot(ccaa_sf) + + geom_sf(aes(fill = porc_women), color = "grey70", linewidth = .3) + + geom_sf(data = can, color = "grey70") + + geom_sf_label(aes(label = porc_women_lab), + fill = "white", alpha = 0.5, + size = 3, label.size = 0 + ) + + scale_fill_gradientn( + colors = hcl.colors(10, "Blues", rev = TRUE), + n.breaks = 10, labels = scales::label_percent(), + guide = guide_legend(title = "Porc. women", position = "inside") ) + - tm_shape(CCAA_sf, point.per = "feature") + - tm_text("porc_women_lab", remove.overlap = TRUE, shadow = TRUE) + - tm_shape(Can) + - tm_lines(col = "grey70") + - tm_layout(legend.position = c("LEFT", "center")) + theme_void() + + theme(legend.position.inside = c(0.1, 0.6)) ``` - + You can combine `sf` objects with static tiles ``` r # Get census -census <- mapSpain::pobmun19 -census$porc_women <- census$women / census$pob19 +census <- mapSpain::pobmun19 %>% + mutate(porc_women = women / pob19) %>% + select(cpro, cmun, porc_women) # Get shapes shape <- esp_get_munic_siane(region = "Segovia", epsg = 3857) provs <- esp_get_prov_siane(epsg = 3857) -shape_pop <- merge(shape, - census, - by = c("cpro", "cmun"), - all.x = TRUE -) +shape_pop <- shape %>% left_join(census) -tile <- - esp_getTiles(shape_pop, - type = "IGNBase.Todo", - zoom = 10, - bbox_expand = 0.1 - ) +tile <- esp_getTiles(shape_pop, type = "IDErioja.Relieve", zoommin = 1) # Plot - -library(tmap) - -tm_shape(tile, raster.downsample = FALSE) + - tm_rgb() + - tm_shape(shape_pop) + - tm_fill("porc_women", - palette = "RdYlBu", - title = "", - n = 8, - alpha = 0.6, - showNA = FALSE, - legend.format = list( - fun = function(x) { - sprintf("%1.0f%%", 100 * x) - }, - text.separator = "-" - ) +library(ggplot2) +library(tidyterra) + +lims <- as.vector(terra::ext(tile)) + +ggplot(remove_missing(shape_pop, na.rm = TRUE)) + + geom_spatraster_rgb(data = tile, maxcell = 10e6) + + geom_sf(aes(fill = porc_women), color = NA) + + geom_sf(data = provs, fill = NA) + + scale_fill_gradientn( + colours = hcl.colors(10, "RdYlBu", alpha = .5), + n.breaks = 8, + labels = function(x) { + sprintf("%1.0f%%", 100 * x) + }, + guide = guide_legend(title = "", ) + ) + + coord_sf( + xlim = lims[c(1, 2)], + ylim = lims[c(3, 4)], + expand = FALSE ) + - tm_shape(provs) + - tm_credits("Source: INE", - fontface = "bold", - position = c("left", "bottom") + labs( + title = "Share of women in Segovia by town (2019)", + caption = "Source: INE, CC BY 4.0 www.iderioja.org" ) + - tm_borders(alpha = 0.5) + - tm_layout( - frame = FALSE, - main.title = "Share of women in Segovia by town (2019)", - main.title.fontface = "bold", - main.title.size = 0.8, - legend.position = c("right", "bottom"), - legend.bg.color = "white", - legend.bg.alpha = 0.7 + theme_void() + + theme( + title = element_text(face = "bold") ) ``` - + ## mapSpain and giscoR If you need to plot Spain along with another countries, consider using -[**giscoR**](https://dieghernan.github.io/giscoR/) package, that is +[**giscoR**](https://ropengov.github.io/giscoR/) package, that is installed as a dependency when you installed **mapSpain**. A basic example: @@ -190,37 +180,32 @@ library(giscoR) # Set the same resolution for a perfect fit -res <- "03" +res <- "20" -# Same crs -target_crs <- 3035 +all_countries <- gisco_get_countries(resolution = res) %>% + st_transform(3035) -all_countries <- gisco_get_countries( - resolution = res, - epsg = target_crs -) -eu_countries <- gisco_get_countries( - resolution = res, region = "EU", - epsg = target_crs -) -ccaa <- esp_get_ccaa( - moveCAN = FALSE, resolution = res, - epsg = target_crs -) +eu_countries <- gisco_get_countries(resolution = res, region = "EU") %>% + st_transform(3035) -# Plot -library(tmap) - -tm_shape(all_countries, bbox = c(23, 14, 67, 54) * 10e4) + - tm_graticules(col = "#DFDFDF", alpha = 0.7) + - tm_fill("#DFDFDF") + - tm_shape(eu_countries) + - tm_polygons("#FDFBEA", border.col = "#656565") + - tm_shape(ccaa) + - tm_polygons("#C12838", border.col = "grey80", lwd = 0.1) +ccaa <- esp_get_ccaa(moveCAN = FALSE, resolution = res) %>% + st_transform(3035) + +library(ggplot2) + +ggplot(all_countries) + + geom_sf(fill = "#DFDFDF", color = "#656565") + + geom_sf(data = eu_countries, fill = "#FDFBEA", color = "#656565") + + geom_sf(data = ccaa, fill = "#C12838", color = "grey80", linewidth = .1) + + # Center in Europe: EPSG 3035 + coord_sf(xlim = c(2377294, 7453440), ylim = c(1313597, 5628510)) + + theme( + panel.background = element_blank(), + panel.grid = element_line(colour = "#DFDFDF", linetype = "dotted") + ) ``` - + ## A note on caching @@ -239,34 +224,32 @@ it will load it, speeding up the process. Some packages recommended for visualization are: -- [**tmap**](https://github.com/r-tmap/tmap) -- [**mapsf**](https://riatelab.github.io/mapsf/) -- [**ggplot2**](https://github.com/tidyverse/ggplot2) + - [**ggspatial**](https://github.com/paleolimbot/ggspatial) -- [**leaflet**](https://rstudio.github.io/leaflet/) +- [**tmap**](https://github.com/r-tmap/tmap) +- [**mapsf**](https://riatelab.github.io/mapsf/) +- [**ggplot2**](https://github.com/tidyverse/ggplot2) + + [**tidyterra**](https://github.com/dieghernan/tidyterra). +- [**leaflet**](https://rstudio.github.io/leaflet/) ## Citation -Please use the following when citing **mapSpain**: - -``` r -citation("mapSpain") -#> -#> To cite the 'mapSpain' package in publications use: -#> -#> Hernangómez, D. (2021). mapSpain: Administrative Boundaries of Spain. -#> R package. http://doi.org/10.5281/zenodo.4318024 -#> -#> A BibTeX entry for LaTeX users is -#> -#> @Manual{, -#> title = {mapSpain: Administrative Boundaries of Spain}, -#> author = {Diego Hernangómez}, -#> year = {2021}, -#> url = {https://ropenspain.github.io/mapSpain/}, -#> doi = {10.5281/zenodo.4318024}, -#> } -``` +

+Hernangómez D (2024). mapSpain: Administrative Boundaries of +Spain. +doi:10.5281/zenodo.5366622, +https://ropenspain.github.io/mapSpain/. +

+ +A BibTeX entry for LaTeX users is: + + @Manual{R-mapspain, + title = {{mapSpain}: Administrative Boundaries of Spain}, + year = {2024}, + version = {0.10.0}, + author = {Diego Hernangómez}, + doi = {10.5281/zenodo.5366622}, + url = {https://ropenspain.github.io/mapSpain/}, + abstract = {Administrative Boundaries of Spain at several levels (Autonomous Communities, Provinces, Municipalities) based on the GISCO Eurostat database and CartoBase SIANE from Instituto Geografico Nacional . It also provides a leaflet plugin and the ability of downloading and processing static tiles.}, + } ## Contribute @@ -285,11 +268,11 @@ Geográfico Nacional: See This package uses data from **GISCO**. GISCO -[(FAQ)](https://ec.europa.eu/eurostat/web/gisco/faq) is a geospatial -open data repository including several data sets at several resolution +[(FAQ)](https://ec.europa.eu/eurostat/web/gisco) is a geospatial open +data repository including several data sets at several resolution levels. -*From GISCO > Geodata > Reference data > Administrative Units / +*From GISCO \> Geodata \> Reference data \> Administrative Units / Statistical Units* > When data downloaded from this page is used in any printed or diff --git a/codemeta.json b/codemeta.json index 2f4a0cc7..5dc0de80 100644 --- a/codemeta.json +++ b/codemeta.json @@ -2,19 +2,19 @@ "@context": "https://doi.org/10.5063/schema/codemeta-2.0", "@type": "SoftwareSourceCode", "identifier": "mapSpain", - "description": "Administrative Boundaries of Spain at several levels (CCAA,\n Provinces, Municipalities) based on the GISCO Eurostat database\n and 'CartoBase SIANE' from\n 'Instituto Geografico Nacional' . It also\n provides a 'leaflet' plugin and the ability of downloading and\n processing static tiles.", + "description": "Administrative Boundaries of Spain at several levels (Autonomous Communities, Provinces, Municipalities) based on the 'GISCO' 'Eurostat' database and 'CartoBase SIANE' from 'Instituto Geografico Nacional' . It also provides a 'leaflet' plugin and the ability of downloading and processing static tiles.", "name": "mapSpain: Administrative Boundaries of Spain", + "relatedLink": ["https://ropenspain.github.io/mapSpain/", "https://CRAN.R-project.org/package=mapSpain"], "codeRepository": "https://github.com/rOpenSpain/mapSpain", - "relatedLink": "https://ropenspain.github.io/mapSpain/", "issueTracker": "https://github.com/rOpenSpain/mapSpain/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.3.0.9000", + "version": "0.10.0", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", "url": "https://r-project.org" }, - "runtimePlatform": "R version 4.1.1 (2021-08-10)", + "runtimePlatform": "R version 4.4.2 (2024-10-31 ucrt)", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -37,14 +37,6 @@ "familyName": "Hernangómez", "email": "diego.hernangomezherrero@gmail.com", "@id": "https://orcid.org/0000-0001-8457-4658" - }, - { - "@type": "Organization", - "name": "EuroGeographics" - }, - { - "@type": "Organization", - "name": "Instituto Geográfico Nacional" } ], "maintainer": [ @@ -57,6 +49,31 @@ } ], "softwareSuggestions": [ + { + "@type": "SoftwareApplication", + "identifier": "curl", + "name": "curl", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=curl" + }, + { + "@type": "SoftwareApplication", + "identifier": "ggplot2", + "name": "ggplot2", + "version": ">= 3.0.0", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=ggplot2" + }, { "@type": "SoftwareApplication", "identifier": "knitr", @@ -71,15 +88,29 @@ }, { "@type": "SoftwareApplication", - "identifier": "rgdal", - "name": "rgdal", + "identifier": "leaflet", + "name": "leaflet", + "version": ">= 2.0.0", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", "name": "Comprehensive R Archive Network (CRAN)", "url": "https://cran.r-project.org" }, - "sameAs": "https://CRAN.R-project.org/package=rgdal" + "sameAs": "https://CRAN.R-project.org/package=leaflet" + }, + { + "@type": "SoftwareApplication", + "identifier": "png", + "name": "png", + "version": ">= 0.1-5", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=png" }, { "@type": "SoftwareApplication", @@ -95,33 +126,34 @@ }, { "@type": "SoftwareApplication", - "identifier": "testthat", - "name": "testthat", - "version": ">= 3.0.0", + "identifier": "slippymath", + "name": "slippymath", + "version": ">= 0.3.1", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", "name": "Comprehensive R Archive Network (CRAN)", "url": "https://cran.r-project.org" }, - "sameAs": "https://CRAN.R-project.org/package=testthat" + "sameAs": "https://CRAN.R-project.org/package=slippymath" }, { "@type": "SoftwareApplication", - "identifier": "tibble", - "name": "tibble", + "identifier": "terra", + "name": "terra", + "version": ">= 1.1-4", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", "name": "Comprehensive R Archive Network (CRAN)", "url": "https://cran.r-project.org" }, - "sameAs": "https://CRAN.R-project.org/package=tibble" + "sameAs": "https://CRAN.R-project.org/package=terra" }, { "@type": "SoftwareApplication", - "identifier": "tmap", - "name": "tmap", + "identifier": "testthat", + "name": "testthat", "version": ">= 3.0.0", "provider": { "@id": "https://cran.r-project.org", @@ -129,7 +161,19 @@ "name": "Comprehensive R Archive Network (CRAN)", "url": "https://cran.r-project.org" }, - "sameAs": "https://CRAN.R-project.org/package=tmap" + "sameAs": "https://CRAN.R-project.org/package=testthat" + }, + { + "@type": "SoftwareApplication", + "identifier": "tidyterra", + "name": "tidyterra", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=tidyterra" } ], "softwareRequirements": { @@ -166,32 +210,6 @@ "sameAs": "https://CRAN.R-project.org/package=giscoR" }, "4": { - "@type": "SoftwareApplication", - "identifier": "leaflet", - "name": "leaflet", - "version": ">= 2.0.0", - "provider": { - "@id": "https://cran.r-project.org", - "@type": "Organization", - "name": "Comprehensive R Archive Network (CRAN)", - "url": "https://cran.r-project.org" - }, - "sameAs": "https://CRAN.R-project.org/package=leaflet" - }, - "5": { - "@type": "SoftwareApplication", - "identifier": "png", - "name": "png", - "version": ">= 0.1-5", - "provider": { - "@id": "https://cran.r-project.org", - "@type": "Organization", - "name": "Comprehensive R Archive Network (CRAN)", - "url": "https://cran.r-project.org" - }, - "sameAs": "https://CRAN.R-project.org/package=png" - }, - "6": { "@type": "SoftwareApplication", "identifier": "rappdirs", "name": "rappdirs", @@ -204,24 +222,11 @@ }, "sameAs": "https://CRAN.R-project.org/package=rappdirs" }, - "7": { - "@type": "SoftwareApplication", - "identifier": "raster", - "name": "raster", - "version": ">= 3.0", - "provider": { - "@id": "https://cran.r-project.org", - "@type": "Organization", - "name": "Comprehensive R Archive Network (CRAN)", - "url": "https://cran.r-project.org" - }, - "sameAs": "https://CRAN.R-project.org/package=raster" - }, - "8": { + "5": { "@type": "SoftwareApplication", "identifier": "sf", "name": "sf", - "version": ">= 0.9", + "version": ">= 0.9.0", "provider": { "@id": "https://cran.r-project.org", "@type": "Organization", @@ -230,20 +235,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=sf" }, - "9": { - "@type": "SoftwareApplication", - "identifier": "slippymath", - "name": "slippymath", - "version": ">= 0.3.1", - "provider": { - "@id": "https://cran.r-project.org", - "@type": "Organization", - "name": "Comprehensive R Archive Network (CRAN)", - "url": "https://cran.r-project.org" - }, - "sameAs": "https://CRAN.R-project.org/package=slippymath" - }, - "10": { + "6": { "@type": "SoftwareApplication", "identifier": "utils", "name": "utils" @@ -252,12 +244,12 @@ }, "applicationCategory": "cartography", "isPartOf": "https://ropenspain.es/", - "keywords": ["rOpenSpain", "tiles", "r", "maps", "spatial", "rstats", "r-package", "municipalities", "Spain", "gisco", "provinces", "ign", "administrative-boundaries", "ccaa", "static-tiles"], - "fileSize": "2735.64KB", + "keywords": ["ropenspain", "tiles", "r", "maps", "spatial", "rstats", "r-package", "municipalities", "spain", "gisco", "provinces", "ign", "administrative-boundaries", "ccaa", "static-tiles", "cran", "ggplot2", "gis"], + "fileSize": "2840.415KB", "citation": [ { "@type": "SoftwareSourceCode", - "datePublished": "2021", + "datePublished": "2024", "author": [ { "@type": "Person", @@ -265,11 +257,15 @@ "familyName": "Hernangómez" } ], - "name": "mapSpain: Administrative Boundaries of Spain", - "identifier": "10.5281/zenodo.4318024", + "name": "{mapSpain}: Administrative Boundaries of Spain", + "identifier": "10.5281/zenodo.5366622", "url": "https://ropenspain.github.io/mapSpain/", - "@id": "https://doi.org/10.5281/zenodo.4318024", - "sameAs": "https://doi.org/10.5281/zenodo.4318024" + "@id": "https://doi.org/10.5281/zenodo.5366622", + "sameAs": "https://doi.org/10.5281/zenodo.5366622" } - ] + ], + "releaseNotes": "https://github.com/rOpenSpain/mapSpain/blob/master/NEWS.md", + "readme": "https://github.com/rOpenSpain/mapSpain/blob/main/README.md", + "contIntegration": ["https://github.com/rOpenSpain/mapSpain/actions/workflows/check-full.yaml", "https://github.com/rOpenSpain/mapSpain/actions/workflows/rhub.yaml", "https://app.codecov.io/gh/rOpenSpain/mapSpain"], + "developmentStatus": "https://www.repostatus.org/#active" } diff --git a/data-raw/create_grids.R b/data-raw/create_grids.R index 6a871187..ff0cec72 100644 --- a/data-raw/create_grids.R +++ b/data-raw/create_grids.R @@ -87,7 +87,7 @@ labelLayer(newgrid, txt = "id") df <- data.frame( iso2.ccaa.code = c("ES-CN", "ES-CE", "ES-ML", "ES-IB"), - id = c(22, 46, 56, 83) + id = c(22, 47, 57, 83) ) finalgrid <- newgrid %>% @@ -221,7 +221,7 @@ plot(st_geometry(REST), col = "blue", add = TRUE) labelLayer(newgrid, txt = "id") df <- data.frame( - id = c(2, 34, 82, 114, 188), + id = c(2, 34, 82, 114, 189), cpro = esp_dict_region_code( c( "Santa Cruz de Tenerife", @@ -256,6 +256,8 @@ final <- final[, newnames] final <- st_make_valid(final) final <- st_transform(final, 4258) +plot(st_geometry(final)) +plot(esp_get_prov() %>% st_transform(4258) %>% st_geometry(), add = TRUE) esp_hexbin_prov <- st_make_valid(final) diff --git a/data-raw/espCCAA.csv b/data-raw/espCCAA.csv index 809d1953..916adf8e 100644 --- a/data-raw/espCCAA.csv +++ b/data-raw/espCCAA.csv @@ -1,20 +1,20 @@ -"codauto","iso2.ccaa.code","nuts1.code","nuts2.code","ine.ccaa.name","iso2.ccaa.name.es","iso2.ccaa.name.ca","iso2.ccaa.name.gl","iso2.ccaa.name.eu","nuts2.name","cldr.ccaa.name.en","cldr.ccaa.name.es","cldr.ccaa.name.ca","cldr.ccaa.name.ga","cldr.ccaa.name.eu","ccaa.shortname.en","ccaa.shortname.es","ccaa.shortname.ca","ccaa.shortname.ga","ccaa.shortname.eu" -"01","ES-AN","ES6","ES61","Andalucía","Andalucía",NA,NA,NA,"Andalucía","Andalusia","Andalucía","Andalusia","Andalucía","Andaluzia","Andalusia","Andalucía","Andalusia","Andalucía","Andaluzia" -"02","ES-AR","ES2","ES24","Aragón","Aragón",NA,NA,NA,"Aragón","Aragon","Aragón","Aragó","Aragón","Aragoi","Aragon","Aragón","Aragó","Aragón","Aragoi" -"03","ES-AS","ES1","ES12","Asturias, Principado de","Asturias, Principado de",NA,NA,NA,"Principado de Asturias","Asturias","Principado de Asturias","Astúries","Principado de Asturias","Asturiesko Printzerria","Asturias","Asturias","Astúries","Asturias","Asturias" -"04","ES-IB","ES5","ES53","Balears, Illes","Islas Baleares","Illes Balears",NA,NA,"Illes Balears","Balearic Islands","Islas Baleares","Illes Balears","Illas Baleares - Illes Balears","Balear Uharteak","Balearic Islands","Baleares","Illes Balears","Illas Baleares","Balear Uharteak" -"05","ES-CN","ES7","ES70","Canarias","Canarias",NA,NA,NA,"Canarias","Canary Islands",NA,NA,NA,NA,"Canary Islands","Canarias","Canàries","Canarias","Kanariak" -"06","ES-CB","ES1","ES13","Cantabria","Cantabria",NA,NA,NA,"Cantabria","Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria","Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria" -"07","ES-CL","ES4","ES41","Castilla y León","Castilla y León",NA,NA,NA,"Castilla y León","Castile and León","Castilla y León","Castella i Lleó","Castela e León","Gaztela eta Leon","Castile and León","Castilla y León","Castella i Lleó","Castela e León","Gaztela eta Leon" -"08","ES-CM","ES4","ES42","Castilla - La Mancha","Castilla-La Mancha",NA,NA,NA,"Castilla-La Mancha","Castile-La Mancha","Castilla-La Mancha","Castella - la Manxa","Castela-A Mancha","Gaztela-Mantxa","Castile-La Mancha","Castilla-La Mancha","Castella - la Manxa","Castela-A Mancha","Gaztela-Mantxa" -"09","ES-CT","ES5","ES51","Cataluña","Cataluña","Catalunya",NA,NA,"Cataluña","Catalonia","Cataluña","Catalunya","Cataluña","Katalunia","Catalonia","Cataluña","Catalunya","Cataluña","Katalunia" -"10","ES-VC","ES5","ES52","Comunitat Valenciana","Valenciana, Comunidad","Valenciana, Comunitat",NA,NA,"Comunidad Valenciana","Valencian Community","Comunidad Valenciana","País Valencià","Comunidade Valenciana","Valentziako Erkidegoa","Valencian Community","Comunidad Valenciana","País Valencià","Comunidade Valenciana","Valentziako Erkidegoa" -"11","ES-EX","ES4","ES43","Extremadura","Extremadura",NA,NA,NA,"Extremadura","Extremadura","Extremadura","Extremadura","Estremadura - Extremadura","Extremadura","Extremadura","Extremadura","Extremadura","Estremadura","Extremadura" -"12","ES-GA","ES1","ES11","Galicia","Galicia",NA,"Galicia",NA,"Galicia","Galicia","Galicia","Galícia","Galicia","Galizia","Galicia","Galicia","Galícia","Galicia","Galizia" -"13","ES-MD","ES3","ES30","Madrid, Comunidad de","Madrid, Comunidad de",NA,NA,NA,"Comunidad de Madrid","Madrid Autonomous Community","Comunidad de Madrid","Comunitat de Madrid","Comunidade de Madrid","Madrilgo Erkidegoa","Madrid","Madrid","Madrid","Madrid","Madril" -"14","ES-MC","ES6","ES62","Murcia, Región de","Murcia, Región de",NA,NA,NA,"Región de Murcia","Murcia Region","Región de Murcia","Regió de Múrcia","Rexión de Murcia","Murtziako Eskualdea","Murcia","Murcia","Múrcia","Murcia","Murtzia" -"15","ES-NC","ES2","ES22","Navarra, Comunidad Foral de","Navarra, Comunidad Foral de",NA,NA,"Nafarroako Foru Komunitatea","Comunidad Foral de Navarra","Navarra Chartered Community","Navarra","Navarra","Navarra","Nafarroako Foru Erkidegoa","Navarra","Navarra","Navarra","Navarra","Nafarroa" -"16","ES-PV","ES2","ES21","País Vasco","País Vasco",NA,NA,"Euskal Herria","País Vasco","Basque Country","País Vasco","Comunitat autònoma del País Basc","País Vasco","Euskal Autonomia Erkidegoa","Basque Country","País Vasco","País Basc","País Vasco","Euskadi" -"17","ES-RI","ES2","ES23","Rioja, La","La Rioja",NA,NA,NA,"La Rioja","La Rioja","La Rioja","La Rioja","A Rioxa","Errioxako Autonomia Erkidegoa","La Rioja","La Rioja","La Rioja","A Rioxa","Errioxa" -"18","ES-CE","ES6","ES63","Ceuta","Ceuta",NA,NA,NA,"Ciudad Autónoma de Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta" -"19","ES-ML","ES6","ES64","Melilla","Melilla",NA,NA,NA,"Ciudad Autónoma de Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla" +"codauto","iso2.ccaa.code","nuts1.code","nuts2.code","ine.ccaa.name","iso2.ccaa.name.es","iso2.ccaa.name.ca","iso2.ccaa.name.gl","iso2.ccaa.name.eu","nuts2.name","cldr.ccaa.name.en","cldr.ccaa.name.es","cldr.ccaa.name.ca","cldr.ccaa.name.ga","cldr.ccaa.name.eu","ccaa.shortname.en","ccaa.shortname.es","ccaa.shortname.ca","ccaa.shortname.ga","ccaa.shortname.eu" +"01","ES-AN","ES6","ES61","Andalucía","Andalucía",NA,NA,NA,"Andalucía","Andalusia","Andalucía","Andalusia","Andalucía","Andaluzia","Andalusia","Andalucía","Andalusia","Andalucía","Andaluzia" +"02","ES-AR","ES2","ES24","Aragón","Aragón",NA,NA,NA,"Aragón","Aragon","Aragón","Aragó","Aragón","Aragoi","Aragon","Aragón","Aragó","Aragón","Aragoi" +"03","ES-AS","ES1","ES12","Asturias, Principado de","Asturias, Principado de",NA,NA,NA,"Principado de Asturias","Asturias","Principado de Asturias","Astúries","Principado de Asturias","Asturiesko Printzerria","Asturias","Asturias","Astúries","Asturias","Asturias" +"04","ES-IB","ES5","ES53","Balears, Illes","Islas Baleares","Illes Balears",NA,NA,"Illes Balears","Balearic Islands","Islas Baleares","Illes Balears","Illas Baleares - Illes Balears","Balear Uharteak","Balearic Islands","Baleares","Illes Balears","Illas Baleares","Balear Uharteak" +"05","ES-CN","ES7","ES70","Canarias","Canarias",NA,NA,NA,"Canarias","Canary Islands",NA,NA,NA,NA,"Canary Islands","Canarias","Canàries","Canarias","Kanariak" +"06","ES-CB","ES1","ES13","Cantabria","Cantabria",NA,NA,NA,"Cantabria","Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria","Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria" +"07","ES-CL","ES4","ES41","Castilla y León","Castilla y León",NA,NA,NA,"Castilla y León","Castile and León","Castilla y León","Castella i Lleó","Castela e León","Gaztela eta Leon","Castile and León","Castilla y León","Castella i Lleó","Castela e León","Gaztela eta Leon" +"08","ES-CM","ES4","ES42","Castilla - La Mancha","Castilla-La Mancha",NA,NA,NA,"Castilla-La Mancha","Castile-La Mancha","Castilla-La Mancha","Castella - la Manxa","Castela-A Mancha","Gaztela-Mantxa","Castile-La Mancha","Castilla-La Mancha","Castella - la Manxa","Castela-A Mancha","Gaztela-Mantxa" +"09","ES-CT","ES5","ES51","Cataluña","Cataluña","Catalunya",NA,NA,"Cataluña","Catalonia","Cataluña","Catalunya","Cataluña","Katalunia","Catalonia","Cataluña","Catalunya","Cataluña","Katalunia" +"10","ES-VC","ES5","ES52","Comunitat Valenciana","Valenciana, Comunidad","Valenciana, Comunitat",NA,NA,"Comunidad Valenciana","Valencian Community","Comunidad Valenciana","País Valencià","Comunidade Valenciana","Valentziako Erkidegoa","Valencian Community","Comunidad Valenciana","País Valencià","Comunidade Valenciana","Valentziako Erkidegoa" +"11","ES-EX","ES4","ES43","Extremadura","Extremadura",NA,NA,NA,"Extremadura","Extremadura","Extremadura","Extremadura","Estremadura - Extremadura","Extremadura","Extremadura","Extremadura","Extremadura","Extremadura","Extremadura" +"12","ES-GA","ES1","ES11","Galicia","Galicia",NA,"Galicia",NA,"Galicia","Galicia","Galicia","Galícia","Galicia","Galizia","Galicia","Galicia","Galícia","Galicia","Galizia" +"13","ES-MD","ES3","ES30","Madrid, Comunidad de","Madrid, Comunidad de",NA,NA,NA,"Comunidad de Madrid","Madrid Autonomous Community","Comunidad de Madrid","Comunitat de Madrid","Comunidade de Madrid","Madrilgo Erkidegoa","Madrid","Madrid","Madrid","Madrid","Madril" +"14","ES-MC","ES6","ES62","Murcia, Región de","Murcia, Región de",NA,NA,NA,"Región de Murcia","Murcia Region","Región de Murcia","Regió de Múrcia","Rexión de Murcia","Murtziako Eskualdea","Murcia","Murcia","Múrcia","Murcia","Murtzia" +"15","ES-NC","ES2","ES22","Navarra, Comunidad Foral de","Navarra, Comunidad Foral de",NA,NA,"Nafarroako Foru Komunitatea","Comunidad Foral de Navarra","Navarra Chartered Community","Navarra","Navarra","Navarra","Nafarroako Foru Erkidegoa","Navarra","Navarra","Navarra","Navarra","Nafarroa" +"16","ES-PV","ES2","ES21","País Vasco","País Vasco",NA,NA,"Euskal Herria","País Vasco","Basque Country","País Vasco","Comunitat autònoma del País Basc","País Vasco","Euskal Autonomia Erkidegoa","Basque Country","País Vasco","País Basc","País Vasco","Euskadi" +"17","ES-RI","ES2","ES23","Rioja, La","La Rioja",NA,NA,NA,"La Rioja","La Rioja","La Rioja","La Rioja","A Rioxa","Errioxako Autonomia Erkidegoa","La Rioja","La Rioja","La Rioja","A Rioxa","Errioxa" +"18","ES-CE","ES6","ES63","Ceuta","Ceuta",NA,NA,NA,"Ciudad Autónoma de Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta" +"19","ES-ML","ES6","ES64","Melilla","Melilla",NA,NA,NA,"Ciudad Autónoma de Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla" diff --git a/data-raw/espNUTS1.csv b/data-raw/espNUTS1.csv index c37d08ec..0b6aa33a 100644 --- a/data-raw/espNUTS1.csv +++ b/data-raw/espNUTS1.csv @@ -1,8 +1,8 @@ -"nuts1.code","nuts1.name","nuts1.name.alt","nuts1.shortname.es" -"ES1","NOROESTE","Noroeste","Noroeste" -"ES2","NORESTE","Noreste","Noreste" -"ES3","COMUNIDAD DE MADRID","Madrid","Madrid" -"ES4","CENTRO (ES)","Centro (ES)","Centro" -"ES5","ESTE","Este","Este" -"ES6","SUR","Sur","Sur" -"ES7","CANARIAS","Canarias","Canarias" +"nuts1.code","nuts1.name","nuts1.name.alt","nuts1.shortname.es" +"ES1","NOROESTE","Noroeste","Noroeste" +"ES2","NORESTE","Noreste","Noreste" +"ES3","COMUNIDAD DE MADRID","Madrid","Madrid" +"ES4","CENTRO (ES)","Centro (ES)","Centro" +"ES5","ESTE","Este","Este" +"ES6","SUR","Sur","Sur" +"ES7","CANARIAS","Canarias","Canarias" diff --git a/data-raw/espNUTS3.csv b/data-raw/espNUTS3.csv index efe95168..a84cd29a 100644 --- a/data-raw/espNUTS3.csv +++ b/data-raw/espNUTS3.csv @@ -1,60 +1,60 @@ -"cpro","nuts3.code","nuts3.name","nuts3.shortname.es" -"15","ES111","A Coruña","La Coruña" -"27","ES112","Lugo","Lugo" -"32","ES113","Ourense","Orense" -"36","ES114","Pontevedra","Pontevedra" -"33","ES120","Asturias","Asturias" -"39","ES130","Cantabria","Cantabria" -"01","ES211","Araba/Álava","Álava" -"20","ES212","Gipuzkoa","Guipúzcoa" -"48","ES213","Bizkaia","Vizcaya" -"31","ES220","Navarra","Navarra" -"26","ES230","La Rioja","La Rioja" -"22","ES241","Huesca","Huesca" -"44","ES242","Teruel","Teruel" -"50","ES243","Zaragoza","Zaragoza" -"28","ES300","Madrid","Madrid" -"05","ES411","Ávila","Ávila" -"09","ES412","Burgos","Burgos" -"24","ES413","León","León" -"34","ES414","Palencia","Palencia" -"37","ES415","Salamanca","Salamanca" -"40","ES416","Segovia","Segovia" -"42","ES417","Soria","Soria" -"47","ES418","Valladolid","Valladolid" -"49","ES419","Zamora","Zamora" -"02","ES421","Albacete","Albacete" -"13","ES422","Ciudad Real","Ciudad Real" -"16","ES423","Cuenca","Cuenca" -"19","ES424","Guadalajara","Guadalajara" -"45","ES425","Toledo","Toledo" -"06","ES431","Badajoz","Badajoz" -"10","ES432","Cáceres","Cáceres" -"08","ES511","Barcelona","Barcelona" -"17","ES512","Girona","Gerona" -"25","ES513","Lleida","Lérida" -"43","ES514","Tarragona","Tarragona" -"03","ES521","Alicante / Alacant","Alicante" -"12","ES522","Castellón / Castelló","Castellón" -"46","ES523","Valencia / València","Valencia" -"07","ES531","Eivissa y Formentera","Ibiza y Formentera" -"07","ES532","Mallorca","Mallorca" -"07","ES533","Menorca","Menorca" -"04","ES611","Almería","Almería" -"11","ES612","Cádiz","Cádiz" -"14","ES613","Córdoba","Córdoba" -"18","ES614","Granada","Granada" -"21","ES615","Huelva","Huelva" -"23","ES616","Jaén","Jaén" -"29","ES617","Málaga","Málaga" -"41","ES618","Sevilla","Sevilla" -"30","ES620","Murcia","Murcia" -"51","ES630","Ceuta","Ceuta" -"52","ES640","Melilla","Melilla" -"38","ES703","El Hierro","El Hierro" -"35","ES704","Fuerteventura","Fuerteventura" -"35","ES705","Gran Canaria","Gran Canaria" -"38","ES706","La Gomera","La Gomera" -"38","ES707","La Palma","La Palma" -"35","ES708","Lanzarote","Lanzarote" -"38","ES709","Tenerife","Tenerife" +"cpro","nuts3.code","nuts3.name","nuts3.shortname.es" +"15","ES111","A Coruña","La Coruña" +"27","ES112","Lugo","Lugo" +"32","ES113","Ourense","Orense" +"36","ES114","Pontevedra","Pontevedra" +"33","ES120","Asturias","Asturias" +"39","ES130","Cantabria","Cantabria" +"01","ES211","Araba/Álava","Álava" +"20","ES212","Gipuzkoa","Guipúzcoa" +"48","ES213","Bizkaia","Vizcaya" +"31","ES220","Navarra","Navarra" +"26","ES230","La Rioja","La Rioja" +"22","ES241","Huesca","Huesca" +"44","ES242","Teruel","Teruel" +"50","ES243","Zaragoza","Zaragoza" +"28","ES300","Madrid","Madrid" +"05","ES411","Ávila","Ávila" +"09","ES412","Burgos","Burgos" +"24","ES413","León","León" +"34","ES414","Palencia","Palencia" +"37","ES415","Salamanca","Salamanca" +"40","ES416","Segovia","Segovia" +"42","ES417","Soria","Soria" +"47","ES418","Valladolid","Valladolid" +"49","ES419","Zamora","Zamora" +"02","ES421","Albacete","Albacete" +"13","ES422","Ciudad Real","Ciudad Real" +"16","ES423","Cuenca","Cuenca" +"19","ES424","Guadalajara","Guadalajara" +"45","ES425","Toledo","Toledo" +"06","ES431","Badajoz","Badajoz" +"10","ES432","Cáceres","Cáceres" +"08","ES511","Barcelona","Barcelona" +"17","ES512","Girona","Gerona" +"25","ES513","Lleida","Lérida" +"43","ES514","Tarragona","Tarragona" +"03","ES521","Alicante / Alacant","Alicante" +"12","ES522","Castellón / Castelló","Castellón" +"46","ES523","Valencia / València","Valencia" +"07","ES531","Eivissa y Formentera","Ibiza y Formentera" +"07","ES532","Mallorca","Mallorca" +"07","ES533","Menorca","Menorca" +"04","ES611","Almería","Almería" +"11","ES612","Cádiz","Cádiz" +"14","ES613","Córdoba","Córdoba" +"18","ES614","Granada","Granada" +"21","ES615","Huelva","Huelva" +"23","ES616","Jaén","Jaén" +"29","ES617","Málaga","Málaga" +"41","ES618","Sevilla","Sevilla" +"30","ES620","Murcia","Murcia" +"51","ES630","Ceuta","Ceuta" +"52","ES640","Melilla","Melilla" +"38","ES703","El Hierro","El Hierro" +"35","ES704","Fuerteventura","Fuerteventura" +"35","ES705","Gran Canaria","Gran Canaria" +"38","ES706","La Gomera","La Gomera" +"38","ES707","La Palma","La Palma" +"35","ES708","Lanzarote","Lanzarote" +"38","ES709","Tenerife","Tenerife" diff --git a/data-raw/espPROV.csv b/data-raw/espPROV.csv index eef47c70..56128113 100644 --- a/data-raw/espPROV.csv +++ b/data-raw/espPROV.csv @@ -1,53 +1,53 @@ -"codauto","cpro","iso2.prov.code","nuts.prov.code","ine.prov.name","iso2.prov.name.es","iso2.prov.name.ca","iso2.prov.name.ga","iso2.prov.name.eu","cldr.prov.name.en","cldr.prov.name.es","cldr.prov.name.ca","cldr.prov.name.ga","cldr.prov.name.eu","prov.shortname.en","prov.shortname.es","prov.shortname.ca","prov.shortname.ga","prov.shortname.eu" -"01","04","ES-AL","ES611","Almería","Almería",NA,NA,NA,"Almería","Provincia de Almería","Província d’Almeria","Provincia de Almería","Almeríako probintzia","Almería","Almería","Almeria","Almería","Almería" -"01","11","ES-CA","ES612","Cádiz","Cádiz",NA,NA,NA,"Cádiz","Provincia de Cádiz","Província de Cadis","Provincia de Cádiz","Cádizko probintzia","Cádiz","Cádiz","Cadis","Cádiz","Cádiz" -"01","14","ES-CO","ES613","Córdoba","Córdoba",NA,NA,NA,"Córdoba","Provincia de Córdoba","Província de Còrdova","Provincia de Córdoba","Kordobako probintzia","Córdoba","Córdoba","Còrdova","Córdoba","Kordoba" -"01","18","ES-GR","ES614","Granada","Granada",NA,NA,NA,"Granada","Provincia de Granada","Província de Granada","Provincia de Granada","Granadako probintzia","Granada","Granada","Granada","Granada","Granada" -"01","21","ES-H","ES615","Huelva","Huelva",NA,NA,NA,"Huelva","Provincia de Huelva","Província de Huelva","Provincia de Huelva","Huelvako probintzia","Huelva","Huelva","Huelva","Huelva","Huelva" -"01","23","ES-J","ES616","Jaén","Jaén",NA,NA,NA,"Jaén","Provincia de Jaén","Província de Jaén","Provincia de Xaén","Jaéngo probintzia","Jaén","Jaén","Jaén","Xaén","Jaén" -"01","29","ES-MA","ES617","Málaga","Málaga",NA,NA,NA,"Málaga","Provincia de Málaga","Província de Màlaga","Provincia de Málaga","Málagako probintzia","Málaga","Málaga","Màlaga","Málaga","Málaga" -"01","41","ES-SE","ES618","Sevilla","Sevilla",NA,NA,NA,"Seville","Provincia de Sevilla","Província de Sevilla","Provincia de Sevilla","Sevillako probintzia","Seville","Sevilla","Sevilla","Sevilla","Sevilla" -"02","22","ES-HU","ES241","Huesca","Huesca",NA,NA,NA,"Huesca","Provincia de Huesca","Província d’Osca","Provincia de Huesca - Uesca","Huescako probintzia","Huesca","Huesca","Osca","Huesca","Huesca" -"02","44","ES-TE","ES242","Teruel","Teruel",NA,NA,NA,"Teruel","Provincia de Teruel","Província de Terol","Provincia de Teruel","Teruelgo probintzia","Teruel","Teruel","Terol","Teruel","Teruel" -"02","50","ES-Z","ES243","Zaragoza","Zaragoza",NA,NA,NA,"Zaragoza","Provincia de Zaragoza","Província de Saragossa","Provincia de Zaragoza","Zaragozako probintzia","Zaragoza","Zaragoza","Saragossa","Zaragoza","Zaragoza" -"03","33","ES-O","ES120","Asturias","Asturias",NA,NA,NA,"Asturias","Principado de Asturias","Astúries","Principado de Asturias","Asturiesko Printzerria","Asturias","Asturias","Astúries","Asturias","Asturias" -"04","07","ES-PM",NA,"Balears, Illes","Baleares","Balears",NA,NA,"Balears Province","Islas Baleares","Illes Balears","Illas Baleares","Balear Uharteak","Balearic Islands","Baleares","Illes Balears","Illas Baleares","Balear Uharteak" -"05","35","ES-GC",NA,"Palmas, Las","Las Palmas",NA,NA,NA,"Las Palmas","Provincia de Las Palmas","Província de Las Palmas","Provincia das Palmas","Las Palmasko probintzia","Las Palmas","Las Palmas","Las Palmas","As Palmas","Las Palmas" -"05","38","ES-TF",NA,"Santa Cruz de Tenerife","Santa Cruz de Tenerife",NA,NA,NA,"Santa Cruz de Tenerife","Provincia de Santa Cruz de Tenerife","Província de Santa Cruz de Tenerife","Provincia de Santa Cruz de Tenerife","Santa Cruz Tenerifekoko probintzia","Santa Cruz de Tenerife","Santa Cruz de Tenerife","Santa Cruz de Tenerife","Santa Cruz de Tenerife","Santa Cruz Tenerifekoa" -"06","39","ES-S","ES130","Cantabria","Cantabria",NA,NA,NA,"Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria","Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria" -"07","05","ES-AV","ES411","Ávila","Ávila",NA,NA,NA,"Ávila","Provincia de Ávila","Província d’Àvila","Provincia de Ávila","Ávilako probintzia","Ávila","Ávila","Àvila","Ávila","Ávila" -"07","09","ES-BU","ES412","Burgos","Burgos",NA,NA,NA,"Burgos","Provincia de Burgos","Província de Burgos","Provincia de Burgos","Burgosko probintzia","Burgos","Burgos","Burgos","Burgos","Burgos" -"07","24","ES-LE","ES413","León","León",NA,NA,NA,"León","Provincia de León","Província de Lleó","Provincia de León","Leóngo probintzia","León","León","Lleó","León","León" -"07","34","ES-P","ES414","Palencia","Palencia",NA,NA,NA,"Palencia","Provincia de Palencia","Província de Palència","Provincia de Palencia","Palentziako probintzia","Palencia","Palencia","Palència","Palencia","Palentzia" -"07","37","ES-SA","ES415","Salamanca","Salamanca",NA,NA,NA,"Salamanca","Provincia de Salamanca","Província de Salamanca","Provincia de Salamanca","Salamancako probintzia","Salamanca","Salamanca","Salamanca","Salamanca","Salamanca" -"07","40","ES-SG","ES416","Segovia","Segovia",NA,NA,NA,"Segovia","Provincia de Segovia","Província de Segòvia","Provincia de Segovia","Segoviako probintzia","Segovia","Segovia","Segòvia","Segovia","Segovia" -"07","42","ES-SO","ES417","Soria","Soria",NA,NA,NA,"Soria","Provincia de Soria","Província de Sòria","Provincia de Soria","Soriako probintzia","Soria","Soria","Sòria","Soria","Soria" -"07","47","ES-VA","ES418","Valladolid","Valladolid",NA,NA,NA,"Valladolid","Provincia de Valladolid","Província de Valladolid","Provincia de Valladolid","Valladolideko probintzia","Valladolid","Valladolid","Valladolid","Valladolid","Valladolid" -"07","49","ES-ZA","ES419","Zamora","Zamora",NA,NA,NA,"Zamora","Provincia de Zamora","Província de Zamora","Provincia de Zamora","Zamorako probintzia","Zamora","Zamora","Zamora","Zamora","Zamora" -"08","02","ES-AB","ES421","Albacete","Albacete",NA,NA,NA,"Albacete","Provincia de Albacete","Província d’Albacete","Provincia de Albacete","Albaceteko probintzia","Albacete","Albacete","Albacete","Albacete","Albacete" -"08","13","ES-CR","ES422","Ciudad Real","Ciudad Real",NA,NA,NA,"Ciudad Real","Provincia de Ciudad Real","Província de Ciudad Real","Provincia de Cidade Real - Ciudad Real","Ciudad Realgo probintzia","Ciudad Real","Ciudad Real","Ciudad Real","Cidade Real","Ciudad Real" -"08","16","ES-CU","ES423","Cuenca","Cuenca",NA,NA,NA,"Cuenca","Provincia de Cuenca","Província de Conca","Provincia de Cuenca","Cuencako probintzia","Cuenca","Cuenca","Conca","Cuenca","Cuenca" -"08","19","ES-GU","ES424","Guadalajara","Guadalajara",NA,NA,NA,"Guadalajara","Provincia de Guadalajara","Província de Guadalajara","Provincia de Guadalaxara - Guadalajara","Guadalajarako probintzia","Guadalajara","Guadalajara","Guadalajara","Guadalaxara","Guadalajara" -"08","45","ES-TO","ES425","Toledo","Toledo",NA,NA,NA,"Toledo","Provincia de Toledo","Província de Toledo","Provincia de Toledo","Toledoko probintzia","Toledo","Toledo","Toledo","Toledo","Toledo" -"09","08","ES-B","ES511","Barcelona","Barcelona",NA,NA,NA,"Barcelona","Provincia de Barcelona","Província de Barcelona","Provincia de Barcelona","Bartzelonako probintzia","Barcelona","Barcelona","Barcelona","Barcelona","Bartzelona" -"09","17","ES-GI","ES512","Girona","Gerona","Girona",NA,NA,"Girona","Provincia de Gerona","Província de Girona","Provincia de Xirona - Girona","Gironako probintzia","Girona","Gerona","Girona","Xirona","Girona" -"09","25","ES-L","ES513","Lleida","Lérida","Lleida",NA,NA,"Lleida","Provincia de Lérida","Província de Lleida","Provincia de Lleida","Lleidako probintzia","Lleida","Lérida","Lleida","Lleida","Lleida" -"09","43","ES-T","ES514","Tarragona","Tarragona","Tarragona",NA,NA,"Tarragona","Provincia de Tarragona","Província de Tarragona","Provincia de Tarragona","Tarragonako probintzia","Tarragona","Tarragona","Tarragona","Tarragona","Tarragona" -"10","03","ES-A","ES521","Alicante/Alacant","Alicante","Alacant",NA,NA,"Alicante","Provincia de Alicante","Província d’Alacant","Provincia de Alacant","Alacanteko probintzia","Alicante","Alicante","Alacant","Alacant","Alacant" -"10","12","ES-CS","ES522","Castellón/Castelló","Castellón","Castelló",NA,NA,"Castellón","Provincia de Castellón","Província de Castelló","Provincia de Castelló","Castellóko probintzia","Castellón","Castellón","Castelló","Castelló","Castelló" -"10","46","ES-V","ES523","Valencia/València","Valencia",NA,NA,NA,"Valencia","Provincia de Valencia","Província de València","Provincia de Valencia","Valentziako probintzia","Valencia","Valencia","València","Valencia","Valentzia" -"11","06","ES-BA","ES431","Badajoz","Badajoz",NA,NA,NA,"Badajoz","Provincia de Badajoz","Província de Badajoz","Provincia de Badaxoz","Badajozko probintzia","Badajoz","Badajoz","Badajoz","Badaxoz","Badajoz" -"11","10","ES-CC","ES432","Cáceres","Cáceres",NA,NA,NA,"Cáceres","Provincia de Cáceres","Província de Càceres","Provincia de Cáceres","Cáceresko probintzia","Cáceres","Cáceres","Càceres","Cáceres","Cáceres" -"12","15","ES-C","ES111","Coruña, A","La Coruña",NA,"A Coruña",NA,"A Coruña","Provincia de La Coruña","Província de la Corunya","Provincia da Coruña","Coruñako probintzia","A Coruña","La Coruña","La Corunya","A Coruña","Coruña" -"12","27","ES-LU","ES112","Lugo","Lugo",NA,"Lugo",NA,"Lugo","Provincia de Lugo","Província de Lugo","Provincia de Lugo","Lugoko probintzia","Lugo","Lugo","Lugo","Lugo","Lugo" -"12","32","ES-OR","ES113","Ourense","Orense",NA,"Ourense",NA,"Ourense","Provincia de Orense","Província d’Ourense","Provincia de Ourense","Ourenseko probintzia","Ourense","Orense","Ourense","Ourense","Ourense" -"12","36","ES-PO","ES114","Pontevedra","Pontevedra",NA,"Pontevedra",NA,"Pontevedra","Provincia de Pontevedra","Província de Pontevedra","Provincia de Pontevedra","Pontevedrako probintzia","Pontevedra","Pontevedra","Pontevedra","Pontevedra","Pontevedra" -"13","28","ES-M","ES300","Madrid","Madrid",NA,NA,NA,"Madrid Province","Provincia de Madrid","Província de Madrid",NA,NA,"Madrid","Madrid","Madrid","Madrid","Madril" -"14","30","ES-MU","ES620","Murcia","Murcia",NA,NA,NA,"Murcia","Provincia de Murcia","Província de Múrcia",NA,NA,"Murcia","Murcia","Múrcia","Murcia","Murtzia" -"15","31","ES-NA","ES220","Navarra","Navarra",NA,NA,"Nafarroa","Navarra","Navarra","Navarra","Navarra","Nafarroako Foru Erkidegoa","Navarra","Navarra","Navarra","Navarra","Nafarroa" -"16","01","ES-VI","ES211","Araba/Álava","Álava",NA,NA,"Araba","Álava","Álava","Àlaba","Provincia de Álava - Araba","Araba","Álava","Álava","Àlaba","Áraba","Araba" -"16","20","ES-SS","ES212","Gipuzkoa",NA,NA,NA,"Gipuzkoa","Gipuzkoa","Guipúzcoa","Guipúscoa","Provincia de Guipúscoa - Gipuzkoa","Gipuzkoa","Gipuzkoa","Guipúzcoa","Guipúscoa","Guipúscoa","Gipuzkoa" -"16","48","ES-BI","ES213","Bizkaia",NA,NA,NA,"Bizkaia","Biscay","Vizcaya","Biscaia","Biscaia - Bizkaia","Bizkaia","Biscay","Vizcaya","Biscaia","Biscaia","Bizkaia" -"17","26","ES-LO","ES230","Rioja, La","La Rioja",NA,NA,NA,"La Rioja","La Rioja","La Rioja","A Rioxa","Errioxako Autonomia Erkidegoa","La Rioja","La Rioja","La Rioja","A Rioxa","Errioxa" -"18","51","ES-CE","ES630","Ceuta","Ceuta",NA,NA,NA,"Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta" -"19","52","ES-ML","ES640","Melilla","Melilla",NA,NA,NA,"Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla" +"codauto","cpro","iso2.prov.code","nuts.prov.code","ine.prov.name","iso2.prov.name.es","iso2.prov.name.ca","iso2.prov.name.ga","iso2.prov.name.eu","cldr.prov.name.en","cldr.prov.name.es","cldr.prov.name.ca","cldr.prov.name.ga","cldr.prov.name.eu","prov.shortname.en","prov.shortname.es","prov.shortname.ca","prov.shortname.ga","prov.shortname.eu" +"01","04","ES-AL","ES611","Almería","Almería",NA,NA,NA,"Almería","Provincia de Almería","Província d’Almeria","Provincia de Almería","Almeríako probintzia","Almería","Almería","Almeria","Almería","Almería" +"01","11","ES-CA","ES612","Cádiz","Cádiz",NA,NA,NA,"Cádiz","Provincia de Cádiz","Província de Cadis","Provincia de Cádiz","Cádizko probintzia","Cádiz","Cádiz","Cadis","Cádiz","Cádiz" +"01","14","ES-CO","ES613","Córdoba","Córdoba",NA,NA,NA,"Córdoba","Provincia de Córdoba","Província de Còrdova","Provincia de Córdoba","Kordobako probintzia","Córdoba","Córdoba","Còrdova","Córdoba","Kordoba" +"01","18","ES-GR","ES614","Granada","Granada",NA,NA,NA,"Granada","Provincia de Granada","Província de Granada","Provincia de Granada","Granadako probintzia","Granada","Granada","Granada","Granada","Granada" +"01","21","ES-H","ES615","Huelva","Huelva",NA,NA,NA,"Huelva","Provincia de Huelva","Província de Huelva","Provincia de Huelva","Huelvako probintzia","Huelva","Huelva","Huelva","Huelva","Huelva" +"01","23","ES-J","ES616","Jaén","Jaén",NA,NA,NA,"Jaén","Provincia de Jaén","Província de Jaén","Provincia de Xaén","Jaéngo probintzia","Jaén","Jaén","Jaén","Xaén","Jaén" +"01","29","ES-MA","ES617","Málaga","Málaga",NA,NA,NA,"Málaga","Provincia de Málaga","Província de Màlaga","Provincia de Málaga","Málagako probintzia","Málaga","Málaga","Màlaga","Málaga","Málaga" +"01","41","ES-SE","ES618","Sevilla","Sevilla",NA,NA,NA,"Seville","Provincia de Sevilla","Província de Sevilla","Provincia de Sevilla","Sevillako probintzia","Seville","Sevilla","Sevilla","Sevilla","Sevilla" +"02","22","ES-HU","ES241","Huesca","Huesca",NA,NA,NA,"Huesca","Provincia de Huesca","Província d’Osca","Provincia de Huesca - Uesca","Huescako probintzia","Huesca","Huesca","Osca","Huesca","Huesca" +"02","44","ES-TE","ES242","Teruel","Teruel",NA,NA,NA,"Teruel","Provincia de Teruel","Província de Terol","Provincia de Teruel","Teruelgo probintzia","Teruel","Teruel","Terol","Teruel","Teruel" +"02","50","ES-Z","ES243","Zaragoza","Zaragoza",NA,NA,NA,"Zaragoza","Provincia de Zaragoza","Província de Saragossa","Provincia de Zaragoza","Zaragozako probintzia","Zaragoza","Zaragoza","Saragossa","Zaragoza","Zaragoza" +"03","33","ES-O","ES120","Asturias","Asturias",NA,NA,NA,"Asturias","Principado de Asturias","Astúries","Principado de Asturias","Asturiesko Printzerria","Asturias","Asturias","Astúries","Asturias","Asturias" +"04","07","ES-PM",NA,"Balears, Illes","Baleares","Balears",NA,NA,"Balears Province","Islas Baleares","Illes Balears","Illas Baleares","Balear Uharteak","Balearic Islands","Baleares","Illes Balears","Illas Baleares","Balear Uharteak" +"05","35","ES-GC",NA,"Palmas, Las","Las Palmas",NA,NA,NA,"Las Palmas","Provincia de Las Palmas","Província de Las Palmas","Provincia das Palmas","Las Palmasko probintzia","Las Palmas","Las Palmas","Las Palmas","As Palmas","Las Palmas" +"05","38","ES-TF",NA,"Santa Cruz de Tenerife","Santa Cruz de Tenerife",NA,NA,NA,"Santa Cruz de Tenerife","Provincia de Santa Cruz de Tenerife","Província de Santa Cruz de Tenerife","Provincia de Santa Cruz de Tenerife","Santa Cruz Tenerifekoko probintzia","Santa Cruz de Tenerife","Santa Cruz de Tenerife","Santa Cruz de Tenerife","Santa Cruz de Tenerife","Santa Cruz Tenerifekoa" +"06","39","ES-S","ES130","Cantabria","Cantabria",NA,NA,NA,"Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria","Cantabria","Cantabria","Cantàbria","Cantabria","Kantabria" +"07","05","ES-AV","ES411","Ávila","Ávila",NA,NA,NA,"Ávila","Provincia de Ávila","Província d’Àvila","Provincia de Ávila","Ávilako probintzia","Ávila","Ávila","Àvila","Ávila","Ávila" +"07","09","ES-BU","ES412","Burgos","Burgos",NA,NA,NA,"Burgos","Provincia de Burgos","Província de Burgos","Provincia de Burgos","Burgosko probintzia","Burgos","Burgos","Burgos","Burgos","Burgos" +"07","24","ES-LE","ES413","León","León",NA,NA,NA,"León","Provincia de León","Província de Lleó","Provincia de León","Leóngo probintzia","León","León","Lleó","León","León" +"07","34","ES-P","ES414","Palencia","Palencia",NA,NA,NA,"Palencia","Provincia de Palencia","Província de Palència","Provincia de Palencia","Palentziako probintzia","Palencia","Palencia","Palència","Palencia","Palentzia" +"07","37","ES-SA","ES415","Salamanca","Salamanca",NA,NA,NA,"Salamanca","Provincia de Salamanca","Província de Salamanca","Provincia de Salamanca","Salamancako probintzia","Salamanca","Salamanca","Salamanca","Salamanca","Salamanca" +"07","40","ES-SG","ES416","Segovia","Segovia",NA,NA,NA,"Segovia","Provincia de Segovia","Província de Segòvia","Provincia de Segovia","Segoviako probintzia","Segovia","Segovia","Segòvia","Segovia","Segovia" +"07","42","ES-SO","ES417","Soria","Soria",NA,NA,NA,"Soria","Provincia de Soria","Província de Sòria","Provincia de Soria","Soriako probintzia","Soria","Soria","Sòria","Soria","Soria" +"07","47","ES-VA","ES418","Valladolid","Valladolid",NA,NA,NA,"Valladolid","Provincia de Valladolid","Província de Valladolid","Provincia de Valladolid","Valladolideko probintzia","Valladolid","Valladolid","Valladolid","Valladolid","Valladolid" +"07","49","ES-ZA","ES419","Zamora","Zamora",NA,NA,NA,"Zamora","Provincia de Zamora","Província de Zamora","Provincia de Zamora","Zamorako probintzia","Zamora","Zamora","Zamora","Zamora","Zamora" +"08","02","ES-AB","ES421","Albacete","Albacete",NA,NA,NA,"Albacete","Provincia de Albacete","Província d’Albacete","Provincia de Albacete","Albaceteko probintzia","Albacete","Albacete","Albacete","Albacete","Albacete" +"08","13","ES-CR","ES422","Ciudad Real","Ciudad Real",NA,NA,NA,"Ciudad Real","Provincia de Ciudad Real","Província de Ciudad Real","Provincia de Cidade Real - Ciudad Real","Ciudad Realgo probintzia","Ciudad Real","Ciudad Real","Ciudad Real","Cidade Real","Ciudad Real" +"08","16","ES-CU","ES423","Cuenca","Cuenca",NA,NA,NA,"Cuenca","Provincia de Cuenca","Província de Conca","Provincia de Cuenca","Cuencako probintzia","Cuenca","Cuenca","Conca","Cuenca","Cuenca" +"08","19","ES-GU","ES424","Guadalajara","Guadalajara",NA,NA,NA,"Guadalajara","Provincia de Guadalajara","Província de Guadalajara","Provincia de Guadalaxara - Guadalajara","Guadalajarako probintzia","Guadalajara","Guadalajara","Guadalajara","Guadalaxara","Guadalajara" +"08","45","ES-TO","ES425","Toledo","Toledo",NA,NA,NA,"Toledo","Provincia de Toledo","Província de Toledo","Provincia de Toledo","Toledoko probintzia","Toledo","Toledo","Toledo","Toledo","Toledo" +"09","08","ES-B","ES511","Barcelona","Barcelona",NA,NA,NA,"Barcelona","Provincia de Barcelona","Província de Barcelona","Provincia de Barcelona","Bartzelonako probintzia","Barcelona","Barcelona","Barcelona","Barcelona","Bartzelona" +"09","17","ES-GI","ES512","Girona","Gerona","Girona",NA,NA,"Girona","Provincia de Gerona","Província de Girona","Provincia de Xirona - Girona","Gironako probintzia","Girona","Gerona","Girona","Xirona","Girona" +"09","25","ES-L","ES513","Lleida","Lérida","Lleida",NA,NA,"Lleida","Provincia de Lérida","Província de Lleida","Provincia de Lleida","Lleidako probintzia","Lleida","Lérida","Lleida","Lleida","Lleida" +"09","43","ES-T","ES514","Tarragona","Tarragona","Tarragona",NA,NA,"Tarragona","Provincia de Tarragona","Província de Tarragona","Provincia de Tarragona","Tarragonako probintzia","Tarragona","Tarragona","Tarragona","Tarragona","Tarragona" +"10","03","ES-A","ES521","Alicante/Alacant","Alicante","Alacant",NA,NA,"Alicante","Provincia de Alicante","Província d’Alacant","Provincia de Alacant","Alacanteko probintzia","Alicante","Alicante","Alacant","Alacant","Alacant" +"10","12","ES-CS","ES522","Castellón/Castelló","Castellón","Castelló",NA,NA,"Castellón","Provincia de Castellón","Província de Castelló","Provincia de Castelló","Castellóko probintzia","Castellón","Castellón","Castelló","Castelló","Castelló" +"10","46","ES-V","ES523","Valencia/València","Valencia",NA,NA,NA,"Valencia","Provincia de Valencia","Província de València","Provincia de Valencia","Valentziako probintzia","Valencia","Valencia","València","Valencia","Valentzia" +"11","06","ES-BA","ES431","Badajoz","Badajoz",NA,NA,NA,"Badajoz","Provincia de Badajoz","Província de Badajoz","Provincia de Badaxoz","Badajozko probintzia","Badajoz","Badajoz","Badajoz","Badaxoz","Badajoz" +"11","10","ES-CC","ES432","Cáceres","Cáceres",NA,NA,NA,"Cáceres","Provincia de Cáceres","Província de Càceres","Provincia de Cáceres","Cáceresko probintzia","Cáceres","Cáceres","Càceres","Cáceres","Cáceres" +"12","15","ES-C","ES111","Coruña, A","La Coruña",NA,"A Coruña",NA,"A Coruña","Provincia de La Coruña","Província de la Corunya","Provincia da Coruña","Coruñako probintzia","A Coruña","La Coruña","La Corunya","A Coruña","Coruña" +"12","27","ES-LU","ES112","Lugo","Lugo",NA,"Lugo",NA,"Lugo","Provincia de Lugo","Província de Lugo","Provincia de Lugo","Lugoko probintzia","Lugo","Lugo","Lugo","Lugo","Lugo" +"12","32","ES-OR","ES113","Ourense","Orense",NA,"Ourense",NA,"Ourense","Provincia de Orense","Província d’Ourense","Provincia de Ourense","Ourenseko probintzia","Ourense","Orense","Ourense","Ourense","Ourense" +"12","36","ES-PO","ES114","Pontevedra","Pontevedra",NA,"Pontevedra",NA,"Pontevedra","Provincia de Pontevedra","Província de Pontevedra","Provincia de Pontevedra","Pontevedrako probintzia","Pontevedra","Pontevedra","Pontevedra","Pontevedra","Pontevedra" +"13","28","ES-M","ES300","Madrid","Madrid",NA,NA,NA,"Madrid Province","Provincia de Madrid","Província de Madrid",NA,NA,"Madrid","Madrid","Madrid","Madrid","Madril" +"14","30","ES-MU","ES620","Murcia","Murcia",NA,NA,NA,"Murcia","Provincia de Murcia","Província de Múrcia",NA,NA,"Murcia","Murcia","Múrcia","Murcia","Murtzia" +"15","31","ES-NA","ES220","Navarra","Navarra",NA,NA,"Nafarroa","Navarra","Navarra","Navarra","Navarra","Nafarroako Foru Erkidegoa","Navarra","Navarra","Navarra","Navarra","Nafarroa" +"16","01","ES-VI","ES211","Araba/Álava","Álava",NA,NA,"Araba","Álava","Álava","Àlaba","Provincia de Álava - Araba","Araba","Álava","Álava","Àlaba","Áraba","Araba" +"16","20","ES-SS","ES212","Gipuzkoa",NA,NA,NA,"Gipuzkoa","Gipuzkoa","Guipúzcoa","Guipúscoa","Provincia de Guipúscoa - Gipuzkoa","Gipuzkoa","Gipuzkoa","Guipúzcoa","Guipúscoa","Guipúscoa","Gipuzkoa" +"16","48","ES-BI","ES213","Bizkaia",NA,NA,NA,"Bizkaia","Biscay","Vizcaya","Biscaia","Biscaia - Bizkaia","Bizkaia","Biscay","Vizcaya","Biscaia","Biscaia","Bizkaia" +"17","26","ES-LO","ES230","Rioja, La","La Rioja",NA,NA,NA,"La Rioja","La Rioja","La Rioja","A Rioxa","Errioxako Autonomia Erkidegoa","La Rioja","La Rioja","La Rioja","A Rioxa","Errioxa" +"18","51","ES-CE","ES630","Ceuta","Ceuta",NA,NA,NA,"Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta","Ceuta" +"19","52","ES-ML","ES640","Melilla","Melilla",NA,NA,NA,"Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla","Melilla" diff --git a/data-raw/esp_grid_ccaa.gpkg b/data-raw/esp_grid_ccaa.gpkg index 0822fb08..c288da28 100644 Binary files a/data-raw/esp_grid_ccaa.gpkg and b/data-raw/esp_grid_ccaa.gpkg differ diff --git a/data-raw/esp_grid_prov.gpkg b/data-raw/esp_grid_prov.gpkg index 19e8e05e..cd07d8b7 100644 Binary files a/data-raw/esp_grid_prov.gpkg and b/data-raw/esp_grid_prov.gpkg differ diff --git a/data-raw/esp_hexbin_ccaa.gpkg b/data-raw/esp_hexbin_ccaa.gpkg index 455fd829..15bf295b 100644 Binary files a/data-raw/esp_hexbin_ccaa.gpkg and b/data-raw/esp_hexbin_ccaa.gpkg differ diff --git a/data-raw/esp_hexbin_prov.gpkg b/data-raw/esp_hexbin_prov.gpkg index fab9609c..b8ec12e3 100644 Binary files a/data-raw/esp_hexbin_prov.gpkg and b/data-raw/esp_hexbin_prov.gpkg differ diff --git a/data-raw/esp_nuts.sf.R b/data-raw/esp_nuts.sf.R index b0b2ae8c..6303ad91 100644 --- a/data-raw/esp_nuts.sf.R +++ b/data-raw/esp_nuts.sf.R @@ -2,14 +2,16 @@ library(giscoR) -options(gisco_cache_dir = "~/R/mapslib/GISCO") + +esp_nuts.sf %>% sf::st_crs() esp_nuts <- gisco_get_nuts( resolution = 1, verbose = TRUE, year = "2016", - country = "ES" + country = "ES", + update_cache = TRUE ) # Convert to ETRS89 diff --git a/data-raw/esp_tiles_providers.R b/data-raw/esp_tiles_providers.R new file mode 100644 index 00000000..4ff0224d --- /dev/null +++ b/data-raw/esp_tiles_providers.R @@ -0,0 +1,132 @@ +## code to prepare `esp_tiles_providers` dataset goes here +rm(list = ls()) +source("./data-raw/helperfuns.R") + +library(dplyr) +library(tidyverse) +library(readxl) + +df <- + read_xlsx("./data-raw/input/leafletproviders-ESP.xlsx") %>% + esp_hlp_utf8() %>% + as.data.frame() + +unique(df$field) + +df_pivoted <- df %>% + pivot_wider( + values_from = value, + names_from = field + ) + + +url_static <- "https://rts.larioja.org/mapa-base/rioja/{z}/{x}/{y}.png" +# Helper to split urls +esp_hlp_split_url <- function(url_static) { + split <- unlist(strsplit(url_static, "?", fixed = TRUE)) + + urlsplit <- list() + if (length(split) > 1) { + urlsplit$q <- paste0(split[1], "?") + } else { + urlsplit$q <- split[1] + } + opts <- unlist(strsplit(split[2], "&")) + + names_opts <- vapply(opts, function(x) { + n <- strsplit(x, "=", fixed = TRUE) + return(unlist(n)[1]) + }, FUN.VALUE = character(1)) + + values_opts <- vapply(opts, function(x) { + n <- strsplit(x, "=", fixed = TRUE) + + unl <- unlist(n) + if (length(unl) == 2) { + return(unl[2]) + } + return("") + }, FUN.VALUE = character(1)) + + + names(values_opts) <- tolower(names_opts) + + urlsplit <- modifyList(urlsplit, as.list(values_opts)) + + return(urlsplit) +} + +len_prov <- seq_len(nrow(df_pivoted)) + +x <- 1 + +esp_tiles_providers <- lapply(len_prov, function(x) { + prov <- df_pivoted[x, ] + + url_st <- as.vector(prov$url_static) + + url <- esp_hlp_split_url(url_st) + + # Compose list + static <- c( + list(attribution = as.vector(prov$attribution_static)), + url + ) + # Add additional options for leaflet + leaflet <- list( + attribution = as.vector(prov$attribution), + minZoom = as.vector(prov$minZoom) + ) + + # Cleanup + leaflet <- leaflet[!is.na(leaflet)] + + # Final output + + l <- list( + static = static, + leaflet = leaflet + ) + + return(l) +}) + +names(esp_tiles_providers) <- df_pivoted$provider +usethis::use_data(esp_tiles_providers, overwrite = TRUE) + +# Check + +rm(list = ls()) +# Try + + +esp_set_cache_dir("~/R/maplibs/GISCO", install = TRUE, overwrite = TRUE) + +esp_hlp_detect_cache_dir() +devtools::load_all() + +# Try MDT +library(tidyterra) +ccaa <- esp_get_ccaa(c("LA Rioja"), epsg = 3857) +tile <- esp_getTiles(ccaa, "PNOA", crop = FALSE, verbose = TRUE) + +ggplot2::ggplot() + + geom_spatraster_rgb(data = tile) + +library(leaflet) + +leaflet() %>% + setView( + lat = 40.4166, + lng = -3.7038400, + zoom = 10 + ) %>% + addProviderEspTiles(provider = "IDErioja.Claro") %>% + addProviderEspTiles(provider = "CaminoDeSantiago", options = list(transparent = TRUE)) + +names(mapSpain::esp_tiles_providers) + +esp_tiles_providers$IDErioja$static$q +provider <- "IGNBase.Todo" + +tt <- esp_tiles_providers diff --git a/data-raw/input/esp_codes.xlsx b/data-raw/input/esp_codes.xlsx index 9c8f262f..7ac7eeeb 100644 Binary files a/data-raw/input/esp_codes.xlsx and b/data-raw/input/esp_codes.xlsx differ diff --git a/data-raw/input/leaflet-providers.js b/data-raw/input/leaflet-providers.js index e905edb9..de88bf21 100644 --- a/data-raw/input/leaflet-providers.js +++ b/data-raw/input/leaflet-providers.js @@ -1,1042 +1,515 @@ -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define(['leaflet'], factory); - } else if (typeof modules === 'object' && module.exports) { - // define a Common JS module that relies on 'leaflet' - module.exports = factory(require('leaflet')); - } else { - // Assume Leaflet is loaded into global object L already - factory(L); - } -}(this, function (L) { - 'use strict'; - - L.TileLayer.Provider = L.TileLayer.extend({ - initialize: function (arg, options) { - var providers = L.TileLayer.Provider.providers; - - var parts = arg.split('.'); - - var providerName = parts[0]; - var variantName = parts[1]; - - if (!providers[providerName]) { - throw 'No such provider (' + providerName + ')'; - } - - var provider = { - url: providers[providerName].url, - options: providers[providerName].options - }; - - // overwrite values in provider from variant. - if (variantName && 'variants' in providers[providerName]) { - if (!(variantName in providers[providerName].variants)) { - throw 'No such variant of ' + providerName + ' (' + variantName + ')'; - } - var variant = providers[providerName].variants[variantName]; - var variantOptions; - if (typeof variant === 'string') { - variantOptions = { - variant: variant - }; - } else { - variantOptions = variant.options; - } - provider = { - url: variant.url || provider.url, - options: L.Util.extend({}, provider.options, variantOptions) - }; - } - - // replace attribution placeholders with their values from toplevel provider attribution, - // recursively - var attributionReplacer = function (attr) { - if (attr.indexOf('{attribution.') === -1) { - return attr; - } - return attr.replace(/\{attribution.(\w*)\}/g, - function (match, attributionName) { - return attributionReplacer(providers[attributionName].options.attribution); - } - ); - }; - provider.options.attribution = attributionReplacer(provider.options.attribution); - - // Compute final options combining provider options with any user overrides - var layerOpts = L.Util.extend({}, provider.options, options); - L.TileLayer.prototype.initialize.call(this, provider.url, layerOpts); - } - }); - - /** - * Definition of providers. - * see http://leafletjs.com/reference.html#tilelayer for options in the options map. - */ - - L.TileLayer.Provider.providers = { - OpenStreetMap: { - url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', - options: { - maxZoom: 19, - attribution: - '© OpenStreetMap contributors' - }, - variants: { - Mapnik: {}, - DE: { - url: 'https://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', - options: { - maxZoom: 18 - } - }, - CH: { - url: 'https://tile.osm.ch/switzerland/{z}/{x}/{y}.png', - options: { - maxZoom: 18, - bounds: [[45, 5], [48, 11]] - } - }, - France: { - url: 'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', - options: { - maxZoom: 20, - attribution: '© Openstreetmap France | {attribution.OpenStreetMap}' - } - }, - HOT: { - url: 'https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', - options: { - attribution: - '{attribution.OpenStreetMap}, ' + - 'Tiles style by Humanitarian OpenStreetMap Team ' + - 'hosted by OpenStreetMap France' - } - }, - BZH: { - url: 'https://tile.openstreetmap.bzh/br/{z}/{x}/{y}.png', - options: { - attribution: '{attribution.OpenStreetMap}, Tiles courtesy of Breton OpenStreetMap Team', - bounds: [[46.2, -5.5], [50, 0.7]] - } - } - } - }, - OpenSeaMap: { - url: 'https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png', - options: { - attribution: 'Map data: © OpenSeaMap contributors' - } - }, - OpenPtMap: { - url: 'http://openptmap.org/tiles/{z}/{x}/{y}.png', - options: { - maxZoom: 17, - attribution: 'Map data: © OpenPtMap contributors' - } - }, - OpenTopoMap: { - url: 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', - options: { - maxZoom: 17, - attribution: 'Map data: {attribution.OpenStreetMap}, SRTM | Map style: © OpenTopoMap (CC-BY-SA)' - } - }, - OpenRailwayMap: { - url: 'https://{s}.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png', - options: { - maxZoom: 19, - attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © OpenRailwayMap (CC-BY-SA)' - } - }, - OpenFireMap: { - url: 'http://openfiremap.org/hytiles/{z}/{x}/{y}.png', - options: { - maxZoom: 19, - attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © OpenFireMap (CC-BY-SA)' - } - }, - SafeCast: { - url: 'https://s3.amazonaws.com/te512.safecast.org/{z}/{x}/{y}.png', - options: { - maxZoom: 16, - attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © SafeCast (CC-BY-SA)' - } - }, - Stadia: { - url: 'https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png', - options: { - maxZoom: 20, - attribution: '© Stadia Maps, © OpenMapTiles © OpenStreetMap contributors' - }, - variants: { - AlidadeSmooth: { - url: 'https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png' - }, - AlidadeSmoothDark: { - url: 'https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png' - }, - OSMBright: { - url: 'https://tiles.stadiamaps.com/tiles/osm_bright/{z}/{x}/{y}{r}.png' - }, - Outdoors: { - url: 'https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}{r}.png' - } - } - }, - Thunderforest: { - url: 'https://{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png?apikey={apikey}', - options: { - attribution: - '© Thunderforest, {attribution.OpenStreetMap}', - variant: 'cycle', - apikey: '', - maxZoom: 22 - }, - variants: { - OpenCycleMap: 'cycle', - Transport: { - options: { - variant: 'transport' - } - }, - TransportDark: { - options: { - variant: 'transport-dark' - } - }, - SpinalMap: { - options: { - variant: 'spinal-map' - } - }, - Landscape: 'landscape', - Outdoors: 'outdoors', - Pioneer: 'pioneer', - MobileAtlas: 'mobile-atlas', - Neighbourhood: 'neighbourhood' - } - }, - CyclOSM: { - url: 'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/{z}/{x}/{y}.png', - options: { - maxZoom: 20, - attribution: 'CyclOSM | Map data: {attribution.OpenStreetMap}' - } - }, - Hydda: { - url: 'https://{s}.tile.openstreetmap.se/hydda/{variant}/{z}/{x}/{y}.png', - options: { - maxZoom: 20, - variant: 'full', - attribution: 'Tiles courtesy of OpenStreetMap Sweden — Map data {attribution.OpenStreetMap}' - }, - variants: { - Full: 'full', - Base: 'base', - RoadsAndLabels: 'roads_and_labels' - } - }, - Jawg: { - url: 'https://{s}.tile.jawg.io/{variant}/{z}/{x}/{y}{r}.png?access-token={accessToken}', - options: { - attribution: - '© JawgMaps ' + - '{attribution.OpenStreetMap}', - minZoom: 0, - maxZoom: 22, - subdomains: 'abcd', - variant: 'jawg-terrain', - // Get your own Jawg access token here : https://www.jawg.io/lab/ - // NB : this is a demonstration key that comes with no guarantee - accessToken: '', - }, - variants: { - Streets: 'jawg-streets', - Terrain: 'jawg-terrain', - Sunny: 'jawg-sunny', - Dark: 'jawg-dark', - Light: 'jawg-light', - Matrix: 'jawg-matrix' - } - }, - MapBox: { - url: 'https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}{r}?access_token={accessToken}', - options: { - attribution: - '© Mapbox ' + - '{attribution.OpenStreetMap} ' + - 'Improve this map', - tileSize: 512, - maxZoom: 18, - zoomOffset: -1, - id: 'mapbox/streets-v11', - accessToken: '', - } - }, - MapTiler: { - url: 'https://api.maptiler.com/maps/{variant}/{z}/{x}/{y}{r}.{ext}?key={key}', - options: { - attribution: - '© MapTiler © OpenStreetMap contributors', - variant: 'streets', - ext: 'png', - key: '', - tileSize: 512, - zoomOffset: -1, - minZoom: 0, - maxZoom: 21 - }, - variants: { - Streets: 'streets', - Basic: 'basic', - Bright: 'bright', - Pastel: 'pastel', - Positron: 'positron', - Hybrid: { - options: { - variant: 'hybrid', - ext: 'jpg' - } - }, - Toner: 'toner', - Topo: 'topo', - Voyager: 'voyager' - } - }, - Stamen: { - url: 'https://stamen-tiles-{s}.a.ssl.fastly.net/{variant}/{z}/{x}/{y}{r}.{ext}', - options: { - attribution: - 'Map tiles by Stamen Design, ' + - 'CC BY 3.0 — ' + - 'Map data {attribution.OpenStreetMap}', - subdomains: 'abcd', - minZoom: 0, - maxZoom: 20, - variant: 'toner', - ext: 'png' - }, - variants: { - Toner: 'toner', - TonerBackground: 'toner-background', - TonerHybrid: 'toner-hybrid', - TonerLines: 'toner-lines', - TonerLabels: 'toner-labels', - TonerLite: 'toner-lite', - Watercolor: { - url: 'https://stamen-tiles-{s}.a.ssl.fastly.net/{variant}/{z}/{x}/{y}.{ext}', - options: { - variant: 'watercolor', - ext: 'jpg', - minZoom: 1, - maxZoom: 16 - } - }, - Terrain: { - options: { - variant: 'terrain', - minZoom: 0, - maxZoom: 18 - } - }, - TerrainBackground: { - options: { - variant: 'terrain-background', - minZoom: 0, - maxZoom: 18 - } - }, - TerrainLabels: { - options: { - variant: 'terrain-labels', - minZoom: 0, - maxZoom: 18 - } - }, - TopOSMRelief: { - url: 'https://stamen-tiles-{s}.a.ssl.fastly.net/{variant}/{z}/{x}/{y}.{ext}', - options: { - variant: 'toposm-color-relief', - ext: 'jpg', - bounds: [[22, -132], [51, -56]] - } - }, - TopOSMFeatures: { - options: { - variant: 'toposm-features', - bounds: [[22, -132], [51, -56]], - opacity: 0.9 - } - } - } - }, - TomTom: { - url: 'https://{s}.api.tomtom.com/map/1/tile/{variant}/{style}/{z}/{x}/{y}.{ext}?key={apikey}', - options: { - variant: 'basic', - maxZoom: 22, - attribution: - '© 1992 - ' + new Date().getFullYear() + ' TomTom. ', - subdomains: 'abcd', - style: 'main', - ext: 'png', - apikey: '', - }, - variants: { - Basic: 'basic', - Hybrid: 'hybrid', - Labels: 'labels' - } - }, - Esri: { - url: 'https://server.arcgisonline.com/ArcGIS/rest/services/{variant}/MapServer/tile/{z}/{y}/{x}', - options: { - variant: 'World_Street_Map', - attribution: 'Tiles © Esri' - }, - variants: { - WorldStreetMap: { - options: { - attribution: - '{attribution.Esri} — ' + - 'Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012' - } - }, - DeLorme: { - options: { - variant: 'Specialty/DeLorme_World_Base_Map', - minZoom: 1, - maxZoom: 11, - attribution: '{attribution.Esri} — Copyright: ©2012 DeLorme' - } - }, - WorldTopoMap: { - options: { - variant: 'World_Topo_Map', - attribution: - '{attribution.Esri} — ' + - 'Esri, DeLorme, NAVTEQ, TomTom, Intermap, iPC, USGS, FAO, NPS, NRCAN, GeoBase, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), and the GIS User Community' - } - }, - WorldImagery: { - options: { - variant: 'World_Imagery', - attribution: - '{attribution.Esri} — ' + - 'Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community' - } - }, - WorldTerrain: { - options: { - variant: 'World_Terrain_Base', - maxZoom: 13, - attribution: - '{attribution.Esri} — ' + - 'Source: USGS, Esri, TANA, DeLorme, and NPS' - } - }, - WorldShadedRelief: { - options: { - variant: 'World_Shaded_Relief', - maxZoom: 13, - attribution: '{attribution.Esri} — Source: Esri' - } - }, - WorldPhysical: { - options: { - variant: 'World_Physical_Map', - maxZoom: 8, - attribution: '{attribution.Esri} — Source: US National Park Service' - } - }, - OceanBasemap: { - options: { - variant: 'Ocean_Basemap', - maxZoom: 13, - attribution: '{attribution.Esri} — Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri' - } - }, - NatGeoWorldMap: { - options: { - variant: 'NatGeo_World_Map', - maxZoom: 16, - attribution: '{attribution.Esri} — National Geographic, Esri, DeLorme, NAVTEQ, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, iPC' - } - }, - WorldGrayCanvas: { - options: { - variant: 'Canvas/World_Light_Gray_Base', - maxZoom: 16, - attribution: '{attribution.Esri} — Esri, DeLorme, NAVTEQ' - } - } - } - }, - OpenWeatherMap: { - url: 'http://{s}.tile.openweathermap.org/map/{variant}/{z}/{x}/{y}.png?appid={apiKey}', - options: { - maxZoom: 19, - attribution: 'Map data © OpenWeatherMap', - apiKey:'', - opacity: 0.5 - }, - variants: { - Clouds: 'clouds', - CloudsClassic: 'clouds_cls', - Precipitation: 'precipitation', - PrecipitationClassic: 'precipitation_cls', - Rain: 'rain', - RainClassic: 'rain_cls', - Pressure: 'pressure', - PressureContour: 'pressure_cntr', - Wind: 'wind', - Temperature: 'temp', - Snow: 'snow' - } - }, - HERE: { - /* - * HERE maps, formerly Nokia maps. - * These basemaps are free, but you need an api id and app key. Please sign up at - * https://developer.here.com/plans - */ - url: - 'https://{s}.{base}.maps.api.here.com/maptile/2.1/' + - '{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?' + - 'app_id={app_id}&app_code={app_code}&lg={language}', - options: { - attribution: - 'Map © 1987-' + new Date().getFullYear() + ' HERE', - subdomains: '1234', - mapID: 'newest', - 'app_id': '', - 'app_code': '', - base: 'base', - variant: 'normal.day', - maxZoom: 20, - type: 'maptile', - language: 'eng', - format: 'png8', - size: '256' - }, - variants: { - normalDay: 'normal.day', - normalDayCustom: 'normal.day.custom', - normalDayGrey: 'normal.day.grey', - normalDayMobile: 'normal.day.mobile', - normalDayGreyMobile: 'normal.day.grey.mobile', - normalDayTransit: 'normal.day.transit', - normalDayTransitMobile: 'normal.day.transit.mobile', - normalDayTraffic: { - options: { - variant: 'normal.traffic.day', - base: 'traffic', - type: 'traffictile' - } - }, - normalNight: 'normal.night', - normalNightMobile: 'normal.night.mobile', - normalNightGrey: 'normal.night.grey', - normalNightGreyMobile: 'normal.night.grey.mobile', - normalNightTransit: 'normal.night.transit', - normalNightTransitMobile: 'normal.night.transit.mobile', - reducedDay: 'reduced.day', - reducedNight: 'reduced.night', - basicMap: { - options: { - type: 'basetile' - } - }, - mapLabels: { - options: { - type: 'labeltile', - format: 'png' - } - }, - trafficFlow: { - options: { - base: 'traffic', - type: 'flowtile' - } - }, - carnavDayGrey: 'carnav.day.grey', - hybridDay: { - options: { - base: 'aerial', - variant: 'hybrid.day' - } - }, - hybridDayMobile: { - options: { - base: 'aerial', - variant: 'hybrid.day.mobile' - } - }, - hybridDayTransit: { - options: { - base: 'aerial', - variant: 'hybrid.day.transit' - } - }, - hybridDayGrey: { - options: { - base: 'aerial', - variant: 'hybrid.grey.day' - } - }, - hybridDayTraffic: { - options: { - variant: 'hybrid.traffic.day', - base: 'traffic', - type: 'traffictile' - } - }, - pedestrianDay: 'pedestrian.day', - pedestrianNight: 'pedestrian.night', - satelliteDay: { - options: { - base: 'aerial', - variant: 'satellite.day' - } - }, - terrainDay: { - options: { - base: 'aerial', - variant: 'terrain.day' - } - }, - terrainDayMobile: { - options: { - base: 'aerial', - variant: 'terrain.day.mobile' - } - } - } - }, - HEREv3: { - /* - * HERE maps API Version 3. - * These basemaps are free, but you need an API key. Please sign up at - * https://developer.here.com/plans - * Version 3 deprecates the app_id and app_code access in favor of apiKey - * - * Supported access methods as of 2019/12/21: - * @see https://developer.here.com/faqs#access-control-1--how-do-you-control-access-to-here-location-services - */ - url: - 'https://{s}.{base}.maps.ls.hereapi.com/maptile/2.1/' + - '{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?' + - 'apiKey={apiKey}&lg={language}', - options: { - attribution: - 'Map © 1987-' + new Date().getFullYear() + ' HERE', - subdomains: '1234', - mapID: 'newest', - apiKey: '', - base: 'base', - variant: 'normal.day', - maxZoom: 20, - type: 'maptile', - language: 'eng', - format: 'png8', - size: '256' - }, - variants: { - normalDay: 'normal.day', - normalDayCustom: 'normal.day.custom', - normalDayGrey: 'normal.day.grey', - normalDayMobile: 'normal.day.mobile', - normalDayGreyMobile: 'normal.day.grey.mobile', - normalDayTransit: 'normal.day.transit', - normalDayTransitMobile: 'normal.day.transit.mobile', - normalNight: 'normal.night', - normalNightMobile: 'normal.night.mobile', - normalNightGrey: 'normal.night.grey', - normalNightGreyMobile: 'normal.night.grey.mobile', - normalNightTransit: 'normal.night.transit', - normalNightTransitMobile: 'normal.night.transit.mobile', - reducedDay: 'reduced.day', - reducedNight: 'reduced.night', - basicMap: { - options: { - type: 'basetile' - } - }, - mapLabels: { - options: { - type: 'labeltile', - format: 'png' - } - }, - trafficFlow: { - options: { - base: 'traffic', - type: 'flowtile' - } - }, - carnavDayGrey: 'carnav.day.grey', - hybridDay: { - options: { - base: 'aerial', - variant: 'hybrid.day' - } - }, - hybridDayMobile: { - options: { - base: 'aerial', - variant: 'hybrid.day.mobile' - } - }, - hybridDayTransit: { - options: { - base: 'aerial', - variant: 'hybrid.day.transit' - } - }, - hybridDayGrey: { - options: { - base: 'aerial', - variant: 'hybrid.grey.day' - } - }, - pedestrianDay: 'pedestrian.day', - pedestrianNight: 'pedestrian.night', - satelliteDay: { - options: { - base: 'aerial', - variant: 'satellite.day' - } - }, - terrainDay: { - options: { - base: 'aerial', - variant: 'terrain.day' - } - }, - terrainDayMobile: { - options: { - base: 'aerial', - variant: 'terrain.day.mobile' - } - } - } - }, - FreeMapSK: { - url: 'https://{s}.freemap.sk/T/{z}/{x}/{y}.jpeg', - options: { - minZoom: 8, - maxZoom: 16, - subdomains: 'abcd', - bounds: [[47.204642, 15.996093], [49.830896, 22.576904]], - attribution: - '{attribution.OpenStreetMap}, vizualization CC-By-SA 2.0 Freemap.sk' - } - }, - MtbMap: { - url: 'http://tile.mtbmap.cz/mtbmap_tiles/{z}/{x}/{y}.png', - options: { - attribution: - '{attribution.OpenStreetMap} & USGS' - } - }, - CartoDB: { - url: 'https://{s}.basemaps.cartocdn.com/{variant}/{z}/{x}/{y}{r}.png', - options: { - attribution: '{attribution.OpenStreetMap} © CARTO', - subdomains: 'abcd', - maxZoom: 19, - variant: 'light_all' - }, - variants: { - Positron: 'light_all', - PositronNoLabels: 'light_nolabels', - PositronOnlyLabels: 'light_only_labels', - DarkMatter: 'dark_all', - DarkMatterNoLabels: 'dark_nolabels', - DarkMatterOnlyLabels: 'dark_only_labels', - Voyager: 'rastertiles/voyager', - VoyagerNoLabels: 'rastertiles/voyager_nolabels', - VoyagerOnlyLabels: 'rastertiles/voyager_only_labels', - VoyagerLabelsUnder: 'rastertiles/voyager_labels_under' - } - }, - HikeBike: { - url: 'https://tiles.wmflabs.org/{variant}/{z}/{x}/{y}.png', - options: { - maxZoom: 19, - attribution: '{attribution.OpenStreetMap}', - variant: 'hikebike' - }, - variants: { - HikeBike: {}, - HillShading: { - options: { - maxZoom: 15, - variant: 'hillshading' - } - } - } - }, - BasemapAT: { - url: 'https://maps{s}.wien.gv.at/basemap/{variant}/{type}/google3857/{z}/{y}/{x}.{format}', - options: { - maxZoom: 19, - attribution: 'Datenquelle: basemap.at', - subdomains: ['', '1', '2', '3', '4'], - type: 'normal', - format: 'png', - bounds: [[46.358770, 8.782379], [49.037872, 17.189532]], - variant: 'geolandbasemap' - }, - variants: { - basemap: { - options: { - maxZoom: 20, // currently only in Vienna - variant: 'geolandbasemap' - } - }, - grau: 'bmapgrau', - overlay: 'bmapoverlay', - terrain: { - options: { - variant: 'bmapgelaende', - type: 'grau', - format: 'jpeg' - } - }, - surface: { - options: { - variant: 'bmapoberflaeche', - type: 'grau', - format: 'jpeg' - } - }, - highdpi: { - options: { - variant: 'bmaphidpi', - format: 'jpeg' - } - }, - orthofoto: { - options: { - maxZoom: 20, // currently only in Vienna - variant: 'bmaporthofoto30cm', - format: 'jpeg' - } - } - } - }, - nlmaps: { - url: 'https://geodata.nationaalgeoregister.nl/tiles/service/wmts/{variant}/EPSG:3857/{z}/{x}/{y}.png', - options: { - minZoom: 6, - maxZoom: 19, - bounds: [[50.5, 3.25], [54, 7.6]], - attribution: 'Kaartgegevens © Kadaster' - }, - variants: { - 'standaard': 'brtachtergrondkaart', - 'pastel': 'brtachtergrondkaartpastel', - 'grijs': 'brtachtergrondkaartgrijs', - 'luchtfoto': { - 'url': 'https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wmts/2018_ortho25/EPSG:3857/{z}/{x}/{y}.png', - } - } - }, - NASAGIBS: { - url: 'https://map1.vis.earthdata.nasa.gov/wmts-webmerc/{variant}/default/{time}/{tilematrixset}{maxZoom}/{z}/{y}/{x}.{format}', - options: { - attribution: - 'Imagery provided by services from the Global Imagery Browse Services (GIBS), operated by the NASA/GSFC/Earth Science Data and Information System ' + - '(ESDIS) with funding provided by NASA/HQ.', - bounds: [[-85.0511287776, -179.999999975], [85.0511287776, 179.999999975]], - minZoom: 1, - maxZoom: 9, - format: 'jpg', - time: '', - tilematrixset: 'GoogleMapsCompatible_Level' - }, - variants: { - ModisTerraTrueColorCR: 'MODIS_Terra_CorrectedReflectance_TrueColor', - ModisTerraBands367CR: 'MODIS_Terra_CorrectedReflectance_Bands367', - ViirsEarthAtNight2012: { - options: { - variant: 'VIIRS_CityLights_2012', - maxZoom: 8 - } - }, - ModisTerraLSTDay: { - options: { - variant: 'MODIS_Terra_Land_Surface_Temp_Day', - format: 'png', - maxZoom: 7, - opacity: 0.75 - } - }, - ModisTerraSnowCover: { - options: { - variant: 'MODIS_Terra_Snow_Cover', - format: 'png', - maxZoom: 8, - opacity: 0.75 - } - }, - ModisTerraAOD: { - options: { - variant: 'MODIS_Terra_Aerosol', - format: 'png', - maxZoom: 6, - opacity: 0.75 - } - }, - ModisTerraChlorophyll: { - options: { - variant: 'MODIS_Terra_Chlorophyll_A', - format: 'png', - maxZoom: 7, - opacity: 0.75 - } - } - } - }, - NLS: { - // NLS maps are copyright National library of Scotland. - // http://maps.nls.uk/projects/api/index.html - // Please contact NLS for anything other than non-commercial low volume usage - // - // Map sources: Ordnance Survey 1:1m to 1:63K, 1920s-1940s - // z0-9 - 1:1m - // z10-11 - quarter inch (1:253440) - // z12-18 - one inch (1:63360) - url: 'https://nls-{s}.tileserver.com/nls/{z}/{x}/{y}.jpg', - options: { - attribution: 'National Library of Scotland Historic Maps', - bounds: [[49.6, -12], [61.7, 3]], - minZoom: 1, - maxZoom: 18, - subdomains: '0123', - } - }, - JusticeMap: { - // Justice Map (http://www.justicemap.org/) - // Visualize race and income data for your community, county and country. - // Includes tools for data journalists, bloggers and community activists. - url: 'http://www.justicemap.org/tile/{size}/{variant}/{z}/{x}/{y}.png', - options: { - attribution: 'Justice Map', - // one of 'county', 'tract', 'block' - size: 'county', - // Bounds for USA, including Alaska and Hawaii - bounds: [[14, -180], [72, -56]] - }, - variants: { - income: 'income', - americanIndian: 'indian', - asian: 'asian', - black: 'black', - hispanic: 'hispanic', - multi: 'multi', - nonWhite: 'nonwhite', - white: 'white', - plurality: 'plural' - } - }, - Wikimedia: { - url: 'https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}{r}.png', - options: { - attribution: 'Wikimedia', - minZoom: 1, - maxZoom: 19 - } - }, - GeoportailFrance: { - url: 'https://wxs.ign.fr/{apikey}/geoportail/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&STYLE={style}&TILEMATRIXSET=PM&FORMAT={format}&LAYER={variant}&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}', - options: { - attribution: 'Geoportail France', - bounds: [[-75, -180], [81, 180]], - minZoom: 2, - maxZoom: 18, - // Get your own geoportail apikey here : http://professionnels.ign.fr/ign/contrats/ - // NB : 'choisirgeoportail' is a demonstration key that comes with no guarantee - apikey: 'choisirgeoportail', - format: 'image/jpeg', - style : 'normal', - variant: 'GEOGRAPHICALGRIDSYSTEMS.MAPS.SCAN-EXPRESS.STANDARD' - }, - variants: { - parcels: { - options : { - variant: 'CADASTRALPARCELS.PARCELS', - maxZoom: 20, - style : 'bdparcellaire', - format: 'image/png' - } - }, - ignMaps: 'GEOGRAPHICALGRIDSYSTEMS.MAPS', - maps: 'GEOGRAPHICALGRIDSYSTEMS.MAPS.SCAN-EXPRESS.STANDARD', - orthos: { - options: { - maxZoom: 19, - variant: 'ORTHOIMAGERY.ORTHOPHOTOS' - } - } - } - }, - OneMapSG: { - url: 'https://maps-{s}.onemap.sg/v3/{variant}/{z}/{x}/{y}.png', - options: { - variant: 'Default', - minZoom: 11, - maxZoom: 18, - bounds: [[1.56073, 104.11475], [1.16, 103.502]], - attribution: ' New OneMap | Map data © contributors, Singapore Land Authority' - }, - variants: { - Default: 'Default', - Night: 'Night', - Original: 'Original', - Grey: 'Grey', - LandLot: 'LandLot' - } - }, - USGS: { - url: 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer/tile/{z}/{y}/{x}', - options: { - maxZoom: 20, - attribution: 'Tiles courtesy of the U.S. Geological Survey' - }, - variants: { - USTopo: {}, - USImagery: { - url: 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}' - }, - USImageryTopo: { - url: 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryTopo/MapServer/tile/{z}/{y}/{x}' - } - } - }, - WaymarkedTrails: { - url: 'https://tile.waymarkedtrails.org/{variant}/{z}/{x}/{y}.png', - options: { - maxZoom: 18, - attribution: 'Map data: {attribution.OpenStreetMap} | Map style: © waymarkedtrails.org (CC-BY-SA)' - }, - variants: { - hiking: 'hiking', - cycling: 'cycling', - mtb: 'mtb', - slopes: 'slopes', - riding: 'riding', - skating: 'skating' - } - } - }; - - L.tileLayer.provider = function (provider, options) { - return new L.TileLayer.Provider(provider, options); - }; - - return L; -})); +// leaflet-providersESP.js plugin v1.3.3 +// (c) D. Hernangomez - MIT License +// https://dieghernan.github.io/leaflet-providersESP/ +// Issues: https://dieghernan.github.io/leaflet-providersESP/issues +// All providers are open source. Please check attributions +// Feel free to contribute +"use strict"; +var providersESPversion = 'v1.3.3'; +// Databases +// WMTS Servers - Tile Maps - Mapas de Teselas +var completeWMTS = "&style=default&tilematrixset=GoogleMapsCompatible&TileMatrix={z}&TileRow={y}&TileCol={x}"; +var providersESP = { + IDErioja: { + url: "https://rts.larioja.org/mapa-base/{variant}/{z}/{x}/{y}.{ext}", + options: { + attribution: "CC BY 4.0 www.iderioja.org", + variant: "rioja", + ext: "png" + }, + variants: { + Base: {}, + Relieve: { + options: { + variant: "rioja_relieve" + } + }, + Claro: { + options: { + variant: "rioja_claro" + } + }, + Oscuro: { + options: { + variant: "rioja_oscuro" + } + } + } + }, + // IGN Mapa Base + IGNBase: { + url: "https://www.ign.es/wmts/ign-base?service=WMTS&request=GetTile&version=1.0.0&Format=image/{ext}&layer={variant}" + completeWMTS, + options: { + attribution: "CC BY 4.0 scne.es. Sistema Geográfico Nacional IGN ", + variant: "IGNBaseTodo", + ext: "png" + }, + variants: { + Todo: "IGNBaseTodo", + Gris: { + options: { + variant: "IGNBase-gris", + ext: "jpeg" + } + }, + TodoNoFondo: { + options: { + variant: "IGNBaseTodo-nofondo", + bounds: [ + [27, -19], + [44, 5] + ], + minZoom: 4 + } + }, + Orto: { + options: { + variant: "IGNBaseOrto", + bounds: [ + [27, -19], + [44, 5] + ], + minZoom: 5 + } + } + } + }, + // MDT + MDT: { + url: "https://servicios.idee.es/wmts/mdt?service=WMTS&request=GetTile&version=1.0.0&Format=image/png&layer={variant}" + completeWMTS, + options: { + attribution: "Infraestructura de Datos Espaciales de España (IDEE)", + variant: "EL.ElevationGridCoverage", + bounds: [ + [22.173559281306314, -47.0716243806546], + [66.88067635831743, + 40.8749629405498 + ] + ] + }, + variants: { + Elevaciones: {}, + Relieve: "Relieve", + CurvasNivel: { + url: "https://servicios.idee.es/wms-inspire/mdt?", + options: { + layers: "EL.ContourLine", + transparent: true, + format: "image/png", + minZoom: 12 + } + }, + SpotElevation: { + url: "https://servicios.idee.es/wms-inspire/mdt?", + options: { + layers: "EL.SpotElevation", + transparent: true, + format: "image/png", + minZoom: 14 + } + } + } + }, + // Plan Nacional de Ortofotografia Aerea + PNOA: { + url: "https://www.ign.es/wmts/pnoa-ma?service=WMTS&request=GetTile&version=1.0.0&Format=image/png&layer=OI.OrthoimageCoverage" + completeWMTS, + options: { + attribution: "{attribution.MDT}", + minZoom: 4, + bounds: [ + [22.173559281306314, -47.0716243806546], + [66.88067635831743, + 40.8749629405498 + ] + ] + }, + variants: { + MaximaActualidad: {}, + Mosaico: { + url: "http://www.ign.es/wms-inspire/pnoa-ma?", + options: { + layers: "OI.MosaicElement", + format: "image/png", + transparent: true + } + } + } + }, + // Ocupacion Suelo + OcupacionSuelo: { + url: "https://servicios.idee.es/wmts/ocupacion-suelo?service=WMTS&request=GetTile&version=1.0.0&Format=image/png&layer={variant}&style=default" + completeWMTS, + options: { + attribution: "CC BY 4.0 scne.es. Infraestructura de Datos Espaciales de España (IDEE)", + variant: "LC.LandCoverSurfaces" + }, + variants: { + Ocupacion: {}, + Usos: "LU.ExistingLandUse" + } + }, + // Light Detection and Ranging - LiDAR + LiDAR: { + url: "https://wmts-mapa-lidar.idee.es/lidar?service=WMTS&request=GetTile&version=1.0.0&Format=image/png&layer={variant}" + completeWMTS, + options: { + attribution: "{attribution.MDT}", + variant: "EL.GridCoverageDSM" + } + }, + // Mapa Topografico Nacional + MTN: { + url: "https://ign.es/wmts/mapa-raster?service=WMTS&request=GetTile&version=1.0.0&Format=image/jpeg&layer=MTN&style=default" + completeWMTS, + options: { + attribution: "{attribution.MDT}", + minZoom: 4, + bounds: [ + [22.173559281306314, -47.0716243806546], + [66.88067635831743, + 40.8749629405498 + ] + ] + } + }, + //WMS Servers + Geofisica: { + url: "https://www.ign.es/wms-inspire/geofisica?", + options: { + layers: "Ultimos10dias", + format: "image/png", + transparent: true, + attribution: "{attribution.IGNBase}" + }, + // Selected + variants: { + Terremotos10dias: {}, + Terremotos30dias: "Ultimos30dias", + Terremotos365dias: "Ultimos365dias", + ObservedEvents: "NZ.ObservedEvent", + HazardArea: "NZ.HazardArea" + } + }, + VigilanciaVolcanica: { + url: "https://wms-volcanologia.ign.es/volcanologia?", + options: { + layers: "erupciones", + format: "image/png", + transparent: true, + attribution: "{attribution.IGNBase}" + }, + // Selected + variants: { + ErupcionesHistoricas: {} + } + }, + CaminoDeSantiago: { + url: "https://www.ign.es/wms-inspire/camino-santiago?", + options: { + layers: "camino_frances", + format: "image/png", + transparent: true, + attribution: "CC BY 4.0 ign.es. Federación Española de Asociaciones de Amigos del Camino de Santiago (FEAACS)" + }, + variants: { + CaminoFrances: {}, + CaminosFrancia: "caminos_francia", + CaminosGalicia: "caminos_galicia", + CaminosDelNorte: "caminos_norte", + CaminosAndaluces: "caminos_andaluces", + CaminosCentro: "caminos_centro", + CaminosEste: "caminos_este", + CaminosCatalanes: "caminos_catalanes", + CaminosSureste: "caminos_sureste", + CaminosInsulares: "caminos_insulares", + CaminosPortugueses: "caminos_portugueses" + } + }, + Catastro: { + url: "https://ovc.catastro.meh.es/cartografia/INSPIRE/spadgcwms.aspx", + options: { + layers: "CP.CadastralParcel", + transparent: true, + minZoom: 10, + format: "image/png", + attribution: "Spanish General Directorate for Cadastre" + }, + variants: { + Catastro: { + url: "http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx", + options: { + layers: "Catastro", + minZoom: 1, + transparent: false + } + }, + Parcela: { + url: "http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx", + options: { + layers: "PARCELA", + minZoom: 15 + } + }, + CadastralParcel: "CP.CadastralParcel", + CadastralZoning: "CP.CadastralZoning", + Address: "AD.Address", + Building: "BU.Building", + BuildingPart: "BU.BuildingPart", + AdministrativeBoundary: "AU.AdministrativeBoundary", + AdministrativeUnit: "AU.AdministrativeUnit" + + } + }, + RedTransporte: { + url: "https://servicios.idee.es/wms-inspire/transportes", + options: { + layers: "TN.RoadTransportNetwork.RoadLink", + transparent: true, + format: "image/png", + attribution: "Sistema Geográfico Nacional SCNE" + }, + variants: { + // Selected, there are more, feel free to contribute + Carreteras: {}, + Ferroviario: "TN.RailTransportNetwork.RailwayLink", + Aerodromo: "TN.AirTransportNetwork.AerodromeArea", + AreaServicio: "TN.RoadTransportNetwork.RoadServiceArea", + EstacionesFerroviario: "TN.RailTransportNetwork.RailwayStationArea", + Puertos: "TN.WaterTransportNetwork.PortArea" + } + }, + Cartociudad: { + url: "https://www.cartociudad.es/wms-inspire/direcciones-ccpp?", + options: { + attribution: "CC BY 4.0 scne.es Cartociudad", + layers: "codigo-postal", + transparent: true, + minZoom: 14, + format: "image/png" + }, + variants: { + CodigosPostales: {}, + Direcciones: { + options: { + layers: "AD.Address", + minZoom: 15 + } + } + } + }, + NombresGeograficos: { + url: "https://www.ign.es/wms-inspire/ngbe?", + options: { + layers: "GN.GeographicalNames", + format: "image/png", + transparent: true, + attribution: "{attribution.IGNBase}", + minZoom: 6 + } + }, + UnidadesAdm: { + url: "https://www.ign.es/wms-inspire/unidades-administrativas?", + options: { + layers: "AU.AdministrativeBoundary", + format: "image/png", + transparent: true, + attribution: "{attribution.IGNBase}" + }, + variants: { + Limites: "AU.AdministrativeBoundary", + Unidades: "AU.AdministrativeUnit" + } + }, + Hidrografia: { + url: "https://servicios.idee.es/wms-inspire/hidrografia?", + options: { + layers: "HY.PhysicalWaters.Waterbodies", + format: "image/png", + transparent: true, + attribution: "CC BY 4.0 scne.es SCNE" + }, + // Selected, there are more, feel free to contribute + variants: { + MasaAgua: {}, + Cuencas: "HY.PhysicalWaters.Catchments", + Subcuencas: { + url: "https://wms.mapama.gob.es/sig/Agua/SubcuencasCauces/wms.aspx?", + options: { + attribution: "Ministerio para la Transición Ecológica y el Reto Demográfico", + layers: "HY.PhysicalWaters.Catchments" + } + }, + POI: "HY.PhysicalWaters.HydroPointOfInterest", + ManMade: { + options: { + minZoom: 10, + layers: "HY.PhysicalWaters.ManMadeObject" + } + }, + LineaCosta: "HY.PhysicalWaters.LandWaterBoundary", + Rios: { + options: { + layers: "HY.Network", + minZoom: 6 + } + }, + Humedales: "HY.PhysicalWaters.Wetland" + } + }, + Militar: { + url: "http://wms-defensa.idee.es/mapas?", + options: { + layers: "CEGET_1M", + format: "image/png", + transparent: true, + attribution: "Centro Geográfico del Ejército de Tierra (CEGET)" + }, + variants: { + CEGET1M: {}, + CEGETM7814: "CEGET_M7814", + CEGETM7815: "CEGET_M7815", + CEGETM682: "ceget_M682", + CECAF1M: "cecaf_cnv_1M" + } + }, + ADIF: { + url: "http://ideadif.adif.es/services/wms?", + options: { + layers: "TN.RailTransportNetwork.RailwayLink", + format: "image/png", + transparent: true, + attribution: "© ADIF" + }, + variants: { + Vias: {}, + Nodos: "TN.RailTransportNetwork.RailwayNode", + Estaciones: "TN.RailTransportNetwork.RailwayStationNode" + } + }, + LimitesMaritimos: { + url: "http://ideihm.covam.es/ihm-inspire/wms-unidadesmaritimas?", + options: { + layers: "AU.MaritimeBoundary", + format: "image/png", + transparent: true, + attribution: "© Instituto Hidrográfico de la Marina" + }, + variants: { + LimitesMaritimos: {}, + LineasBase: "AU.Baseline" + } + }, + Copernicus: { + url: "https://servicios.idee.es/wms/copernicus-landservice-spain?", + options: { + layers: "HRLForestTCD2015", + format: "image/png", + transparent: true, + attribution: "{attribution.IGNBase}" + }, + variants: { + Forest: {}, + ForestLeaf: "HRLForestDLT2015", + WaterWet: "HRLWaterWetT2015", + SoilSeal: "HRLImpervioDens2015", + GrassLand: "HRLGrassLand2015", + RiparianGreen: "Copernicus_RZ_GLE", + RiparianLandCover: "Copernicus_RZ_LCLU", + Natura2k: "N2k_LCLU_2012", + UrbanAtlas: { + options: { + layers: "Urban_Atlas_2012", + minZoom: 8 + } + } + } + }, + ParquesNaturales: { + url: "http://sigred.oapn.es/geoserverOAPN/LimitesParquesNacionalesZPP/ows?", + options: { + layers: "view_red_oapn_limite_pn", + format: "image/png", + transparent: true, + attribution: "Ministerio para la Transición Ecológica y el Reto Demográfico" + }, + variants: { + Limites: {}, + ZonasPerifericas: "view_red_oapn_zpp" + } + } +}; +// Adapted from https://github.com/leaflet-extras/leaflet-providers +// Copyright (c) 2013 Leaflet Providers contributors All rights reserved. +// BSD 2-Clause "Simplified" License +function providerOpts(arg, options) { + var providers = providersESP; + var parts = arg.split('.'); + var providerName = parts[0]; + var variantName = parts[1]; + if (!providers[providerName]) { + throw 'No such provider (' + providerName + ')'; + } + var provider = { + url: providers[providerName].url, + options: providers[providerName].options + }; + if (variantName) { + provider.options.providerName = providerName + '.' + variantName; + } else { + provider.options.providerName = providerName; + } + // overwrite values in provider from variant. + if (variantName && 'variants' in providers[providerName]) { + if (!(variantName in providers[providerName].variants)) { + throw 'No such variant of ' + providerName + ' (' + variantName + ')'; + } + var variant = providers[providerName].variants[variantName]; + //Guess WMS or WMTS + var finalurl = variant.url || provider.url; + //According to template Tiles uses {x} while WMS not. + var wmts = finalurl.includes("{x}"); + var variantOptions; + if (typeof variant === 'string') { + // Depending on WMTS or Tiles + if (wmts) { + variantOptions = { + variant: variant + }; + } else { + variantOptions = { + layers: variant + }; + } + } else { + variantOptions = variant.options; + } + provider = { + url: variant.url || provider.url, + options: L.Util.extend({}, provider.options, variantOptions) + }; + } + // replace attribution placeholders with their values from toplevel provider attribution, + // recursively + function attributionReplacer(attr) { + if (attr.indexOf('{attribution.') === -1) { + return attr; + } + return attr.replace(/\{attribution.(\w*)\}/g, function(match, attributionName) { + return attributionReplacer(providers[attributionName].options.attribution); + }); + } + provider.options.attribution = attributionReplacer(provider.options.attribution); + // Compute final options combining provider options with any user overrides + var layerOpts = L.Util.extend({}, provider.options, options); + var providerend = { + url: provider.url, + options: layerOpts + }; + return providerend; +} +L.tileLayer.providerESP = function(name, opts) { + var newprov = providerOpts(name, opts); + var nameurl = newprov.url; + if (nameurl.includes("{x}")) { + return L.tileLayer(newprov.url, newprov.options); + } else { + return L.tileLayer.wms(newprov.url, newprov.options); + } +} \ No newline at end of file diff --git a/data-raw/input/leafletproviders-ESP.html b/data-raw/input/leafletproviders-ESP.html index 579f930e..c45b38e0 100644 --- a/data-raw/input/leafletproviders-ESP.html +++ b/data-raw/input/leafletproviders-ESP.html @@ -1,148 +1,148 @@ - - - - leaflet-providersESP - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - -
providerfieldvalue
- - \ No newline at end of file + + + + leaflet-providersESP + + + + + + + + + + + + + + + + + + +

+ + + + + + + + + + +
providerfieldvalue
+ + diff --git a/data-raw/input/leafletproviders-ESP.xlsx b/data-raw/input/leafletproviders-ESP.xlsx index c1901447..c9eba335 100644 Binary files a/data-raw/input/leafletproviders-ESP.xlsx and b/data-raw/input/leafletproviders-ESP.xlsx differ diff --git a/data-raw/input/leafletproviders.html b/data-raw/input/leafletproviders.html index 4539e73b..d03f80f0 100644 --- a/data-raw/input/leafletproviders.html +++ b/data-raw/input/leafletproviders.html @@ -1,135 +1,135 @@ - - - - leaflet-providersESP - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - -
providerfieldvalue
- - \ No newline at end of file + + + + leaflet-providersESP + + + + + + + + + + + + + + + + + + + + +

+ + + + + + + + + +
providerfieldvalue
+ + diff --git a/data-raw/input/pobmun19.xlsx b/data-raw/input/pobmun19.xlsx index 4b3b1dbe..8af39182 100644 Binary files a/data-raw/input/pobmun19.xlsx and b/data-raw/input/pobmun19.xlsx differ diff --git a/data-raw/leaflet.providersESP.df.R b/data-raw/leaflet.providersESP.df.R index c7932e2e..59d40ad0 100644 --- a/data-raw/leaflet.providersESP.df.R +++ b/data-raw/leaflet.providersESP.df.R @@ -10,5 +10,21 @@ leaflet.providersESP.df <- esp_hlp_utf8() %>% as.data.frame() +tb <- as_tibble(leaflet.providersESP.df) usethis::use_data(leaflet.providersESP.df, overwrite = TRUE, compress = "xz") + + +rm(list = ls()) +# Try + + +devtools::load_all() + +# Try MDT +library(tidyterra) +ccaa <- esp_get_ccaa(c("Andalucia"), epsg = 3857) +tile <- esp_getTiles(ccaa, "IDErioja", crop = FALSE) + +ggplot2::ggplot() + + geom_spatraster_rgb(data = tile) diff --git a/data-raw/logo.R b/data-raw/logo.R index 989981ec..e0b9f515 100644 --- a/data-raw/logo.R +++ b/data-raw/logo.R @@ -28,10 +28,10 @@ a <- ggplot(map) + data = map2, color = "#FABD00", fill = NA, - lwd = 0.1 + linewidth = 0.1 ) + - geom_sf(data = l, color = "#FABD00", lwd = 0.1) + - geom_sf(data = p, color = "#FABD00", lwd = 0.1) + + geom_sf(data = l, color = "#FABD00", linewidth = 0.1) + + geom_sf(data = p, color = "#FABD00", linewidth = 0.1) + theme_void() diff --git a/data/esp_codelist.rda b/data/esp_codelist.rda index 19200388..fd903ee6 100644 Binary files a/data/esp_codelist.rda and b/data/esp_codelist.rda differ diff --git a/data/esp_munic.sf.rda b/data/esp_munic.sf.rda index 90215d05..31da2761 100644 Binary files a/data/esp_munic.sf.rda and b/data/esp_munic.sf.rda differ diff --git a/data/esp_nuts.sf.rda b/data/esp_nuts.sf.rda index 22e47cdc..0b799160 100644 Binary files a/data/esp_nuts.sf.rda and b/data/esp_nuts.sf.rda differ diff --git a/data/esp_tiles_providers.rda b/data/esp_tiles_providers.rda new file mode 100644 index 00000000..7449597c Binary files /dev/null and b/data/esp_tiles_providers.rda differ diff --git a/data/leaflet.providersESP.df.rda b/data/leaflet.providersESP.df.rda index 9d770925..7e51fb4e 100644 Binary files a/data/leaflet.providersESP.df.rda and b/data/leaflet.providersESP.df.rda differ diff --git a/data/pobmun19.rda b/data/pobmun19.rda index bfd709ab..8482253e 100644 Binary files a/data/pobmun19.rda and b/data/pobmun19.rda differ diff --git a/dev/.gitignore b/dev/.gitignore deleted file mode 100644 index b14c5486..00000000 --- a/dev/.gitignore +++ /dev/null @@ -1 +0,0 @@ -debug.log diff --git a/dev/ci-documents.yaml b/dev/ci-documents.yaml deleted file mode 100644 index bdaa13e7..00000000 --- a/dev/ci-documents.yaml +++ /dev/null @@ -1,45 +0,0 @@ -on: - push: - paths: - - _pkgdown.yml - -name: Update man and README - CI - -jobs: - render: - name: Update docs - runs-on: macOS-latest - steps: - - uses: actions/checkout@v2 - - uses: r-lib/actions/setup-r@v1 - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - install.packages('pkgdown') - install.packages("roxygen2") - # Additional packages - install.packages("styler") - - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - uses: actions/cache@v2 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - name: Install package - run: R CMD INSTALL . - - name: Pkgdown - run: Rscript -e 'pkgdown::build_site(devel = TRUE, lazy = FALSE)' - - name: Commit results - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - git add -A - git commit -m 'Update docs' || echo "No changes to commit" - git push origin || echo "No changes to commit" diff --git a/dev/dev.R b/dev/dev.R deleted file mode 100644 index 300e1424..00000000 --- a/dev/dev.R +++ /dev/null @@ -1,350 +0,0 @@ -options(mapSpain_cache_dir = "~/R/mapslib/GISCO") - - -roxygen2::roxygenise() -tinytest::test_all() -devtools::check() - -# issue template -devtools::build_readme() -devtools::build_rmd("vignettes/mapSpain.Rmd") -devtools::build_rmd("vignettes/working_imagery.Rmd") -devtools::build_rmd("vignettes/x01_regioncodes.Rmd") - -urlchecker::url_check() - -devtools::check(remote = TRUE, manual = TRUE) - - -revdepcheck::revdep_check(num_workers = 4) - -devtools::spell_check() -devtools::check_rhub() -devtools::check_win_release() -devtools::check_win_devel() -devtools::check_win_oldrelease() - -codemetar::write_codemeta(write_minimeta = TRUE) - -devtools::release() - - - - - - - - - -install.packages("devtools") - -covr::package_coverage() - -install.packages("covr", dependencies = TRUE) - -a <- esp_get_ccaa() - -f <- esp_get_hex_ccaa() -plot(st_geometry(f)) - -f <- esp_get_hex_ccaa() -f <- st_make_valid(f) -st_is_valid(f) - -st_crs(f) - -library(mapSpain) - -s <- esp_get_hex_prov() -s <- st_transform(s,3857) -st_is_valid(s) -par(mar=c(0,0,0,0)) -plot(st_geometry(s)) - -devtools::build_readme() - -tinytest::test_all() - -help(giscoR) - -usethis::use_cran_comments() - -devtools::spell_check() -codemetar::write_codemeta(write_minimeta = TRUE) - -??mapSpain - -devtools::release() - -devtools::check() - -tinytest::test_all() - -options(mapSpain_cache_dir="~/R/mapslib/GISCO") - -devtools::revdep("mapSpain") -pkgdown::build_articles() -pkgdown::clean_site() -pkgdown::build_article("mapSpain") - -pkgdown::build_articles_index() - -pkgdown::build_site(lazy = TRUE) - -devtools::spell_check() - -pkgdown::clean_site() - -sessionInfo() - -tinytest::test_all() - -hcl.pals("sequential") - -devtools::check() -devtools::check_win_release() -devtools::check_win_devel() -devtools::check_win_oldrelease() -devtools::check_rhub() - -dev - -codemetar::write_codemeta(write_minimeta = TRUE) - - -devtools::build_manual(path = "./dev") -pkgdown::build_favicons(overwrite = TRUE) - -pkgdown::build_site(lazy = TRUE) -pkgdown::build_articles(lazy = FALSE) - -pkgdown::build_site() -pkgdown::build_reference_index() - -pkgdown::build_favicons(overwrite = TRUE) - -usethis::use_readme_rmd() -devtools::build_readme() -pkgdown::build_() - -pkgdown::clean_site() -devtools::document() -interactive() - -leaflet.providersESP.df - -leafle -tinytest::test_all() - - - -# Checks release - - -devtools::spell_check() -devtools::check() -devtools::check_rhub() -devtools::check_win_release() -devtools::check_win_devel() -devtools::check_win_oldrelease() - -devtools::release() - -install.packages("devtools",dependencies = TRUE) - -rhub::validate_email() - -leaflet::addP - -point <- st_point(c(-3.6886664,40.3922413)) -point <- st_sfc(point) -point <- st_set_crs(point,4326) -point <- st_transform(point,3857) -#point <- st_buffer(point,1000) -a <- esp_getTiles(point, type = "Catastro.Parcela", - verbose = TRUE, - crop = TRUE, - res=256) - - -raster::plotRGB(a) -plot(st_geometry(point), add=TRUE) - -point - -library(mapSpain) - -sessionInfo() - -f <- mapSpain::leaflet.providersESP -f <- unique(f$provider) - - -library(goodpractice) - -gp() - -tinytest::test_all() - -xx <- esp_get_ccaa() - -xx <- sf::st_transform(xx,3857) - -options(mapSpain_cache_dir = "~/R/mapslib/GISCO") - -rt <- esp_getTiles(xx, type = f[1], verbose = TRUE, zoom = 4 ) - -par(mar=c(0,0,0,0)) -cartography::tilesLayer(rt) - -lintr::lint_package() - - -tinytest::test_all() -covr::report() - - -ff <- mapSpain::leaflet.providersESP - -leaflet::addp - -addTiles( - map, - urlTemplate = "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", - attribution = NULL, - layerId = NULL, - group = NULL, - options = tileOptions(), - data = getMapData(map) -) - - -addProviderTiles( - map, - provider, - layerId = NULL, - group = NULL, - options = providerTileOptions() -) - -providerTileOptions( - errorTileUrl = "", - noWrap = FALSE, - opacity = NULL, - zIndex = NULL, - updateWhenIdle = NULL, - detectRetina = FALSE, - ... -) - -aa <- leaflet::WMSTileOptions() -bb <- leaflet::tileOptions(arg = 1) - - -ff <- mapSpain::leaflet.providersESP - -library(leaflet) - -cc <- do.call( leaflet::tileOptions,c(aa,bb)) - -cc - -WMSTileOptions( - styles = "", - format = "image/jpeg", - transparent = FALSE, - version = "1.1.1", - crs = NULL, - ... -) - -addWMSTiles( - map, - baseUrl, - layerId = NULL, - group = NULL, - options = WMSTileOptions(), - attribution = NULL, - layers = "", - data = getMapData(map) -) - - -devtools::build_manual("./dev") - -library(goodpractice) - -gp() - -lintr::lint_package() - -f <- esp_get_nuts(region = "Madrid", moveCAN = TRUE, epsg = 3857) -p <- esp_getTiles(f, type = "IGNBase.Gris", verbose = TRUE) -par(mar=c(0,0,0,0)) -cartography::tilesLayer(p) - - -x <- f -update_cache = FALSE -cache_dir = NULL -verbose = FALSE -type = "IDErioja" -zoom = NULL -crop = TRUE -res = 512 - - - -xinit <- x - -if (nrow(x) == 1 && sf::st_is(x, "POINT")) { - x <- sf::st_transform(x, 3857) - x <- sf::st_buffer(sf::st_geometry(x), 1000) - crop <- FALSE -} - -leafletProvidersESP <- mapSpain::leaflet.providersESP -provs <- - leafletProvidersESP[leafletProvidersESP$provider == type,] - -if (nrow(provs) == 0) { - stop( - "No match for type = '", - type, - "' found. Available providers are:\n\n", - paste0("'", unique(leafletProvidersESP$provider), "'", collapse = ", ") - ) - -} - - -cache_dir <- esp_hlp_cachedir(cache_dir) -cache_dir <- esp_hlp_cachedir(paste0(cache_dir, "/", type)) - - -x <- sf::st_transform(x, 4326) -bbx <- - sf::st_bbox(sf::st_transform(sf::st_as_sfc(sf::st_bbox(x)), 4326)) - -# select a default zoom level -if (is.null(zoom)) { - gz <- slippymath::bbox_tile_query(bbx) - zoom <- min(gz[gz$total_tiles %in% 4:10, "zoom"]) - - if (verbose) { - message("Auto zoom level: ", zoom) - } -} -minZoom <- as.numeric() - -!is.na(as.numeric(minZoom)) - -if (length(minZoom) > 0) { - zoom <- max(zoom, minZoom) - - if (verbose & minZoom == zoom) - message("\nSwiching. Minimum zoom for this provider is ", zoom, "\n") - - -} - diff --git a/dev/esp_munic.sf.rda b/dev/esp_munic.sf.rda deleted file mode 100644 index d52f7142..00000000 Binary files a/dev/esp_munic.sf.rda and /dev/null differ diff --git a/dev/mapSpain_0.0.0-9000.pdf b/dev/mapSpain_0.0.0-9000.pdf deleted file mode 100644 index 317ec1f4..00000000 Binary files a/dev/mapSpain_0.0.0-9000.pdf and /dev/null differ diff --git a/dev/mapSpain_0.1.0.pdf b/dev/mapSpain_0.1.0.pdf deleted file mode 100644 index 4f1ede90..00000000 Binary files a/dev/mapSpain_0.1.0.pdf and /dev/null differ diff --git a/dev/mapSpain_0.1.2.pdf b/dev/mapSpain_0.1.2.pdf deleted file mode 100644 index 21a90eef..00000000 Binary files a/dev/mapSpain_0.1.2.pdf and /dev/null differ diff --git a/dev/mapSpain_0.2.0.pdf b/dev/mapSpain_0.2.0.pdf deleted file mode 100644 index bd8b4b9a..00000000 Binary files a/dev/mapSpain_0.2.0.pdf and /dev/null differ diff --git a/dev/mapSpain_0.2.1.9000.pdf b/dev/mapSpain_0.2.1.9000.pdf deleted file mode 100644 index 78999735..00000000 Binary files a/dev/mapSpain_0.2.1.9000.pdf and /dev/null differ diff --git a/dev/test.Rmd b/dev/test.Rmd deleted file mode 100644 index 162194dc..00000000 --- a/dev/test.Rmd +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: "Try" -output: html_document ---- - -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -``` - -## R Markdown - -This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . - -When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: - -```{r cars} - - - -library(leaflet) -library(mapSpain) - -library(leaflet) - -CaminodeSantiago <- - leaflet() %>% setView(lat = 42.8282163, - lng = -8.701177, - zoom = 8) %>% - addProviderEspTiles(provider = "IGNBase.Gris") %>% - addProviderEspTiles("CaminoDeSantiago.CaminoFrances") - - -# df <- unique(leaflet.providersESP.df$provider)[1] -# -# -# for (i in seq_len(length(df))){ -# prov <- df[i] -# PuertadelSol <- PuertadelSol %>% addProviderEspTiles(df[i], group = df[i]) -# -# } -# PuertadelSol <- PuertadelSol %>% addLayersControl( -# overlayGroups = df -# ) %>% hideGroup(df[-1]) - - - -CaminodeSantiago - -``` diff --git a/dev/test.html b/dev/test.html deleted file mode 100644 index 0bac6a7a..00000000 --- a/dev/test.html +++ /dev/null @@ -1,4354 +0,0 @@ - - - - - - - - - - - - - -Try - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - -
-

R Markdown

-

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

-

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

-
library(leaflet)
-library(mapSpain)
-
-library(leaflet)
-
-CaminodeSantiago <-
-  leaflet() %>% setView(lat = 42.8282163,
-                        lng = -8.701177,
-                        zoom = 8) %>%
-  addProviderEspTiles(provider = "IGNBase.Gris") %>%
-  addProviderEspTiles("CaminoDeSantiago.CaminoFrances")
-
-
-# df <- unique(leaflet.providersESP.df$provider)[1]
-# 
-# 
-# for (i in seq_len(length(df))){
-#   prov <- df[i]
-#   PuertadelSol <- PuertadelSol %>% addProviderEspTiles(df[i], group = df[i])
-#   
-# }
-# PuertadelSol <- PuertadelSol %>% addLayersControl(
-#   overlayGroups = df
-# ) %>% hideGroup(df[-1])
-
-
-
-CaminodeSantiago
-
- -
- - - - -
- - - - - - - - - - - - - - - diff --git a/img/README-giscoR-1.png b/img/README-giscoR-1.png index 566240b3..595da9fc 100644 Binary files a/img/README-giscoR-1.png and b/img/README-giscoR-1.png differ diff --git a/img/README-giscoR-1.svg b/img/README-giscoR-1.svg deleted file mode 100644 index 3acc2f53..00000000 --- a/img/README-giscoR-1.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/img/README-static-1.png b/img/README-static-1.png index 2420e065..00bd8169 100644 Binary files a/img/README-static-1.png and b/img/README-static-1.png differ diff --git a/img/README-static-1.svg b/img/README-static-1.svg deleted file mode 100644 index e21e0c85..00000000 --- a/img/README-static-1.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/img/README-tile-1.png b/img/README-tile-1.png index 7b35cf24..61f5df7b 100644 Binary files a/img/README-tile-1.png and b/img/README-tile-1.png differ diff --git a/img/README-tile-1.svg b/img/README-tile-1.svg deleted file mode 100644 index 14c9fc0c..00000000 --- a/img/README-tile-1.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/inst/CITATION b/inst/CITATION index c2bcda44..79de67b9 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -1,15 +1,18 @@ -citHeader("To cite the 'mapSpain' package in publications use:") +year <- format(Sys.time(), "%Y") +abs <- trimws(gsub("\\s+", " ", meta$Description)) +abs <- gsub("'", "", abs) +title <- gsub("'", "", meta$Title) -year = format(Sys.time(), "%Y") -vers = paste('R package version', meta$Version) -url = 'https://ropenspain.github.io/mapSpain/' -citEntry( - , - entry = 'manual', - title = paste('mapSpain:', 'Administrative Boundaries of Spain'), - author = "Diego Hernangómez", + +bibentry( + "Manual", + header = "To cite the 'mapSpain' package in publications use:", + title = paste("{mapSpain}:", title), year = year, - url = url, - doi = '10.5281/zenodo.4318024', - textVersion = paste0('Hernangómez, D. (', year, '). mapSpain: Administrative Boundaries of Spain. ', 'R package. ', 'http://doi.org/10.5281/zenodo.4318024') + version = meta$Version, + author = person("Diego", "Hernangómez"), + doi = "10.5281/zenodo.5366622", + url = unlist(strsplit(meta$URL, ","))[1], + abstract = abs, + key = "R-mapspain" ) diff --git a/inst/WORDLIST b/inst/WORDLIST index 57bdcd1e..15b4190a 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,176 +1,93 @@ -ADIF ANE -Aerodromo -Andalucia -AreaServicio +Alboran +BDN +Baleares +Banco Bathymetry +Bierzo CCAA CDN -CECAF -CEGET -CEGETM CLDR -CMD -CNTR -CadastralParcel -CadastralZoning -CaminoDeSantiago -CaminoFrances -CaminosAndaluces -CaminosCatalanes -CaminosCentro -CaminosDelNorte -CaminosEste -CaminosGalicia -CaminosInsulares -CaminosPiemonts -CaminosPortugueses -CaminosSureste -CaminosTolosana -CaminosTuronensis -Carreteras +CRS +Canarias CartoBase -Cartociudad -Catastro +Castilla +Centre Ceuta -Choropleth -CodigosPostales -Cuencas -CurvasNivel -DOI +Comarcas Datos -Direcciones +EEA EPSG +ESDAC ETRS -Elevaciones -Espaciales -España -Estaciones -EstacionesFerroviario +El Estadistica Eurostat FID -Ferroviario -ForestLeaf GISCO +Galicia Galician -Geodata -Geofisica Geografico -Geográfico -GrassLand Hexbin -Hidrografia -Humedales Hypsometry -IDERioja -IDErioja +IDEE IGN -IGNBase INE -Infraestructura Instituto LAEA -LATN LAU -LEVL -LandCover -LazyLoad -LiDAR -Limites -LimitesMaritimos -LineaCosta -LineasBase +Liedekerke +MAPA +MITECO MTN -ManMade -MasaAgua -MaximaActualidad +Mapa Melilla -Militar -Mosaico +Montanarella Nacional -Natura -Nodos -NombresGeograficos -Ocupacion -OcupacionSuelo +Naturaleza +Navarra +OGC +ORCID OpenStreetMap -Orto -PNOA -Parcela -ParquesNaturales -Puertos -QUICKFIX -README +Panagos +REGCAN RGBA -RedTransporte +RegCan Renviron -Rioja's -RiparianGreen -RiparianLandCover SIANE -SoilSeal -Subcuencas -Tenerife -Terremotos -Todo -TodoNoFondo +Topografico URBN -Unidades -UnidadesAdm -UrbanAtlas -Usos -Verwaltungsgrenzen -Vias -VigilanciaVolcanica WGS WMS WMTS -WaterWet +WMTSproviders YYYY -ZonasPerifericas -administratives +alboran bathymetry -bezüglich -ccaa -centroid +ceuta choropleth -cldr +choropleths cmun -codauto -codecov -codelist +comarca +comarcas +config cpro de -der -df -dias dir -doi +ec +esdac eu -ga +europa geojson geospatial -ggplot -ggspatial -giscoR hexbin -https hydrographic hypsometry -ign -ine -io -iso javascript -lang -les -limites +jrc +kms +melilla +merindades +pre providersESP -ropenspain -roxygen -shortname -sianedata spanish -tmap -zenodo diff --git a/inst/examples/esp_get_gridmap.R b/inst/examples/esp_get_gridmap.R index 618e0de0..5d0cf1a1 100644 --- a/inst/examples/esp_get_gridmap.R +++ b/inst/examples/esp_get_gridmap.R @@ -1,49 +1,57 @@ - - -esp <- esp_get_country() -hexccaa <- esp_get_hex_ccaa() - -library(tmap) - - -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(hexccaa) + - tm_polygons("codauto", alpha = 0.6, legend.show = FALSE) + - tm_shape(hexccaa) + - tm_text("label") + - tm_layout(main.title = "Hexbin: CCAA") - - - -hexprov <- esp_get_hex_prov() - -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(hexprov) + - tm_polygons("cpro", alpha = 0.6, legend.show = FALSE) + - tm_shape(hexprov) + - tm_text("label") + - tm_layout(main.title = "Hexbin: Provinces") - - - -gridccaa <- esp_get_grid_ccaa() - -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(gridccaa) + - tm_polygons("codauto", alpha = 0.6, legend.show = FALSE) + - tm_shape(gridccaa) + - tm_text("label") + - tm_layout(main.title = "Grid: CCAA") - -gridprov <- esp_get_grid_prov() - -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(gridprov) + - tm_polygons("cpro", alpha = 0.6, legend.show = FALSE) + - tm_shape(gridprov) + - tm_text("label") + - tm_layout(main.title = "Grid: Provinces") +esp <- esp_get_country() +hexccaa <- esp_get_hex_ccaa() + +library(ggplot2) + +ggplot(hexccaa) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Hexbin: CCAA") + + + + + +hexprov <- esp_get_hex_prov() + +ggplot(hexprov) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Hexbin: Provinces") + + + +gridccaa <- esp_get_grid_ccaa() + +ggplot(gridccaa) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Grid: CCAA") + + +gridprov <- esp_get_grid_prov() + +ggplot(gridprov) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Grid: Provinces") diff --git a/inst/examples/esp_munic_sf.R b/inst/examples/esp_munic_sf.R index d75e617c..67a80802 100644 --- a/inst/examples/esp_munic_sf.R +++ b/inst/examples/esp_munic_sf.R @@ -1,31 +1,30 @@ -data("esp_munic.sf") - -teruel_cpro <- esp_dict_region_code("Teruel", destination = "cpro") - -teruel_sf <- esp_munic.sf[esp_munic.sf$cpro == teruel_cpro, ] -teruel_city <- teruel_sf[teruel_sf$name == "Teruel", ] - -# Plot - -library(tmap) - -tm_shape(teruel_sf) + - tm_polygons("#FDFBEA") + - tm_shape(teruel_city) + - tm_fill( - col = "name", - palette = "#C12838", - labels = "City of Teruel", - title = "" - ) + - tm_graticules(lines = FALSE) + - tm_layout( - main.title = "Municipalities of Teruel", - legend.position = c("left", "top") - ) + - tm_scale_bar() + - tm_compass( - type = "rose", - size = 3, - position = c("left", "bottom") - ) +data("esp_munic.sf") + +teruel_cpro <- esp_dict_region_code("Teruel", destination = "cpro") + +teruel_sf <- esp_munic.sf[esp_munic.sf$cpro == teruel_cpro, ] +teruel_city <- teruel_sf[teruel_sf$name == "Teruel", ] + +# Plot + +library(ggplot2) + +ggplot(teruel_sf) + + geom_sf(fill = "#FDFBEA") + + geom_sf(data = teruel_city, aes(fill = name)) + + scale_fill_manual( + values = "#C12838", + labels = "City of Teruel" + ) + + guides(fill = guide_legend(position = "inside")) + + labs( + fill = "", + title = "Municipalities of Teruel" + ) + + theme_minimal() + + theme( + text = element_text(face = "bold"), + panel.background = element_rect(colour = "black"), + panel.grid = element_blank(), + legend.position.inside = c(.2, .95) + ) diff --git a/inst/examples/esp_nuts_sf.R b/inst/examples/esp_nuts_sf.R index 6b8ca3b8..718d64c4 100644 --- a/inst/examples/esp_nuts_sf.R +++ b/inst/examples/esp_nuts_sf.R @@ -9,23 +9,21 @@ nuts3 <- esp_nuts.sf[esp_nuts.sf$LEVL_CODE == 3, ] spain <- esp_get_country(moveCAN = FALSE) -library(tmap) - # Plot Urban Type: See # https://ec.europa.eu/eurostat/web/rural-development/methodology -tm_shape(nuts3) + - tm_polygons( - "URBN_TYPE", - style = "cat", - border.col = "black", - border.alpha = 0.3, - title = "Urban topology", - labels = c("Urban", "Intermediate", "Rural"), - palette = c("grey80", "#FFC183", "#68AC20") + +library(ggplot2) + +nuts3$URBN_TYPE_cat <- as.factor(nuts3$URBN_TYPE) + +levels(nuts3$URBN_TYPE_cat) +levels(nuts3$URBN_TYPE_cat) <- c("Urban", "Intermediate", "Rural") + +ggplot(nuts3) + + geom_sf(aes(fill = URBN_TYPE_cat), linewidth = .1) + + scale_fill_manual(values = c("grey80", "#FFC183", "#68AC20")) + + labs( + title = "NUTS3 levels of Spain", + fill = "Urban topology" ) + - tm_graticules(lines = FALSE) + - tm_layout( - main.title = "NUTS3 levels of Spain", - legend.position = c("left", "center"), - legend.title.size = 0.8 - ) + theme_linedraw() diff --git a/inst/schemaorg.json b/inst/schemaorg.json new file mode 100644 index 00000000..7fcbf7e8 --- /dev/null +++ b/inst/schemaorg.json @@ -0,0 +1,45 @@ +{ + "@context": "https://schema.org", + "@graph": [ + { + "type": "SoftwareSourceCode", + "author": { + "id": "https://orcid.org/0000-0001-8457-4658" + }, + "codeRepository": "https://github.com/rOpenSpain/mapSpain", + "copyrightHolder": { + "id": "https://orcid.org/0000-0001-8457-4658", + "type": "Person", + "email": "diego.hernangomezherrero@gmail.com", + "familyName": "Hernangómez", + "givenName": "Diego" + }, + "description": "Administrative Boundaries of Spain at several levels (Autonomous Communities, Provinces, Municipalities) based on the 'GISCO' 'Eurostat' database and 'CartoBase SIANE' from 'Instituto Geografico Nacional' . It also provides a 'leaflet' plugin and the ability of downloading and processing static tiles.", + "license": "https://spdx.org/licenses/GPL-3.0", + "name": "mapSpain: Administrative Boundaries of Spain", + "programmingLanguage": { + "type": "ComputerLanguage", + "name": "R", + "url": "https://r-project.org" + }, + "provider": { + "id": "https://cran.r-project.org", + "type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "runtimePlatform": "R version 4.4.2 (2024-10-31 ucrt)", + "version": "0.10.0" + }, + { + "id": "https://doi.org/10.5281/zenodo.5366622", + "type": "SoftwareSourceCode", + "author": { + "type": "Person", + "familyName": "Hernangómez", + "givenName": "Diego" + }, + "name": "{mapSpain}: Administrative Boundaries of Spain" + } + ] +} diff --git a/man/addProviderEspTiles.Rd b/man/addProviderEspTiles.Rd index c3304490..4585fd17 100644 --- a/man/addProviderEspTiles.Rd +++ b/man/addProviderEspTiles.Rd @@ -3,10 +3,11 @@ \name{addProviderEspTiles} \alias{addProviderEspTiles} \alias{providerEspTileOptions} -\title{Include base tiles of Spanish public administrations on a \strong{leaflet} map} +\title{Include base tiles of Spanish public administrations on a \CRANpkg{leaflet} +map} \source{ \url{https://dieghernan.github.io/leaflet-providersESP/} leaflet plugin, -\strong{v1.2.0}. +\strong{v1.3.3}. } \usage{ addProviderEspTiles( @@ -20,63 +21,51 @@ addProviderEspTiles( providerEspTileOptions(...) } \arguments{ -\item{map}{A map widget created from \code{\link[leaflet:leaflet]{leaflet::leaflet()}}.} +\item{map}{the map to add the tile layer to} -\item{provider}{Name of the provider, see \link{leaflet.providersESP.df} for +\item{provider}{Name of the provider, see \link{esp_tiles_providers} for values available.} -\item{layerId}{the layer id} +\item{layerId}{the layer id to assign} -\item{group}{The name of the group the newly created layers should belong to -Human-friendly group names are permitted–they need not be short, -identifier-style names. Any number of layers and even different types of -layers (e.g. markers and polygons) can share the same group name. See -\code{\link[leaflet:map-layers]{leaflet::addTiles()}}.} +\item{group}{the name of the group the newly created layers should belong to +(for \code{\link[leaflet]{clearGroup}} and \code{\link[leaflet]{addLayersControl}} purposes). +Human-friendly group names are permitted--they need not be short, +identifier-style names.} -\item{options}{a list of extra options for tile layers, popups, paths -(circles, rectangles, polygons, ...), or other map elements} +\item{options}{tile options} -\item{...}{ - Arguments passed on to \code{\link[leaflet:addProviderTiles]{leaflet::providerTileOptions}} - \describe{ - \item{\code{errorTileUrl}}{the tile layer options; see -\url{https://leafletjs.com/reference-1.3.4.html#tilelayer}} - \item{\code{noWrap}}{the tile layer options; see -\url{https://leafletjs.com/reference-1.3.4.html#tilelayer}} - \item{\code{opacity}}{the tile layer options; see -\url{https://leafletjs.com/reference-1.3.4.html#tilelayer}} - \item{\code{zIndex}}{the tile layer options; see -\url{https://leafletjs.com/reference-1.3.4.html#tilelayer}} - \item{\code{updateWhenIdle}}{the tile layer options; see -\url{https://leafletjs.com/reference-1.3.4.html#tilelayer}} - \item{\code{detectRetina}}{the tile layer options; see -\url{https://leafletjs.com/reference-1.3.4.html#tilelayer}} - }} +\item{...}{Arguments passed on to \code{\link[leaflet:addProviderTiles]{leaflet::providerTileOptions()}}.} } \value{ -A map object generated with \code{\link[leaflet:leaflet]{leaflet::leaflet()}}. +A modified \code{\link[leaflet:leaflet]{leaflet::leaflet()}} \code{map} object. } \description{ -Include tiles of public Spanish organisms to a -\code{\link[leaflet:leaflet]{leaflet::leaflet()}} map. +Include tiles of public Spanish organisms to a \code{\link[leaflet:leaflet]{leaflet::leaflet()}} map. } \details{ -\code{\link[=providerEspTileOptions]{providerEspTileOptions()}} is a wrapper of -\code{\link[leaflet:addProviderTiles]{leaflet::providerTileOptions()}}. +\code{\link[=providerEspTileOptions]{providerEspTileOptions()}} is a wrapper of \code{\link[leaflet:addProviderTiles]{leaflet::providerTileOptions()}}. } \examples{ library(leaflet) -PuertadelSol <- - leaflet() \%>\% - setView( - lat = 40.4166, - lng = -3.7038400, - zoom = 18 +leafmap <- leaflet(width = "100\%", height = "60vh") \%>\% + setView(lat = 40.4166, lng = -3.7038400, zoom = 10) \%>\% + addTiles(group = "Default (OSM)") \%>\% + addProviderEspTiles( + provider = "IDErioja.Claro", + group = "IDErioja Claro" ) \%>\% - addProviderEspTiles(provider = "IGNBase.Gris") \%>\% - addProviderEspTiles(provider = "RedTransporte.Carreteras") + addProviderEspTiles( + provider = "RedTransporte.Carreteras", + group = "Carreteras" + ) \%>\% + addLayersControl( + baseGroups = c("IDErioja Claro", "Default (OSM)"), + overlayGroups = "Carreteras", + options = layersControlOptions(collapsed = FALSE) + ) -PuertadelSol +leafmap } \seealso{ \code{\link[leaflet:leaflet]{leaflet::leaflet()}}, \code{\link[leaflet:map-layers]{leaflet::addTiles()}} @@ -85,6 +74,7 @@ PuertadelSol Other imagery utilities: \code{\link{esp_getTiles}()}, -\code{\link{leaflet.providersESP.df}} +\code{\link{esp_make_provider}()}, +\code{\link{esp_tiles_providers}} } \concept{imagery utilities} diff --git a/man/esp_check_access.Rd b/man/esp_check_access.Rd new file mode 100644 index 00000000..a82bd558 --- /dev/null +++ b/man/esp_check_access.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_check_access.R +\name{esp_check_access} +\alias{esp_check_access} +\title{Check access to SIANE data} +\usage{ +esp_check_access() +} +\value{ +a logical. +} +\description{ +Check if R has access to resources at +\url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}. +} +\examples{ + +esp_check_access() +} +\seealso{ +\code{\link[giscoR:gisco_check_access]{giscoR::gisco_check_access()}} + +Other helper: +\code{\link{esp_move_can}()} +} +\concept{helper} diff --git a/man/esp_clear_cache.Rd b/man/esp_clear_cache.Rd index 06e684fd..fcf45e51 100644 --- a/man/esp_clear_cache.Rd +++ b/man/esp_clear_cache.Rd @@ -2,16 +2,16 @@ % Please edit documentation in R/esp_cache_clear.R \name{esp_clear_cache} \alias{esp_clear_cache} -\title{Clear your \strong{mapSpain} cache dir} +\title{Clear your \CRANpkg{mapSpain} cache dir} \usage{ -esp_clear_cache(config = TRUE, cached_data = TRUE, verbose = FALSE) +esp_clear_cache(config = FALSE, cached_data = TRUE, verbose = FALSE) } \arguments{ -\item{config}{if \code{TRUE}, will delete the configuration folder of -\strong{mapSpain}.} +\item{config}{Logical. If \code{TRUE}, will delete the configuration folder of +\CRANpkg{mapSpain}.} -\item{cached_data}{If this is set to \code{TRUE}, it will delete your -\code{cache_dir} and all its content.} +\item{cached_data}{Logical. If \code{TRUE}, it will delete your \code{cache_dir} and +all its content.} \item{verbose}{Logical, displays information. Useful for debugging, default is \code{FALSE}.} @@ -23,7 +23,7 @@ Invisible. This function is called for its side effects. \strong{Use this function with caution}. This function would clear your cached data and configuration, specifically: \itemize{ -\item Deletes the \strong{mapSpain} config directory +\item Deletes the \CRANpkg{mapSpain} config directory (\code{rappdirs::user_config_dir("mapSpain", "R")}). \item Deletes the \code{cache_dir} directory. \item Deletes the values on stored on \code{Sys.getenv("MAPSPAIN_CACHE_DIR")} and @@ -32,7 +32,7 @@ data and configuration, specifically: } \details{ This is an overkill function that is intended to reset your status -as it you would never have installed and/or used \strong{mapSpain}. +as it you would never have installed and/or used \CRANpkg{mapSpain}. } \examples{ @@ -45,6 +45,7 @@ Sys.getenv("MAPSPAIN_CACHE_DIR") } \seealso{ Other cache utilities: +\code{\link{esp_detect_cache_dir}()}, \code{\link{esp_set_cache_dir}()} } \concept{cache utilities} diff --git a/man/esp_codelist.Rd b/man/esp_codelist.Rd index 060184dd..6ab23e75 100644 --- a/man/esp_codelist.Rd +++ b/man/esp_codelist.Rd @@ -4,86 +4,109 @@ \encoding{UTF-8} \name{esp_codelist} \alias{esp_codelist} -\title{Spanish Code Translation Data Frame} +\title{Database with codes and names of spanish regions} \format{ -A data frame with 59 rows -codes as columns -\itemize{ -\item \strong{nuts+.code}: NUTS code of each subdivision. -\item \strong{nuts+.code}: NUTS name of each subdivision. -\item \strong{codauto}: INE code of each autonomous community. -\item \strong{iso2.+.code}: ISO2 code of each autonomous -community and province. -\item \strong{ine.+.name}: INE name of each autonomous community -and province. -\item \strong{iso2.+.name.(lang)}: ISO2 name of each autonomous community -and province. Several languages available. -\item \strong{cldr.+.name.(lang)}: CLDR name of each autonomous community and -province. Several languages available. -\item \strong{ccaa.short.+}: Short (common) name of each autonomous -community. Several languages available. -\item \strong{cpro}: INE code of each province. -\item \strong{prov.shortname.+}: Short (common) name of each province. -Several languages available. +A \code{\link[base:data.frame]{data.frame}} with 59 rows +codes and columns: + +\describe{ +\item{nuts1.code}{NUTS 1 code} +\item{nuts1.name}{NUTS 1 name} +\item{nuts1.name.alt}{NUTS 1 alternative name} +\item{nuts1.shortname.es}{NUTS1 1 short (common) name (Spanish)} +\item{codauto}{INE code of the autonomous community} +\item{iso2.ccaa.code}{ISO2 code of the autonomous community} +\item{nuts2.code}{NUTS 2 Code} +\item{ine.ccaa.name}{INE name of the autonomous community} +\item{iso2.ccaa.name.es}{ISO2 name of the autonomous community (Spanish)} +\item{iso2.ccaa.name.ca}{ISO2 name of the autonomous community (Catalan)} +\item{iso2.ccaa.name.gl}{ISO2 name of the autonomous community (Galician)} +\item{iso2.ccaa.name.eu}{ISO2 name of the autonomous community (Basque)} +\item{nuts2.name}{NUTS 2 name} +\item{cldr.ccaa.name.en}{CLDR name of the autonomous community (English)} +\item{cldr.ccaa.name.es}{CLDR name of the autonomous community (Spanish)} +\item{cldr.ccaa.name.ca}{CLDR name of the autonomous community (Catalan)} +\item{cldr.ccaa.name.ga}{CLDR name of the autonomous community (Galician)} +\item{cldr.ccaa.name.eu}{CLDR name of the autonomous community (Basque)} +\item{ccaa.shortname.en}{Short (common) name of the autonomous community +(English)} +\item{ccaa.shortname.es}{Short (common) name of the autonomous community +(Spanish)} +\item{ccaa.shortname.ca}{Short (common) name of the autonomous community +(Catalan)} +\item{ccaa.shortname.ga}{Short (common) name of the autonomous community +(Galician)} +\item{ccaa.shortname.eu}{Short (common) name of the autonomous community +(Basque)} +\item{cpro}{INE code of the province} +\item{iso2.prov.code}{ISO2 code of the province} +\item{nuts.prov.code}{NUTS code of the province} +\item{ine.prov.name}{INE name of the province} +\item{iso2.prov.name.es}{ISO2 name of the province (Spanish)} +\item{iso2.prov.name.ca}{ISO2 name of the province (Catalan)} +\item{iso2.prov.name.ga}{ISO2 name of the province (Galician)} +\item{iso2.prov.name.eu}{ISO2 name of the province (Basque)} +\item{cldr.prov.name.en}{CLDR name of the province (English)} +\item{cldr.prov.name.es}{CLDR name of the province (Spanish)} +\item{cldr.prov.name.ca}{CLDR name of the province (Catalan)} +\item{cldr.prov.name.ga}{CLDR name of the province (Galician)} +\item{cldr.prov.name.eu}{CLDR name of the province (Basque)} +\item{prov.shortname.en}{Short (common) name of the province (English)} +\item{prov.shortname.es}{Short (common) name of the province (Spanish)} +\item{prov.shortname.ca}{Short (common) name of the province (Catalan)} +\item{prov.shortname.ga}{Short (common) name of the province (Galician)} +\item{prov.shortname.eu}{Short (common) name of the province (Basque)} +\item{nuts3.code}{NUTS 3 code} +\item{nuts3.name}{NUTS 3 name} +\item{nuts3.shortname.es}{NUTS 3 short (common) name} } } \source{ \itemize{ \item \strong{INE}: Instituto Nacional de Estadistica: \url{https://www.ine.es/} -\item \strong{Eurostat (NUTS)}: \url{https://ec.europa.eu/eurostat/web/nuts/background} -\item \strong{ISO}: \url{https://www.iso.org/obp/ui/#iso:code:3166:ES} +\item \strong{Eurostat (NUTS)}: \url{https://ec.europa.eu/eurostat/web/nuts/overview} +\item \strong{ISO}: \url{https://www.iso.org/home.html} \item \strong{CLDR}: \url{https://unicode-org.github.io/cldr-staging/charts/38/index.html} } } \description{ -A data frame used internally for translating codes and names of the -different subdivisions of Spain. The data frame provides the hierarchy of -the subdivisions including NUTS1 level, Autonomous Communities -(equivalent to NUTS2), Provinces and NUTS3 level. See Note. +A \code{data.frame} object used internally for translating codes and names of the +different subdivisions of Spain. The \code{data.frame} provides the hierarchy of +the subdivisions including NUTS1 level, autonomous communities (equivalent +to NUTS2), provinces and NUTS3 level. See \strong{Note}. } \note{ -Languages available are: -\itemize{ -\item \strong{"en"}: English -\item \strong{"es"}: Spanish -\item \strong{"ca"}: Catalan -\item \strong{"ga"}: Galician -\item \strong{"eu"}: Basque -} - Although NUTS2 matches the first subdivision level of Spain (CCAA - Autonomous Communities), it should be noted that NUTS3 does not match the second subdivision level of Spain (Provinces). NUTS3 provides a -dedicated code for major islands whereas the Provinces doesn't. +dedicated code for major islands whereas the provinces doesn't. Ceuta and Melilla has an specific status (Autonomous Cities) but are -considered as communities with a single province (as Madrid, Asturias -or Murcia) on this dataset. +considered as autonomous communities with a single province (as Madrid, +Asturias or Murcia) on this database. } \examples{ data("esp_codelist") - -library(tibble) - -glimpse(as_tibble(esp_codelist)) } \seealso{ Other datasets: \code{\link{esp_munic.sf}}, \code{\link{esp_nuts.sf}}, -\code{\link{leaflet.providersESP.df}}, +\code{\link{esp_tiles_providers}}, \code{\link{pobmun19}} Other political: \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} Other dictionary: \code{\link{esp_dict_region_code}()} diff --git a/man/esp_detect_cache_dir.Rd b/man/esp_detect_cache_dir.Rd new file mode 100644 index 00000000..3ebd249c --- /dev/null +++ b/man/esp_detect_cache_dir.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_cache.R +\name{esp_detect_cache_dir} +\alias{esp_detect_cache_dir} +\title{Detect cache dir for \CRANpkg{mapSpain}} +\usage{ +esp_detect_cache_dir(x = NULL) +} +\arguments{ +\item{x}{Ignored.} +} +\value{ +A character with the path to your \code{cache_dir}. +} +\description{ +Helper function to detect the current cache folder. See +\code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. +} +\examples{ +esp_detect_cache_dir() + +} +\seealso{ +Other cache utilities: +\code{\link{esp_clear_cache}()}, +\code{\link{esp_set_cache_dir}()} +} +\concept{cache utilities} diff --git a/man/esp_dict.Rd b/man/esp_dict.Rd index 7a0ff5a7..81c8e84d 100644 --- a/man/esp_dict.Rd +++ b/man/esp_dict.Rd @@ -3,7 +3,7 @@ \name{esp_dict_region_code} \alias{esp_dict_region_code} \alias{esp_dict_translate} -\title{Convert and translate Subdivision Names} +\title{Convert and translate subdivision names} \usage{ esp_dict_region_code(sourcevar, origin = "text", destination = "text") @@ -12,8 +12,8 @@ esp_dict_translate(sourcevar, lang = "en", all = FALSE) \arguments{ \item{sourcevar}{Vector which contains the subdivision names to be converted.} -\item{origin, destination}{One of \code{"text"}, \code{"nuts"}, \code{"iso2"}, -\code{"codauto"} and \code{"cpro"}.} +\item{origin, destination}{One of \code{"text"}, \code{"nuts"}, \code{"iso2"}, \code{"codauto"} +and \code{"cpro"}.} \item{lang}{Language of translation. Available languages are: \itemize{ @@ -30,9 +30,9 @@ On \code{FALSE} it returns a character vector. See \strong{Value}.} \value{ \code{\link[=esp_dict_region_code]{esp_dict_region_code()}} returns a vector of characters. -\code{\link[=esp_dict_translate]{esp_dict_translate()}} returns a character vector or a named -list with each of the possible names of each \code{sourcevar} on the required -language \code{lang}. +\code{\link[=esp_dict_translate]{esp_dict_translate()}} returns a \code{character} vector or a named \code{list} with +each of the possible names of each \code{sourcevar} on the required language +\code{lang}. } \description{ Converts long subdivision names into different coding schemes and languages. @@ -78,10 +78,8 @@ esp_dict_region_code(valsmix, destination = "iso2") } -vals <- c( - "La Rioja", "Sevilla", "Madrid", - "Jaen", "Orense", "Baleares" -) +vals <- c("La Rioja", "Sevilla", "Madrid", "Jaen", "Orense", "Baleares") + esp_dict_translate(vals) esp_dict_translate(vals, lang = "es") esp_dict_translate(vals, lang = "ca") diff --git a/man/esp_getTiles.Rd b/man/esp_getTiles.Rd index c96cd9a6..088534c0 100644 --- a/man/esp_getTiles.Rd +++ b/man/esp_getTiles.Rd @@ -1,134 +1,191 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/esp_getTiles.R -\name{esp_getTiles} -\alias{esp_getTiles} -\title{Get static tiles from public administrations of Spanish.} -\source{ -\url{https://dieghernan.github.io/leaflet-providersESP/} leaflet plugin, -\strong{v1.2.0}. - -For plotting, you can use \code{\link[raster:plotRGB]{raster::plotRGB()}}, \code{\link[tmap:tm_raster]{tmap::tm_rgb()}}. -} -\usage{ -esp_getTiles( - x, - type = "IDErioja", - zoom = NULL, - zoommin = 0, - crop = TRUE, - res = 512, - bbox_expand = 0.05, - transparent = TRUE, - mask = FALSE, - update_cache = FALSE, - cache_dir = NULL, - verbose = FALSE -) -} -\arguments{ -\item{x}{An \code{sf} object.} - -\item{type}{Name of the provider. See \link{leaflet.providersESP.df}.} - -\item{zoom}{Zoom level. If \code{NULL}, it is determined automatically. If set, -it overrides \code{zoommin}. Only valid for WMTS tiles. On a single point it -applies a buffer to the point and on \code{zoom = NULL} the function set a zoom -level of 18. See \strong{Details}.} - -\item{zoommin}{Delta on default \code{zoom}. The default value is designed to -download fewer tiles than you probably want. Use \code{1} or \code{2} to -increase the resolution.} - -\item{crop}{\code{TRUE} if results should be cropped to the specified \code{x} extent, -\code{FALSE} otherwise. If \code{x} is an \code{sf} object with one \code{POINT}, crop is set -to \code{FALSE}.} - -\item{res}{Resolution (in pixels) of the final tile. Only valid for WMS.} - -\item{bbox_expand}{A numeric value that indicates the expansion percentage -of the bounding box of \code{x}.} - -\item{transparent}{Logical. Provides transparent background, if supported. -Depends on the selected provider on \code{type}.} - -\item{mask}{\code{TRUE} if the result should be masked to \code{x}.} - -\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. -When set to \code{TRUE} it would force a fresh download of the source file.} - -\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} - -\item{verbose}{Logical, displays information. Useful for debugging, -default is \code{FALSE}.} -} -\value{ -A \code{RasterBrick} is returned, with 3 (RGB) or 4 (RGBA) layers, depending on -the provider. See \code{\link[raster:brick]{raster::brick()}}. -. -} -\description{ -Get static map tiles based on a spatial object. Maps can be fetched from -various open map servers. - -This function is a implementation of the javascript plugin -\href{https://dieghernan.github.io/leaflet-providersESP/}{leaflet-providersESP} -\strong{v1.2.0}. -} -\details{ -Zoom levels are described on the -\href{https://wiki.openstreetmap.org/wiki/Zoom_levels}{OpenStreetMap wiki}:\tabular{rl}{ - zoom \tab area to represent \cr - 0 \tab whole world \cr - 3 \tab large country \cr - 5 \tab state \cr - 8 \tab county \cr - 10 \tab metropolitan area \cr - 11 \tab city \cr - 13 \tab village or suburb \cr - 16 \tab streets \cr - 18 \tab some buildings, trees \cr -} - - -For a complete list of providers see \link{leaflet.providersESP.df}. - -Most WMS/WMTS providers provide tiles on "EPSG:3857". In case that the tile -looks deformed, try projecting first \code{x}: - -\code{x <- sf::st_transform(x, 3857)} -} -\section{About caching}{ -You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. - -Sometimes cached files may be corrupt. On that case, try re-downloading -the data setting \code{update_cache = TRUE}. - -If you experience any problem on download, try to download the -corresponding .geojson file by any other method and save it on your -\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. -} - -\examples{ -\dontrun{ -# This script downloads tiles to your local machine -# Run only if you are online - -Murcia <- esp_get_ccaa_siane("Murcia", epsg = 3857) -Tile <- esp_getTiles(Murcia) - -library(tmap) - -tm_shape(Tile, raster.downsample = FALSE) + - tm_rgb(interpolate = FALSE) + - tm_shape(Murcia) + - tm_borders() -} -} -\seealso{ -\code{\link[raster:brick]{raster::brick()}}. - -Other imagery utilities: -\code{\link{addProviderEspTiles}()}, -\code{\link{leaflet.providersESP.df}} -} -\concept{imagery utilities} +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_getTiles.R +\name{esp_getTiles} +\alias{esp_getTiles} +\title{Get static tiles from public administrations of Spain} +\source{ +\url{https://dieghernan.github.io/leaflet-providersESP/} leaflet plugin, +\strong{v1.3.3}. +} +\usage{ +esp_getTiles( + x, + type = "IDErioja", + zoom = NULL, + zoommin = 0, + crop = TRUE, + res = 512, + bbox_expand = 0.05, + transparent = TRUE, + mask = FALSE, + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE, + options = NULL +) +} +\arguments{ +\item{x}{An \code{\link[sf:sf]{sf}} or \code{\link[sf:sfc]{sfc}} object.} + +\item{type}{This parameter could be either: +\itemize{ +\item The name of one of the pre-defined providers +(see \code{\link[=esp_tiles_providers]{esp_tiles_providers()}}). +\item A list with two named elements \code{id} and \code{q} with your own parameters. +See \code{\link[=esp_make_provider]{esp_make_provider()}} and examples. +}} + +\item{zoom}{Zoom level. If \code{NULL}, it is determined automatically. If set, +it overrides \code{zoommin}. Only valid for WMTS tiles. On a single point it +applies a buffer to the point and on \code{zoom = NULL} the function set a zoom +level of 18. See \strong{Details}.} + +\item{zoommin}{Delta on default \code{zoom}. The default value is designed to +download fewer tiles than you probably want. Use \code{1} or \code{2} to +increase the resolution.} + +\item{crop}{\code{TRUE} if results should be cropped to the specified \code{x} extent, +\code{FALSE} otherwise. If \code{x} is an \code{\link[sf:sf]{sf}} object with one \code{POINT}, +\code{crop} is set to \code{FALSE}.} + +\item{res}{Resolution (in pixels) of the final tile. Only valid for WMS.} + +\item{bbox_expand}{A numeric value that indicates the expansion percentage +of the bounding box of \code{x}.} + +\item{transparent}{Logical. Provides transparent background, if supported. +Depends on the selected provider on \code{type}.} + +\item{mask}{\code{TRUE} if the result should be masked to \code{x}.} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} + +\item{options}{A named list containing additional options to pass to the +query.} +} +\value{ +A \code{SpatRaster} is returned, with 3 (RGB) or 4 (RGBA) layers, depending on +the provider. See \code{\link[terra:rast]{terra::rast()}}. +. +} +\description{ +Get static map tiles based on a spatial object. Maps can be fetched from +various open map servers. + +This function is a implementation of the javascript plugin +\href{https://dieghernan.github.io/leaflet-providersESP/}{leaflet-providersESP} +\strong{v1.3.3}. +} +\details{ +Zoom levels are described on the +\href{https://wiki.openstreetmap.org/wiki/Zoom_levels}{OpenStreetMap wiki}:\tabular{rl}{ + zoom \tab area to represent \cr + 0 \tab whole world \cr + 3 \tab large country \cr + 5 \tab state \cr + 8 \tab county \cr + 10 \tab metropolitan area \cr + 11 \tab city \cr + 13 \tab village or suburb \cr + 16 \tab streets \cr + 18 \tab some buildings, trees \cr +} + + +For a complete list of providers see \link{esp_tiles_providers}. + +Most WMS/WMTS providers provide tiles on "EPSG:3857". In case that the tile +looks deformed, try projecting first \code{x}: + +\code{x <- sf::st_transform(x, 3857)} +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\examples{ +\dontrun{ +# This script downloads tiles to your local machine +# Run only if you are online + +segovia <- esp_get_prov_siane("segovia", epsg = 3857) +tile <- esp_getTiles(segovia, "IGNBase.Todo") + +library(ggplot2) +library(tidyterra) + +ggplot(segovia) + + geom_spatraster_rgb(data = tile, maxcell = Inf) + + geom_sf(fill = NA) + +# Another provider + +tile2 <- esp_getTiles(segovia, type = "MDT") + +ggplot(segovia) + + geom_spatraster_rgb(data = tile2, maxcell = Inf) + + geom_sf(fill = NA) + +# A custom WMS provided + +custom_wms <- esp_make_provider( + id = "an_id_for_caching", + q = "https://idecyl.jcyl.es/geoserver/ge/wms?", + service = "WMS", + version = "1.3.0", + format = "image/png", + layers = "geolog_cyl_litologia" +) + +custom_wms_tile <- esp_getTiles(segovia, custom_wms) + +autoplot(custom_wms_tile, maxcell = Inf) + + geom_sf(data = segovia, fill = NA, color = "red") + +# A custom WMTS provider + +custom_wmts <- esp_make_provider( + id = "cyl_wmts", + q = "https://www.ign.es/wmts/pnoa-ma?", + service = "WMTS", + layer = "OI.OrthoimageCoverage" +) + +custom_wmts_tile <- esp_getTiles(segovia, custom_wmts) + +autoplot(custom_wmts_tile, maxcell = Inf) + + geom_sf(data = segovia, fill = NA, color = "white", linewidth = 2) + +# Example from https://leaflet-extras.github.io/leaflet-providers/preview/ +cartodb_voyager <- list( + id = "CartoDB_Voyager", + q = "https://a.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}.png" +) +cartodb <- esp_getTiles(segovia, cartodb_voyager, zoommin = 1) + +autoplot(cartodb, maxcell = Inf) + + geom_sf(data = segovia, fill = NA, color = "black", linewidth = 1) +} +} +\seealso{ +\code{\link[terra:rast]{terra::rast()}}. + +Other imagery utilities: +\code{\link{addProviderEspTiles}()}, +\code{\link{esp_make_provider}()}, +\code{\link{esp_tiles_providers}} +} +\concept{imagery utilities} diff --git a/man/esp_get_can_box.Rd b/man/esp_get_can_box.Rd index 8eaf4acb..2b14a006 100644 --- a/man/esp_get_can_box.Rd +++ b/man/esp_get_can_box.Rd @@ -3,7 +3,7 @@ \name{esp_get_can_box} \alias{esp_get_can_box} \alias{esp_get_can_provinces} -\title{Get \code{sf} lines and polygons for insetting the Canary Islands} +\title{Get \code{\link[sf:sf]{sf}} lines and polygons for insetting the Canary Islands} \source{ \code{esp_get_can_provinces} extracted from CartoBase ANE, \code{se89_mult_admin_provcan_l.shp} file. @@ -25,14 +25,15 @@ Initial position can be adjusted using the vector of coordinates. See \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} } \value{ -A \code{sf} polygon or line depending of \code{style} parameter. +A \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} depending of \code{style} +parameter. \code{esp_get_can_provinces} returns a \code{LINESTRING} object. } @@ -50,13 +51,17 @@ Islands. \item \code{\link[=esp_get_can_provinces]{esp_get_can_provinces()}} is used to draw a separator line between the two provinces of the Canary Islands. } + +See also \code{\link[=esp_move_can]{esp_move_can()}} to displace stand-alone objects on the Canary +Islands. } \section{Displacing the Canary Islands}{ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ @@ -66,31 +71,31 @@ Box <- esp_get_can_box() Line <- esp_get_can_provinces() # Plot +library(ggplot2) -library(tmap) - - -tm_shape(Provs) + - tm_polygons() + - tm_shape(Box) + - tm_lines() + - tm_shape(Line) + - tm_lines() +ggplot(Provs) + + geom_sf() + + geom_sf(data = Box) + + geom_sf(data = Line) + + theme_linedraw() \donttest{ # Displacing Canary -Provs_D <- esp_get_prov(moveCAN = c(15, 0)) +# By same factor -Box_D <- esp_get_can_box(style = "left", moveCAN = c(15, 0)) +displace <- c(15, 0) -Line_D <- esp_get_can_provinces(moveCAN = c(15, 0)) +Provs_D <- esp_get_prov(moveCAN = displace) -tm_shape(Provs_D) + - tm_polygons() + - tm_shape(Box_D) + - tm_lines() + - tm_shape(Line_D) + - tm_lines() +Box_D <- esp_get_can_box(style = "left", moveCAN = displace) + +Line_D <- esp_get_can_provinces(moveCAN = displace) + +ggplot(Provs_D) + + geom_sf() + + geom_sf(data = Box_D) + + geom_sf(data = Line_D) + + theme_linedraw() # Example with poly option @@ -123,18 +128,17 @@ CCAA <- esp_get_ccaa( # Plot -tm_shape(Countries, bbox = c(-10, 34.6, 4.3, 44)) + - tm_polygons(col = "#DFDFDF") + - tm_shape(CANbox) + - tm_polygons(col = "#C7E7FB") + - tm_shape(CANbox) + - tm_borders(lwd = 2) + - tm_shape(CCAA) + - tm_polygons("#FDFBEA") + - tm_graticules(lines = FALSE) + - tm_layout( - bg.color = "#C7E7FB", - frame.double.line = TRUE +ggplot(Countries) + + geom_sf(fill = "#DFDFDF") + + geom_sf(data = CANbox, fill = "#C7E7FB", linewidth = 1) + + geom_sf(data = CCAA, fill = "#FDFBEA") + + coord_sf( + xlim = c(-10, 4.3), + ylim = c(34.6, 44) + ) + + theme( + panel.background = element_rect(fill = "#C7E7FB"), + panel.grid = element_blank() ) } } @@ -143,10 +147,16 @@ Other political: \code{\link{esp_codelist}}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} + +Other Canary Islands: +\code{\link{esp_move_can}()} } +\concept{Canary Islands} \concept{political} diff --git a/man/esp_get_capimun.Rd b/man/esp_get_capimun.Rd index b9169afe..a79e7c64 100644 --- a/man/esp_get_capimun.Rd +++ b/man/esp_get_capimun.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/esp_get_capimun.R \name{esp_get_capimun} \alias{esp_get_capimun} -\title{Get \code{sf} points of the municipalities of Spain} +\title{Get \code{\link[sf:sf]{sf}} \code{POINT} of the municipalities of Spain} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). @@ -27,10 +27,10 @@ esp_get_capimun( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -47,8 +47,8 @@ default is \code{FALSE}.} \item{region}{A vector of names and/or codes for provinces or \code{NULL} to get all the municipalities. See \strong{Details}.} -\item{munic}{A name or \code{\link[base:grep]{regex}} expression with the names of the -required municipalities. \code{NULL} would not produce any filtering.} +\item{munic}{A name or \code{\link[base:grep]{regex}} expression with the names of +the required municipalities. \code{NULL} would return all municipalities.} \item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates \code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. @@ -56,29 +56,29 @@ Initial position can be adjusted using the vector of coordinates. See \strong{Displacing the Canary Islands}.} \item{rawcols}{Logical. Setting this to \code{TRUE} would add the raw columns of -the dataset provided by IGN.} +the resulting object as provided by IGN.} } \value{ -A \code{sf} point object. +A \code{\link[sf:sf]{sf}} \code{POINT} object. } \description{ -Get a \code{sf} point with the location of the political powers for +Get a \code{\link[sf:sf]{sf}} \code{POINT} with the location of the political powers for each municipality (possibly the center of the municipality). Note that this differs of the centroid of the boundaries of the municipality, returned by \code{\link[=esp_get_munic]{esp_get_munic()}}. } \details{ -\code{year} could be passed as a single year ("YYYY" format, as end of year) or -as a specific date ("YYYY-MM-DD" format). Historical information starts as +\code{year} could be passed as a single year (\code{YYYY} format, as end of year) or +as a specific date (\code{YYYY-MM-DD} format). Historical information starts as of 2005. When using \code{region} you can use and mix names and NUTS codes (levels 1, -2 or 3), ISO codes (corresponding to level 2 or 3) or "cpro". See +2 or 3), ISO codes (corresponding to level 2 or 3) or \code{cpro}. See \link{esp_codelist} -When calling a superior level (Province, Autonomous Community or NUTS1) , -all the municipalities of that level would be added. +When calling a higher level (province, CCAA or NUTS1), all the municipalities +of that level would be added. } \section{About caching}{ You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. @@ -96,7 +96,8 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ @@ -121,7 +122,7 @@ capimun <- esp_get_capimun(munic = "Valladolid", epsg = 3857) capimun$type <- "Capimun" # Get a tile to check -tile <- esp_getTiles(area, zoommin = 2) +tile <- esp_getTiles(area, "IGNBase.Todo", zoommin = 2) # Join both point geometries points <- rbind( @@ -129,21 +130,18 @@ points <- rbind( capimun[, "type"] ) + # Check on plot -library(tmap) - -tm_shape(tile, raster.downsample = FALSE) + - tm_rgb() + - tm_shape(area) + - tm_borders(col = "grey40") + - tm_shape(points) + - tm_symbols(col = "type", alpha = 0.8, pal = "RdBu") + - tm_layout( - main.title = "Centroid vs. capimun", - legend.outside = TRUE, - legend.outside.size = 0.3, - legend.text.size = 1 - ) +library(ggplot2) +library(tidyterra) + +ggplot(points) + + geom_spatraster_rgb(data = tile, maxcell = Inf) + + geom_sf(data = area, fill = NA, color = "blue") + + geom_sf(data = points, aes(fill = type), size = 5, shape = 21) + + scale_fill_manual(values = c("green", "red")) + + theme_void() + + labs(title = "Centroid vs. capimun") } } \seealso{ @@ -151,11 +149,13 @@ Other political: \code{\link{esp_codelist}}, \code{\link{esp_get_can_box}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} Other municipalities: \code{\link{esp_get_munic}()}, diff --git a/man/esp_get_ccaa.Rd b/man/esp_get_ccaa.Rd index c568f2c2..98acf2e1 100644 --- a/man/esp_get_ccaa.Rd +++ b/man/esp_get_ccaa.Rd @@ -3,13 +3,13 @@ \name{esp_get_ccaa} \alias{esp_get_ccaa} \alias{esp_get_ccaa_siane} -\title{Get Autonomous Communities of Spain as \code{sf} polygons and points} +\title{Get Autonomous Communities of Spain as \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{POINT}} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). } \usage{ -esp_get_ccaa(ccaa = NULL, ...) +esp_get_ccaa(ccaa = NULL, moveCAN = TRUE, ...) esp_get_ccaa_siane( ccaa = NULL, @@ -28,26 +28,31 @@ esp_get_ccaa_siane( \item{ccaa}{A vector of names and/or codes for autonomous communities or \code{NULL} to get all the autonomous communities. See \strong{Details}.} +\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates +\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. +Initial position can be adjusted using the vector of coordinates. See +\strong{Displacing the Canary Islands}.} + \item{...}{ Arguments passed on to \code{\link[=esp_get_nuts]{esp_get_nuts}} \describe{ \item{\code{spatialtype}}{Type of geometry to be returned: \itemize{ -\item \code{"LB"}: Labels - point object. -\item \code{"RG"}: Regions - polygon object. +\item \code{"LB"}: Labels - \code{POINT} object. +\item \code{"RG"}: Regions - \code{POLYGON} object. }} }} \item{year}{Release year. See \code{\link[=esp_get_nuts]{esp_get_nuts()}} for \code{\link[=esp_get_ccaa]{esp_get_ccaa()}} and -\strong{Details} for \code{\link[=esp_get_ccaa_siane]{esp_get_ccaa_siane()}}} +\strong{Details} for \code{\link[=esp_get_ccaa_siane]{esp_get_ccaa_siane()}}.} \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -61,24 +66,19 @@ When set to \code{TRUE} it would force a fresh download of the source file.} \item{verbose}{Logical, displays information. Useful for debugging, default is \code{FALSE}.} -\item{resolution}{Resolution of the polygon. Values available are -"3", "6.5" or "10".} - -\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates -\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. -Initial position can be adjusted using the vector of coordinates. See -\strong{Displacing the Canary Islands}.} +\item{resolution}{Resolution of the \code{POLYGON}. Values available are +\code{3}, \code{6.5} or \code{10}.} \item{rawcols}{Logical. Setting this to \code{TRUE} would add the raw columns of -the dataset provided by IGN.} +the resulting object as provided by IGN.} } \value{ -A \code{sf} object specified by \code{spatialtype}. +A \code{\link[sf:sf]{sf}} object specified by \code{spatialtype}. } \description{ Returns -\href{https://en.wikipedia.org/wiki/Autonomous_communities_of_Spain}{Autonomous Communities of Spain} -as polygons and points at a specified scale. +\href{https://en.wikipedia.org/wiki/Autonomous_communities_of_Spain}{Autonomous Communities of Spain} as +\code{sf} \code{POLYGON} or \code{POINT} at a specified scale. \itemize{ \item \code{\link[=esp_get_ccaa]{esp_get_ccaa()}} uses GISCO (Eurostat) as source. Please use \code{\link[giscoR:gisco_attributions]{giscoR::gisco_attributions()}} @@ -92,14 +92,14 @@ Years available are 2005 up to today. } \details{ When using \code{ccaa} you can use and mix names and NUTS codes (levels 1 or 2), -ISO codes (corresponding to level 2) or "codauto" (see \link{esp_codelist}). +ISO codes (corresponding to level 2) or \code{codauto} (see \link{esp_codelist}). Ceuta and Melilla are considered as Autonomous Communities on this function. When calling a NUTS1 level, all the Autonomous Communities of that level would be added. -On \code{\link[=esp_get_ccaa_siane]{esp_get_ccaa_siane()}}, \code{year} could be passed as a single year ("YYYY" -format, as end of year) or as a specific date ("YYYY-MM-DD" format). +On \code{\link[=esp_get_ccaa_siane]{esp_get_ccaa_siane()}}, \code{year} could be passed as a single year (\code{YYYY} +format, as end of year) or as a specific date (\code{YYYY-MM-DD} format). Historical information starts as of 2005. } \section{About caching}{ @@ -118,15 +118,17 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ ccaa <- esp_get_ccaa() -library(tmap) +library(ggplot2) -qtm(ccaa) +ggplot(ccaa) + + geom_sf() # Random CCAA Random <- esp_get_ccaa(ccaa = c( @@ -139,21 +141,17 @@ Random <- esp_get_ccaa(ccaa = c( )) -tm_shape(Random) + - tm_polygons(col = "codauto", legend.show = FALSE) + - tm_shape(Random, point.per = "feature") + - tm_text("codauto", - auto.placement = TRUE, - shadow = TRUE - ) - +ggplot(Random) + + geom_sf(aes(fill = codauto), show.legend = FALSE) + + geom_sf_label(aes(label = codauto), alpha = 0.3) # All CCAA of a Zone plus an addition Mix <- esp_get_ccaa(ccaa = c("La Rioja", "Noroeste")) -qtm(Mix) +ggplot(Mix) + + geom_sf() # Combine with giscoR to get countries \donttest{ @@ -170,12 +168,14 @@ ccaa <- esp_get_ccaa(moveCAN = FALSE, resolution = res) europe <- st_transform(europe, 3035) ccaa <- st_transform(ccaa, 3035) -tm_shape(europe, bbox = c(23, 14, 74, 55) * 10e4) + - tm_graticules() + - tm_polygons("#DFDFDF", border.col = "#656565") + - tm_shape(ccaa) + - tm_polygons("#FDFBEA", border.col = "#656565") + - tm_layout(bg.color = "#C7E7FB") +ggplot(europe) + + geom_sf(fill = "#DFDFDF", color = "#656565") + + geom_sf(data = ccaa, fill = "#FDFBEA", color = "#656565") + + coord_sf( + xlim = c(23, 74) * 10e4, + ylim = c(14, 55) * 10e4 + ) + + theme(panel.background = element_rect(fill = "#C7E7FB")) } } \seealso{ @@ -183,10 +183,12 @@ Other political: \code{\link{esp_codelist}}, \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} } \concept{political} diff --git a/man/esp_get_comarca.Rd b/man/esp_get_comarca.Rd new file mode 100644 index 00000000..f868e952 --- /dev/null +++ b/man/esp_get_comarca.Rd @@ -0,0 +1,167 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_get_comarca.R +\name{esp_get_comarca} +\alias{esp_get_comarca} +\title{Get 'comarcas' of Spain as \code{\link[sf:sf]{sf}} \code{POLYGON}} +\source{ +INE: PC_Axis files, IGN, Ministry of Agriculture, Fisheries and Food (MAPA). +} +\usage{ +esp_get_comarca( + region = NULL, + comarca = NULL, + moveCAN = TRUE, + type = c("INE", "IGN", "AGR", "LIV"), + epsg = "4258", + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) +} +\arguments{ +\item{region}{A vector of names and/or codes for provinces or \code{NULL} to get +all the comarcas. See \strong{Details}.} + +\item{comarca}{A name or \code{\link[base:grep]{regex}} expression with the names of +the required comarcas. \code{NULL} would return all the possible comarcas.} + +\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates +\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. +Initial position can be adjusted using the vector of coordinates. See +\strong{Displacing the Canary Islands}.} + +\item{type}{One of \code{"INE"}, \code{"IGN"}, \code{"AGR"}, \code{"LIV"}. Type of comarca to +return, see \strong{Details}.} + +\item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. +One of: +\itemize{ +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. +}} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} +} +\value{ +A \code{\link[sf:sf]{sf}} polygon object. +} +\description{ +Returns 'comarcas' of Spain as \code{sf} \code{POLYGON} objects. +} +\details{ +\subsection{About comarcas}{ + +'Comarcas' (English equivalent: district, county, area or zone) does not +always have a formal legal status. They correspond mainly to natural areas +(valleys, river basins etc.) or even to historical regions or ancient +kingdoms. + +In the case of Spain, comarcas only have an administrative character legally +recognized in Catalonia, the Basque Country, Navarra (named merindades +instead), in the region of El Bierzo (Castilla y Leon) and Aragon. Galicia, +the Principality of Asturias, and Andalusia have functional comarcas. +} + +\subsection{Types}{ + +\code{esp_get_comarca()} can retrieve several types of comarcas, each one +provided under different classification criteria. +\itemize{ +\item \code{"INE"}: Comarcas as defined by the National Statistics Institute (INE). +\item \code{"IGN"}: Official comarcas, only available on some Autonomous Communities, +provided by the National Geographic Institute. +\item \code{"AGR"}: Agrarian comarcas defined by the Ministry of Agriculture, +Fisheries and Food (MAPA). +\item \code{"LIV"}: Livestock comarcas defined by the Ministry of Agriculture, +Fisheries and Food (MAPA). +} +} + +\subsection{Misc}{ + +When using \code{region} you can use and mix names and NUTS codes +(levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or +"cpro" (see \link{esp_codelist}). + +When calling a higher level (Province, Autonomous Community or NUTS1), +all the comarcas of that level would be added. +} + +\subsection{Legal Notice}{ + +The use of the information contained on the +\href{https://www.ine.es/en/index.htm}{INE website} may be carried out by users or +re-use agents, at their own risk, and they will be the sole liable parties +in the case of having to answer to third parties due to damages arising +from such use. +} +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\section{Displacing the Canary Islands}{ +While \code{moveCAN} is useful for visualization, it would alter the actual +geographic position of the Canary Islands. When using the output for +spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or +\code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. +} + +\examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\donttest{ +comarcas <- esp_get_comarca(moveCAN = FALSE) + +library(ggplot2) + +ggplot(comarcas) + + geom_sf() + +# IGN provides recognized comarcas + +rec <- esp_get_comarca(type = "IGN") + +ggplot(rec) + + geom_sf(aes(fill = t_comarca)) + +# Legal Comarcas of Catalunya + +comarcas_cat <- esp_get_comarca("Catalunya", type = "IGN") + +ggplot(comarcas_cat) + + geom_sf(aes(fill = ine.prov.name)) + + labs(fill = "Province") +} +\dontshow{\}) # examplesIf} +} +\seealso{ +Other political: +\code{\link{esp_codelist}}, +\code{\link{esp_get_can_box}()}, +\code{\link{esp_get_capimun}()}, +\code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_country}()}, +\code{\link{esp_get_gridmap}}, +\code{\link{esp_get_munic}()}, +\code{\link{esp_get_nuts}()}, +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} +} +\concept{political} diff --git a/man/esp_get_country.Rd b/man/esp_get_country.Rd index 5931aabd..456168a7 100644 --- a/man/esp_get_country.Rd +++ b/man/esp_get_country.Rd @@ -2,11 +2,16 @@ % Please edit documentation in R/esp_get_country.R \name{esp_get_country} \alias{esp_get_country} -\title{Get the borders of Spain as a \code{sf} polygon} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} representing Spain} \usage{ -esp_get_country(...) +esp_get_country(moveCAN = TRUE, ...) } \arguments{ +\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates +\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. +Initial position can be adjusted using the vector of coordinates. See +\strong{Displacing the Canary Islands}.} + \item{...}{ Arguments passed on to \code{\link[=esp_get_nuts]{esp_get_nuts}} \describe{ @@ -15,10 +20,10 @@ esp_get_country(...) \item{\code{epsg}}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{\code{cache}}{A logical whether to do caching. Default is \code{TRUE}. See \strong{About caching}.} @@ -29,23 +34,19 @@ When set to \code{TRUE} it would force a fresh download of the source file.} default is \code{FALSE}.} \item{\code{resolution}}{Resolution of the geospatial data. One of \itemize{ -\item "60": 1:60million -\item "20": 1:20million -\item "10": 1:10million -\item "03": 1:3million -\item "01": 1:1million +\item \code{"60"}: 1:60million +\item \code{"20"}: 1:20million +\item \code{"10"}: 1:10million +\item \code{"03"}: 1:3million +\item \code{"01"}: 1:1million }} - \item{\code{moveCAN}}{A logical \code{TRUE/FALSE} or a vector of coordinates -\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. -Initial position can be adjusted using the vector of coordinates. See -\strong{Displacing the Canary Islands}.} }} } \value{ -A \code{sf} polygon object. +A \code{\link[sf:sf]{sf}} \code{POLYGON} object. } \description{ -Returns the boundaries of Spain as a single \code{sf} polygon at a +Returns the boundaries of Spain as a single \code{\link[sf:sf]{sf}} \code{POLYGON} at a specified scale. } \section{About caching}{ @@ -64,7 +65,8 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ @@ -75,14 +77,20 @@ OriginalCan <- esp_get_country(moveCAN = FALSE) nrow(OriginalCan) -library(tmap) -qtm(OriginalCan, fill = "grey70") +library(ggplot2) + +ggplot(OriginalCan) + + geom_sf(fill = "grey70") + # Less resolution MovedCan <- esp_get_country(moveCAN = TRUE, resolution = "20") -qtm(MovedCan, fill = "grey70") +library(ggplot2) + +ggplot(MovedCan) + + geom_sf(fill = "grey70") } \seealso{ Other political: @@ -90,9 +98,11 @@ Other political: \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} } \concept{political} diff --git a/man/esp_get_grid_BDN.Rd b/man/esp_get_grid_BDN.Rd new file mode 100644 index 00000000..5f045d9a --- /dev/null +++ b/man/esp_get_grid_BDN.Rd @@ -0,0 +1,94 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_get_grid_BDN.R +\name{esp_get_grid_BDN} +\alias{esp_get_grid_BDN} +\alias{esp_get_grid_BDN_ccaa} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} with the national geographic grids from BDN} +\source{ +BDN data via a custom CDN (see +\url{https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN}). + +See original metadata and source on +\url{https://www.miteco.gob.es/es/biodiversidad/servicios/banco-datos-naturaleza/informacion-disponible/bdn-cart-aux-descargas-ccaa.html} +} +\usage{ +esp_get_grid_BDN( + resolution = 10, + type = "main", + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) + +esp_get_grid_BDN_ccaa( + ccaa, + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) +} +\arguments{ +\item{resolution}{Resolution of the grid in kms. Could be \code{5} or \code{10}.} + +\item{type}{The scope of the grid. It could be mainland Spain (\code{"main"}) or +the Canary Islands (\code{"canary"}).} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} + +\item{ccaa}{A vector of names and/or codes for autonomous communities. +See \strong{Details} on \code{\link[=esp_get_ccaa]{esp_get_ccaa()}}.} +} +\value{ +A \code{\link[sf:sf]{sf}} \code{POLYGON}. +} +\description{ +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} with the geographic grids of Spain as +provided on the Banco de Datos de la Naturaleza (Nature Data Bank), by the +Ministry of Environment (MITECO): +\itemize{ +\item \code{\link[=esp_get_grid_BDN]{esp_get_grid_BDN()}} extracts country-wide grids with resolutions +5x5 or 10x10 kms. +\item \code{\link[=esp_get_grid_BDN_ccaa]{esp_get_grid_BDN_ccaa()}} extracts grids by Autonomous Community with +resolution 1x1 km. +} +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\donttest{ +grid <- esp_get_grid_BDN(resolution = "10", type = "main") + +library(ggplot2) + +ggplot(grid) + + geom_sf() + + theme_light() + + labs(title = "BDN Grid for Spain") +} +\dontshow{\}) # examplesIf} +} +\seealso{ +\code{\link[=esp_get_ccaa]{esp_get_ccaa()}} + +Other grids: +\code{\link{esp_get_grid_EEA}()}, +\code{\link{esp_get_grid_ESDAC}()}, +\code{\link{esp_get_grid_MTN}()} +} +\concept{grids} diff --git a/man/esp_get_grid_EEA.Rd b/man/esp_get_grid_EEA.Rd new file mode 100644 index 00000000..06910bb0 --- /dev/null +++ b/man/esp_get_grid_EEA.Rd @@ -0,0 +1,75 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_get_grid_EEA.R +\name{esp_get_grid_EEA} +\alias{esp_get_grid_EEA} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} of the national geographic grids from EEA} +\source{ +\href{https://www.eea.europa.eu/en/datahub/datahubitem-view/3c362237-daa4-45e2-8c16-aaadfb1a003b}{EEA reference grid}. +} +\usage{ +esp_get_grid_EEA( + resolution = 100, + type = "main", + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) +} +\arguments{ +\item{resolution}{Resolution of the grid in kms. Could be \code{1}, \code{10} or \code{100}.} + +\item{type}{The scope of the grid. It could be mainland Spain (\code{"main"}) or +the Canary Islands (\code{"canary"}).} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} +} +\value{ +A \code{\link[sf:sf]{sf}} \code{POLYGON}. +} +\description{ +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} with the geographic grids of Spain as +provided by the European Environment Agency (EEA). +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontrun{ + +grid <- esp_get_grid_EEA(type = "main", resolution = 100) +grid_can <- esp_get_grid_EEA(type = "canary", resolution = 100) +esp <- esp_get_country(moveCAN = FALSE) + +library(ggplot2) + +ggplot(grid) + + geom_sf() + + geom_sf(data = grid_can) + + geom_sf(data = esp, fill = NA) + + theme_light() + + labs(title = "EEA Grid for Spain") +} +\dontshow{\}) # examplesIf} +} +\seealso{ +Other grids: +\code{\link{esp_get_grid_BDN}()}, +\code{\link{esp_get_grid_ESDAC}()}, +\code{\link{esp_get_grid_MTN}()} +} +\concept{grids} diff --git a/man/esp_get_grid_ESDAC.Rd b/man/esp_get_grid_ESDAC.Rd new file mode 100644 index 00000000..98ae0700 --- /dev/null +++ b/man/esp_get_grid_ESDAC.Rd @@ -0,0 +1,78 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_get_grid_ESDAC.R +\name{esp_get_grid_ESDAC} +\alias{esp_get_grid_ESDAC} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} of the national geographic grids from ESDAC} +\source{ +\href{https://esdac.jrc.ec.europa.eu/content/european-reference-grids}{EEA reference grid}. +} +\usage{ +esp_get_grid_ESDAC( + resolution = 10, + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) +} +\arguments{ +\item{resolution}{Resolution of the grid in kms. Could be \code{1} or \code{10}.} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} +} +\value{ +A \code{\link[sf:sf]{sf}} \code{POLYGON}. +} +\description{ +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} with the geographic grids of Spain as +provided by the European Soil Data Centre (ESDAC). +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontrun{ +grid <- esp_get_grid_ESDAC() +esp <- esp_get_country(moveCAN = FALSE) + +library(ggplot2) + +ggplot(grid) + + geom_sf() + + geom_sf(data = esp, color = "grey50", fill = NA) + + theme_light() + + labs(title = "ESDAC Grid for Spain") +} +\dontshow{\}) # examplesIf} +} +\references{ +\itemize{ +\item Panagos P., Van Liedekerke M., Jones A., Montanarella L., "European Soil +Data Centre: Response to European policy support and public data +requirements"; (2012) \emph{Land Use Policy}, 29 (2), pp. 329-338. +\doi{10.1016/j.landusepol.2011.07.003} +\item European Soil Data Centre (ESDAC), esdac.jrc.ec.europa.eu, European +Commission, Joint Research Centre. +} +} +\seealso{ +Other grids: +\code{\link{esp_get_grid_BDN}()}, +\code{\link{esp_get_grid_EEA}()}, +\code{\link{esp_get_grid_MTN}()} +} +\concept{grids} diff --git a/man/esp_get_grid_MTN.Rd b/man/esp_get_grid_MTN.Rd new file mode 100644 index 00000000..9671e8dc --- /dev/null +++ b/man/esp_get_grid_MTN.Rd @@ -0,0 +1,134 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_get_grid_MTN.R +\name{esp_get_grid_MTN} +\alias{esp_get_grid_MTN} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} of the national geographic grids from IGN} +\source{ +IGN data via a custom CDN (see +\url{https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN}). +} +\usage{ +esp_get_grid_MTN( + grid = "MTN25_ETRS89_Peninsula_Baleares_Canarias", + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) +} +\arguments{ +\item{grid}{Name of the grid to be loaded. See \strong{Details}.} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} +} +\value{ +A \code{\link[sf:sf]{sf}} \code{POLYGON}. +} +\description{ +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} with the geographic grids of Spain. +} +\details{ +Metadata available on +\url{https://github.com/rOpenSpain/mapSpain/tree/sianedata/MTN}. + +Possible values of \code{grid} are:\tabular{l}{ + \strong{grid_name} \cr + MTN25_ED50_Peninsula_Baleares \cr + MTN25_ETRS89_ceuta_melilla_alboran \cr + MTN25_ETRS89_Peninsula_Baleares_Canarias \cr + MTN25_RegCan95_Canarias \cr + MTN50_ED50_Peninsula_Baleares \cr + MTN50_ETRS89_Peninsula_Baleares_Canarias \cr + MTN50_RegCan95_Canarias \cr +} + +\subsection{MTN Grids}{ + +A description of the MTN (Mapa Topografico Nacional) grids available: + +\strong{MTN25_ED50_Peninsula_Baleares} + +MTN25 grid corresponding to the Peninsula and Balearic Islands, in ED50 and +geographical coordinates (longitude, latitude) This is the real MTN25 grid, +that is, the one that divides the current printed series of the map, taking +into account special sheets and irregularities. + +\strong{MTN50_ED50_Peninsula_Baleares} + +MTN50 grid corresponding to the Peninsula and Balearic Islands, in ED50 and +geographical coordinates (longitude, latitude) This is the real MTN50 grid, +that is, the one that divides the current printed series of the map, taking +into account special sheets and irregularities. + +\strong{MTN25_ETRS89_ceuta_melilla_alboran} + +MTN25 grid corresponding to Ceuta, Melilla, Alboran and Spanish territories +in North Africa, adjusted to the new official geodetic reference system +ETRS89, in geographical coordinates (longitude, latitude). + +\strong{MTN25_ETRS89_Peninsula_Baleares_Canarias} + +MTN25 real grid corresponding to the Peninsula, the Balearic Islands and the +Canary Islands, adjusted to the new ETRS89 official reference geodetic +system, in geographical coordinates (longitude, latitude). + +\strong{MTN50_ETRS89_Peninsula_Baleares_Canarias} + +MTN50 real grid corresponding to the Peninsula, the Balearic Islands and the +Canary Islands, adjusted to the new ETRS89 official reference geodetic +system, in geographical coordinates (longitude, latitude). + +\strong{MTN25_RegCan95_Canarias} + +MTN25 grid corresponding to the Canary Islands, in REGCAN95 (WGS84 +compatible) and geographic coordinates (longitude, latitude). It is the real +MTN25 grid, that is, the one that divides the current printed series of the +map, taking into account the special distribution of the Canary Islands +sheets. + +\strong{MTN50_RegCan95_Canarias} + +MTN50 grid corresponding to the Canary Islands, in REGCAN95 (WGS84 +compatible) and geographic coordinates (longitude, latitude). This is the +real grid of the MTN50, that is, the one that divides the current printed +series of the map, taking into account the special distribution of the +Canary Islands sheets. +} +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\donttest{ +grid <- esp_get_grid_MTN(grid = "MTN50_ETRS89_Peninsula_Baleares_Canarias") + +library(ggplot2) + +ggplot(grid) + + geom_sf() + + theme_light() + + labs(title = "MTN50 Grid for Spain") +} +\dontshow{\}) # examplesIf} +} +\seealso{ +Other grids: +\code{\link{esp_get_grid_BDN}()}, +\code{\link{esp_get_grid_EEA}()}, +\code{\link{esp_get_grid_ESDAC}()} +} +\concept{grids} diff --git a/man/esp_get_gridmap.Rd b/man/esp_get_gridmap.Rd index 2daf5d81..ad740d52 100644 --- a/man/esp_get_gridmap.Rd +++ b/man/esp_get_gridmap.Rd @@ -6,7 +6,7 @@ \alias{esp_get_hex_ccaa} \alias{esp_get_grid_prov} \alias{esp_get_grid_ccaa} -\title{Get a \code{sf} hexbin or squared polygon of Spain} +\title{Get a \code{\link[sf:sf]{sf}} hexbin or squared \code{POLYGON} of Spain} \usage{ esp_get_hex_prov(prov = NULL) @@ -17,18 +17,18 @@ esp_get_grid_prov(prov = NULL) esp_get_grid_ccaa(ccaa = NULL) } \arguments{ -\item{prov}{A vector of names and/or codes for provinces -or \code{NULL} to get all the provinces. See \strong{Details}.} +\item{prov}{A vector of names and/or codes for provinces or \code{NULL} to get all +the provinces. See \strong{Details}.} \item{ccaa}{A vector of names and/or codes for autonomous communities or \code{NULL} to get all the autonomous communities. See \strong{Details}.} } \value{ -A \code{sf} POLYGON object. +A \code{\link[sf:sf]{sf}} \code{POLYGON} object. } \description{ -Loads a hexbin map (\code{sf} object) or a map of squares with the boundaries of -the provinces or autonomous communities of Spain. +Loads a hexbin map (\code{\link[sf:sf]{sf}} object) or a map of squares with the +boundaries of the provinces or autonomous communities of Spain. } \details{ Hexbin or grid map has an advantage over usual choropleth maps. @@ -36,85 +36,74 @@ In choropleths, a large polygon data looks more emphasized just because of its size, what introduces a bias. Here with hexbin, each region is represented equally dismissing the bias. -You can use and mix names, ISO codes, "codauto"/"cpro" codes (see +You can use and mix names, ISO codes, \code{"codauto"/ "cpro"} codes (see \link{esp_codelist}) and NUTS codes of different levels. When using a code corresponding of a higher level (e.g. \code{esp_get_prov("Andalucia")}) all the corresponding units of that level are -provided (in this case , all the provinces of Andalucia). +provided (in this case , all the provinces of Andalusia). Results are provided in \strong{EPSG:4258}, use \code{\link[sf:st_transform]{sf::st_transform()}} to change the projection. } -\section{About caching}{ -You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. - -Sometimes cached files may be corrupt. On that case, try re-downloading -the data setting \code{update_cache = TRUE}. - -If you experience any problem on download, try to download the -corresponding .geojson file by any other method and save it on your -\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. -} - -\section{Displacing the Canary Islands}{ -While \code{moveCAN} is useful for visualization, it would alter the actual -geographic position of the Canary Islands. When using the output for -spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or -\code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. -} - \examples{ - - esp <- esp_get_country() hexccaa <- esp_get_hex_ccaa() -library(tmap) +library(ggplot2) + +ggplot(hexccaa) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Hexbin: CCAA") -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(hexccaa) + - tm_polygons("codauto", alpha = 0.6, legend.show = FALSE) + - tm_shape(hexccaa) + - tm_text("label") + - tm_layout(main.title = "Hexbin: CCAA") hexprov <- esp_get_hex_prov() -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(hexprov) + - tm_polygons("cpro", alpha = 0.6, legend.show = FALSE) + - tm_shape(hexprov) + - tm_text("label") + - tm_layout(main.title = "Hexbin: Provinces") +ggplot(hexprov) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Hexbin: Provinces") gridccaa <- esp_get_grid_ccaa() -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(gridccaa) + - tm_polygons("codauto", alpha = 0.6, legend.show = FALSE) + - tm_shape(gridccaa) + - tm_text("label") + - tm_layout(main.title = "Grid: CCAA") +ggplot(gridccaa) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Grid: CCAA") + gridprov <- esp_get_grid_prov() -tm_shape(esp, bbox = c(-13.5, 32, 7, 45)) + - tm_polygons() + - tm_shape(gridprov) + - tm_polygons("cpro", alpha = 0.6, legend.show = FALSE) + - tm_shape(gridprov) + - tm_text("label") + - tm_layout(main.title = "Grid: Provinces") +ggplot(gridprov) + + geom_sf(data = esp) + + geom_sf(aes(fill = codauto), + alpha = 0.3, + show.legend = FALSE + ) + + geom_sf_text(aes(label = label), check_overlap = TRUE) + + theme_void() + + labs(title = "Grid: Provinces") } \seealso{ Other political: @@ -122,9 +111,11 @@ Other political: \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_munic}()}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} } \concept{political} diff --git a/man/esp_get_hydrobasin.Rd b/man/esp_get_hydrobasin.Rd index bae8511e..da4d7db6 100644 --- a/man/esp_get_hydrobasin.Rd +++ b/man/esp_get_hydrobasin.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/esp_get_hydrobasin.R \name{esp_get_hydrobasin} \alias{esp_get_hydrobasin} -\title{Get \code{sf} polygons of the drainage basin demarcations of Spain} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} of the drainage basin demarcations of Spain} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). @@ -22,10 +22,10 @@ esp_get_hydrobasin( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -39,18 +39,18 @@ When set to \code{TRUE} it would force a fresh download of the source file.} \item{verbose}{Logical, displays information. Useful for debugging, default is \code{FALSE}.} -\item{resolution}{Resolution of the polygon. Values available are +\item{resolution}{Resolution of the \code{POLYGON}. Values available are \code{"3"}, \code{"6.5"} or \code{"10"}.} \item{domain}{Possible values are \code{"land"}, that includes only the ground part or the ground or \code{"landsea"}, that includes both the ground -and the related sea waters of the basin} +and the related sea waters of the basin.} } \value{ -A \code{sf} polygon object. +A \code{\link[sf:sf]{sf}} \code{POLYGON} object. } \description{ -Loads a \code{sf} polygon object containing areas with the required +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} object containing areas with the required hydrographic elements of Spain. } \details{ @@ -69,28 +69,29 @@ corresponding .geojson file by any other method and save it on your } \examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ -all <- esp_get_prov(moveCAN = FALSE) hydroland <- esp_get_hydrobasin(domain = "land") hydrolandsea <- esp_get_hydrobasin(domain = "landsea") -library(tmap) +library(ggplot2) -tm_shape(hydrolandsea, bbox = c(-9.5, 35, 4.5, 44)) + - tm_fill("skyblue4") + - tm_shape(all) + - tm_polygons("grey90") + - tm_shape(hydroland) + - tm_polygons("skyblue", alpha = 0.5, border.col = "blue") + - tm_text( - text = "rotulo", - remove.overlap = TRUE, - size = 0.5, + +ggplot(hydroland) + + geom_sf(data = hydrolandsea, fill = "skyblue4", alpha = .4) + + geom_sf(fill = "skyblue", alpha = .5) + + geom_sf_text(aes(label = rotulo), + size = 3, check_overlap = TRUE, fontface = "bold", - shadow = TRUE + family = "serif" + ) + + coord_sf( + xlim = c(-9.5, 4.5), + ylim = c(35, 44) ) + - tm_layout(bg.color = "grey95") + theme_void() } +\dontshow{\}) # examplesIf} } \seealso{ Other natural: diff --git a/man/esp_get_hypsobath.Rd b/man/esp_get_hypsobath.Rd index 42b1ef6f..24de54d8 100644 --- a/man/esp_get_hypsobath.Rd +++ b/man/esp_get_hypsobath.Rd @@ -2,7 +2,8 @@ % Please edit documentation in R/esp_get_hypsobath.R \name{esp_get_hypsobath} \alias{esp_get_hypsobath} -\title{Get \code{sf} polygons and lines with the hypsometry and bathymetry of Spain} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} with hypsometry and +bathymetry of Spain} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). @@ -22,10 +23,10 @@ esp_get_hypsobath( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -42,15 +43,15 @@ default is \code{FALSE}.} \item{resolution}{Resolution of the shape. Values available are \code{"3"} or \code{"6.5"}.} -\item{spatialtype}{Spatial type of the output. Use \code{"area"} for polygons or -\code{"line"} for lines.} +\item{spatialtype}{Spatial type of the output. Use \code{"area"} for \code{POLYGON} or +\code{"line"} for \code{LINESTRING}.} } \value{ -A \code{sf} polygon or line object. +A \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} object. } \description{ -Loads a \code{sf} polygon or line object representing the hypsometry and -bathymetry of Spain. +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} object representing the +hypsometry and bathymetry of Spain. \itemize{ \item \strong{Hypsometry} represents the the elevation and depth of features of the Earth's surface relative to mean sea level. @@ -74,14 +75,21 @@ corresponding .geojson file by any other method and save it on your } \examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ # This code would produce a nice plot - It will take a few seconds to run -library(tmap) +library(ggplot2) hypsobath <- esp_get_hypsobath() +# Error on the data provided - There is an empty shape +# Remove: + +hypsobath <- hypsobath[!sf::st_is_empty(hypsobath), ] + # Tints from Wikipedia -# https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Maps/Conventions/Topographic_maps +# https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Maps/Conventions/ +# Topographic_maps bath_tints <- colorRampPalette( rev( @@ -112,34 +120,46 @@ levels <- sort(unique(hypsobath$val_inf)) br_bath <- length(levels[levels < 0]) br_terrain <- length(levels) - br_bath -bath_tints(br_bath) - pal <- c(bath_tints((br_bath)), hyps_tints((br_terrain))) # Plot Canary Islands -tm_shape(hypsobath, bbox = c(-18.6, 27, -13, 29.5)) + - tm_fill("val_inf", - style = "cat", - palette = pal, - title = "Elevation", - legend.reverse = TRUE +ggplot(hypsobath) + + geom_sf(aes(fill = as.factor(val_inf)), + color = NA ) + - tm_layout( - legend.outside = TRUE - ) + coord_sf( + xlim = c(-18.6, -13), + ylim = c(27, 29.5) + ) + + scale_fill_manual(values = pal) + + guides(fill = guide_legend( + title = "Elevation", + direction = "horizontal", + label.position = "bottom", + title.position = "top", + nrow = 1 + )) + + theme(legend.position = "bottom") # Plot Mainland -tm_shape(hypsobath, bbox = c(-9.5, 35.8, 4.4, 44)) + - tm_fill("val_inf", - style = "cat", - palette = pal, - title = "Elevation", - legend.reverse = TRUE +ggplot(hypsobath) + + geom_sf(aes(fill = as.factor(val_inf)), + color = NA ) + - tm_layout(legend.outside = TRUE) + coord_sf( + xlim = c(-9.5, 4.4), + ylim = c(35.8, 44) + ) + + scale_fill_manual(values = pal) + + guides(fill = guide_legend( + title = "Elevation", + reverse = TRUE, + keyheight = .8 + )) } +\dontshow{\}) # examplesIf} } \seealso{ Other natural: diff --git a/man/esp_get_munic.Rd b/man/esp_get_munic.Rd index 8fd72403..e15fb7e0 100644 --- a/man/esp_get_munic.Rd +++ b/man/esp_get_munic.Rd @@ -3,7 +3,7 @@ \name{esp_get_munic} \alias{esp_get_munic} \alias{esp_get_munic_siane} -\title{Get municipalities of Spain as \code{sf} polygons} +\title{Get municipalities of Spain as \code{\link[sf:sf]{sf}} \code{POLYGON}} \source{ \href{https://gisco-services.ec.europa.eu/distribution/v2/}{GISCO API} @@ -43,10 +43,10 @@ esp_get_munic_siane( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -63,8 +63,8 @@ default is \code{FALSE}.} \item{region}{A vector of names and/or codes for provinces or \code{NULL} to get all the municipalities. See \strong{Details}.} -\item{munic}{A name or \code{\link[base:grep]{regex}} expression with the names of the -required municipalities. \code{NULL} would not produce any filtering.} +\item{munic}{A name or \code{\link[base:grep]{regex}} expression with the names of +the required municipalities. \code{NULL} would return all municipalities.} \item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates \code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. @@ -75,16 +75,16 @@ Initial position can be adjusted using the vector of coordinates. See \code{"3"}, \code{"6.5"} or \code{"10"}.} \item{rawcols}{Logical. Setting this to \code{TRUE} would add the raw columns of -the dataset provided by IGN.} +the resulting object as provided by IGN.} } \value{ -A \code{sf} polygon +A \code{\link[sf:sf]{sf}} \code{POLYGON}. } \description{ -Returns municipalities of Spain as polygons at a specified scale. +Returns municipalities of Spain \code{sf} POLYGON` at a specified scale. \itemize{ \item \code{\link[=esp_get_munic]{esp_get_munic()}} uses GISCO (Eurostat) as source. Please use -\code{\link[giscoR:gisco_attributions]{giscoR::gisco_attributions()}} +\code{\link[giscoR:gisco_attributions]{giscoR::gisco_attributions()}}. } \itemize{ @@ -98,18 +98,18 @@ The years available are: \itemize{ \item \code{\link[=esp_get_munic]{esp_get_munic()}}: \code{year} could be one of "2001", "2004", "2006", "2008", "2010", "2013" and any year between 2016 and 2019. -See \code{\link[giscoR:gisco_get]{giscoR::gisco_get_lau()}}, \code{\link[giscoR:gisco_get]{giscoR::gisco_get_communes()}}. +See \code{\link[giscoR:gisco_get_lau]{giscoR::gisco_get_lau()}}, \code{\link[giscoR:gisco_get_lau]{giscoR::gisco_get_communes()}}. \item \code{\link[=esp_get_munic_siane]{esp_get_munic_siane()}}: \code{year} could be passed as a single year ("YYYY" format, as end of year) or as a specific date ("YYYY-MM-DD" format). Historical information starts as of 2005. } -When using \code{region} you can use and mix names and NUTS codes -(levels 1, 2 or 3), ISO codes (corresponding to level 2 or 3) or -"cpro" (see \link{esp_codelist}). +When using \code{region} you can use and mix names and NUTS codes (levels 1, 2 or +3), ISO codes (corresponding to level 2 or 3) or \code{"cpro"} +(see \link{esp_codelist}). -When calling a superior level (Province, Autonomous Community or NUTS1) , -all the municipalities of that level would be added. +When calling a higher level (Province, Autonomous Community or NUTS1), all +the municipalities of that level would be added. } \section{About caching}{ You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. @@ -127,10 +127,12 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ +\donttest{ # Get munics Base <- esp_get_munic(year = "2019", region = "Castilla y Leon") @@ -150,38 +152,41 @@ Base_pop <- merge(Base, pobmun19, br <- sort(c( 0, 50, 100, 200, 500, 1000, 5000, 50000, 100000, - max(Base_pop$pob19) + Inf )) +Base_pop$cuts <- cut(Base_pop$pob19, br, dig.lab = 20) + # Plot -library(tmap) -tm_shape(Base_pop) + - tm_fill( - col = "pob19", palette = "cividis", - breaks = br, - title = "Persons" +library(ggplot2) + + +ggplot(Base_pop) + + geom_sf(aes(fill = cuts), color = NA) + + geom_sf(data = provs, fill = NA, color = "grey70") + + scale_fill_manual(values = hcl.colors(length(br), "cividis")) + + labs( + title = "Population in Castilla y Leon", + subtitle = "INE, 2019", + fill = "Persons" ) + - tm_shape(provs) + - tm_borders(col = "white", alpha = 0.25) + - tm_layout( - legend.outside = TRUE, - legend.position = c("right", "center"), - main.title = "Population in Castilla y Leon (2019)", - frame = FALSE - ) + theme_void() +} } \seealso{ -\code{\link[giscoR:gisco_get]{giscoR::gisco_get_lau()}}, \code{\link[base:regex]{base::regex()}}. +\code{\link[giscoR:gisco_get_lau]{giscoR::gisco_get_lau()}}, \code{\link[base:regex]{base::regex()}}. Other political: \code{\link{esp_codelist}}, \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_nuts}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} Other municipalities: \code{\link{esp_get_capimun}()}, diff --git a/man/esp_get_nuts.Rd b/man/esp_get_nuts.Rd index 4bfb94b0..bc72153a 100644 --- a/man/esp_get_nuts.Rd +++ b/man/esp_get_nuts.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/esp_get_nuts.R \name{esp_get_nuts} \alias{esp_get_nuts} -\title{Get NUTS of Spain as \code{sf} polygons and points} +\title{Get NUTS of Spain as \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{POINT}} \source{ \href{https://gisco-services.ec.europa.eu/distribution/v2/}{GISCO API} } @@ -28,10 +28,10 @@ esp_get_nuts( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -47,24 +47,24 @@ default is \code{FALSE}.} \item{resolution}{Resolution of the geospatial data. One of \itemize{ -\item "60": 1:60million -\item "20": 1:20million -\item "10": 1:10million -\item "03": 1:3million -\item "01": 1:1million +\item \code{"60"}: 1:60million +\item \code{"20"}: 1:20million +\item \code{"10"}: 1:10million +\item \code{"03"}: 1:3million +\item \code{"01"}: 1:1million }} \item{spatialtype}{Type of geometry to be returned: \itemize{ -\item \code{"LB"}: Labels - point object. -\item \code{"RG"}: Regions - polygon object. +\item \code{"LB"}: Labels - \code{POINT} object. +\item \code{"RG"}: Regions - \code{POLYGON} object. }} \item{region}{Optional. A vector of region names, NUTS or ISO codes (see \code{\link[=esp_dict_region_code]{esp_dict_region_code()}}).} -\item{nuts_level}{NUTS level. One of "0" (Country-level), "1", "2" or "3". -See \strong{Description}.} +\item{nuts_level}{NUTS level. One of \code{"0"} (Country-level), \code{"1"}, \code{"2"} or +\code{"3"}. See \strong{Description}.} \item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates \code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. @@ -72,22 +72,21 @@ Initial position can be adjusted using the vector of coordinates. See \strong{Displacing the Canary Islands}.} } \value{ -A \code{sf} object specified by \code{spatialtype}. +A \code{\link[sf:sf]{sf}} object specified by \code{spatialtype}. } \description{ -Returns -\href{https://en.wikipedia.org/wiki/NUTS_statistical_regions_of_Spain}{NUTS regions of Spain} -as polygons and points at a specified scale, as provided by +Returns \href{https://en.wikipedia.org/wiki/NUTS_statistical_regions_of_Spain}{NUTS regions of Spain} +as \code{POLYGON} or \code{POINT} at a specified scale, as provided by \href{https://ec.europa.eu/eurostat/web/gisco}{GISCO} (Geographic Information System of the Commission, depending of Eurostat). NUTS are provided at three different levels: \itemize{ -\item \strong{"0"}: Country level -\item \strong{"1"}: Groups of autonomous communities -\item \strong{"2"}: Autonomous communities +\item \strong{"0"}: Country level. +\item \strong{"1"}: Groups of autonomous communities. +\item \strong{"2"}: Autonomous communities (CCAA). \item \strong{"3"}: Roughly matches the provinces, but providing specific individual -objects for each major island +objects for each major island. } } \note{ @@ -110,88 +109,86 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ NUTS1 <- esp_get_nuts(nuts_level = 1, moveCAN = TRUE) +library(ggplot2) -library(tmap) - -tm_shape(NUTS1) + - tm_graticules() + - tm_polygons() + - tm_credits(giscoR::gisco_attributions(), - fontface = "italic", - size = 0.7 - ) + - tm_layout( - main.title = "NUTS1: Displacing Canary Islands", - main.title.size = 0.9, - main.title.fontface = "bold", - attr.outside = TRUE +ggplot(NUTS1) + + geom_sf() + + labs( + title = "NUTS1: Displacing Canary Islands", + caption = giscoR::gisco_attributions() ) + NUTS1_alt <- esp_get_nuts(nuts_level = 1, moveCAN = c(15, 0)) -tm_shape(NUTS1_alt) + - tm_graticules() + - tm_polygons() + - tm_credits(giscoR::gisco_attributions(), - fontface = "italic", - size = 0.7 - ) + - tm_layout( - main.title = "NUTS1: Displacing Canary Islands to the right", - main.title.size = 0.9, - main.title.fontface = "bold", - attr.outside = TRUE + +ggplot(NUTS1_alt) + + geom_sf() + + labs( + title = "NUTS1: Displacing Canary Islands", + subtitle = "to the right", + caption = giscoR::gisco_attributions() ) + NUTS1_orig <- esp_get_nuts(nuts_level = 1, moveCAN = FALSE) -tm_shape(NUTS1_orig) + - tm_graticules() + - tm_polygons() + - tm_credits(giscoR::gisco_attributions(), - fontface = "italic", - size = 0.7 - ) + - tm_layout( - main.title = "NUTS1: Canary Islands on the true location", - main.title.size = 0.9, - main.title.fontface = "bold", - attr.outside = TRUE +ggplot(NUTS1_orig) + + geom_sf() + + labs( + title = "NUTS1", + subtitle = "Canary Islands on the true location", + caption = giscoR::gisco_attributions() ) -AndOriental <- - esp_get_nuts(region = c("Almeria", "Granada", "Jaen", "Malaga")) +AndOriental <- esp_get_nuts(region = c( + "Almeria", "Granada", + "Jaen", "Malaga" +)) + -qtm(AndOriental, main.title = "Andalucia Oriental") +ggplot(AndOriental) + + geom_sf() RandomRegions <- esp_get_nuts(region = c("ES1", "ES300", "ES51")) -qtm(RandomRegions, main.title = "Random regions") + +ggplot(RandomRegions) + + geom_sf() + + labs(title = "Random Regions") + MixingCodes <- esp_get_nuts(region = c("ES4", "ES-PV", "Valencia")) -qtm(MixingCodes, main.title = "Mixing codes") + + +ggplot(MixingCodes) + + geom_sf() + + labs(title = "Mixing Codes") } \seealso{ -\code{\link[giscoR:gisco_get]{giscoR::gisco_get_nuts()}}, \code{\link[=esp_dict_region_code]{esp_dict_region_code()}}. +\code{\link[giscoR:gisco_get_nuts]{giscoR::gisco_get_nuts()}}, \code{\link[=esp_dict_region_code]{esp_dict_region_code()}}. Other political: \code{\link{esp_codelist}}, \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, -\code{\link{esp_get_prov}()} +\code{\link{esp_get_prov}()}, +\code{\link{esp_get_simpl_prov}()} Other nuts: \code{\link{esp_nuts.sf}} diff --git a/man/esp_get_prov.Rd b/man/esp_get_prov.Rd index ed6ccd30..cd549aa8 100644 --- a/man/esp_get_prov.Rd +++ b/man/esp_get_prov.Rd @@ -3,13 +3,13 @@ \name{esp_get_prov} \alias{esp_get_prov} \alias{esp_get_prov_siane} -\title{Get Provinces of Spain as \code{sf} polygons and points} +\title{Get Provinces of Spain as \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{POINT}} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). } \usage{ -esp_get_prov(prov = NULL, ...) +esp_get_prov(prov = NULL, moveCAN = TRUE, ...) esp_get_prov_siane( prov = NULL, @@ -25,29 +25,34 @@ esp_get_prov_siane( ) } \arguments{ -\item{prov}{A vector of names and/or codes for provinces -or \code{NULL} to get all the provinces. See \strong{Details}.} +\item{prov}{A vector of names and/or codes for provinces or \code{NULL} to get all +the provinces. See \strong{Details}.} + +\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates +\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. +Initial position can be adjusted using the vector of coordinates. See +\strong{Displacing the Canary Islands}.} \item{...}{ Arguments passed on to \code{\link[=esp_get_nuts]{esp_get_nuts}} \describe{ \item{\code{spatialtype}}{Type of geometry to be returned: \itemize{ -\item \code{"LB"}: Labels - point object. -\item \code{"RG"}: Regions - polygon object. +\item \code{"LB"}: Labels - \code{POINT} object. +\item \code{"RG"}: Regions - \code{POLYGON} object. }} }} \item{year}{Release year. See \code{\link[=esp_get_nuts]{esp_get_nuts()}} for \code{\link[=esp_get_prov]{esp_get_prov()}} and -\strong{Details} for \code{\link[=esp_get_prov_siane]{esp_get_prov_siane()}}} +\strong{Details} for \code{\link[=esp_get_prov_siane]{esp_get_prov_siane()}}.} \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -61,24 +66,19 @@ When set to \code{TRUE} it would force a fresh download of the source file.} \item{verbose}{Logical, displays information. Useful for debugging, default is \code{FALSE}.} -\item{resolution}{Resolution of the polygon. Values available are -"3", "6.5" or "10".} - -\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates -\code{c(lat, lon)}. It places the Canary Islands close to Spain's mainland. -Initial position can be adjusted using the vector of coordinates. See -\strong{Displacing the Canary Islands}.} +\item{resolution}{Resolution of the \code{POLYGON}. Values available are +\code{3}, \code{6.5} or \code{10}.} \item{rawcols}{Logical. Setting this to \code{TRUE} would add the raw columns of -the dataset provided by IGN.} +the resulting object as provided by IGN.} } \value{ -A \code{sf} object specified by \code{spatialtype}. +A \code{\link[sf:sf]{sf}} object specified by \code{spatialtype}. } \description{ Returns \href{https://en.wikipedia.org/wiki/Provinces_of_Spain}{provinces of Spain} -as polygons and points at a specified scale. +as \code{POLYGON} or \code{POINT} at a specified scale. \itemize{ \item \code{\link[=esp_get_prov]{esp_get_prov()}} uses GISCO (Eurostat) as source. Please use \code{\link[giscoR:gisco_attributions]{giscoR::gisco_attributions()}} @@ -97,8 +97,8 @@ When using \code{prov} you can use and mix names and NUTS codes (levels 1, 2 or Ceuta and Melilla are considered as provinces on this dataset. -When calling a superior level (Autonomous Community or NUTS1) , -all the provinces of that level would be added. +When calling a higher level (Autonomous Community or NUTS1), all the +provinces of that level would be added. On \code{\link[=esp_get_prov_siane]{esp_get_prov_siane()}}, \code{year} could be passed as a single year ("YYYY" format, as end of year) or as a specific date ("YYYY-MM-DD" format). @@ -120,30 +120,34 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ prov <- esp_get_prov() -library(tmap) +library(ggplot2) -qtm(prov) +ggplot(prov) + + geom_sf() + + theme_void() +\donttest{ # Random Provinces -Random <- - esp_get_prov(prov = c( - "Zamora", - "Palencia", - "ES-GR", - "ES521", - "01" - )) +Random <- esp_get_prov(prov = c( + "Zamora", "Palencia", "ES-GR", + "ES521", "01" +)) -tm_shape(Random) + - tm_polygons(col = "codauto", legend.show = FALSE, palette = "Spectral") +ggplot(Random) + + geom_sf(aes(fill = codauto), show.legend = FALSE, alpha = 0.5) + + scale_fill_manual(values = hcl.colors( + nrow(Random), "Spectral" + )) + + theme_minimal() # All Provinces of a Zone plus an addition @@ -153,19 +157,28 @@ Mix <- esp_get_prov(prov = c( "Castilla y Leon", "La Rioja" )) -qtm(Mix) +Mix$CCAA <- esp_dict_region_code( + Mix$codauto, + origin = "codauto" +) + +ggplot(Mix) + + geom_sf(aes(fill = CCAA), alpha = 0.5) + + scale_fill_discrete(type = hcl.colors(5, "Temps")) + + theme_classic() # ISO codes available allprovs <- esp_get_prov() - -tm_shape(allprovs, point.per = "feature") + - tm_polygons() + - tm_text("iso2.prov.code", - remove.overlap = TRUE, - shadow = TRUE - ) +ggplot(allprovs) + + geom_sf(fill = NA) + + geom_sf_text(aes(label = iso2.prov.code), + check_overlap = TRUE, + fontface = "bold" + ) + + theme_void() +} } \seealso{ Other political: @@ -173,9 +186,11 @@ Other political: \code{\link{esp_get_can_box}()}, \code{\link{esp_get_capimun}()}, \code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, \code{\link{esp_get_country}()}, \code{\link{esp_get_gridmap}}, \code{\link{esp_get_munic}()}, -\code{\link{esp_get_nuts}()} +\code{\link{esp_get_nuts}()}, +\code{\link{esp_get_simpl_prov}()} } \concept{political} diff --git a/man/esp_get_railway.Rd b/man/esp_get_railway.Rd index b3c6dbec..1fab0b9d 100644 --- a/man/esp_get_railway.Rd +++ b/man/esp_get_railway.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/esp_get_railway.R \name{esp_get_railway} \alias{esp_get_railway} -\title{Get \code{sf} lines and points with the railways of Spain} +\title{Get \code{\link[sf:sf]{sf}} \code{LINESTRING} or \code{POINT} with the railways of Spain} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). @@ -24,10 +24,10 @@ esp_get_railway( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -46,11 +46,11 @@ for extracting the railway as lines and \code{"point"} for extracting stations.} } \value{ -A \code{sf} line or point object. +A \code{\link[sf:sf]{sf}} \code{LINESTRING} or \code{POINT} object. } \description{ -Loads a \code{sf} lines or point object representing the nodes and railway -lines of Spain. +Loads a \code{\link[sf:sf]{sf}} \code{LINESTRING} or \code{POINT} object representing the +nodes and railway lines of Spain. } \section{About caching}{ You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. @@ -64,6 +64,7 @@ corresponding .geojson file by any other method and save it on your } \examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ provs <- esp_get_prov() @@ -77,20 +78,29 @@ stations <- esp_get_railway(spatialtype = "point") # Map -library(tmap) +library(ggplot2) -tm_shape(provs, bbox = c(-7.5, 38, -2.5, 41)) + - tm_polygons(col = "grey99", border.col = "grey50") + - tm_shape(ccaa) + - tm_borders("black") + - tm_shape(rails) + - tm_lines("tipo", - legend.col.show = FALSE, lwd = 3, - palette = "viridis" +ggplot(provs) + + geom_sf(fill = "grey99", color = "grey50") + + geom_sf(data = ccaa, fill = NA) + + geom_sf( + data = rails, aes(color = tipo), + show.legend = FALSE, linewidth = 1.5 ) + - tm_shape(stations) + - tm_symbols("red", size = .3, alpha = 0.5, shape = 19) + geom_sf( + data = stations, + color = "red", alpha = 0.5 + ) + + coord_sf( + xlim = c(-7.5, -2.5), + ylim = c(38, 41) + ) + + scale_color_manual(values = hcl.colors( + length(unique(rails$tipo)), "viridis" + )) + + theme_minimal() } +\dontshow{\}) # examplesIf} } \seealso{ Other infrastructure: diff --git a/man/esp_get_rivers.Rd b/man/esp_get_rivers.Rd index 9e1eee19..9e7d6fe2 100644 --- a/man/esp_get_rivers.Rd +++ b/man/esp_get_rivers.Rd @@ -2,7 +2,8 @@ % Please edit documentation in R/esp_get_rivers.R \name{esp_get_rivers} \alias{esp_get_rivers} -\title{Get \code{sf} polygon and lines of rivers, channels and other wetlands of Spain} +\title{Get \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} of rivers, channels and other +wetlands of Spain} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). @@ -23,10 +24,10 @@ esp_get_rivers( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -40,27 +41,28 @@ When set to \code{TRUE} it would force a fresh download of the source file.} \item{verbose}{Logical, displays information. Useful for debugging, default is \code{FALSE}.} -\item{resolution}{Resolution of the polygon. Values available are +\item{resolution}{Resolution of the \code{POLYGON}. Values available are \code{"3"}, \code{"6.5"} or \code{"10"}.} -\item{spatialtype}{Spatial type of the output. Use \code{"area"} for polygons or -\code{"line"} for lines.} +\item{spatialtype}{Spatial type of the output. Use \code{"area"} for \code{POLYGON} or +\code{"line"} for \code{LINESTRING}.} \item{name}{Optional. A character or \code{\link[base:grep]{regex}} expression with the name of the element(s) to be extracted.} } \value{ -A \code{sf} polygon or line object. +A \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} object. } \description{ -Loads a \code{sf} polygon or line object representing rivers, channels, -reservoirs and other wetlands of Spain +Loads a \code{\link[sf:sf]{sf}} \code{POLYGON} or \code{LINESTRING} object representing +rivers, channels, reservoirs and other wetlands of Spain. } \details{ Metadata available on \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata/}. } \examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ # Use of regex @@ -79,25 +81,36 @@ shapeEsp <- esp_get_country(moveCAN = FALSE) MainRivers <- esp_get_rivers(name = "Tajo$|Ebro$|Ebre$|Duero|Guadiana$|Guadalquivir") +sf::st_bbox(MainRivers) +library(ggplot2) -library(tmap) - -tm_shape(shapeEsp, bbox = MainRivers) + - tm_borders() + - tm_shape(MainRivers) + - tm_lines(col = "skyblue", lwd = 3) +ggplot(shapeEsp) + + geom_sf() + + geom_sf(data = MainRivers, color = "skyblue", linewidth = 2) + + coord_sf( + xlim = c(-7.5, 1), + ylim = c(36.8, 43) + ) + + theme_void() # Wetlands in South-West Andalucia and <- esp_get_prov(c("Huelva", "Sevilla", "Cadiz")) Wetlands <- esp_get_rivers(spatialtype = "area") - -tm_shape(and) + - tm_polygons() + - tm_shape(Wetlands) + - tm_polygons(col = "skyblue", alpha = 0.5, border.col = "skyblue", lwd = 2) +ggplot(and) + + geom_sf() + + geom_sf( + data = Wetlands, fill = "skyblue", + color = "skyblue", alpha = 0.5 + ) + + coord_sf( + xlim = c(-7.5, -4.5), + ylim = c(36, 38.5) + ) + + theme_void() } +\dontshow{\}) # examplesIf} } \seealso{ Other natural: diff --git a/man/esp_get_roads.Rd b/man/esp_get_roads.Rd index bd7dffca..dd5f87b2 100644 --- a/man/esp_get_roads.Rd +++ b/man/esp_get_roads.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/esp_get_roads.R \name{esp_get_roads} \alias{esp_get_roads} -\title{Get \code{sf} lines of the roads of Spain} +\title{Get \code{\link[sf:sf]{sf}} \code{LINESTRING} of the roads of Spain} \source{ IGN data via a custom CDN (see \url{https://github.com/rOpenSpain/mapSpain/tree/sianedata}). @@ -24,10 +24,10 @@ esp_get_roads( \item{epsg}{projection of the map: 4-digit \href{https://epsg.io/}{EPSG code}. One of: \itemize{ -\item \code{"4258"}: ETRS89 -\item \code{"4326"}: WGS84 -\item \code{"3035"}: ETRS89 / ETRS-LAEA -\item \code{"3857"}: Pseudo-Mercator +\item \code{"4258"}: ETRS89. +\item \code{"4326"}: WGS84. +\item \code{"3035"}: ETRS89 / ETRS-LAEA. +\item \code{"3857"}: Pseudo-Mercator. }} \item{cache}{A logical whether to do caching. Default is \code{TRUE}. See @@ -47,10 +47,11 @@ Initial position can be adjusted using the vector of coordinates. See \strong{Displacing the Canary Islands}.} } \value{ -A \code{sf} line object. +A \code{\link[sf:sf]{sf}} \code{LINESTRING} object. } \description{ -Loads a \code{sf} line object representing the main roads of Spain. +Loads a \code{\link[sf:sf]{sf}} \code{LINESTRING} object representing the main roads of +Spain. } \details{ \code{year} could be passed as a single year ("YYYY" format, as end of year) or @@ -72,29 +73,31 @@ While \code{moveCAN} is useful for visualization, it would alter the actual geographic position of the Canary Islands. When using the output for spatial analysis or using tiles (e.g. with \code{\link[=esp_getTiles]{esp_getTiles()}} or \code{\link[=addProviderEspTiles]{addProviderEspTiles()}}) this option should be set to \code{FALSE} in order to -get the actual coordinates, instead of the modified ones. +get the actual coordinates, instead of the modified ones. See also +\code{\link[=esp_move_can]{esp_move_can()}} for displacing stand-alone \code{\link[sf:sf]{sf}} objects. } \examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ -#' + country <- esp_get_country() Roads <- esp_get_roads() +library(ggplot2) -library(tmap) - -tm_shape(country) + - tm_fill(col = "grey90") + - tm_shape(Roads) + - tm_lines("tipo", - palette = c("#003399", "#003399", "#ff0000", "#ffff00") +ggplot(country) + + geom_sf(fill = "grey90") + + geom_sf(data = Roads, aes(color = tipo), show.legend = "line") + + scale_color_manual( + values = c("#003399", "#003399", "#ff0000", "#ffff00") ) + - tm_layout( - legend.outside = TRUE, - legend.outside.position = "bottom" - ) + guides(color = guide_legend(direction = "vertical")) + + theme_minimal() + + labs(color = "Road type") + + theme(legend.position = "bottom") } +\dontshow{\}) # examplesIf} } \seealso{ Other infrastructure: diff --git a/man/esp_get_simplified.Rd b/man/esp_get_simplified.Rd new file mode 100644 index 00000000..af1cc9cc --- /dev/null +++ b/man/esp_get_simplified.Rd @@ -0,0 +1,112 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_get_simplified.R +\name{esp_get_simpl_prov} +\alias{esp_get_simpl_prov} +\alias{esp_get_simpl_ccaa} +\title{Get a simplified map of provinces and autonomous communities of Spain} +\source{ +INE: PC_Axis files +} +\usage{ +esp_get_simpl_prov( + prov = NULL, + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) + +esp_get_simpl_ccaa( + ccaa = NULL, + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE +) +} +\arguments{ +\item{prov}{A vector of names and/or codes for provinces or \code{NULL} to get all +the provinces. See \strong{Details}.} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} + +\item{ccaa}{A vector of names and/or codes for autonomous communities +or \code{NULL} to get all the autonomous communities. See \strong{Details}.} +} +\value{ +A \code{\link[sf:sf]{sf}} \code{POLYGON} object. +} +\description{ +Loads a simplified map (\code{\link[sf:sf]{sf}} object) with the boundaries of the +provinces or autonomous communities of Spain, as provided by the \strong{INE} +(Instituto Nacional de Estadistica). +} +\details{ +Results are provided \strong{without CRS}, as provided on source. + +You can use and mix names, ISO codes, \code{"codauto"/"cpro"} codes (see +\link{esp_codelist}) and NUTS codes of different levels. + +When using a code corresponding of a higher level (e.g. +\code{esp_get_simpl_prov("Andalucia")}) all the corresponding units of that level +are provided (in this case , all the provinces of Andalusia). +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=esp_set_cache_dir]{esp_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding .geojson file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. +} + +\examples{ +\dontshow{if (esp_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\donttest{ +prov_simp <- esp_get_simpl_prov() + +library(ggplot2) + +ggplot(prov_simp) + + geom_sf(aes(fill = ine.ccaa.name)) + + labs(fill = "CCAA") + +# Provs of Single CCAA + +and_simple <- esp_get_simpl_prov("Andalucia") + +ggplot(and_simple) + + geom_sf() + +# CCAAs + +ccaa_simp <- esp_get_simpl_ccaa() + +ggplot(ccaa_simp) + + geom_sf() + + geom_sf_text(aes(label = ine.ccaa.name), check_overlap = TRUE) +} +\dontshow{\}) # examplesIf} +} +\seealso{ +\code{\link[=esp_get_hex_prov]{esp_get_hex_prov()}}, \code{\link[=esp_get_hex_ccaa]{esp_get_hex_ccaa()}} + +Other political: +\code{\link{esp_codelist}}, +\code{\link{esp_get_can_box}()}, +\code{\link{esp_get_capimun}()}, +\code{\link{esp_get_ccaa}()}, +\code{\link{esp_get_comarca}()}, +\code{\link{esp_get_country}()}, +\code{\link{esp_get_gridmap}}, +\code{\link{esp_get_munic}()}, +\code{\link{esp_get_nuts}()}, +\code{\link{esp_get_prov}()} +} +\concept{political} diff --git a/man/esp_make_provider.Rd b/man/esp_make_provider.Rd new file mode 100644 index 00000000..f19ddcb1 --- /dev/null +++ b/man/esp_make_provider.Rd @@ -0,0 +1,72 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_make_provider.R +\name{esp_make_provider} +\alias{esp_make_provider} +\title{Create a custom tile provider} +\usage{ +esp_make_provider(id, q, service, layers, ...) +} +\arguments{ +\item{id}{An identifier for the user. Would be used also for identifying +cached tiles.} + +\item{q}{The base url of the service.} + +\item{service}{The type of tile service, either \code{"WMS"} or \code{"WMTS"}.} + +\item{layers}{The name of the layer to retrieve.} + +\item{...}{Additional parameters to the query, like \code{version}, \code{format}, +\code{crs/srs}, \code{style}, ... depending on the capabilities of the service.} +} +\value{ +A named list with two elements \code{id} and \code{q}. +} +\description{ +Helper function for \code{\link[=esp_getTiles]{esp_getTiles()}} that helps to create a custom provider. +} +\details{ +This function is meant to work with services provided as of the +\href{http://opengeospatial.github.io/e-learning/wms/text/operations.html#getmap}{OGC Standard}. + +Note that: +\itemize{ +\item \CRANpkg{mapSpain} would not provide advice on the parameter \code{q} to be +provided. +\item Currently, on \strong{WMTS} requests only services with +\code{tilematrixset=GoogleMapsCompatible} are supported. +} +} +\examples{ +\dontrun{ +# This script downloads tiles to your local machine +# Run only if you are online + +custom_wms <- esp_make_provider( + id = "an_id_for_caching", + q = "https://idecyl.jcyl.es/geoserver/ge/wms?", + service = "WMS", + version = "1.3.0", + layers = "geolog_cyl_litologia" +) + +x <- esp_get_ccaa("Castilla y León", epsg = 3857) + +mytile <- esp_getTiles(x, type = custom_wms) + +tidyterra::autoplot(mytile) + + ggplot2::geom_sf(data = x, fill = NA) +} +} +\seealso{ +\code{\link[=esp_getTiles]{esp_getTiles()}}. + +For a list of potential providers from Spain check +\href{https://www.idee.es/segun-tipo-de-servicio}{IDEE Directory}. + +Other imagery utilities: +\code{\link{addProviderEspTiles}()}, +\code{\link{esp_getTiles}()}, +\code{\link{esp_tiles_providers}} +} +\concept{imagery utilities} diff --git a/man/esp_move_can.Rd b/man/esp_move_can.Rd new file mode 100644 index 00000000..8bc3f723 --- /dev/null +++ b/man/esp_move_can.Rd @@ -0,0 +1,77 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/esp_move_can.R +\name{esp_move_can} +\alias{esp_move_can} +\title{Displace a \code{\link[sf:sf]{sf}} object located in the Canary Islands} +\usage{ +esp_move_can(x, moveCAN = TRUE) +} +\arguments{ +\item{x}{An \code{\link[sf:sf]{sf}} object. It may be \code{sf} or \code{sfc} object.} + +\item{moveCAN}{A logical \code{TRUE/FALSE} or a vector of coordinates +\code{c(lat, lon)}.} +} +\value{ +A \code{\link[sf:sf]{sf}} object of the same class and same CRS than \code{x} +but displaced accordingly. +} +\description{ +Helper function to displace an external \code{\link[sf:sf]{sf}} object (potentially +representing a location in the Canary Islands) to align it with the objects +provided by \code{\link[sf:sf]{sf}} with the option \code{moveCAN = TRUE}. +} +\details{ +This is a helper function that intends to ease the representation of objects +located in the Canary Islands that have been obtained from other sources +rather than the package \CRANpkg{mapSpain}. +} +\examples{ +library(sf) +teide <- data.frame( + name = "Teide Peak", + lon = -16.6437593, + lat = 28.2722883 +) + +teide_sf <- st_as_sf(teide, coords = c("lon", "lat"), crs = 4326) + +# If we use any mapSpain produced object with moveCAN = TRUE... + +esp <- esp_get_country(moveCAN = c(13, 0)) + +library(ggplot2) + + +ggplot(esp) + + geom_sf() + + geom_sf(data = teide_sf, color = "red") + + labs( + title = "Canary Islands displaced", + subtitle = "But not the external Teide object" + ) + + + +# But we can + +teide_sf_disp <- esp_move_can(teide_sf, moveCAN = c(13, 0)) + +ggplot(esp) + + geom_sf() + + geom_sf(data = teide_sf_disp, color = "red") + + labs( + title = "Canary Islands displaced", + subtitle = "And also the external Teide object" + ) + +} +\seealso{ +Other helper: +\code{\link{esp_check_access}()} + +Other Canary Islands: +\code{\link{esp_get_can_box}()} +} +\concept{Canary Islands} +\concept{helper} diff --git a/man/esp_munic.sf.Rd b/man/esp_munic.sf.Rd index 3bf7d017..66916e69 100644 --- a/man/esp_munic.sf.Rd +++ b/man/esp_munic.sf.Rd @@ -1,78 +1,78 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\encoding{UTF-8} -\name{esp_munic.sf} -\alias{esp_munic.sf} -\title{All Municipalities \code{POLYGON} object of Spain (2019)} -\format{ -A \code{POLYGON} data frame (resolution: 1:1million, EPSG:4258) object with -8,131 rows and fields: -\itemize{ -\item \strong{codauto}: INE code of each autonomous community. -\item \strong{ine.ccaa.name}: INE name of each autonomous community. -\item \strong{cpro}: INE code of each province. -\item \strong{ine.prov.name}: INE name of each province. -\item \strong{cmun}: INE code of each municipality. -\item \strong{name}: Name of the municipality. -\item \strong{LAU_CODE}: LAU Code (GISCO) of the municipality. This is a -combination of \strong{cpro} and \strong{cmun}, aligned with INE coding scheme. -\item \strong{geometry}: geometry field. -} -} -\source{ -\url{https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/}, LAU 2019 -data. -} -\description{ -A \code{sf} object including all municipalities of Spain as provided by GISCO -(2019 version). -} -\examples{ -data("esp_munic.sf") - -teruel_cpro <- esp_dict_region_code("Teruel", destination = "cpro") - -teruel_sf <- esp_munic.sf[esp_munic.sf$cpro == teruel_cpro, ] -teruel_city <- teruel_sf[teruel_sf$name == "Teruel", ] - -# Plot - -library(tmap) - -tm_shape(teruel_sf) + - tm_polygons("#FDFBEA") + - tm_shape(teruel_city) + - tm_fill( - col = "name", - palette = "#C12838", - labels = "City of Teruel", - title = "" - ) + - tm_graticules(lines = FALSE) + - tm_layout( - main.title = "Municipalities of Teruel", - legend.position = c("left", "top") - ) + - tm_scale_bar() + - tm_compass( - type = "rose", - size = 3, - position = c("left", "bottom") - ) -} -\seealso{ -\code{\link[=esp_get_munic]{esp_get_munic()}}. - -Other datasets: -\code{\link{esp_codelist}}, -\code{\link{esp_nuts.sf}}, -\code{\link{leaflet.providersESP.df}}, -\code{\link{pobmun19}} - -Other municipalities: -\code{\link{esp_get_capimun}()}, -\code{\link{esp_get_munic}()} -} -\concept{datasets} -\concept{municipalities} +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\encoding{UTF-8} +\name{esp_munic.sf} +\alias{esp_munic.sf} +\title{\code{\link[sf:sf]{sf}} object with all the municipalities of Spain (2019)} +\format{ +A \code{\link[sf:sf]{sf}} object (resolution: 1:1 million, EPSG:4258) object with +8,131 rows and columns: +\describe{ +\item{codauto}{INE code of the autonomous community.} +\item{ine.ccaa.name}{INE name of the autonomous community.} +\item{cpro}{INE code of the province.} +\item{ine.prov.name}{INE name of the province.} +\item{cmun}{INE code of the municipality.} +\item{name}{Name of the municipality.} +\item{LAU_CODE}{LAU Code (GISCO) of the municipality. This is a +combination of \strong{cpro} and \strong{cmun} fields, aligned with INE coding +scheme.} +\item{geometry}{geometry field.} +} +} +\source{ +\url{https://ec.europa.eu/eurostat/web/gisco/geodata/statistical-units/local-administrative-units}, +LAU 2019 data. +} +\description{ +A \code{\link[sf:sf]{sf}} object including all municipalities of Spain as provided +by GISCO (2019 version). +} +\examples{ +data("esp_munic.sf") + +teruel_cpro <- esp_dict_region_code("Teruel", destination = "cpro") + +teruel_sf <- esp_munic.sf[esp_munic.sf$cpro == teruel_cpro, ] +teruel_city <- teruel_sf[teruel_sf$name == "Teruel", ] + +# Plot + +library(ggplot2) + +ggplot(teruel_sf) + + geom_sf(fill = "#FDFBEA") + + geom_sf(data = teruel_city, aes(fill = name)) + + scale_fill_manual( + values = "#C12838", + labels = "City of Teruel" + ) + + guides(fill = guide_legend(position = "inside")) + + labs( + fill = "", + title = "Municipalities of Teruel" + ) + + theme_minimal() + + theme( + text = element_text(face = "bold"), + panel.background = element_rect(colour = "black"), + panel.grid = element_blank(), + legend.position.inside = c(.2, .95) + ) +} +\seealso{ +\code{\link[=esp_get_munic]{esp_get_munic()}}. + +Other datasets: +\code{\link{esp_codelist}}, +\code{\link{esp_nuts.sf}}, +\code{\link{esp_tiles_providers}}, +\code{\link{pobmun19}} + +Other municipalities: +\code{\link{esp_get_capimun}()}, +\code{\link{esp_get_munic}()} +} +\concept{datasets} +\concept{municipalities} diff --git a/man/esp_nuts.sf.Rd b/man/esp_nuts.sf.Rd index 3f1a620b..e90b6ea0 100644 --- a/man/esp_nuts.sf.Rd +++ b/man/esp_nuts.sf.Rd @@ -1,76 +1,104 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.R -\docType{data} -\encoding{UTF-8} -\name{esp_nuts.sf} -\alias{esp_nuts.sf} -\title{All NUTS \code{POLYGON} object of Spain} -\format{ -A \code{POLYGON} data frame (resolution: 1:1million, EPSG:4258) object with -86 rows and fields: -\itemize{ -\item COAST_TYPE: COAST_TYPE -\item FID: FID -\item NUTS_NAME: NUTS name on local alphabet -\item MOUNT_TYPE: MOUNT_TYPE -\item NAME_LATN: Name on Latin characters -\item CNTR_CODE: Eurostat Country code -\item URBN_TYPE: URBN_TYPE -\item NUTS_ID: NUTS identifier -\item LEVL_CODE: NUTS level code (0,1,2,3) -\item geometry: geometry field -} -} -\source{ -\url{https://gisco-services.ec.europa.eu/distribution/v2/nuts/}, file -\code{NUTS_RG_20M_2016_4326.geojson}. -} -\description{ -A \code{sf} object including all NUTS levels of Spain as provided by -GISCO (2016 version). -} -\examples{ -data("esp_nuts.sf") - -nuts <- esp_nuts.sf - -# Select NUTS 3 -nuts3 <- esp_nuts.sf[esp_nuts.sf$LEVL_CODE == 3, ] - -# Combine with full shape - -spain <- esp_get_country(moveCAN = FALSE) - -library(tmap) - -# Plot Urban Type: See -# https://ec.europa.eu/eurostat/web/rural-development/methodology -tm_shape(nuts3) + - tm_polygons( - "URBN_TYPE", - style = "cat", - border.col = "black", - border.alpha = 0.3, - title = "Urban topology", - labels = c("Urban", "Intermediate", "Rural"), - palette = c("grey80", "#FFC183", "#68AC20") - ) + - tm_graticules(lines = FALSE) + - tm_layout( - main.title = "NUTS3 levels of Spain", - legend.position = c("left", "center"), - legend.title.size = 0.8 - ) -} -\seealso{ -Other datasets: -\code{\link{esp_codelist}}, -\code{\link{esp_munic.sf}}, -\code{\link{leaflet.providersESP.df}}, -\code{\link{pobmun19}} - -Other nuts: -\code{\link{esp_get_nuts}()} -} -\concept{datasets} -\concept{nuts} +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\encoding{UTF-8} +\name{esp_nuts.sf} +\alias{esp_nuts.sf} +\title{\code{\link[sf:sf]{sf}} object with all the NUTS levels of Spain (2016)} +\format{ +A \code{\link[sf:sf]{sf}} object (resolution: 1:1million, EPSG:4258) with +86 rows and columns: +\describe{ +\item{LEVL_CODE}{NUTS level code (0,1,2,3)} +\item{NUTS_ID}{NUTS identifier} +\item{URBN_TYPE}{Urban Type, see Details} +\item{CNTR_CODE}{Eurostat Country code \code{ES}} +\item{NAME_LATN}{NUTS name on Latin characters} +\item{NUTS_NAME}{NUTS name on local alphabet} +\item{MOUNT_TYPE}{Mount Type, see Details} +\item{COAST_TYPE}{Coast Type, see Details} +\item{FID}{FID} +\item{geometry}{geometry field} +} +} +\source{ +\url{https://gisco-services.ec.europa.eu/distribution/v2/nuts/}, file +\code{NUTS_RG_20M_2016_4326.geojson}. +} +\description{ +A \code{\link[sf:sf]{sf}} object including all NUTS levels of Spain as provided by +GISCO (2016 version). +} +\details{ +\strong{MOUNT_TYPE}: Mountain typology: +\itemize{ +\item 1: More than 50 \% of the surface is covered by topographic mountain areas. +\item 2: More than 50 \% of the regional population lives in topographic +mountain areas. +\item 3: More than 50 \% of the surface is covered by topographic mountain areas +and where more than 50 \% of the regional population lives in these +mountain areas. +\item 4: Non-mountain region / other regions. +\item 0: No classification provided +} + +\strong{URBN_TYPE}: Urban-rural typology: +\itemize{ +\item 1: Predominantly urban region. +\item 2: Intermediate region. +\item 3: Predominantly rural region. +\item 0: No classification provided +} + +\strong{COAST_TYPE}: Coastal typology: +\itemize{ +\item 1: Coastal (on coast). +\item 2: Coastal (less than 50\% of population living within 50 km. of the +coastline). +\item 3: Non-coastal region. +\item 0: No classification provided +} +} +\examples{ +data("esp_nuts.sf") + +nuts <- esp_nuts.sf + +# Select NUTS 3 +nuts3 <- esp_nuts.sf[esp_nuts.sf$LEVL_CODE == 3, ] + +# Combine with full shape + +spain <- esp_get_country(moveCAN = FALSE) + +# Plot Urban Type: See +# https://ec.europa.eu/eurostat/web/rural-development/methodology + +library(ggplot2) + +nuts3$URBN_TYPE_cat <- as.factor(nuts3$URBN_TYPE) + +levels(nuts3$URBN_TYPE_cat) +levels(nuts3$URBN_TYPE_cat) <- c("Urban", "Intermediate", "Rural") + +ggplot(nuts3) + + geom_sf(aes(fill = URBN_TYPE_cat), linewidth = .1) + + scale_fill_manual(values = c("grey80", "#FFC183", "#68AC20")) + + labs( + title = "NUTS3 levels of Spain", + fill = "Urban topology" + ) + + theme_linedraw() +} +\seealso{ +Other datasets: +\code{\link{esp_codelist}}, +\code{\link{esp_munic.sf}}, +\code{\link{esp_tiles_providers}}, +\code{\link{pobmun19}} + +Other nuts: +\code{\link{esp_get_nuts}()} +} +\concept{datasets} +\concept{nuts} diff --git a/man/esp_set_cache_dir.Rd b/man/esp_set_cache_dir.Rd index 6613cc31..050889aa 100644 --- a/man/esp_set_cache_dir.Rd +++ b/man/esp_set_cache_dir.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/esp_cache.R \name{esp_set_cache_dir} \alias{esp_set_cache_dir} -\title{Set your \strong{mapSpain} cache dir} +\title{Set your \CRANpkg{mapSpain} cache dir} \usage{ esp_set_cache_dir( cache_dir, @@ -15,12 +15,12 @@ esp_set_cache_dir( \item{cache_dir}{A path to a cache directory. On missing value the function would store the cached files on a temporary dir (See \code{\link[base:tempfile]{base::tempdir()}}).} -\item{overwrite}{If this is set to \code{TRUE}, it will overwrite an existing -\code{MAPSPAIN_CACHE_DIR} that you already have in local machine.} +\item{overwrite}{Logical. If this is set to \code{TRUE}, it will overwrite an +existing \code{MAPSPAIN_CACHE_DIR} that you already have in local machine.} -\item{install}{if \code{TRUE}, will install the key in your local machine for -use in future sessions. Defaults to \code{FALSE.} If \code{cache_dir} is \code{FALSE} -this parameter is set to \code{FALSE} automatically.} +\item{install}{Logical. If \code{TRUE}, will install the key in your local +machine for use in future sessions. Defaults to \code{FALSE.} If \code{cache_dir} +is \code{FALSE} this parameter is set to \code{FALSE} automatically.} \item{verbose}{Logical, displays information. Useful for debugging, default is \code{FALSE}.} @@ -59,6 +59,7 @@ Sys.getenv("MAPSPAIN_CACHE_DIR") \code{\link[rappdirs:user_data_dir]{rappdirs::user_config_dir()}} Other cache utilities: -\code{\link{esp_clear_cache}()} +\code{\link{esp_clear_cache}()}, +\code{\link{esp_detect_cache_dir}()} } \concept{cache utilities} diff --git a/man/esp_tiles_providers.Rd b/man/esp_tiles_providers.Rd new file mode 100644 index 00000000..ec45beb1 --- /dev/null +++ b/man/esp_tiles_providers.Rd @@ -0,0 +1,164 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\encoding{UTF-8} +\name{esp_tiles_providers} +\alias{esp_tiles_providers} +\title{Database of public WMS and WMTS of Spain} +\format{ +A named \code{list} of the providers available with the following structure: +\itemize{ +\item Each item of the list is named with the provider alias. +\item Each element of the list contains two nested named lists: +\itemize{ +\item \code{static} with the parameters to get static tiles plus an additional item +named \code{attribution}. +\item \code{leaflet} with additional parameters to be passed onto +\code{\link[=addProviderEspTiles]{addProviderEspTiles()}}. +} +} +} +\source{ +\url{https://dieghernan.github.io/leaflet-providersESP/} leaflet plugin, +\strong{v1.3.3}. +} +\description{ +A named \code{\link[base:list]{list}} of length 102 +containing the parameters of the url information of different public WMS and +WMTSproviders of Spain. + +Implementation of javascript plugin +\href{https://dieghernan.github.io/leaflet-providersESP/}{leaflet-providersESP} +\strong{v1.3.3}. +} +\details{ +Providers available to be passed to \code{type} on \code{\link[=esp_getTiles]{esp_getTiles()}} are: +\itemize{ +\item \code{"IDErioja"} +\item \code{"IDErioja.Base"} +\item \code{"IDErioja.Relieve"} +\item \code{"IDErioja.Claro"} +\item \code{"IDErioja.Oscuro"} +\item \code{"IGNBase"} +\item \code{"IGNBase.Todo"} +\item \code{"IGNBase.Gris"} +\item \code{"IGNBase.TodoNoFondo"} +\item \code{"IGNBase.Orto"} +\item \code{"MDT"} +\item \code{"MDT.Elevaciones"} +\item \code{"MDT.Relieve"} +\item \code{"MDT.CurvasNivel"} +\item \code{"MDT.SpotElevation"} +\item \code{"PNOA"} +\item \code{"PNOA.MaximaActualidad"} +\item \code{"PNOA.Mosaico"} +\item \code{"OcupacionSuelo"} +\item \code{"OcupacionSuelo.Ocupacion"} +\item \code{"OcupacionSuelo.Usos"} +\item \code{"LiDAR"} +\item \code{"MTN"} +\item \code{"Geofisica"} +\item \code{"Geofisica.Terremotos10dias"} +\item \code{"Geofisica.Terremotos30dias"} +\item \code{"Geofisica.Terremotos365dias"} +\item \code{"Geofisica.ObservedEvents"} +\item \code{"Geofisica.HazardArea"} +\item \code{"VigilanciaVolcanica"} +\item \code{"VigilanciaVolcanica.ErupcionesHistoricas"} +\item \code{"CaminoDeSantiago"} +\item \code{"CaminoDeSantiago.CaminoFrances"} +\item \code{"CaminoDeSantiago.CaminosFrancia"} +\item \code{"CaminoDeSantiago.CaminosGalicia"} +\item \code{"CaminoDeSantiago.CaminosDelNorte"} +\item \code{"CaminoDeSantiago.CaminosAndaluces"} +\item \code{"CaminoDeSantiago.CaminosCentro"} +\item \code{"CaminoDeSantiago.CaminosEste"} +\item \code{"CaminoDeSantiago.CaminosCatalanes"} +\item \code{"CaminoDeSantiago.CaminosSureste"} +\item \code{"CaminoDeSantiago.CaminosInsulares"} +\item \code{"CaminoDeSantiago.CaminosPortugueses"} +\item \code{"Catastro"} +\item \code{"Catastro.Catastro"} +\item \code{"Catastro.Parcela"} +\item \code{"Catastro.CadastralParcel"} +\item \code{"Catastro.CadastralZoning"} +\item \code{"Catastro.Address"} +\item \code{"Catastro.Building"} +\item \code{"Catastro.BuildingPart"} +\item \code{"Catastro.AdministrativeBoundary"} +\item \code{"Catastro.AdministrativeUnit"} +\item \code{"RedTransporte"} +\item \code{"RedTransporte.Carreteras"} +\item \code{"RedTransporte.Ferroviario"} +\item \code{"RedTransporte.Aerodromo"} +\item \code{"RedTransporte.AreaServicio"} +\item \code{"RedTransporte.EstacionesFerroviario"} +\item \code{"RedTransporte.Puertos"} +\item \code{"Cartociudad"} +\item \code{"Cartociudad.CodigosPostales"} +\item \code{"Cartociudad.Direcciones"} +\item \code{"NombresGeograficos"} +\item \code{"UnidadesAdm"} +\item \code{"UnidadesAdm.Limites"} +\item \code{"UnidadesAdm.Unidades"} +\item \code{"Hidrografia"} +\item \code{"Hidrografia.MasaAgua"} +\item \code{"Hidrografia.Cuencas"} +\item \code{"Hidrografia.Subcuencas"} +\item \code{"Hidrografia.POI"} +\item \code{"Hidrografia.ManMade"} +\item \code{"Hidrografia.LineaCosta"} +\item \code{"Hidrografia.Rios"} +\item \code{"Hidrografia.Humedales"} +\item \code{"Militar"} +\item \code{"Militar.CEGET1M"} +\item \code{"Militar.CEGETM7814"} +\item \code{"Militar.CEGETM7815"} +\item \code{"Militar.CEGETM682"} +\item \code{"Militar.CECAF1M"} +\item \code{"ADIF"} +\item \code{"ADIF.Vias"} +\item \code{"ADIF.Nodos"} +\item \code{"ADIF.Estaciones"} +\item \code{"LimitesMaritimos"} +\item \code{"LimitesMaritimos.LimitesMaritimos"} +\item \code{"LimitesMaritimos.LineasBase"} +\item \code{"Copernicus"} +\item \code{"Copernicus.Forest"} +\item \code{"Copernicus.ForestLeaf"} +\item \code{"Copernicus.WaterWet"} +\item \code{"Copernicus.SoilSeal"} +\item \code{"Copernicus.GrassLand"} +\item \code{"Copernicus.RiparianGreen"} +\item \code{"Copernicus.RiparianLandCover"} +\item \code{"Copernicus.Natura2k"} +\item \code{"Copernicus.UrbanAtlas"} +\item \code{"ParquesNaturales"} +\item \code{"ParquesNaturales.Limites"} +\item \code{"ParquesNaturales.ZonasPerifericas"} +} +} +\examples{ +data("esp_tiles_providers") +# Get a single provider + +single <- esp_tiles_providers[["IGNBase.Todo"]] +single$static + +single$leaflet + +} +\seealso{ +Other datasets: +\code{\link{esp_codelist}}, +\code{\link{esp_munic.sf}}, +\code{\link{esp_nuts.sf}}, +\code{\link{pobmun19}} + +Other imagery utilities: +\code{\link{addProviderEspTiles}()}, +\code{\link{esp_getTiles}()}, +\code{\link{esp_make_provider}()} +} +\concept{datasets} +\concept{imagery utilities} diff --git a/man/figures/lifecycle-archived.svg b/man/figures/lifecycle-archived.svg new file mode 100644 index 00000000..de77bc26 --- /dev/null +++ b/man/figures/lifecycle-archived.svg @@ -0,0 +1 @@ +lifecyclelifecyclearchivedarchived \ No newline at end of file diff --git a/man/figures/lifecycle-defunct.svg b/man/figures/lifecycle-defunct.svg new file mode 100644 index 00000000..0aff3f66 --- /dev/null +++ b/man/figures/lifecycle-defunct.svg @@ -0,0 +1 @@ +lifecyclelifecycledefunctdefunct \ No newline at end of file diff --git a/man/figures/lifecycle-deprecated.svg b/man/figures/lifecycle-deprecated.svg new file mode 100644 index 00000000..975dda3f --- /dev/null +++ b/man/figures/lifecycle-deprecated.svg @@ -0,0 +1 @@ +lifecyclelifecycledeprecateddeprecated \ No newline at end of file diff --git a/man/figures/lifecycle-experimental.svg b/man/figures/lifecycle-experimental.svg new file mode 100644 index 00000000..2a468612 --- /dev/null +++ b/man/figures/lifecycle-experimental.svg @@ -0,0 +1 @@ +lifecyclelifecycleexperimentalexperimental \ No newline at end of file diff --git a/man/figures/lifecycle-maturing.svg b/man/figures/lifecycle-maturing.svg new file mode 100644 index 00000000..62b17df8 --- /dev/null +++ b/man/figures/lifecycle-maturing.svg @@ -0,0 +1 @@ +lifecyclelifecyclematuringmaturing \ No newline at end of file diff --git a/man/figures/lifecycle-questioning.svg b/man/figures/lifecycle-questioning.svg new file mode 100644 index 00000000..b81ac409 --- /dev/null +++ b/man/figures/lifecycle-questioning.svg @@ -0,0 +1 @@ +lifecyclelifecyclequestioningquestioning \ No newline at end of file diff --git a/man/figures/lifecycle-stable.svg b/man/figures/lifecycle-stable.svg new file mode 100644 index 00000000..08c424c9 --- /dev/null +++ b/man/figures/lifecycle-stable.svg @@ -0,0 +1 @@ +lifecyclelifecyclestablestable \ No newline at end of file diff --git a/man/figures/lifecycle-superseded.svg b/man/figures/lifecycle-superseded.svg new file mode 100644 index 00000000..d4d98c42 --- /dev/null +++ b/man/figures/lifecycle-superseded.svg @@ -0,0 +1 @@ +lifecyclelifecyclesupersededsuperseded \ No newline at end of file diff --git a/man/figures/logo.png b/man/figures/logo.png index fe0f25d7..c384b285 100644 Binary files a/man/figures/logo.png and b/man/figures/logo.png differ diff --git a/man/leaflet.providersESP.df.Rd b/man/leaflet.providersESP.df.Rd index bd0adbab..9560ec49 100644 --- a/man/leaflet.providersESP.df.Rd +++ b/man/leaflet.providersESP.df.Rd @@ -4,145 +4,30 @@ \encoding{UTF-8} \name{leaflet.providersESP.df} \alias{leaflet.providersESP.df} -\title{Public WMS and WMTS of Spain} +\title{(Superseded) Database of public WMS and WMTS of Spain} \format{ -A data frame object with a list of the required parameters for calling +A \code{data.frame} object with a list of the required parameters for calling the service: -\itemize{ -\item \strong{provider}: Provider name. -\item \strong{field}: Description of \code{value}. -\item \strong{value}: INE code of each province. +\describe{ +\item{provider}{Provider name}. +\item{field}{Description of \code{value}}. +\item{value}{INE code of each province}. } } \source{ \url{https://dieghernan.github.io/leaflet-providersESP/} leaflet plugin, -\strong{v1.2.0}. +\strong{v1.3.3}. } \description{ -A data frame containing information of different public WMS and WMTS -providers of Spain +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} -This function is a implementation of the javascript plugin -\href{https://dieghernan.github.io/leaflet-providersESP/}{leaflet-providersESP} -\strong{v1.2.0}. -} -\details{ -Providers available to be passed to \code{type} on \code{\link[=esp_getTiles]{esp_getTiles()}} are:\tabular{l}{ - provider \cr - 'IDErioja' \cr - 'IGNBase' \cr - 'IGNBase.Todo' \cr - 'IGNBase.Gris' \cr - 'IGNBase.TodoNoFondo' \cr - 'IGNBase.Orto' \cr - 'MDT' \cr - 'MDT.Elevaciones' \cr - 'MDT.Relieve' \cr - 'MDT.CurvasNivel' \cr - 'PNOA' \cr - 'PNOA.MaximaActualidad' \cr - 'PNOA.Mosaico' \cr - 'OcupacionSuelo' \cr - 'OcupacionSuelo.Ocupacion' \cr - 'OcupacionSuelo.Usos' \cr - 'LiDAR' \cr - 'MTN' \cr - 'Geofisica' \cr - 'Geofisica.Terremotos10dias' \cr - 'Geofisica.Terremotos30dias' \cr - 'Geofisica.Terremotos365dias' \cr - 'Geofisica.VigilanciaVolcanica' \cr - 'CaminoDeSantiago' \cr - 'CaminoDeSantiago.CaminoFrances' \cr - 'CaminoDeSantiago.CaminosTuronensis' \cr - 'CaminoDeSantiago.CaminosGalicia' \cr - 'CaminoDeSantiago.CaminosDelNorte' \cr - 'CaminoDeSantiago.CaminosAndaluces' \cr - 'CaminoDeSantiago.CaminosCentro' \cr - 'CaminoDeSantiago.CaminosEste' \cr - 'CaminoDeSantiago.CaminosCatalanes' \cr - 'CaminoDeSantiago.CaminosSureste' \cr - 'CaminoDeSantiago.CaminosInsulares' \cr - 'CaminoDeSantiago.CaminosPiemonts' \cr - 'CaminoDeSantiago.CaminosTolosana' \cr - 'CaminoDeSantiago.CaminosPortugueses' \cr - 'Catastro' \cr - 'Catastro.Catastro' \cr - 'Catastro.Parcela' \cr - 'Catastro.CadastralParcel' \cr - 'Catastro.CadastralZoning' \cr - 'Catastro.Address' \cr - 'Catastro.Building' \cr - 'RedTransporte' \cr - 'RedTransporte.Carreteras' \cr - 'RedTransporte.Ferroviario' \cr - 'RedTransporte.Aerodromo' \cr - 'RedTransporte.AreaServicio' \cr - 'RedTransporte.EstacionesFerroviario' \cr - 'RedTransporte.Puertos' \cr - 'Cartociudad' \cr - 'Cartociudad.CodigosPostales' \cr - 'Cartociudad.Direcciones' \cr - 'NombresGeograficos' \cr - 'UnidadesAdm' \cr - 'UnidadesAdm.Limites' \cr - 'UnidadesAdm.Unidades' \cr - 'Hidrografia' \cr - 'Hidrografia.MasaAgua' \cr - 'Hidrografia.Cuencas' \cr - 'Hidrografia.Subcuencas' \cr - 'Hidrografia.POI' \cr - 'Hidrografia.ManMade' \cr - 'Hidrografia.LineaCosta' \cr - 'Hidrografia.Rios' \cr - 'Hidrografia.Humedales' \cr - 'Militar' \cr - 'Militar.CEGET1M' \cr - 'Militar.CEGETM7814' \cr - 'Militar.CEGETM7815' \cr - 'Militar.CEGETM682' \cr - 'Militar.CECAF1M' \cr - 'ADIF' \cr - 'ADIF.Vias' \cr - 'ADIF.Nodos' \cr - 'ADIF.Estaciones' \cr - 'LimitesMaritimos' \cr - 'LimitesMaritimos.LimitesMaritimos' \cr - 'LimitesMaritimos.LineasBase' \cr - 'Copernicus' \cr - 'Copernicus.LandCover' \cr - 'Copernicus.Forest' \cr - 'Copernicus.ForestLeaf' \cr - 'Copernicus.WaterWet' \cr - 'Copernicus.SoilSeal' \cr - 'Copernicus.GrassLand' \cr - 'Copernicus.Local' \cr - 'Copernicus.RiparianGreen' \cr - 'Copernicus.RiparianLandCover' \cr - 'Copernicus.Natura2k' \cr - 'Copernicus.UrbanAtlas' \cr - 'ParquesNaturales' \cr - 'ParquesNaturales.Limites' \cr - 'ParquesNaturales.ZonasPerifericas' \cr -} +This \code{data.frame} is not longer in use by \CRANpkg{mapSpain}. See +\link{esp_tiles_providers} instead. + +A \code{data.frame} containing information of different public WMS and WMTS +providers of Spain } \examples{ data("leaflet.providersESP.df") - -library(tibble) - -as_tibble(leaflet.providersESP.df) -} -\seealso{ -Other datasets: -\code{\link{esp_codelist}}, -\code{\link{esp_munic.sf}}, -\code{\link{esp_nuts.sf}}, -\code{\link{pobmun19}} - -Other imagery utilities: -\code{\link{addProviderEspTiles}()}, -\code{\link{esp_getTiles}()} } -\concept{datasets} -\concept{imagery utilities} +\keyword{internal} diff --git a/man/mapSpain-package.Rd b/man/mapSpain-package.Rd index b4156a29..2a51dbe6 100644 --- a/man/mapSpain-package.Rd +++ b/man/mapSpain-package.Rd @@ -2,73 +2,25 @@ % Please edit documentation in R/mapSpain-package.R \docType{package} \name{mapSpain-package} -\alias{mapSpain-package} \alias{mapSpain} -\title{mapSpain package} -\source{ -\href{https://ec.europa.eu/eurostat/web/gisco/geodata}{GISCO webpage} -} +\alias{mapSpain-package} +\title{mapSpain: Administrative Boundaries of Spain} \description{ -\if{html}{\figure{logo.png}{options: width=120 alt="mapSpain logo" align='right'}} -This package provides Administrative Boundaries of Spain based on -the GISCO (Geographic Information System of the Commission) Eurostat -database and CartoBase SIANE from -Instituto Geográfico Nacional. -} -\details{ -\tabular{ll}{ - \tab \cr - \strong{Package} \tab mapSpain \cr - \strong{Type} \tab Package \cr - \strong{Version} \tab 0.3.0.9000 \cr - \strong{Date} \tab 2021 \cr - \strong{License} \tab GPL-3 \cr - \strong{LazyLoad} \tab yes \cr -} -} -\section{COPYRIGHT NOTICE (IGN)}{ -This package uses data from CartoBase SIANE, provided by Instituto -Geografico Nacional (IGN): +\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} -Atlas Nacional de España (ANE) -\href{https://creativecommons.org/licenses/by/4.0/deed.en}{CC BY 4.0} -\href{https://www.ign.es/}{ign.es} +Administrative Boundaries of Spain at several levels (Autonomous Communities, Provinces, Municipalities) based on the 'GISCO' 'Eurostat' database \url{https://ec.europa.eu/eurostat/web/gisco} and 'CartoBase SIANE' from 'Instituto Geografico Nacional' \url{https://www.ign.es/}. It also provides a 'leaflet' plugin and the ability of downloading and processing static tiles. } - -\section{COPYRIGHT NOTICE (GISCO)}{ -When data downloaded from GISCO -is used in any printed or electronic publication, -in addition to any other provisions -applicable to the whole Eurostat website, -data source will have to be acknowledged -in the legend of the map and -in the introductory page of the publication -with the following copyright notice: +\seealso{ +Useful links: \itemize{ -\item EN: (C) EuroGeographics for the administrative boundaries -\item FR: (C) EuroGeographics pour les limites administratives -\item DE: (C) EuroGeographics bezüglich der Verwaltungsgrenzen + \item \url{https://ropenspain.github.io/mapSpain/} + \item \url{https://github.com/rOpenSpain/mapSpain} + \item Report bugs at \url{https://github.com/rOpenSpain/mapSpain/issues} } -For publications in languages other than -English, French or German, -the translation of the copyright notice -in the language of the publication shall be used. - -If you intend to use the data commercially, -please contact EuroGeographics for -information regarding their license agreements. } +\author{ +\strong{Maintainer}: Diego Hernangómez \email{diego.hernangomezherrero@gmail.com} (\href{https://orcid.org/0000-0001-8457-4658}{ORCID}) [copyright holder] -\references{ -See \code{citation("mapSpain")}. -} -\seealso{ -Useful links: -\itemize{ -\item \url{https://ropenspain.github.io/mapSpain/} -\item \url{https://github.com/rOpenSpain/mapSpain} -\item Report bugs at \url{https://github.com/rOpenSpain/mapSpain/issues} -} } -\keyword{package} +\keyword{internal} diff --git a/man/pobmun19.Rd b/man/pobmun19.Rd index 231100cb..6ba96970 100644 --- a/man/pobmun19.Rd +++ b/man/pobmun19.Rd @@ -3,26 +3,36 @@ \docType{data} \name{pobmun19} \alias{pobmun19} -\title{Population by municipality (2019)} +\title{Database with the population of Spain by municipality (2019)} +\format{ +An example \code{data.frame} object with +8,131 rows containing the +population data by municipality in Spain (2019). + +\describe{ +\item{cpro}{INE code of the province.} +\item{provincia}{name of the province.} +\item{cmun}{INE code of the municipality.} +\item{name}{Name of the municipality.} +\item{pob19}{Overall population (2019)} +\item{men}{Men population (2019)} +\item{women}{Women population (2019)} +} +} \source{ INE: Instituto Nacional de Estadistica \url{https://www.ine.es/} } \description{ -A data frame with 8,131 -rows containing the population data by municipality in Spain (2019). +Database with the population of Spain by municipality (2019) } \examples{ data("pobmun19") - -library(tibble) - -as_tibble(pobmun19) } \seealso{ Other datasets: \code{\link{esp_codelist}}, \code{\link{esp_munic.sf}}, \code{\link{esp_nuts.sf}}, -\code{\link{leaflet.providersESP.df}} +\code{\link{esp_tiles_providers}} } \concept{datasets} diff --git a/mapSpain.Rproj b/mapSpain.Rproj index f0d61875..eb71633c 100644 --- a/mapSpain.Rproj +++ b/mapSpain.Rproj @@ -14,8 +14,12 @@ LaTeX: pdfLaTeX AutoAppendNewline: Yes StripTrailingWhitespace: Yes +LineEndingConversion: Posix BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source PackageRoxygenize: rd,collate,namespace,vignette + +MarkdownWrap: Column +MarkdownWrapAtColumn: 80 diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 5a91d23d..cede23ba 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -1,73 +1,122 @@ -url: https://ropenspain.github.io/mapSpain +url: 'https://ropenspain.github.io/mapSpain' +repo: + branch: main reference: - - title: "Political" - desc: These functions return `sf` objects with political boundaries + - title: Political + desc: > + These functions return sf objects with + political boundaries. contents: - has_concept("political") - - -esp_codelist - - - title: "Natural" - desc: These functions return `sf` objects with natural features + - giscoR::gisco_get_nuts() + - title: Natural + desc: > + These functions return sf objects with natural + features. contents: - has_concept("natural") - - - title: "Infrastructures" - desc: These functions return `sf` objects with man-made features + - title: Infrastructures + desc: > + These functions return sf objects with + man-made features. contents: - has_concept("infrastructure") - - title: Tiles - desc: Return static tiles or create a leaflet map + desc: > + Return static tiles or create a leaflet map. contents: - has_concept("imagery utilities") - - -leaflet.providersESP.df - + - ggplot2::geom_sf() + - tidyterra::geom_spatraster_rgb() + - title: Geographic grids + contents: + - has_concept("grids") - title: Cache management contents: - has_concept("cache utilities") - - - title: "Dictionary" - desc: Translation across languages and coding systems + - title: Dictionary + desc: > + Translation across languages and coding systems. contents: - esp_dict_region_code - - - title: "Datasets" - desc: These objects are datasets already included in the package. + - title: Datasets + desc: > + These objects are datasets already included in the package. contents: - has_concept("datasets") - - title: Helpers - desc: A collection of helper functions + desc: > + A collection of helper functions. contents: - has_concept("helper") - - - title: "About the package" + - title: About the package contents: - mapSpain-package template: + bootstrap: 5 package: rostemplate params: - ganalytics: 'G-PWKD479RCT' + ganalytics: "G-5N21Z0YYJJ" docsearch: - api_key: '2621bfcaa3de971834f4026466317ee7' - index_name: 'mapSpain' + api_key: "2621bfcaa3de971834f4026466317ee7" + index_name: mapSpain opengraph: twitter: - creator: "@dhernangomez" - site: "@rOpenSpain" + creator: '@dhernangomez' + site: '@rOpenSpain' card: summary_large_image home: - title: mapSpain | Administrative Boundaries of Spain Including CCAA, Provinces and Municipalities - description: Administrative Boundaries of Spain based on the GISCO (Geographic Information System of the Commission) Eurostat database. It also provides a leaflet plugin and the ability of downloading and processing static tiles. + title: >- + mapSpain | Administrative Boundaries of Spain Including CCAA, Provinces and + Municipalities + description: >- + Administrative Boundaries of Spain based on the GISCO (Geographic + Information System of the Commission) Eurostat database. It also provides a + leaflet plugin and the ability of downloading and processing static tiles. + +navbar: + structure: + right: + - search + - twitter + - github + components: + home: ~ + articles: + text: Articles + menu: + - text: Working with imagery + href: articles/articles/working_imagery.html + - text: 'Annex: Codes and names of the Spanish regions' + href: articles/articles/x01_regioncodes.html + - text: ----- + - text: Other materials + - text: 'mapSpain: Mapas de España en R (xaringan)' + href: 'https://dieghernan.github.io/rpubs/mapSpain_slides/' + - text: 'mapSpain: Mapas de España en R (.Rmd)' + href: articles/articles/x02_mapasesp.html + - text: 'Grupo de Usuarios R Madrid 25-nov-2021 (video)' + href: 'http://madrid.r-es.org/69-jueves-25-de-noviembre-de-2021/' + twitter: + icon: fa-twitter + href: 'http://twitter.com/dhernangomez' + aria-label: Twitter authors: Diego Hernangómez: - href: https://dieghernan.github.io/ + href: 'https://dieghernan.github.io/' EuroGeographics: - href: https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units + href: >- + https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/administrative-units-statistical-units Instituto Geográfico Nacional: - href: https://www.ign.es/ + href: 'https://www.ign.es/' + diff --git a/pkgdown/favicon/apple-touch-icon-120x120.png b/pkgdown/favicon/apple-touch-icon-120x120.png index 76cb1e9b..e4681d49 100644 Binary files a/pkgdown/favicon/apple-touch-icon-120x120.png and b/pkgdown/favicon/apple-touch-icon-120x120.png differ diff --git a/pkgdown/favicon/apple-touch-icon-152x152.png b/pkgdown/favicon/apple-touch-icon-152x152.png index 02a6383d..b690e80d 100644 Binary files a/pkgdown/favicon/apple-touch-icon-152x152.png and b/pkgdown/favicon/apple-touch-icon-152x152.png differ diff --git a/pkgdown/favicon/apple-touch-icon-180x180.png b/pkgdown/favicon/apple-touch-icon-180x180.png index f7f5b376..36424b02 100644 Binary files a/pkgdown/favicon/apple-touch-icon-180x180.png and b/pkgdown/favicon/apple-touch-icon-180x180.png differ diff --git a/pkgdown/favicon/apple-touch-icon-60x60.png b/pkgdown/favicon/apple-touch-icon-60x60.png index f72fc790..98484b1b 100644 Binary files a/pkgdown/favicon/apple-touch-icon-60x60.png and b/pkgdown/favicon/apple-touch-icon-60x60.png differ diff --git a/pkgdown/favicon/apple-touch-icon-76x76.png b/pkgdown/favicon/apple-touch-icon-76x76.png index 2e71af58..a68c7c64 100644 Binary files a/pkgdown/favicon/apple-touch-icon-76x76.png and b/pkgdown/favicon/apple-touch-icon-76x76.png differ diff --git a/pkgdown/favicon/apple-touch-icon.png b/pkgdown/favicon/apple-touch-icon.png index f7f5b376..36424b02 100644 Binary files a/pkgdown/favicon/apple-touch-icon.png and b/pkgdown/favicon/apple-touch-icon.png differ diff --git a/pkgdown/favicon/favicon-16x16.png b/pkgdown/favicon/favicon-16x16.png index 6b6e17d2..de3e0a18 100644 Binary files a/pkgdown/favicon/favicon-16x16.png and b/pkgdown/favicon/favicon-16x16.png differ diff --git a/pkgdown/favicon/favicon-32x32.png b/pkgdown/favicon/favicon-32x32.png index 6cecaec0..3b5fb4be 100644 Binary files a/pkgdown/favicon/favicon-32x32.png and b/pkgdown/favicon/favicon-32x32.png differ diff --git a/pkgdown/favicon/favicon.ico b/pkgdown/favicon/favicon.ico index b665f051..ce32a60f 100644 Binary files a/pkgdown/favicon/favicon.ico and b/pkgdown/favicon/favicon.ico differ diff --git a/revdep/.gitignore b/revdep/.gitignore new file mode 100644 index 00000000..d3ac4e16 --- /dev/null +++ b/revdep/.gitignore @@ -0,0 +1,9 @@ +checks +library +checks.noindex +library.noindex +data.sqlite +*.html +download +lib +cloud.noindex diff --git a/revdep/README.md b/revdep/README.md new file mode 100644 index 00000000..63feb4b3 --- /dev/null +++ b/revdep/README.md @@ -0,0 +1,43 @@ +# Platform + +|field |value | +|:--------|:------------------------------------------| +|version |R version 4.4.2 (2024-10-31 ucrt) | +|os |Windows 11 x64 (build 26100) | +|system |x86_64, mingw32 | +|ui |RStudio | +|language |(EN) | +|collate |Spanish_Spain.utf8 | +|ctype |Spanish_Spain.utf8 | +|tz |Europe/Madrid | +|date |2024-12-15 | +|rstudio |2024.09.1+394 Cranberry Hibiscus (desktop) | +|pandoc |3.1.12.2 @ C:\PROGRA~1\Pandoc\pandoc.exe | + +# Dependencies + +|package |old |new |Δ | +|:-----------|:--------|:--------|:--| +|mapSpain |0.9.2 |0.10.0 |* | +|classInt |0.4-10 |0.4-10 | | +|countrycode |1.6.0 |1.6.0 | | +|DBI |1.2.3 |1.2.3 | | +|e1071 |1.7-16 |1.7-16 | | +|geojsonsf |2.0.3 |2.0.3 | | +|geometries |0.2.4 |0.2.4 | | +|giscoR |0.6.0 |0.6.0 | | +|jsonify |1.2.2 |1.2.2 | | +|jsonlite |1.8.9 |1.8.9 | | +|magrittr |2.0.3 |2.0.3 | | +|proxy |0.4-27 |0.4-27 | | +|rapidjsonr |1.2.0 |1.2.0 | | +|rappdirs |0.3.3 |0.3.3 | | +|Rcpp |1.0.13-1 |1.0.13-1 | | +|s2 |1.1.7 |1.1.7 | | +|sf |1.0-19 |1.0-19 | | +|sfheaders |0.4.4 |0.4.4 | | +|units |0.8-5 |0.8-5 | | +|wk |0.9.4 |0.9.4 | | + +# Revdeps + diff --git a/revdep/cran.md b/revdep/cran.md new file mode 100644 index 00000000..29c19611 --- /dev/null +++ b/revdep/cran.md @@ -0,0 +1,7 @@ +## revdepcheck results + +We checked 3 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. + + * We saw 0 new problems + * We failed to check 0 packages + diff --git a/revdep/failures.md b/revdep/failures.md new file mode 100644 index 00000000..9a207363 --- /dev/null +++ b/revdep/failures.md @@ -0,0 +1 @@ +*Wow, no problems at all. :)* \ No newline at end of file diff --git a/revdep/problems.md b/revdep/problems.md new file mode 100644 index 00000000..9a207363 --- /dev/null +++ b/revdep/problems.md @@ -0,0 +1 @@ +*Wow, no problems at all. :)* \ No newline at end of file diff --git a/tests/testthat/_snaps/esp_getTiles/frombbox.png b/tests/testthat/_snaps/esp_getTiles/frombbox.png new file mode 100644 index 00000000..e7241726 Binary files /dev/null and b/tests/testthat/_snaps/esp_getTiles/frombbox.png differ diff --git a/tests/testthat/_snaps/esp_getTiles/opaque.png b/tests/testthat/_snaps/esp_getTiles/opaque.png new file mode 100644 index 00000000..3e6572b6 Binary files /dev/null and b/tests/testthat/_snaps/esp_getTiles/opaque.png differ diff --git a/tests/testthat/_snaps/esp_getTiles/point.png b/tests/testthat/_snaps/esp_getTiles/point.png new file mode 100644 index 00000000..0c8e4b50 Binary files /dev/null and b/tests/testthat/_snaps/esp_getTiles/point.png differ diff --git a/tests/testthat/_snaps/esp_getTiles/sfc.png b/tests/testthat/_snaps/esp_getTiles/sfc.png new file mode 100644 index 00000000..e7241726 Binary files /dev/null and b/tests/testthat/_snaps/esp_getTiles/sfc.png differ diff --git a/tests/testthat/_snaps/esp_getTiles/silent.png b/tests/testthat/_snaps/esp_getTiles/silent.png new file mode 100644 index 00000000..2558a025 Binary files /dev/null and b/tests/testthat/_snaps/esp_getTiles/silent.png differ diff --git a/tests/testthat/_snaps/esp_getTiles/transp.png b/tests/testthat/_snaps/esp_getTiles/transp.png new file mode 100644 index 00000000..565ef3ac Binary files /dev/null and b/tests/testthat/_snaps/esp_getTiles/transp.png differ diff --git a/tests/testthat/test-addProviderEspTiles.R b/tests/testthat/test-addProviderEspTiles.R index 1c1465a6..8cbee6e2 100644 --- a/tests/testthat/test-addProviderEspTiles.R +++ b/tests/testthat/test-addProviderEspTiles.R @@ -1,4 +1,7 @@ test_that("Testing leaflet", { + skip_if_not_installed("leaflet") + skip_on_cran() + library(leaflet) expect_silent(providerEspTileOptions()) @@ -20,7 +23,7 @@ test_that("Testing leaflet", { lng = -3.7038400, zoom = 18 ) %>% - addProviderEspTiles(provider = "IGNBase.Gris") %>% + addProviderEspTiles(provider = "IDErioja.Claro") %>% addProviderEspTiles(provider = "RedTransporte.Carreteras") ) }) diff --git a/tests/testthat/test-esp_cache.R b/tests/testthat/test-esp_cache.R new file mode 100644 index 00000000..9f353f84 --- /dev/null +++ b/tests/testthat/test-esp_cache.R @@ -0,0 +1,46 @@ +test_that("Test cache online", { + # Get current cache dir + current <- esp_detect_cache_dir() + + cat("User cache dir is ", current, "\n") + + # Set a temp cache dir + expect_message(esp_set_cache_dir(verbose = TRUE)) + testdir <- expect_silent(esp_set_cache_dir( + file.path(current, "testthat"), + verbose = FALSE + )) + + expect_identical(esp_detect_cache_dir(), testdir) + + # Clean + expect_silent(esp_clear_cache(config = FALSE, verbose = FALSE)) + # Cache dir should be deleted now + expect_false(dir.exists(testdir)) + + + # Reset just for testing all cases + testdir <- file.path(tempdir(), "mapSpain", "testthat") + expect_message(esp_set_cache_dir(testdir)) + + cat("Testing cache dir is ", Sys.getenv("MAPSPAIN_CACHE_DIR"), "\n") + + + skip_on_cran() + skip_if_siane_offline() + + expect_message(esp_get_ccaa_siane(verbose = TRUE)) + + expect_true(dir.exists(testdir)) + + expect_message(esp_clear_cache(config = FALSE, verbose = TRUE)) + + # Cache dir should be deleted now + expect_false(dir.exists(testdir)) + + # Restore cache + expect_message(esp_set_cache_dir(current, verbose = TRUE)) + expect_silent(esp_set_cache_dir(current, verbose = FALSE)) + expect_equal(current, Sys.getenv("MAPSPAIN_CACHE_DIR")) + expect_true(dir.exists(current)) +}) diff --git a/tests/testthat/test-esp_dict.R b/tests/testthat/test-esp_dict.R index 211c71f9..05a3d493 100644 --- a/tests/testthat/test-esp_dict.R +++ b/tests/testthat/test-esp_dict.R @@ -9,6 +9,22 @@ test_that("Testing dict", { expect_silent(esp_dict_region_code(vals, destination = "cpro")) expect_silent(esp_dict_region_code(vals, destination = "iso2")) + # test fix on new database + expect_silent( + esp_dict_region_code( + c( + "Ciudad Autónoma de Ceuta", + "Ciudad Autónoma de Melilla", + "Región de Murcia", + "Principado de Asturias", + "Ciudad de Ceuta", + "Ciudad de Melilla", + "Sta. Cruz de Tenerife" + ), + destination = "cpro" + ) + ) + # test different casing of strings expect_silent(esp_dict_region_code(c( "AlBaceTe", @@ -60,4 +76,18 @@ test_that("Testing dict", { expect_false(all(vals == test)) expect_true(all(vals == esp_dict_translate(test, "es"))) + expect_silent( + esp_dict_translate( + c( + "Ciudad Autónoma de Ceuta", + "Ciudad Autónoma de Melilla", + "Región de Murcia", + "Principado de Asturias", + "Ciudad de Ceuta", + "Ciudad de Melilla", + "Sta. Cruz de Tenerife" + ), + lang = "eu" + ) + ) }) diff --git a/tests/testthat/test-esp_getTiles.R b/tests/testthat/test-esp_getTiles.R index 4e4b8944..69bdd9f0 100644 --- a/tests/testthat/test-esp_getTiles.R +++ b/tests/testthat/test-esp_getTiles.R @@ -1,43 +1,306 @@ -poly <- esp_get_ccaa("La Rioja") -expect_error(esp_getTiles(poly, type = "FFF")) +test_that("tiles error", { + skip_if_not_installed("terra") + + + df <- data.frame(a = 1, b = 2) + + expect_error(esp_getTiles(df), "Only sf and sfc objects allowed") + + ff <- esp_get_prov("La Rioja") + + expect_error(esp_getTiles(ff, + type = "IGNBase", + options = list(format = "image/aabbcc") + )) + expect_error(esp_getTiles(ff, type = list(format = "image/aabbcc"))) +}) + test_that("tiles online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + poly <- esp_get_ccaa("La Rioja") + expect_error(esp_getTiles(poly, type = "FFF")) # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + skip_on_os("linux") + + save_png <- function(code, width = 200, height = 200) { + path <- tempfile(fileext = ".png") + png(path, width = width, height = height) + on.exit(dev.off()) + terra::plotRGB(code) + + path + } + expect_s4_class(esp_getTiles(poly, "IGNBase.Todo"), "SpatRaster") + + expect_message(esp_getTiles(poly, + "IGNBase.Todo", + zoom = 7, + verbose = TRUE, + update_cache = TRUE + )) + + + s <- esp_getTiles(poly, "IGNBase.Todo", zoom = 7) + + + # With sfc + geom <- sf::st_geometry(poly) + + # Convert from bbox + + bbox <- sf::st_bbox(poly) + expect_error(esp_getTiles(bbox, "IGNBase.Todo", zoom = 7)) + expect_silent(esp_getTiles(sf::st_as_sfc(bbox), "IGNBase.Todo", + zoom = 7 + )) + + frombbox <- esp_getTiles(sf::st_as_sfc(bbox), "IGNBase.Todo", + zoom = 7 + ) + + expect_s3_class(geom, "sfc") + + expect_silent(esp_getTiles(geom, "IGNBase.Todo", + zoom = 7 + )) - expect_true("RasterBrick" %in% class(esp_getTiles(poly))) - expect_message(esp_getTiles(poly, zoom = 5, verbose = TRUE)) - expect_message(esp_getTiles(sf::st_geometry(poly), verbose = TRUE)) - expect_message(esp_getTiles(poly, verbose = TRUE)) + sfc <- esp_getTiles(geom, "IGNBase.Todo", zoom = 7) + + # From cache + expect_message(esp_getTiles(poly, "IGNBase.Todo", + zoom = 7, verbose = TRUE + )) + expect_message(esp_getTiles(poly, "IGNBase.Todo", + zoom = 7, verbose = TRUE + )) expect_message(esp_getTiles( poly, - zoom = 2, + zoom = 7, verbose = TRUE, type = "IGNBase.Orto" )) + expect_message(esp_getTiles(poly, + type = "PNOA", + verbose = TRUE, mask = TRUE + )) + expect_message(esp_getTiles(poly, + type = "PNOA", + verbose = TRUE, mask = TRUE + )) + + + # Try with jpg + provs <- leaflet.providersESP.df + jpeg <- provs[provs$value == "jpeg", ] + + expect_message(esp_getTiles(poly, + type = as.character(jpeg$provider[1]), + verbose = TRUE + )) + + s <- esp_getTiles(poly, + type = jpeg$provider + ) + + expect_s4_class(s, "SpatRaster") + + # Check layers + n <- expect_silent(esp_getTiles(poly, + type = "Catastro" + )) + + + expect_equal(terra::nlyr(n), 4) + + opaque <- expect_silent(esp_getTiles(poly, + type = "Catastro", + transparent = FALSE + )) + + expect_equal(terra::nlyr(opaque), 3) + + # Run only locally + skip_on_ci() + # Single point point <- esp_get_ccaa("Madrid") point <- sf::st_transform(point, 3857) - point <- sf::st_sample(point, 1) + point <- sf::st_centroid( + sf::st_geometry(point), + of_largest_polygon = TRUE + ) + expect_length(point, 1) + expect_s3_class(point, "sfc_POINT") expect_message(esp_getTiles(point, - type = "RedTransporte.Carreteras", + "IGNBase.Todo", verbose = TRUE )) - expect_message(esp_getTiles(poly, - type = "RedTransporte.Carreteras", - verbose = TRUE, mask = TRUE - )) - expect_message(esp_getTiles(poly, - type = "RedTransporte.Carreteras", - verbose = TRUE, mask = TRUE - )) + + p <- esp_getTiles(point, "IGNBase.Todo", verbose = TRUE) + + + + expect_snapshot_file(save_png(opaque), "opaque.png") + expect_snapshot_file(save_png(n), "transp.png") + expect_snapshot_file(save_png(s), "silent.png") + expect_snapshot_file(save_png(p), "point.png") + expect_snapshot_file(save_png(sfc), "sfc.png") + expect_snapshot_file(save_png(frombbox), "frombbox.png") +}) + + +test_that("tiles masks and crops", { + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + + poly <- esp_get_ccaa("La Rioja", epsg = 4326) + tile <- esp_getTiles(poly, "IGNBase.Todo", crop = FALSE) + expect_s4_class(tile, "SpatRaster") + + tilecrop <- esp_getTiles(poly, "IGNBase.Todo", crop = TRUE) + expect_s4_class(tilecrop, "SpatRaster") + + tilemask <- esp_getTiles(poly, "IGNBase.Todo", mask = TRUE) + expect_s4_class(tilemask, "SpatRaster") + + # Try with EPSG 3857 + + poly <- esp_get_ccaa("La Rioja", epsg = 3857) + tile <- esp_getTiles(poly, "IGNBase.Todo", crop = FALSE) + expect_s4_class(tile, "SpatRaster") + + tilecrop <- esp_getTiles(poly, "IGNBase.Todo", crop = TRUE) + expect_s4_class(tilecrop, "SpatRaster") + + tilemask <- esp_getTiles(poly, "IGNBase.Todo", mask = TRUE) + expect_s4_class(tilemask, "SpatRaster") +}) + + +test_that("tiles options", { + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + + poly <- esp_get_capimun(munic = "^Santiago de compos", epsg = 3857) + poly <- sf::st_buffer(poly, 2000) + + tile2 <- esp_getTiles(poly, + type = "CaminoDeSantiago", + options = list( + version = "1.3.0", + crs = "EPSG:25830", + format = "image/jpeg" + ) + ) + + expect_s4_class(tile2, "SpatRaster") + + # Known problem on SSH certificate of catastro on ci + skip_on_ci() + tile <- esp_getTiles(poly, + type = "Catastro.Building", + options = list(styles = "elfcadastre") + ) + expect_s4_class(tile, "SpatRaster") +}) + +test_that("Custom WMS", { + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + + segovia <- esp_get_prov("segovia", epsg = 3857) + custom_wms <- list( + id = "new_cached_test", + q = paste0( + "https://idecyl.jcyl.es/geoserver/ge/wms?request=GetMap", + "&service=WMS&version=1.3.0", + "&format=image/png", + "&CRS=epsg:3857", + "&layers=geolog_cyl_litologia", + "&styles=" + ) + ) + + tile <- esp_getTiles(segovia, type = custom_wms) + expect_s4_class(tile, "SpatRaster") +}) + + +test_that("Custom WMTS", { + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + + segovia <- esp_get_prov("segovia", epsg = 3857) + custom_wmts <- list( + id = "cyl_wmts", + q = paste0( + "https://www.ign.es/wmts/ign-base?", + "request=GetTile&service=WMTS&version=1.0.0", + "&format=image/png", + "&tilematrixset=GoogleMapsCompatible", + "&layer=IGNBaseTodo-nofondo&style=default" + ) + ) + + + tile <- esp_getTiles(segovia, type = custom_wmts) + expect_s4_class(tile, "SpatRaster") + + # Non-INSPIRE e.g OSM + another_wms <- list( + id = "OSM2", + q = "https://tile.openstreetmap.org/{z}/{x}/{y}.png" + ) + + tile2 <- esp_getTiles(segovia, type = another_wms) + expect_s4_class(tile2, "SpatRaster") + + # With another extension + esri_wsm <- list( + id = "ESRI_WorldStreetMap", + q = paste0( + "https://server.arcgisonline.com/ArcGIS/rest/services/", + "World_Street_Map/MapServer/tile/{z}/{y}/{x}.jpg" + ) + ) + + tile3 <- esp_getTiles(segovia, type = esri_wsm) + expect_s4_class(tile3, "SpatRaster") }) diff --git a/tests/testthat/test-esp_get_capimun.R b/tests/testthat/test-esp_get_capimun.R index 963188a0..574d5eb8 100644 --- a/tests/testthat/test-esp_get_capimun.R +++ b/tests/testthat/test-esp_get_capimun.R @@ -1,9 +1,7 @@ - test_that("capimun online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() expect_silent(esp_get_capimun()) expect_silent(esp_get_capimun(rawcols = TRUE)) diff --git a/tests/testthat/test-esp_get_ccaa.R b/tests/testthat/test-esp_get_ccaa.R index 053f8c77..2d118dc1 100644 --- a/tests/testthat/test-esp_get_ccaa.R +++ b/tests/testthat/test-esp_get_ccaa.R @@ -1,9 +1,9 @@ test_that("CCAA", { - expect_error(esp_get_ccaa("FFF")) + expect_warning(expect_error(esp_get_ccaa("FFF"))) expect_silent(esp_get_ccaa()) expect_silent(esp_get_ccaa(ccaa = c("Galicia", "ES7", "Centro"))) expect_warning(esp_get_ccaa(ccaa = "Zamora")) - expect_error(esp_get_ccaa(ccaa = "ES6x")) + expect_warning(expect_error(esp_get_ccaa(ccaa = "ES6x"))) expect_warning(esp_get_ccaa(ccaa = "Barcelona")) # Test all @@ -13,7 +13,7 @@ test_that("CCAA", { n <- esp_get_ccaa(ccaa = f$nuts1.code) expect_equal(nrow(n), 19) - n <- esp_get_ccaa(ccaa = c("Melilla")) + n <- esp_get_ccaa(ccaa = "Melilla") expect_equal(nrow(n), 1) n <- esp_get_ccaa(ccaa = f$nuts1.name.alt) @@ -34,17 +34,17 @@ test_that("CCAA", { # Test siane test_that("ccaa online", { - expect_warning(expect_error(esp_get_ccaa_siane("FFF"))) + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() + expect_error(esp_get_ccaa_siane(epsg = "FFF")) - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + expect_silent(esp_get_ccaa_siane()) + expect_message(esp_get_ccaa_siane(cache = FALSE, verbose = TRUE)) - expect_silent(esp_get_ccaa_siane()) expect_silent(esp_get_ccaa_siane("Canarias")) expect_silent(esp_get_ccaa_siane(rawcols = TRUE)) expect_silent(esp_get_ccaa_siane(ccaa = c("Galicia", "ES7", "Centro"))) @@ -75,7 +75,7 @@ test_that("ccaa online", { n <- esp_get_ccaa_siane(ccaa = f$nuts1.code) expect_equal(nrow(n), 19) - n <- esp_get_ccaa_siane(ccaa = c("Melilla")) + n <- esp_get_ccaa_siane(ccaa = "Melilla") expect_equal(nrow(n), 1) n <- esp_get_ccaa_siane(ccaa = f$nuts1.name.alt) diff --git a/tests/testthat/test-esp_get_comarca.R b/tests/testthat/test-esp_get_comarca.R new file mode 100644 index 00000000..3edbf452 --- /dev/null +++ b/tests/testthat/test-esp_get_comarca.R @@ -0,0 +1,35 @@ +test_that("comarcas online", { + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() + + expect_silent(esp_get_comarca()) + + expect_message(esp_get_comarca(verbose = TRUE)) + expect_message(esp_get_comarca(verbose = TRUE, update_cache = TRUE)) + expect_message(esp_get_comarca(region = "Canarias", verbose = TRUE)) + + expect_warning(expect_error(expect_warning(esp_get_comarca(region = "XX")))) + expect_error(esp_get_comarca(epsg = "5689")) + expect_error(expect_warning(esp_get_comarca(comarca = "XX"))) + + expect_silent(esp_get_comarca(moveCAN = FALSE)) + expect_silent(esp_get_comarca(moveCAN = c(0, 10))) + expect_silent(esp_get_comarca(comarca = "Rioja")) + expect_silent(esp_get_comarca(region = "Alava")) + + + a <- mapSpain::esp_codelist + n <- a$nuts1.name + + s <- esp_get_comarca(region = n) + expect_equal(length(unique(s$cpro)), 52) + + # Types + ine <- esp_get_comarca() + ign <- esp_get_comarca(type = "IGN") + agr <- esp_get_comarca(type = "AGR") + liv <- esp_get_comarca(type = "LIV") + + expect_length(unique(c(nrow(ine), nrow(ign), nrow(agr), nrow(liv))), 4) +}) diff --git a/tests/testthat/test-esp_get_country.R b/tests/testthat/test-esp_get_country.R index 993156b3..10fb2417 100644 --- a/tests/testthat/test-esp_get_country.R +++ b/tests/testthat/test-esp_get_country.R @@ -1 +1,3 @@ -expect_silent(esp_get_country()) +test_that("Check country", { + expect_silent(esp_get_country()) +}) diff --git a/tests/testthat/test-esp_get_grid_BDN.R b/tests/testthat/test-esp_get_grid_BDN.R new file mode 100644 index 00000000..81ed87e3 --- /dev/null +++ b/tests/testthat/test-esp_get_grid_BDN.R @@ -0,0 +1,63 @@ +test_that("Errors", { + expect_error(esp_get_grid_BDN("50")) + expect_error(esp_get_grid_BDN(type = "50")) + expect_warning(expect_error(esp_get_grid_BDN_ccaa("Sevilla"))) +}) + +test_that("BDN grid online", { + skip_on_cran() + skip_if_siane_offline() + + expect_message( + esp_get_grid_BDN( + cache_dir = tempdir(), + verbose = TRUE + ) + ) + + expect_message( + esp_get_grid_BDN( + cache_dir = tempdir(), + update_cache = TRUE, + verbose = TRUE + ) + ) + + expect_message( + esp_get_grid_BDN( + type = "canary", + cache_dir = tempdir(), + update_cache = TRUE, + verbose = TRUE + ) + ) + expect_silent(esp_get_grid_BDN( + resolution = 5, type = "canary", + cache_dir = tempdir() + )) +}) + + +test_that("BDN grid online CCAA", { + skip_on_cran() + skip_if_siane_offline() + + expect_message( + esp_get_grid_BDN_ccaa("Ceuta", + cache_dir = tempdir(), + verbose = TRUE + ) + ) + + expect_message( + esp_get_grid_BDN_ccaa("Ceuta", + cache_dir = tempdir(), + update_cache = TRUE, + verbose = TRUE + ) + ) + + expect_silent(esp_get_grid_BDN_ccaa("Melilla", + cache_dir = tempdir() + )) +}) diff --git a/tests/testthat/test-esp_get_grid_EEA.R b/tests/testthat/test-esp_get_grid_EEA.R new file mode 100644 index 00000000..a037fe52 --- /dev/null +++ b/tests/testthat/test-esp_get_grid_EEA.R @@ -0,0 +1,26 @@ +test_that("Errors", { + expect_error(esp_get_grid_EEA("50")) + expect_error(esp_get_grid_EEA(type = "50")) +}) + +test_that("EEA grid online", { + skip_on_cran() + skip_if_siane_offline() + + expect_message( + esp_get_grid_EEA( + cache_dir = tempdir(), + verbose = TRUE + ) + ) + + expect_message( + esp_get_grid_EEA( + cache_dir = tempdir(), + update_cache = TRUE, + verbose = TRUE + ) + ) + expect_silent(esp_get_grid_EEA()) + expect_silent(esp_get_grid_EEA(type = "canary", resolution = 10)) +}) diff --git a/tests/testthat/test-esp_get_grid_ESDAC.R b/tests/testthat/test-esp_get_grid_ESDAC.R new file mode 100644 index 00000000..df8abe70 --- /dev/null +++ b/tests/testthat/test-esp_get_grid_ESDAC.R @@ -0,0 +1,24 @@ +test_that("Errors", { + expect_error(esp_get_grid_ESDAC("50")) +}) + +test_that("ESDAC grid online", { + skip_on_cran() + skip_if_siane_offline() + + expect_message( + esp_get_grid_ESDAC( + cache_dir = tempdir(), + verbose = TRUE + ) + ) + + expect_message( + esp_get_grid_ESDAC( + cache_dir = tempdir(), + update_cache = TRUE, + verbose = TRUE + ) + ) + expect_silent(esp_get_grid_ESDAC()) +}) diff --git a/tests/testthat/test-esp_get_grid_MTN.R b/tests/testthat/test-esp_get_grid_MTN.R new file mode 100644 index 00000000..21e8aa5a --- /dev/null +++ b/tests/testthat/test-esp_get_grid_MTN.R @@ -0,0 +1,25 @@ +test_that("Errors", { + expect_error(esp_get_grid_MTN("abcde")) +}) + + +test_that("MTN grid online", { + skip_on_cran() + skip_if_siane_offline() + + expect_message( + esp_get_grid_MTN( + cache_dir = tempdir(), + verbose = TRUE + ) + ) + + expect_message( + esp_get_grid_MTN( + cache_dir = tempdir(), + update_cache = TRUE, + verbose = TRUE + ) + ) + expect_silent(esp_get_grid_MTN()) +}) diff --git a/tests/testthat/test-esp_get_gridmap.R b/tests/testthat/test-esp_get_gridmap.R index 7f8e8a8b..d0cd4d78 100644 --- a/tests/testthat/test-esp_get_gridmap.R +++ b/tests/testthat/test-esp_get_gridmap.R @@ -1,15 +1,25 @@ -expect_silent(esp_get_hex_ccaa()) -expect_silent(esp_get_hex_prov()) -expect_silent(esp_get_hex_prov("ES1")) -expect_silent(esp_get_hex_ccaa("ES1")) +test_that("Test gridmaps", { + expect_silent(esp_get_hex_ccaa()) + expect_silent(esp_get_hex_prov()) + expect_silent(esp_get_hex_prov("ES1")) + expect_silent(esp_get_hex_ccaa("ES1")) -expect_silent(esp_get_grid_ccaa()) -expect_silent(esp_get_grid_prov()) -expect_silent(esp_get_grid_ccaa("ES1")) -expect_silent(esp_get_grid_prov("ES1")) + expect_silent(esp_get_grid_ccaa()) + expect_silent(esp_get_grid_prov()) + expect_silent(esp_get_grid_ccaa("ES1")) + expect_silent(esp_get_grid_prov("ES1")) -ccaa <- esp_get_hex_ccaa() -expect_silent(sf::st_transform(ccaa, 3857)) + expect_warning( + expect_error(esp_get_hex_prov("Mallorca")) + ) -prov <- esp_get_hex_prov() -expect_silent(sf::st_transform(prov, 3857)) + expect_warning( + expect_error(esp_get_grid_prov("Mallorca")) + ) + + ccaa <- esp_get_hex_ccaa() + expect_silent(sf::st_transform(ccaa, 3857)) + + prov <- esp_get_hex_prov() + expect_silent(sf::st_transform(prov, 3857)) +}) diff --git a/tests/testthat/test-esp_get_hydrobasin.R b/tests/testthat/test-esp_get_hydrobasin.R index 45f25fd0..18bd3d08 100644 --- a/tests/testthat/test-esp_get_hydrobasin.R +++ b/tests/testthat/test-esp_get_hydrobasin.R @@ -1,13 +1,11 @@ -expect_error(esp_get_hydrobasin(epsg = 3367)) -expect_error(esp_get_hydrobasin(domain = "f")) - +test_that("hydrobasin online", { + expect_error(esp_get_hydrobasin(epsg = 3367)) + expect_error(esp_get_hydrobasin(domain = "f")) + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() -test_that("hydrobasin online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) expect_silent(esp_get_hydrobasin( domain = "landsea", resolution = "10", diff --git a/tests/testthat/test-esp_get_hypsobath.R b/tests/testthat/test-esp_get_hypsobath.R index 05c35dd1..6431e8f9 100644 --- a/tests/testthat/test-esp_get_hypsobath.R +++ b/tests/testthat/test-esp_get_hypsobath.R @@ -1,13 +1,11 @@ -expect_error(esp_get_hypsobath(epsg = 3367)) -expect_error(esp_get_hypsobath(spatialtype = "f")) -expect_error(esp_get_hypsobath(resolution = "10")) - - test_that("hypsobath online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + expect_error(esp_get_hypsobath(epsg = 3367)) + expect_error(esp_get_hypsobath(spatialtype = "f")) + expect_error(esp_get_hypsobath(resolution = "10")) + + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() expect_silent(esp_get_hypsobath( spatialtype = "line", diff --git a/tests/testthat/test-esp_get_munic.R b/tests/testthat/test-esp_get_munic.R index acbfe27e..d5318b6d 100644 --- a/tests/testthat/test-esp_get_munic.R +++ b/tests/testthat/test-esp_get_munic.R @@ -16,14 +16,19 @@ test_that("munic local", { s <- esp_get_munic(region = n) expect_equal(length(unique(s$cpro)), 52) + + skip_on_cran() + skip_if_gisco_offline() + + a2 <- esp_get_munic(year = 2018, region = "Alava") + expect_s3_class(a2, "sf") }) # SIANE test_that("munic online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() expect_silent(esp_get_munic_siane()) expect_silent(esp_get_munic_siane(rawcols = TRUE)) diff --git a/tests/testthat/test-esp_get_nuts.R b/tests/testthat/test-esp_get_nuts.R index bd0f8ed0..c72005dd 100644 --- a/tests/testthat/test-esp_get_nuts.R +++ b/tests/testthat/test-esp_get_nuts.R @@ -1,49 +1,59 @@ -expect_silent(esp_get_nuts()) -expect_silent(esp_get_nuts(resolution = 1)) -expect_silent(esp_get_nuts(nuts_level = 2, moveCAN = FALSE)) -expect_silent(esp_get_nuts(nuts_level = 2, moveCAN = c(2, 2))) - -expect_silent(esp_get_nuts(region = c("ES-AN", "ES-PV", "ES-P"))) - -expect_silent(esp_get_nuts(region = "Leon")) -expect_silent(esp_get_nuts(region = "Canarias")) -expect_silent(esp_get_nuts(region = "ES1")) -expect_message(esp_get_nuts(verbose = TRUE)) -expect_error(esp_get_nuts(resolution = 32)) -expect_error(esp_get_nuts(spatialtype = "XX")) -expect_error(esp_get_nuts(nuts_level = "XX")) -expect_warning(expect_error(esp_get_nuts(region = "Maidrid"))) - -# Check all nuts codes -a <- unique(c( - esp_codelist$nuts1.code, - esp_codelist$nuts2.code, - esp_codelist$nuts3.code -)) - -l1 <- unique(esp_codelist$nuts1.code) -ff <- esp_get_nuts(region = l1) -expect_equal(length(l1), nrow(ff)) - -l1 <- unique(esp_codelist$nuts2.code) -ff <- esp_get_nuts(region = l1) -expect_equal(length(l1), nrow(ff)) - -l1 <- unique(esp_codelist$nuts3.code) -ff <- esp_get_nuts(region = l1) -expect_equal(length(l1), nrow(ff)) - - -# Check all iso codes -b <- unique(c( - esp_codelist$iso2.ccaa.code, - esp_codelist$iso2.prov.code -)) -expect_warning(esp_get_nuts(region = b)) - -# Check names - -expect_silent(esp_get_nuts(region = esp_codelist$nuts1.name)) -expect_silent(esp_get_nuts(region = esp_codelist$nuts2.name)) -expect_silent(esp_get_nuts(region = esp_codelist$nuts3.name)) -expect_silent(esp_get_nuts(resolution = "20")) +test_that("Test local NUTS", { + expect_silent(esp_get_nuts()) + expect_silent(esp_get_nuts(resolution = 1)) + expect_silent(esp_get_nuts(nuts_level = 2, moveCAN = FALSE)) + expect_silent(esp_get_nuts(nuts_level = 2, moveCAN = c(2, 2))) + + expect_silent(esp_get_nuts(region = c("ES-AN", "ES-PV", "ES-P"))) + + expect_silent(esp_get_nuts(region = "Leon")) + expect_silent(esp_get_nuts(region = "Canarias")) + expect_silent(esp_get_nuts(region = "ES1")) + expect_message(esp_get_nuts(verbose = TRUE)) + expect_error(esp_get_nuts(resolution = 32)) + expect_error(esp_get_nuts(spatialtype = "XX")) + expect_error(esp_get_nuts(nuts_level = "XX")) + expect_warning(expect_error(esp_get_nuts(region = "Maidrid"))) + + # Check all nuts codes + a <- unique(c( + esp_codelist$nuts1.code, + esp_codelist$nuts2.code, + esp_codelist$nuts3.code + )) + + l1 <- unique(esp_codelist$nuts1.code) + ff <- esp_get_nuts(region = l1) + expect_equal(length(l1), nrow(ff)) + + l1 <- unique(esp_codelist$nuts2.code) + ff <- esp_get_nuts(region = l1) + expect_equal(length(l1), nrow(ff)) + + l1 <- unique(esp_codelist$nuts3.code) + ff <- esp_get_nuts(region = l1) + expect_equal(length(l1), nrow(ff)) + + + # Check all iso codes + b <- unique(c( + esp_codelist$iso2.ccaa.code, + esp_codelist$iso2.prov.code + )) + expect_warning(esp_get_nuts(region = b)) + + # Check names + + expect_silent(esp_get_nuts(region = esp_codelist$nuts1.name)) + expect_silent(esp_get_nuts(region = esp_codelist$nuts2.name)) + expect_silent(esp_get_nuts(region = esp_codelist$nuts3.name)) + expect_silent(esp_get_nuts(resolution = "20")) +}) + +test_that("Test NUTS online", { + skip_on_cran() + skip_if_gisco_offline() + + expect_silent(esp_get_nuts(resolution = "60", year = 2021)) + expect_silent(esp_get_nuts(resolution = "60", year = 2016)) +}) diff --git a/tests/testthat/test-esp_get_prov.R b/tests/testthat/test-esp_get_prov.R index 5f270a31..81864afe 100644 --- a/tests/testthat/test-esp_get_prov.R +++ b/tests/testthat/test-esp_get_prov.R @@ -20,10 +20,10 @@ test_that("prov offline", { n <- esp_get_prov(prov = f$nuts1.code) expect_equal(nrow(n), 52) - n <- esp_get_prov(prov = c("Canarias")) + n <- esp_get_prov(prov = "Canarias") expect_equal(nrow(n), 2) - n <- esp_get_prov(prov = c("Baleares")) + n <- esp_get_prov(prov = "Baleares") expect_equal(nrow(n), 1) n <- esp_get_prov(prov = f$nuts1.name.alt) @@ -46,10 +46,13 @@ test_that("prov offline", { }) test_that("prov online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() + + n <- expect_silent(esp_get_prov(resolution = 60, year = 2006)) + expect_equal(nrow(n), 52) + expect_s3_class(n, "sf") expect_warning(expect_warning(expect_error( esp_get_prov_siane("FFF") @@ -63,12 +66,12 @@ test_that("prov online", { expect_warning(expect_error(esp_get_prov_siane(prov = "ES6x"))) - expect_equal( + expect_identical( sf::st_crs(esp_get_prov_siane(epsg = 3035)), sf::st_crs(3035) ) - expect_equal( + expect_identical( sf::st_crs(esp_get_prov_siane(epsg = 3857)), sf::st_crs(3857) ) @@ -89,10 +92,10 @@ test_that("prov online", { n <- esp_get_prov_siane(prov = f$nuts1.code) expect_equal(nrow(n), 52) - n <- esp_get_prov_siane(prov = c("Canarias")) + n <- esp_get_prov_siane(prov = "Canarias") expect_equal(nrow(n), 2) - n <- esp_get_prov_siane(prov = c("Baleares")) + n <- esp_get_prov_siane(prov = "Baleares") expect_equal(nrow(n), 1) n <- esp_get_prov_siane(prov = f$nuts1.name.alt) diff --git a/tests/testthat/test-esp_get_railway.R b/tests/testthat/test-esp_get_railway.R index 4e7f6010..a4e5d499 100644 --- a/tests/testthat/test-esp_get_railway.R +++ b/tests/testthat/test-esp_get_railway.R @@ -1,17 +1,14 @@ -expect_error(esp_get_railway(epsg = 3367)) -expect_error(esp_get_railway(spatialtype = "aaff")) - - test_that("railway online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + expect_error(esp_get_railway(epsg = 3367)) + expect_error(esp_get_railway(spatialtype = "aaff")) + + skip_on_cran() + skip_if_siane_offline() expect_silent(esp_get_railway()) l <- esp_get_railway(epsg = 3857) - expect_true(sf::st_crs(l) == sf::st_crs(3857)) + expect_identical(sf::st_crs(l), sf::st_crs(3857)) expect_silent(esp_get_railway(spatialtype = "point")) }) diff --git a/tests/testthat/test-esp_get_rivers.R b/tests/testthat/test-esp_get_rivers.R index 80d208b2..07164ba1 100644 --- a/tests/testthat/test-esp_get_rivers.R +++ b/tests/testthat/test-esp_get_rivers.R @@ -1,13 +1,9 @@ -expect_error(esp_get_rivers(epsg = 3367)) -expect_error(esp_get_rivers(spatialtype = "f")) - - - test_that("rivers online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + expect_error(esp_get_rivers(epsg = 3367)) + expect_error(esp_get_rivers(spatialtype = "f")) + + skip_on_cran() + skip_if_siane_offline() expect_silent(esp_get_rivers( spatialtype = "line", diff --git a/tests/testthat/test-esp_get_roads.R b/tests/testthat/test-esp_get_roads.R index 30317132..02a84272 100644 --- a/tests/testthat/test-esp_get_roads.R +++ b/tests/testthat/test-esp_get_roads.R @@ -1,17 +1,14 @@ -expect_error(esp_get_roads(epsg = 3367)) - - test_that("roads online", { - skip_if_not( - giscoR::gisco_check_access(), - "Skipping... GISCO not reachable." - ) + expect_error(esp_get_roads(epsg = 3367)) + + skip_on_cran() + skip_if_siane_offline() expect_silent(esp_get_roads()) l <- esp_get_roads(epsg = 3857) - expect_true(sf::st_crs(l) == sf::st_crs(3857)) + expect_identical(sf::st_crs(l), sf::st_crs(3857)) expect_silent(esp_get_roads(moveCAN = FALSE)) expect_silent(esp_get_roads(moveCAN = TRUE)) expect_silent(esp_get_roads(moveCAN = c(2, 2))) diff --git a/tests/testthat/test-esp_get_simplified.R b/tests/testthat/test-esp_get_simplified.R new file mode 100644 index 00000000..ac7190b8 --- /dev/null +++ b/tests/testthat/test-esp_get_simplified.R @@ -0,0 +1,56 @@ +test_that("simplified prov online", { + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() + + expect_silent(esp_get_simpl_prov()) + + expect_message(esp_get_simpl_prov(verbose = TRUE)) + expect_message(esp_get_simpl_prov(verbose = TRUE, update_cache = TRUE)) + expect_message(esp_get_simpl_prov(prov = "Canarias", verbose = TRUE)) + + can <- esp_get_simpl_prov("Canarias") + expect_equal(nrow(can), 2) + expect_equal(sf::st_crs(can), sf::st_crs(NA)) + + expect_error(esp_get_simp_prov(prov = "5689")) + + expect_silent(esp_get_simpl_prov(prov = "La Rioja")) + expect_silent(esp_get_simpl_prov(prov = "Alava")) + + + a <- mapSpain::esp_codelist + n <- a$nuts1.name + + s <- esp_get_simpl_prov(prov = n) + expect_equal(length(unique(s$cpro)), 52) +}) + + +test_that("simplified ccaa online", { + skip_on_cran() + skip_if_siane_offline() + skip_if_gisco_offline() + + expect_silent(esp_get_simpl_ccaa()) + + expect_message(esp_get_simpl_ccaa(verbose = TRUE)) + expect_message(esp_get_simpl_ccaa(verbose = TRUE, update_cache = TRUE)) + expect_message(esp_get_simpl_ccaa(ccaa = "Canarias", verbose = TRUE)) + + can <- esp_get_simpl_ccaa("Canarias") + expect_equal(nrow(can), 1) + expect_equal(sf::st_crs(can), sf::st_crs(NA)) + + expect_error(esp_get_simp_prov(prov = "5689")) + + expect_silent(esp_get_simpl_ccaa(ccaa = "La Rioja")) + expect_silent(esp_get_simpl_ccaa(ccaa = "Pais Vasco")) + + + a <- mapSpain::esp_codelist + n <- a$nuts1.name + + s <- esp_get_simpl_ccaa(ccaa = n) + expect_equal(length(unique(s$codauto)), 19) +}) diff --git a/tests/testthat/test-esp_make_provider.R b/tests/testthat/test-esp_make_provider.R new file mode 100644 index 00000000..6a0126dd --- /dev/null +++ b/tests/testthat/test-esp_make_provider.R @@ -0,0 +1,59 @@ +test_that("Custom WMTS provider", { + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + + segovia <- esp_get_prov("segovia", epsg = 3857) + custom_wmts <- esp_make_provider( + id = "wmts_test", + q = "https://www.ign.es/wmts/ign-base?", + service = "WMTS", + layer = "IGNBaseTodo-nofondo" + ) + + + tile <- esp_getTiles(segovia, type = custom_wmts) + expect_s4_class(tile, "SpatRaster") +}) + +test_that("Custom WMS provider", { + skip_if_not_installed("slippymath") + skip_if_not_installed("terra") + skip_if_not_installed("png") + + + # Skip test as tiles sometimes are not available + skip_on_cran() + skip_if_offline() + segovia <- esp_get_prov("segovia", epsg = 3857) + + custom_wms_11 <- esp_make_provider( + id = "wms_1.1", + q = "https://idecyl.jcyl.es/geoserver/ge/wms?", + service = "WMS", + version = "1.1.1", + crs = "EPSG:25830", + layers = "geolog_cyl_litologia" + ) + + custom_wms_13 <- esp_make_provider( + id = "wms_1.3", + q = "https://idecyl.jcyl.es/geoserver/ge/wms?", + service = "WMS", + version = "1.3.0", + crs = "EPSG:25830", + layers = "geolog_cyl_litologia" + ) + + # Both works + + tilewms1 <- esp_getTiles(segovia, custom_wms_11, cache_dir = tempdir()) + expect_s4_class(tilewms1, "SpatRaster") + tilewms13 <- esp_getTiles(segovia, custom_wms_13, cache_dir = tempdir()) + expect_s4_class(tilewms13, "SpatRaster") +}) diff --git a/tests/testthat/test-esp_move_can.R b/tests/testthat/test-esp_move_can.R new file mode 100644 index 00000000..3bb4e81b --- /dev/null +++ b/tests/testthat/test-esp_move_can.R @@ -0,0 +1,126 @@ +test_that("Errors", { + teide <- data.frame( + name = "Teide Peak", + lon = -16.6437593, + lat = 28.2722883 + ) + + expect_error( + esp_move_can(teide), "should be an `sf` or `sfc`" + ) +}) + +test_that("sfc", { + teide <- data.frame( + name = rep("test", 20), + lon = seq(-16.1, -15.8, length.out = 20), + lat = seq(28.2, 29, length.out = 20) + ) + + teide_sf <- sf::st_as_sf(teide, coords = c("lon", "lat"), crs = 4326) + + teide_sfc <- sf::st_geometry(teide_sf) + + # Do nothing + moved <- esp_move_can(teide_sfc, moveCAN = FALSE) + expect_identical(moved, teide_sfc) + + # Moved + moved2 <- esp_move_can(teide_sfc, moveCAN = TRUE) + expect_identical(length(moved2), length(teide_sfc)) + expect_identical(sf::st_crs(moved2), sf::st_crs(teide_sfc)) + + # Moved with another CRS + teide_sfc_3857 <- sf::st_transform(teide_sfc, 3857) + moved3 <- esp_move_can(teide_sfc_3857, moveCAN = TRUE) + expect_identical(length(moved3), length(teide_sfc)) + expect_identical(sf::st_crs(moved3), sf::st_crs(teide_sfc_3857)) + + # Check movs + + # Avoid errors due to changes in precision across GDAL versions + skip_on_cran() + + a1 <- sf::st_geometry(moved3[1]) - sf::st_geometry(teide_sfc_3857[1]) + mat <- sf::st_coordinates(a1) + + # Default mov in 3857 + expect_identical( + as.data.frame(mat), + data.frame(X = 550000, Y = 920000) + ) + + + # Mov with params + + moved4 <- esp_move_can(teide_sfc, moveCAN = c(5, 10)) + + a2 <- sf::st_geometry(moved4) - sf::st_geometry(teide_sfc) + mat2 <- sf::st_coordinates(a2) + + + + expect_equal(sort(unique(as.integer(mat2))), c(9L, 14L)) +}) + + +test_that("sf", { + teide <- data.frame( + name = rep("test", 20), + lon = seq(-16.1, -15.8, length.out = 20), + lat = seq(28.2, 29, length.out = 20) + ) + + teide_sf <- sf::st_as_sf(teide, coords = c("lon", "lat"), crs = 4326) + + # Col with other name + teide_sf2 <- sf::st_sf(sf::st_drop_geometry(teide_sf), + mygeomcol = sf::st_geometry(teide_sf) + ) + # Do nothing + moved <- esp_move_can(teide_sf, moveCAN = FALSE) + expect_identical(moved, teide_sf) + + moved_n <- esp_move_can(teide_sf2, moveCAN = FALSE) + expect_identical(moved_n, teide_sf2) + + expect_true(all(sf::st_is_valid(moved_n))) + + + # Moved + moved2 <- esp_move_can(teide_sf, moveCAN = TRUE) + + expect_identical(nrow(moved2), nrow(teide_sf)) + expect_identical(sf::st_crs(moved2), sf::st_crs(teide_sf)) + + + # Moved with another CRS + teide_sf_3857 <- sf::st_transform(teide_sf2, 3857) + moved3 <- esp_move_can(teide_sf_3857, moveCAN = TRUE) + expect_identical(nrow(moved3), nrow(teide_sf2)) + expect_identical(sf::st_crs(moved3), sf::st_crs(teide_sf_3857)) + expect_identical(names(moved3), names(teide_sf_3857)) + + expect_true(all(sf::st_is_valid(moved3))) +}) + + +test_that("Empty", { + teide <- data.frame( + name = rep("test", 20), + lon = seq(-16.1, -15.8, length.out = 20), + lat = seq(28.2, 29, length.out = 20) + ) + + teide_sf <- sf::st_as_sf(teide, coords = c("lon", "lat"), crs = 4326) + teide_null <- teide_sf[teide_sf$name != "test", ] + expect_equal(nrow(teide_null), 0) + expect_identical(teide_null, esp_move_can(teide_null, moveCAN = TRUE)) + + # sfc + teide_null_sfc <- sf::st_geometry(teide_null) + expect_equal(length(teide_null_sfc), 0) + expect_identical(teide_null_sfc, esp_move_can(teide_null_sfc, + moveCAN = TRUE + )) +}) diff --git a/vignettes/.gitignore b/vignettes/.gitignore index e29182d0..ba7abf32 100644 --- a/vignettes/.gitignore +++ b/vignettes/.gitignore @@ -1,3 +1,3 @@ -*.html -*.R -*_files +*.html +*.R +*_files diff --git a/vignettes/articles/artcache/ES1-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES1-region-20m-3035-2016.geojson new file mode 100644 index 00000000..2b750259 --- /dev/null +++ b/vignettes/articles/artcache/ES1-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[2937503.8036, 2435257.6954999994], [2954461.5582999997, 2426794.9991999995], [3013289.117900001, 2416326.1071000006], [3050302.261499999, 2416381.2411], [3062756.6448, 2403338.035700001], [3084362.336100001, 2398767.9298], [3099054.6741000004, 2387047.762], [3150432.1084000003, 2367561.8840999994], [3203983.3313999996, 2367327.088300001], [3208871.4484, 2361436.1776], [3225979.4145, 2365608.3013000004], [3257969.7192, 2342918.488500001], [3247176.1088999994, 2333849.6775], [3234489.9704, 2334614.8868000004], [3232789.2897999994, 2322638.6021999996], [3214481.3960999995, 2328317.7947000004], [3193779.3111000005, 2318292.9058999997], [3187396.0602, 2310678.455], [3189500.0430999994, 2304026.1525], [3192778.1324000005, 2293707.5615], [3179180.033500001, 2291421.2546999995], [3179988.7774, 2294987.7567999996], [3177367.3874999993, 2295483.9648], [3175411.4093999993, 2291867.773499999], [3172460.7660000008, 2291846.463300001], [3166500.6481999997, 2297553.6778999995], [3163653.3541, 2308938.1927000005], [3162283.3367999997, 2314443.0578000005], [3150300.8507000003, 2327782.3135], [3125001.4101, 2330449.2777999993], [3119952.0965, 2349559.6811999995], [3114346.7486000005, 2355112.6822999995], [3094136.622199999, 2345448.7804000005], [3048685.008199999, 2347782.8335999995], [3038149.1797, 2342700.5812], [3023674.524, 2356815.2456], [3001189.7097999994, 2357750.468699999], [2994681.9268999994, 2359967.0779], [2980150.943, 2350072.215399999], [2956202.5001, 2354584.1778999995], [2936043.7424, 2333131.239499999], [2926589.3499999996, 2315020.3358999994], [2944719.5591, 2307475.7106999997], [2945643.7040999997, 2303861.4520999994], [2948850.6717000008, 2291380.4398999996], [2944189.9134, 2281962.3007999994], [2941104.2640000004, 2280259.488500001], [2926620.4451, 2272296.880000001], [2921462.8126999997, 2255028.6382999998], [2907503.1931999996, 2258468.334899999], [2901984.571900001, 2249097.1273999996], [2883306.2030999996, 2247534.3863999993], [2859373.747199999, 2261749.4075000007], [2831796.0873000007, 2259162.0669], [2822605.4909000006, 2261163.0436000004], [2822722.6854999997, 2273363.4974000007], [2832880.003799999, 2283735.9595999997], [2828168.7161, 2298249.038899999], [2792762.2869000006, 2295351.0687000006], [2767741.0801, 2281168.122199999], [2772997.4926999994, 2304416.7413], [2782898.739600001, 2318620.7733999994], [2780793.9690000005, 2324281.2563000005], [2786763.514799999, 2333587.2589], [2784755.2191000003, 2342963.994999999], [2799517.0140000004, 2366660.8057000004], [2774322.6575000007, 2359149.954399999], [2777221.4427000005, 2373844.0162000004], [2780986.464400001, 2380115.5913999993], [2769061.5746, 2387610.065300001], [2772613.307600001, 2397702.6197999995], [2766202.4473, 2409964.9420999996], [2779797.0932, 2427419.2749000005], [2805072.315300001, 2436826.299799999], [2852337.91, 2431867.034600001], [2854181.182600001, 2446264.8859], [2860187.5771999992, 2452219.0573999994], [2890090.4826999996, 2464326.1389000006], [2906664.9859999996, 2459935.7007999998], [2924764.3367999997, 2453330.8389999997], [2937503.8036, 2435257.6954999994]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "NOROESTE", "CNTR_CODE": "ES", "NUTS_ID": "ES1", "NUTS_NAME": "NOROESTE", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES2-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES2-region-20m-3035-2016.geojson new file mode 100644 index 00000000..9804f4d0 --- /dev/null +++ b/vignettes/articles/artcache/ES2-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[3316621.8169, 2329179.4541999996], [3335345.1622, 2322916.2401], [3341910.601500001, 2323169.1314000003], [3367335.8532, 2324216.1876], [3371028.6866999995, 2317520.1096], [3397694.8827, 2309107.644200001], [3396567.6382, 2301239.6446], [3393238.9976000004, 2295071.6588000003], [3388515.9386, 2290867.5961000007], [3390329.3769000005, 2286691.9133], [3394195.744999999, 2284662.8965000007], [3401218.5362, 2288232.7707], [3415371.4922, 2280546.2672000006], [3446154.712200001, 2264004.4198000003], [3448542.5567000005, 2261149.1261], [3457203.3002000004, 2250825.017999999], [3478445.4934, 2251519.461100001], [3500825.0139000006, 2231742.1478000004], [3523131.0829000007, 2228802.3719999995], [3540709.943499999, 2226544.1711], [3555449.739, 2223671.0808000006], [3559281.443600001, 2216650.5559], [3561366.8620999996, 2212838.5025999993], [3556633.6624999996, 2200724.4694], [3557510.1657, 2190946.7178000007], [3558337.4133, 2181789.6730000004], [3554519.3172999993, 2172582.4569000006], [3538345.1034999993, 2135019.659], [3518616.277899999, 2117218.7269], [3520560.8320000004, 2100690.4952000007], [3512138.6203000005, 2085822.6787], [3514609.2875999995, 2071150.8484000005], [3502247.4944, 2055401.1425], [3498096.7468, 2050131.1634], [3498214.3501999993, 2025913.1195], [3489478.1235000007, 2013464.2942999993], [3479740.1206, 2011540.4266999997], [3460230.7227, 2021226.8385000005], [3444256.0562999994, 2011015.7123000007], [3447760.3978000004, 2000384.5781999994], [3443278.191299999, 1977061.9713000003], [3434512.3191, 1968204.7197999991], [3422811.5934999995, 1966295.9483000003], [3413308.836100001, 1952055.6316], [3392927.6007000003, 1938813.8468999993], [3395896.5285, 1931187.1455000006], [3389645.4748, 1931462.4814999998], [3381928.4350000005, 1942915.9730999991], [3367939.042300001, 1945405.4098000005], [3366572.0955, 1949885.1067999993], [3368902.2589, 1958422.3059999999], [3358878.972100001, 1969812.3660000004], [3344584.6417999994, 1968319.6502], [3318343.6432000007, 2000696.9396000002], [3331823.5679, 2017019.0307], [3342794.4805999994, 2020941.2387000006], [3342725.3554, 2058005.5736999996], [3327481.2235000003, 2077678.5802999996], [3309793.2765999995, 2085984.7526999991], [3306154.4099000003, 2085580.9211], [3306374.5276999995, 2109656.6722999997], [3311477.2315999996, 2115649.2814000007], [3320573.4825999998, 2115289.217700001], [3324325.0501000006, 2130880.3687999994], [3338191.2777999993, 2145215.0406], [3339164.6708000004, 2173247.9261000007], [3322602.5621000007, 2173140.0863000005], [3320153.2068000007, 2179318.8586], [3315555.7653, 2190964.2083], [3301555.1323000006, 2198436.843699999], [3290066.9048999995, 2197804.2820999995], [3287270.8214, 2195094.202299999], [3280351.7048000004, 2188400.773], [3265947.7237, 2198859.9618999995], [3253551.0661999993, 2193820.4492000006], [3241876.8972999994, 2214289.3730999995], [3248847.259400001, 2242595.8125], [3248354.4751999993, 2252463.9134], [3252208.2777999993, 2261013.1689], [3255192.270300001, 2262449.0764000006], [3268897.3400999997, 2260428.375499999], [3262169.4164000005, 2268634.2475000005], [3244989.3155000005, 2289733.8762], [3249720.886600001, 2293031.0437000003], [3260589.2171, 2300629.2070000004], [3256755.159499999, 2303490.7809999995], [3255442.84, 2321747.763699999], [3245936.8885999992, 2326401.1130999997], [3232789.2897999994, 2322638.6021999996], [3234489.9704, 2334614.8868000004], [3247176.1088999994, 2333849.6775], [3257969.7192, 2342918.488500001], [3290874.4088000003, 2347125.3575], [3303924.7156000007, 2338002.361199999], [3309102.9305000007, 2334397.8362000007], [3316621.8169, 2329179.4541999996]], [[3276782.8600999992, 2262324.396299999], [3290514.7684000004, 2258419.6279000007], [3292057.6103000008, 2262987.3589999992], [3293444.5076, 2267095.6284999996], [3292781.291200001, 2267579.033], [3281829.005999999, 2275583.3948], [3273671.9174000006, 2277245.969799999], [3270083.6382999998, 2271642.5656000003], [3276782.8600999992, 2262324.396299999]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "NORESTE", "CNTR_CODE": "ES", "NUTS_ID": "ES2", "NUTS_NAME": "NORESTE", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES230-region-01m-3857-2016.geojson b/vignettes/articles/artcache/ES230-region-01m-3857-2016.geojson new file mode 100644 index 00000000..6e733f23 --- /dev/null +++ b/vignettes/articles/artcache/ES230-region-01m-3857-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3857"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[-332918.2782999985, 5257624.306199998], [-332184.42170000076, 5256727.696699999], [-331979.03119999915, 5256754.490500003], [-331502.2635000013, 5256816.686499998], [-330597.0276999995, 5257452.551100001], [-327804.3942999989, 5257118.777800001], [-326546.03869999945, 5256414.576499999], [-325523.1823000014, 5254566.399700001], [-325110.7993000001, 5254374.122199997], [-324611.5870000012, 5254231.618500002], [-324289.59540000185, 5254314.745399997], [-324049.4235999994, 5254269.135200001], [-323798.1198000014, 5254382.215599999], [-323323.11950000003, 5254329.116800003], [-323292.99810000136, 5255192.081200004], [-322254.88500000164, 5255426.663599998], [-321864.33729999885, 5255178.993699998], [-322015.5947000012, 5254539.558600001], [-320841.5854999982, 5254414.513800003], [-320900.0870999992, 5255036.167800002], [-320303.4433000013, 5255812.978799999], [-318854.8586000018, 5256361.5239999965], [-318164.18470000103, 5257058.571699999], [-316529.90480000153, 5255657.446599998], [-316952.5181999989, 5253914.608599998], [-316350.4006000012, 5252580.200199999], [-315832.04140000045, 5252596.913400002], [-315520.9034000002, 5252668.4551], [-314814.3586000018, 5253085.011100002], [-314622.8333999999, 5253176.220299996], [-314401.5859000012, 5253208.514300004], [-313912.33680000156, 5253472.693999998], [-313786.71269999817, 5253202.766400002], [-313861.24109999835, 5252658.018700004], [-314141.2652999982, 5251819.745099999], [-314329.0612999983, 5251500.109099999], [-313787.4695000015, 5251025.247599997], [-313985.0692999996, 5249948.371299997], [-316169.3903999999, 5248346.5075], [-315815.3355999999, 5246827.130400002], [-314880.77849999815, 5245727.775300004], [-314479.2868999988, 5244468.516199999], [-313733.1229000017, 5244817.070200004], [-313458.09760000184, 5246418.393200003], [-313278.4836000018, 5246640.9661], [-313056.1229000017, 5246668.0227999985], [-312439.6911999993, 5246335.335900001], [-312085.1942999996, 5245927.617600001], [-311368.58570000157, 5247390.428099997], [-309335.14350000024, 5248449.549800001], [-308597.8275000006, 5250675.259400003], [-308772.5810999982, 5252266.342], [-307898.5795999989, 5254328.511699997], [-307650.1413999982, 5254604.628799997], [-306958.05629999936, 5254227.378200002], [-306013.1895999983, 5254808.761699997], [-305188.8925999999, 5254678.683600001], [-304008.7932999991, 5253898.108499996], [-301709.91600000113, 5251475.793700002], [-301268.6134000011, 5251253.829700001], [-298861.81540000066, 5250663.428199999], [-298535.49720000103, 5250583.380400002], [-298861.81540000066, 5249228.065700002], [-299038.6871000007, 5248493.454599999], [-299148.62959999964, 5245169.800800003], [-299610.565200001, 5242628.582400002], [-300466.1110999994, 5240321.711300001], [-301176.49650000036, 5238701.498099998], [-300532.8471999988, 5238730.2689], [-299950.53489999846, 5238953.868699998], [-298861.81540000066, 5239538.319600001], [-297995.43290000036, 5240003.414499998], [-298012.71119999886, 5237793.257399999], [-297047.43389999866, 5237644.363300003], [-296757.4466000013, 5237656.444200002], [-296537.81329999864, 5237325.207400002], [-296346.1768000014, 5237140.906800002], [-296146.30260000005, 5236985.375200003], [-295727.01779999956, 5236780.847599998], [-295565.60449999943, 5236465.722199999], [-295505.10240000114, 5235712.453500003], [-295438.1994000003, 5235494.743000001], [-294919.0375000015, 5233947.4152000025], [-294417.3300999999, 5233660.9738000035], [-293148.76300000027, 5234429.347599998], [-292603.0740999989, 5235409.281300001], [-290869.13899999857, 5235502.400200002], [-290384.12750000134, 5235974.482699998], [-289964.64660000056, 5236557.580499999], [-288690.4589000009, 5235118.571900003], [-289533.8136, 5233838.526000001], [-289608.10909999907, 5232778.5132], [-288911.05959999934, 5232071.550099999], [-288105.75869999826, 5232344.660599999], [-288482.90190000087, 5233542.5178999975], [-287029.79019999877, 5233689.9507], [-286621.5368999988, 5234584.227799997], [-286475.0505999997, 5234905.105300002], [-285941.7809999995, 5235202.812799998], [-284478.32919999957, 5233885.893600002], [-283745.7010000013, 5233825.695299998], [-283374.3392000012, 5233735.4278], [-282459.07030000165, 5233633.613700002], [-281710.8104000017, 5233923.5823], [-282445.0434000008, 5234673.5273], [-282396.02540000156, 5235416.268299997], [-280546.1779000014, 5237290.444499999], [-279851.29989999905, 5238927.3627], [-279218.5150000006, 5238973.365699999], [-278898.79470000044, 5238201.383100003], [-280229.8557000011, 5236116.197899997], [-280147.7122000009, 5234895.389399998], [-275751.180399999, 5234181.7924000025], [-275653.8872000016, 5234382.112400003], [-275420.39460000023, 5234682.675800003], [-275451.17440000176, 5234905.575900003], [-275247.5153999999, 5235036.314199999], [-272599.72569999844, 5235701.9604], [-272183.89169999957, 5235219.7434], [-271566.3467999995, 5234820.129000001], [-271453.5245000012, 5234531.411600001], [-271017.0408000015, 5234612.780000001], [-270629.76029999927, 5234591.645300001], [-270338.43719999865, 5234618.214599997], [-269851.6926999986, 5234484.613799997], [-269473.20639999956, 5234553.753899999], [-268763.6735999994, 5234402.489100002], [-267060.881000001, 5231993.965999998], [-264477.59219999984, 5231884.775300004], [-263372.9444000013, 5230557.7051], [-262384.79089999944, 5231098.589599997], [-261992.51179999858, 5231015.696400002], [-261351.6554000005, 5229204.6994], [-260958.87950000167, 5228859.170299999], [-259623.19590000063, 5229285.042000003], [-259997.61820000038, 5230778.5898], [-259546.32759999856, 5231304.635799997], [-258926.27320000157, 5231300.514799997], [-257822.07299999893, 5230491.118699998], [-255902.0177000016, 5229826.916100003], [-255387.0320999995, 5230157.169200003], [-255613.80490000173, 5231270.464599997], [-254702.00059999898, 5231243.0722], [-254562.08150000125, 5230252.266400002], [-253741.68939999864, 5229432.721500002], [-253291.36250000075, 5228113.270300001], [-252774.7751000002, 5227997.842699997], [-252016.80799999833, 5228507.5315999985], [-251351.4508999996, 5228296.0634], [-249198.1666000001, 5227145.032799996], [-249072.83949999884, 5226687.134000003], [-249455.39660000056, 5225741.9745000005], [-249063.8909999989, 5225254.5836], [-246692.86230000108, 5224597.490400001], [-246350.05730000138, 5224233.409999996], [-246624.69949999824, 5223551.090999998], [-246112.42170000076, 5223312.464299999], [-244608.69159999862, 5223954.563199997], [-243378.72419999912, 5223848.4065999985], [-242357.10110000148, 5222441.217699997], [-241290.96200000122, 5222294.570699997], [-240386.15359999985, 5222620.632399999], [-239769.79399999976, 5223744.078000002], [-239073.05189999938, 5223629.874899998], [-237442.97100000083, 5224278.271600001], [-235024.8333999999, 5224031.495099999], [-234428.623399999, 5223410.571699999], [-235427.2146999985, 5221205.8697], [-235013.2562999986, 5220492.435500003], [-234678.07039999962, 5219992.892800003], [-232512.14730000123, 5218651.7038], [-232971.87939999998, 5217439.825599998], [-231483.0236000009, 5216193.4133], [-232544.86450000107, 5214673.9749], [-232654.61879999936, 5213093.4661], [-230397.82409999892, 5212507.987499997], [-228350.8812999986, 5213812.2739999965], [-227716.1521999985, 5214909.805799998], [-227209.20329999924, 5215031.153499998], [-226896.95210000128, 5215151.2223000005], [-226285.08449999988, 5215467.295199998], [-225862.0705000013, 5215452.907499999], [-224812.27199999988, 5216335.118799999], [-224401.86389999837, 5216456.8737], [-223391.54019999877, 5215293.9859], [-222097.77690000087, 5215498.740500003], [-220682.872299999, 5214472.297499999], [-220204.68450000137, 5213631.353100002], [-219406.5593000017, 5213985.765299998], [-219300.5100999996, 5213187.151600003], [-218809.81799999997, 5212528.395900004], [-219086.42419999838, 5211737.7258], [-218753.43329999968, 5211251.196699999], [-216254.33850000054, 5211237.406199999], [-215030.8889000006, 5209457.082000002], [-213568.6138000004, 5210080.357900001], [-213553.49610000104, 5208418.670900002], [-212358.17550000176, 5207326.693099998], [-212993.8291000016, 5206067.321400002], [-210498.12840000167, 5204490.064300001], [-209437.54529999942, 5204132.677900001], [-208355.05249999836, 5204364.310500003], [-207802.68180000037, 5202359.842600003], [-207947.42480000108, 5201280.847000003], [-208075.66490000114, 5200865.364299998], [-208306.3187999986, 5200684.630500004], [-208858.46350000054, 5199852.081200004], [-208854.45600000024, 5199644.368900001], [-208762.33909999952, 5199365.5211], [-208466.89719999954, 5198944.407399997], [-206581.17060000077, 5198544.928499997], [-206022.93780000135, 5199801.421400003], [-205193.5476000011, 5198992.608900003], [-203682.1424999982, 5197709.477399997], [-202802.2949000001, 5198298.540600002], [-202412.39710000157, 5197907.193700001], [-202584.44139999896, 5196981.963100001], [-202597.74399999902, 5196110.121399999], [-202552.04740000144, 5195804.991999999], [-202434.8280000016, 5195604.284000002], [-202248.4791000001, 5195417.336199999], [-201095.9475999996, 5195088.714100003], [-200350.64909999818, 5194438.873300001], [-198283.68290000036, 5194636.409699999], [-197157.501600001, 5193226.382399999], [-196794.89950000122, 5193336.671099998], [-196485.2514999993, 5194135.902800001], [-193956.53880000114, 5192937.776500002], [-193267.01089999825, 5193216.3325999975], [-192367.2424999997, 5192929.153399996], [-192064.6937999986, 5193167.786799997], [-190084.2188999988, 5192139.788199998], [-189526.95059999824, 5189848.868299998], [-187178.38039999828, 5189844.044200003], [-186906.09299999848, 5189227.962899998], [-188784.82539999858, 5188100.132399999], [-189304.5491000004, 5186848.5471], [-188600.35190000013, 5184878.575499997], [-187116.8007999994, 5183733.371299997], [-189526.95059999824, 5182208.358000003], [-191457.89130000025, 5180986.562600002], [-192153.8878000006, 5182266.908200003], [-193751.47940000147, 5183422.275399998], [-196382.1897, 5183485.832900003], [-198005.52479999885, 5182254.852499999], [-198330.5025999993, 5181667.0854], [-200097.52690000087, 5182183.388499998], [-200886.79839999974, 5183122.553000003], [-202921.09010000154, 5183893.8325999975], [-204491.37920000032, 5182437.685400002], [-204920.76630000025, 5180165.0261999965], [-206935.22819999978, 5178235.974699996], [-207556.41710000113, 5177076.949699998], [-211210.0320999995, 5172901.081799999], [-212535.68030000106, 5169838.326700002], [-211951.50310000032, 5169058.9120000005], [-211623.84650000185, 5165475.847000003], [-210993.01440000162, 5165040.428499997], [-209750.50429999828, 5164943.9092999995], [-208434.7762000002, 5162992.259900004], [-207565.70850000158, 5163070.5336000025], [-206620.89440000057, 5161502.093099996], [-206018.89609999955, 5161667.736599997], [-205627.52659999952, 5162176.082699999], [-206014.2223000005, 5160598.482299998], [-205404.83430000022, 5159043.157799996], [-207524.5197999999, 5157569.145300001], [-206669.03180000186, 5155945.933200002], [-207798.3123999983, 5154871.705799997], [-209012.58540000021, 5153854.778300002], [-210472.03950000182, 5153161.021499999], [-212249.08819999918, 5152830.400899999], [-212141.82409999892, 5152461.710900001], [-212771.15989999846, 5151946.381399997], [-213195.52650000155, 5150834.647699997], [-213878.57459999993, 5151077.917499997], [-215831.99210000038, 5149898.564000003], [-217553.8214999996, 5150033.282700002], [-218431.0102000013, 5149081.3486], [-220645.13819999993, 5148891.224699996], [-222254.3739, 5150373.076200001], [-222859.54899999872, 5151781.376999997], [-224011.74549999833, 5152150.2924000025], [-224401.86389999837, 5152668.567100003], [-225765.13749999925, 5153865.348499998], [-226690.12049999833, 5151904.978600003], [-227753.88479999825, 5153445.9767], [-228344.495099999, 5153620.6017], [-229975.42960000038, 5154034.860200003], [-231123.30790000036, 5153622.921700001], [-231702.71990000084, 5154114.442500003], [-234759.28269999847, 5154639.445299998], [-235413.15419999883, 5155271.5995000005], [-235456.97569999844, 5155900.269900002], [-236368.8718000017, 5160182.998099998], [-235118.9539999999, 5160530.8928999975], [-234911.23189999908, 5160722.8483000025], [-234694.6041000001, 5161141.748300001], [-234620.63230000064, 5161393.187100001], [-235409.4684999995, 5162634.598099999], [-235736.39979999885, 5164228.240400001], [-237015.10649999976, 5164984.670199998], [-238131.36309999973, 5166465.6884], [-239315.36820000038, 5167383.072300002], [-240268.93400000036, 5169306.006700002], [-240572.15399999917, 5170925.893399999], [-237637.95919999853, 5172265.3379999995], [-236808.5009999983, 5173232.479699999], [-236921.03770000115, 5175574.991499998], [-239127.2906000018, 5176636.160499997], [-242188.4653000012, 5176683.648800001], [-244441.77629999816, 5176359.073799998], [-245858.496199999, 5176607.418899998], [-247486.8975000009, 5175753.9912], [-249043.6090000011, 5176257.819700003], [-251441.78599999845, 5174157.979199998], [-252650.27100000158, 5174251.397399999], [-253965.73039999977, 5177323.249399997], [-254023.88919999823, 5178779.187899999], [-253747.30649999902, 5179456.655500002], [-254142.5725999996, 5180756.372400001], [-257831.79190000147, 5182634.240400001], [-259036.06929999962, 5182587.001000002], [-259614.75230000168, 5182875.8134], [-260577.38760000095, 5182784.753799997], [-260934.4448999986, 5182797.290399998], [-261400.4838999994, 5182977.759099998], [-261719.13599999994, 5182704.5801], [-262384.79089999944, 5182615.6712], [-262778.5636, 5182563.0766], [-263903.1686999984, 5182486.883299999], [-264515.6486000009, 5182177.687399998], [-265186.90509999916, 5182324.890100002], [-265817.1403999999, 5182344.3320999965], [-266382.4763999991, 5182034.540299997], [-266547.84149999917, 5181893.6472999975], [-266857.6992999986, 5181513.389300004], [-267323.6827000007, 5181907.3838], [-271699.59259999916, 5181430.566799998], [-273609.4926000014, 5178403.462200001], [-275047.0493000001, 5178091.822400004], [-276509.6405999996, 5177027.2051], [-277603.6020000018, 5177775.559], [-279247.72560000047, 5178285.261100002], [-279933.78770000115, 5178150.201200001], [-279916.3104999997, 5177916.026799999], [-280134.8863000013, 5177595.500100002], [-280038.4836000018, 5177253.151799999], [-280123.6431000009, 5176715.682899997], [-280108.16959999874, 5176367.139600001], [-280275.09319999814, 5176127.307899997], [-280253.33029999956, 5175918.988499999], [-280458.1581000015, 5175669.491300002], [-280324.0181000009, 5175319.261100002], [-280332.3671000004, 5174583.887199998], [-280768.81639999896, 5173528.782300003], [-280010.81810000166, 5172201.586400002], [-279956.27419999987, 5171298.051100001], [-281843.0811999999, 5169392.123199999], [-283673.7237999998, 5168642.191], [-285433.6048000008, 5163516.464299999], [-286621.5368999988, 5162008.386500001], [-287195.38069999963, 5160417.728600003], [-287970.498300001, 5160753.181000002], [-288687.22879999876, 5161005.1338], [-289054.3605000004, 5161268.552900001], [-289633.6114999987, 5161261.737099998], [-290247.5940999985, 5161337.760600001], [-290510.69779999927, 5161413.185599998], [-291113.7153999992, 5161843.501500003], [-291768.8306000009, 5161706.2776999995], [-292155.99980000034, 5161714.367200002], [-292397.06219999865, 5161951.439300001], [-292921.9893000014, 5161786.873999998], [-294163.7025000006, 5161559.992700003], [-294494.21009999886, 5161607.480800003], [-294999.7674999982, 5161545.761299998], [-295388.88479999825, 5161726.876100004], [-295695.2917000018, 5161789.196000002], [-296087.804299999, 5161781.181299999], [-297623.06700000167, 5160687.497599997], [-298861.81540000066, 5161154.353100002], [-299073.8093000017, 5161234.248599999], [-300993.36470000073, 5163105.773699999], [-301709.91600000113, 5163036.714000002], [-302824.30319999903, 5163343.7293], [-303222.38170000166, 5163307.694700003], [-303588.2888999991, 5163219.668899998], [-303785.15740000084, 5163053.957999997], [-304750.6314000003, 5162568.678199999], [-305102.95760000125, 5162514.368600003], [-305703.2479000017, 5162277.2075999975], [-305859.98580000177, 5162479.011299998], [-305946.6479999982, 5162700.7456], [-306974.40520000085, 5165864.691799998], [-305054.28280000016, 5168235.968000002], [-304238.58740000054, 5170196.446500003], [-301501.8962999992, 5174178.348999999], [-301438.52270000055, 5176775.5891999975], [-303797.436999999, 5179389.516199999], [-304842.3029999994, 5179692.399700001], [-305667.0859000012, 5179517.890600003], [-306311.2822000012, 5178744.8928999975], [-307852.5183000006, 5179662.1669000015], [-308605.1149000004, 5179606.708499998], [-310761.9395000003, 5177281.211400002], [-310658.78730000183, 5175008.007700004], [-311991.7206999995, 5172891.938500002], [-311411.3803999983, 5171976.507399999], [-311184.5185999982, 5170805.834700003], [-311498.43470000103, 5169711.303000003], [-311471.9351999983, 5167996.784199998], [-312229.26630000025, 5167800.015299998], [-313151.03119999915, 5166523.097000003], [-314375.80739999935, 5167037.117600001], [-316664.8781999983, 5166142.483499996], [-317896.9811999984, 5165372.629000001], [-318605.12849999964, 5163945.101599999], [-320430.0929999985, 5162685.388800003], [-321588.5199000016, 5162566.184900001], [-321846.02120000124, 5163525.477600001], [-324344.64290000126, 5164401.154600002], [-324556.59910000116, 5166843.011799999], [-326372.4695999995, 5173007.868500002], [-326394.9107000008, 5174008.762800001], [-327150.8286000006, 5174359.399599999], [-329356.91420000046, 5173853.744999997], [-331389.19040000066, 5173573.635300003], [-331979.03119999915, 5173744.686399996], [-333013.5254999995, 5174044.685199998], [-334516.41699999943, 5173528.555100001], [-336501.69860000163, 5174306.905599996], [-337786.74969999865, 5173862.2949], [-339443.1279999986, 5177888.490500003], [-339808.8126000017, 5178776.445299998], [-340543.13159999996, 5180038.888400003], [-341326.76509999856, 5180969.375], [-342159.49060000107, 5181348.485399999], [-343290.6079000011, 5180988.814199999], [-343998.33740000054, 5183069.271899998], [-344011.4406999983, 5184884.055500001], [-345395.29399999976, 5186747.9366], [-346758.9893000014, 5187798.081], [-346792.8691999987, 5189089.391000003], [-348021.22150000185, 5190150.023199998], [-348271.2329999991, 5190981.104699999], [-345778.4371000007, 5192801.322899997], [-345255.84219999984, 5193560.010300003], [-345051.1719000004, 5194621.5814], [-345369.2210999988, 5195827.393399999], [-343922.69889999926, 5197930.737999998], [-344754.79850000143, 5200422.769199997], [-343937.4855000004, 5201965.485299997], [-344625.2208000012, 5202920.680299997], [-344682.8090999983, 5204230.937899999], [-345784.5240000002, 5207961.237000003], [-345482.8095000014, 5209019.339400001], [-344663.2996000014, 5209926.425800003], [-346211.96599999815, 5211824.3182], [-346154.74709999934, 5212976.812299997], [-345936.00499999896, 5213813.8697], [-343247.48420000076, 5213939.2695999965], [-341201.28810000047, 5214431.386399999], [-341069.34959999844, 5215511.821800001], [-341843.5102000013, 5216482.852600001], [-343367.0705999993, 5218756.244900003], [-345582.00829999894, 5218883.454400003], [-345544.91369999945, 5219416.878600001], [-345017.4140999988, 5220492.435500003], [-344659.37590000033, 5221742.616599999], [-345160.88219999894, 5223490.137599997], [-344241.5795000009, 5223965.731299996], [-344019.24969999865, 5224455.987899996], [-342663.82349999994, 5223457.442199998], [-342746.25560000166, 5221976.405000001], [-342859.52320000157, 5221478.983599998], [-343161.6442999989, 5220688.921899997], [-343074.21440000087, 5220492.435500003], [-342310.33089999855, 5219658.523800001], [-341131.4550999999, 5217065.673900001], [-340856.77419999987, 5216871.9738000035], [-340668.69999999925, 5216679.4076000005], [-340383.6107000001, 5216580.564599998], [-339876.7730999999, 5217077.201200001], [-340222.7076999992, 5218911.576499999], [-340805.8966999985, 5220492.435500003], [-341087.59519999847, 5221727.9548999965], [-340928.35269999877, 5222066.108000003], [-340520.03280000016, 5222576.828100003], [-340520.36670000106, 5223106.573899999], [-340350.32620000094, 5223669.6734], [-341007.44519999996, 5224838.575499997], [-340383.1655000001, 5226196.306000002], [-339650.29360000044, 5227098.526100002], [-339082.00759999827, 5227892.065200001], [-339557.8984000012, 5228863.545599997], [-340113.16000000015, 5229498.957800001], [-340750.185800001, 5230431.974100001], [-341108.5788999982, 5231784.170000002], [-341491.9354999997, 5232099.909199998], [-342141.38369999826, 5232546.553199999], [-343175.8931999989, 5232538.408299997], [-344026.76370000094, 5232830.838100001], [-344139.3634000011, 5234095.8992], [-344423.561999999, 5234101.1071000025], [-344502.3762000017, 5234368.903499998], [-344341.74219999835, 5234889.422499999], [-344099.622299999, 5235095.0414], [-343785.4787000008, 5235255.750299998], [-343623.0078999996, 5235411.253399998], [-343219.47480000183, 5235657.723399997], [-342802.41629999876, 5236018.268200003], [-342325.4679000005, 5237239.965099998], [-342351.51669999957, 5237631.678400002], [-342196.55999999866, 5238534.387400001], [-342431.6667000018, 5239218.8576000035], [-342054.01110000163, 5240429.356399998], [-342435.12469999865, 5240918.370200001], [-343177.23519999906, 5241001.9142], [-343329.6810999997, 5241503.024700001], [-343911.0987999998, 5241857.165100001], [-345098.7380999997, 5241515.023699999], [-346093.31799999997, 5240616.8440999985], [-347997.6721000001, 5241278.146399997], [-348908.0676999986, 5242520.7798999995], [-345723.8317000009, 5244291.019199997], [-345185.90839999914, 5245291.305399999], [-343788.65129999816, 5246306.466300003], [-343199.9772000015, 5247402.182099998], [-343556.5502000004, 5248590.082900003], [-341491.9354999997, 5249602.606700003], [-340925.3471000008, 5249593.0293999985], [-340621.38919999823, 5249644.967500001], [-341185.30970000103, 5250462.279700004], [-340732.57349999994, 5251610.004600003], [-341491.9354999997, 5253175.233800001], [-341822.76359999925, 5254420.525600001], [-342665.43769999966, 5254868.741800003], [-343446.07239999995, 5255510.250100002], [-343087.84750000015, 5256037.618199997], [-343329.0687999986, 5257434.387599997], [-342546.7685999982, 5257232.080600001], [-341491.9354999997, 5257198.427199997], [-341194.46189999953, 5257281.925800003], [-340471.83139999956, 5257282.531099997], [-339614.0590999983, 5257358.118600003], [-338501.64339999855, 5257337.840800002], [-337750.6264999993, 5257033.149599999], [-337443.8856000006, 5257085.128799997], [-337237.5549999997, 5257059.101300001], [-336956.4732000008, 5256909.596299998], [-336440.2291000001, 5256402.840300001], [-335966.39770000055, 5256146.522], [-335776.26399999857, 5256350.8649], [-335872.77800000086, 5256540.156499997], [-335605.44420000166, 5257356.983599998], [-335155.991799999, 5257580.420400001], [-334931.7386999987, 5257459.205499999], [-334490.6352000013, 5257975.8552], [-332918.2782999985, 5257624.306199998]], [[-327862.50569999963, 5251867.612099998], [-327629.51410000026, 5251055.948799998], [-327237.8920999989, 5250441.009599999], [-326866.19629999995, 5250387.932999998], [-325907.95809999853, 5250695.962899998], [-325348.2437000014, 5251405.513499998], [-326119.68780000135, 5252224.769000001], [-326139.4470000006, 5252976.559600003], [-326410.6768999994, 5253232.715999998], [-326669.7730999999, 5253408.784999996], [-327311.1959999986, 5252380.552100003], [-327541.96130000055, 5252274.377400003], [-327700.7028999999, 5252122.074600004], [-327862.50569999963, 5251867.612099998]], [[-333274.1163999997, 5253522.4070999995], [-333891.9032999985, 5251422.829499997], [-332052.84970000014, 5252912.502700001], [-332316.0645999983, 5253430.113200001], [-333274.1163999997, 5253522.4070999995]]]}, "type": "Feature", "properties": {"COAST_TYPE": 3, "MOUNT_TYPE": 2, "NAME_LATN": "La Rioja", "CNTR_CODE": "ES", "NUTS_ID": "ES230", "NUTS_NAME": "La Rioja", "LEVL_CODE": 3, "URBN_TYPE": 2}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES3-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES3-region-20m-3035-2016.geojson new file mode 100644 index 00000000..f5ef9cb2 --- /dev/null +++ b/vignettes/articles/artcache/ES3-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "MultiPolygon", "coordinates": [[[[3202266.1798, 2008291.9937999994], [3208186.1379000004, 1992004.4617999997], [3198669.207800001, 1983222.7755999994], [3182657.6909, 1987089.0864000004], [3151608.075099999, 1979255.4945999999], [3150440.5073000006, 1983539.7216999996], [3159467.4145, 1989756.1532000005], [3160598.7853999995, 1995064.6379000004], [3127465.6620000005, 2017649.447899999], [3116661.3882, 2023000.7436999995], [3105096.5325000007, 2018719.5039000008], [3099761.3676999994, 2025696.8311], [3088533.8883999996, 2020064.3471000008], [3082330.612400001, 2021947.4032000005], [3106569.1263999995, 2040446.1953999996], [3111580.2049000002, 2054606.7230999991], [3126360.241699999, 2066777.7544999998], [3143259.5385999996, 2076570.5775000006], [3152614.7422, 2091351.5243999995], [3186712.0832, 2109110.6219999995], [3194938.7591999993, 2090932.0110999998], [3184369.311899999, 2065861.6651000008], [3202013.0601000004, 2033206.0689000003], [3205507.1086, 2019824.0485999994], [3202266.1798, 2008291.9937999994]]], [[[3147811.1428999994, 1978511.5833], [3139456.127699999, 1970659.8823000006], [3136066.923800001, 1976893.6017000005], [3142664.294399999, 1984145.4758000001], [3147811.1428999994, 1978511.5833]]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "COMUNIDAD DE MADRID", "CNTR_CODE": "ES", "NUTS_ID": "ES3", "NUTS_NAME": "COMUNIDAD DE MADRID", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES30-region-01m-3857-2016.geojson b/vignettes/articles/artcache/ES30-region-01m-3857-2016.geojson new file mode 100644 index 00000000..2e400f0f --- /dev/null +++ b/vignettes/articles/artcache/ES30-region-01m-3857-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3857"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "MultiPolygon", "coordinates": [[[[-393687.55739999935, 5036048.566799998], [-393789.97140000015, 5035273.2914], [-394176.5839000009, 5034435.617200002], [-393351.26669999957, 5034034.010600001], [-392631.57079999894, 5032990.627999999], [-390659.12640000135, 5032419.161899999], [-389065.76099999994, 5029359.812399998], [-388270.8467000015, 5026325.674099997], [-387583.2906000018, 5026147.299599998], [-386835.7314000018, 5026396.901100002], [-383999.7217999995, 5024351.749300003], [-382108.2489, 5024760.237000003], [-381571.52160000056, 5024585.866400003], [-381433.9197999984, 5022086.903099999], [-382350.8198999986, 5020326.816799998], [-382803.79509999976, 5018630.949699998], [-381940.28990000114, 5018483.429399997], [-381780.0454999991, 5018270.528800003], [-381372.17080000043, 5017000.011399999], [-380885.26779999956, 5016343.171300001], [-379304.24430000037, 5014670.226499997], [-379118.8416999988, 5014308.550899997], [-378720.98580000177, 5013923.506200001], [-378566.8082999997, 5013674.4155], [-378189.9919000007, 5013339.698399998], [-378143.0150000006, 5013021.145199999], [-377851.8033000007, 5012376.252499998], [-378110.7324000001, 5012207.513599999], [-378564.35929999873, 5011670.046700001], [-380506.21649999917, 5010501.114500001], [-380296.935899999, 5010090.5616], [-380282.0747000016, 5009757.221199997], [-380526.75499999896, 5009305.560000002], [-380275.8407999985, 5008772.603100002], [-380396.5111999996, 5008594.932700001], [-380872.06799999997, 5007510.918799996], [-382392.94999999925, 5004415.445900001], [-382679.9967, 5002522.154600002], [-383737.501699999, 5001092.414499998], [-384178.5909000002, 4999491.493699998], [-383518.5329999998, 4999020.552699998], [-383475.40129999816, 4998647.489799999], [-384012.6165000014, 4998432.4278], [-384990.7573999986, 4998732.538800001], [-385122.36019999906, 4997540.811800003], [-383260.88599999994, 4996658.8434000015], [-383015.8808000013, 4996184.868799999], [-383363.18290000036, 4995624.940499999], [-383047.75180000067, 4994721.891000003], [-383085.6405000016, 4994055.075599998], [-383852.6303999983, 4994043.575499997], [-386383.497299999, 4992444.663699999], [-386435.41259999946, 4991930.747100003], [-385900.05319999903, 4991217.789899997], [-386288.09519999847, 4990539.236199997], [-386842.65949999914, 4990366.085199997], [-386328.3916000016, 4989273.6329], [-387218.2377000004, 4988411.0119], [-387126.1145000011, 4986315.2108], [-388587.23530000076, 4984040.2478], [-388782.25620000064, 4982649.804700002], [-389846.47839999944, 4982532.362800002], [-389974.3845000006, 4982218.491499998], [-389862.564100001, 4981926.392200001], [-389889.3920999989, 4981610.187799998], [-390074.4050000012, 4981296.934299998], [-390633.3401999995, 4981488.149300002], [-390889.3194000013, 4981188.646899998], [-389884.77230000123, 4981130.203100003], [-389394.5769000016, 4981235.4021999985], [-385185.07400000095, 4980177.494900003], [-383976.98220000044, 4978566.369400002], [-383696.3548000008, 4977502.0057], [-383392.2569000013, 4976945.071199998], [-383432.1832000017, 4975420.615400001], [-384176.5313999988, 4973785.755599998], [-384081.40890000015, 4973309.901500002], [-383894.6147999987, 4973026.882799998], [-383615.0359000005, 4973215.805799998], [-383413.2137000002, 4973477.013400003], [-383131.5196999982, 4973727.2826000005], [-382919.567400001, 4973546.136100002], [-382763.7201000005, 4973330.468900003], [-382333.3713000007, 4972722.062100001], [-382569.9893000014, 4971706.122599997], [-385119.12689999864, 4968604.705700003], [-385474.79349999875, 4967299.235200003], [-386100.2991999984, 4966708.510600001], [-384646.34959999844, 4966301.502099998], [-383735.3299999982, 4964984.601800002], [-383009.8306999989, 4964481.025399998], [-381541.5581, 4964230.590899996], [-381296.84329999983, 4965431.8298999965], [-380885.26779999956, 4965418.198399998], [-380191.4226000011, 4964166.134099998], [-379077.9673999995, 4963845.2304000035], [-378460.0529999994, 4966929.831], [-378140.3990000002, 4966945.613600001], [-377729.5188000016, 4967078.7754999995], [-377293.4246999994, 4966359.546599999], [-377011.5080999993, 4966125.760899998], [-376878.31430000067, 4965848.748599999], [-376601.0174999982, 4965742.3204], [-375597.83150000125, 4965066.1567], [-374380.1187000014, 4961518.827799998], [-374611.12590000033, 4960965.473999999], [-374456.67069999874, 4960386.863200001], [-372587.32250000164, 4959697.300099999], [-372412.6640000008, 4959107.899400003], [-371792.70050000027, 4958914.128200002], [-370067.7468000017, 4959735.843699999], [-369174.0036999993, 4961606.903700002], [-368957.6449000016, 4960805.5858], [-369842.1490000002, 4959477.3926], [-370060.64090000093, 4957891.131800003], [-371284.0133999996, 4957121.149700001], [-369747.0207999982, 4955301.763599999], [-370692.0527999997, 4954261.555100001], [-370757.0225000009, 4953649.0473000035], [-370488.91629999876, 4952796.5515], [-368816.8922000006, 4950918.062200002], [-367186.2745999992, 4949885.649599999], [-365858.0742999986, 4949493.378200002], [-365577.4613999985, 4948125.601400003], [-365933.80530000106, 4947418.508400001], [-365539.85119999945, 4946216.234700002], [-366912.5843999982, 4944385.495399997], [-366207.50620000064, 4943513.038800001], [-365630.90469999984, 4943921.469300002], [-364716.0518000014, 4943830.748400003], [-361718.4362999983, 4945227.547399998], [-360854.7360999994, 4944184.681199998], [-359839.65239999816, 4943697.310500003], [-359792.7762000002, 4944677.131099999], [-358602.6163999997, 4942616.9388], [-356276.0821999982, 4941069.2238000035], [-356082.5518999994, 4939624.036799997], [-356346.71440000087, 4938686.403399996], [-355685.4765999988, 4935730.972199999], [-356189.8988999985, 4933743.286399998], [-356049.3244000003, 4930414.0493], [-353185.16899999976, 4929643.869400002], [-351253.45809999853, 4930000.555799998], [-349776.04459999874, 4926149.5722], [-348475.3132000007, 4924994.012900002], [-349035.5106999986, 4922916.549999997], [-349868.03539999947, 4922261.534900002], [-349471.31700000167, 4920685.6428999975], [-350645.4866999984, 4920306.065700002], [-350901.63650000095, 4919409.6316], [-350500.8082999997, 4918483.547700003], [-349904.76680000126, 4918118.107900001], [-349798.07499999925, 4917025.9036], [-351027.28119999915, 4915898.809799999], [-351042.11989999935, 4914355.683399998], [-353875.0159999989, 4911661.0079], [-354166.9675000012, 4910253.552500002], [-354002.15900000185, 4909929.869999997], [-354143.14510000125, 4909289.396600001], [-354139.8612000011, 4908901.892499998], [-354038.4490999989, 4908445.226400003], [-354139.8612000011, 4907952.754199997], [-354465.3594000004, 4907098.848499998], [-354729.1865000017, 4906563.617299996], [-354703.9726999998, 4906027.6127], [-354447.436900001, 4905208.669500001], [-355406.3429999985, 4903686.809299998], [-355559.40729999915, 4903523.068700001], [-355894.08940000087, 4903434.671700001], [-355628.9820000008, 4903075.038599998], [-355587.2371999994, 4902047.556299999], [-354252.4932000004, 4901230.131499998], [-353243.68360000104, 4900025.284100004], [-352777.1143000014, 4901677.218800001], [-350983.7639000006, 4904336.514700003], [-349871.41220000014, 4904817.234200001], [-348098.9635999985, 4906579.801899999], [-346484.25279999897, 4907509.9223000035], [-346124.5795000009, 4907468.3325999975], [-344774.9816999994, 4905490.416500002], [-344943.02439999953, 4903882.802900001], [-343684.5432999991, 4901921.143799998], [-343851.2496000007, 4900552.745399997], [-342845.60269999877, 4898832.3138], [-343067.86989999935, 4897159.722599998], [-342860.3957999982, 4896102.815800004], [-343762.9365000017, 4895090.560800001], [-343443.9847000018, 4894760.567000002], [-343407.70650000125, 4893049.8532000035], [-342598.4076000005, 4891138.159599997], [-342524.7479999997, 4890118.790100001], [-341493.5773999989, 4888912.292599998], [-342466.48739999905, 4888766.1098000035], [-343364.76419999823, 4889641.9086000025], [-343817.29769999906, 4889611.805200003], [-344682.11290000007, 4888496.428599998], [-344458.42069999874, 4887828.681999996], [-344682.99159999937, 4886816.604500003], [-342136.8471999988, 4885015.802900001], [-341931.38899999857, 4884027.310699999], [-340370.29879999906, 4882391.7304000035], [-339838.92449999973, 4880391.380800001], [-340908.36620000005, 4878919.456], [-343730.0839000009, 4876314.456299998], [-344555.75389999896, 4875904.420599997], [-347097.56749999896, 4874868.557599999], [-349627.08029999956, 4875127.0222999975], [-350595.5599000007, 4875536.7689], [-351542.9444000013, 4875312.329800002], [-351927.6088999994, 4875377.420900002], [-352065.97679999843, 4877786.5176], [-352560.8256999999, 4878385.763400003], [-352551.1959999986, 4879075.955600001], [-353747.39279999956, 4879250.2168999985], [-353989.44110000134, 4878896.236599997], [-353751.41849999875, 4878467.1554000005], [-354937.688000001, 4877933.551200002], [-355070.7285999991, 4877160.873400003], [-356009.31819999963, 4875967.265500002], [-357498.819600001, 4874872.479099996], [-360695.09160000086, 4873763.256200001], [-362246.7597000003, 4874258.920500003], [-362675.40459999815, 4873425.142800003], [-363463.5364000015, 4874110.5864999965], [-363741.3861999996, 4873702.539300002], [-364306.27870000154, 4873698.1071000025], [-364652.41750000045, 4872863.0842999965], [-365826.0142999999, 4873545.576800004], [-366408.7718999982, 4873522.671800002], [-367631.2875000015, 4873776.1570999995], [-368682.69029999897, 4875825.437299997], [-370252.9805999994, 4877309.9152000025], [-371162.0452999994, 4877684.080600001], [-372349.11389999837, 4877585.101199999], [-374114.682599999, 4876934.204800002], [-375939.43180000037, 4876720.116800003], [-376114.6601999998, 4875580.450400002], [-375693.9118999988, 4873738.762999997], [-375964.3977999985, 4873293.556699999], [-376781.2254999988, 4873386.039499998], [-377632.188000001, 4872794.018700004], [-377840.0590999983, 4871096.350599997], [-378919.66149999946, 4871046.5898], [-379399.4545000009, 4871348.849799998], [-379597.7049999982, 4871944.403700002], [-380885.26779999956, 4872503.664300002], [-381281.30260000005, 4872594.327500001], [-381880.50279999897, 4871625.7206000015], [-383577.95340000093, 4871437.171899997], [-383777.69260000065, 4872846.287699997], [-384597.04289999977, 4873119.529700004], [-384793.2644000016, 4872680.518399999], [-386050.48750000075, 4872000.722999997], [-386619.77160000056, 4872063.0418], [-386716.1163999997, 4872554.613600001], [-387763.13919999823, 4872481.1963], [-388269.32279999927, 4872042.851099998], [-388814.0201999992, 4872840.668399997], [-389611.0918999985, 4872555.2195999995], [-390221.2190000005, 4872783.772200003], [-390882.4175999984, 4872204.596500002], [-391292.2402999997, 4872228.952600002], [-391517.4395999983, 4871239.2727999985], [-392054.38919999823, 4869731.206200004], [-391792.3431000002, 4868999.862599999], [-393071.9772000015, 4868584.981799997], [-395238.4605999999, 4868495.033], [-399584.27910000086, 4867775.629199997], [-400248.75569999963, 4866140.348200001], [-401806.0700000003, 4865678.941100001], [-402486.47260000184, 4865059.734099999], [-403188.04989999905, 4864707.046700001], [-404114.2644999996, 4864763.366099998], [-404867.74269999936, 4864210.218500003], [-404226.2842000015, 4861752.9943], [-404129.04740000144, 4861380.510799997], [-404808.5291999988, 4860994.506700002], [-407393.96440000087, 4860962.607199997], [-408092.52219999954, 4860631.119099997], [-409363.60990000144, 4860191.171400003], [-411541.1435999982, 4858306.454499997], [-413158.1682999991, 4859244.9636999965], [-416712.65480000153, 4857301.866899997], [-417230.806499999, 4855776.599399999], [-418248.9615999982, 4854462.986100003], [-420648.9670000002, 4852931.263700001], [-423550.37689999864, 4849681.991999999], [-423491.68129999936, 4849210.456100002], [-424336.65190000087, 4849356.9081000015], [-424672.00189999864, 4849352.555799998], [-426828.20419999957, 4851376.187799998], [-428085.02849999815, 4851795.963299997], [-430187.78170000017, 4851929.4419], [-431410.6158999987, 4852971.815300003], [-430607.04780000076, 4853974.665399998], [-431315.5628999993, 4855473.9738000035], [-430515.7184999995, 4856059.1592999995], [-429646.3564000018, 4856243.038800001], [-428887.84369999915, 4857086.069399998], [-427507.24120000005, 4857432.178300001], [-427057.5603, 4856239.837899998], [-426642.75869999826, 4856037.847400002], [-425952.5192000009, 4857847.724299997], [-425422.4622000009, 4858183.045199998], [-423747.6840999983, 4859041.533699997], [-422797.91149999946, 4858232.056100003], [-421460.8225999996, 4858084.704800002], [-421119.9541000016, 4859458.999600001], [-419079.9006999992, 4860732.679099999], [-418608.80849999934, 4859943.7885000035], [-419490.5720000006, 4858793.2195999995], [-418733.78880000114, 4858529.944700003], [-417785.5346999988, 4859280.287299998], [-417980.4321000017, 4860914.674400002], [-416396.2958999984, 4860487.208400004], [-415256.08989999816, 4860801.9573], [-414861.63749999925, 4861416.366700001], [-416252.8586000018, 4861752.9943], [-416858.65630000085, 4863010.163900003], [-416376.9866000004, 4863184.515100002], [-415720.11019999906, 4862757.382299997], [-415474.8425000012, 4863861.253300004], [-414920.6378999986, 4864158.977799997], [-414249.814199999, 4864048.626000002], [-414430.4136000015, 4865524.3891], [-413561.92709999904, 4866491.884499997], [-412949.93129999936, 4867692.7161], [-411903.13699999824, 4868705.967100002], [-410601.01949999854, 4869070.422200002], [-410179.4783000015, 4868371.711400002], [-409733.0144000016, 4868282.0964], [-408273.9173000008, 4869984.303400002], [-408232.0020000003, 4870740.191799998], [-407673.3707999997, 4871253.258000001], [-406335.49120000005, 4870667.113399997], [-405998.45259999856, 4871889.8539], [-404801.8407000005, 4872089.277599998], [-405012.28880000114, 4873244.477899998], [-403052.3729000017, 4874128.635200001], [-403339.40129999816, 4874900.5145], [-402689.33680000156, 4875962.7346], [-403889.3792999983, 4877244.366899997], [-401815.69590000063, 4878075.3571000025], [-401236.1154000014, 4879543.752099998], [-401543.63439999893, 4879725.0402000025], [-402235.6510999985, 4879479.760600001], [-402489.3894999996, 4879970.0842999965], [-401581.50079999864, 4881784.630400002], [-406918.0194000006, 4884219.745399997], [-407948.32939999923, 4885437.813900001], [-408225.49329999834, 4886781.6679000035], [-408578.0978000015, 4886563.308300003], [-409403.3092, 4886180.6263], [-409529.1559000015, 4885815.359300002], [-409804.5603, 4885624.758900002], [-410052.3018000014, 4885176.9570999965], [-410408.7468000017, 4885281.498199999], [-410918.3117999993, 4885247.864399999], [-412371.08680000156, 4885930.245499998], [-412519.8652999997, 4886141.164800003], [-412875.8093999997, 4886398.249399997], [-413301.71770000085, 4886549.474399999], [-413880.1895000003, 4887227.940399997], [-414337.2115999982, 4887425.634900004], [-415004.9615999982, 4887011.609700002], [-415834.7371000014, 4886179.0244999975], [-416291.9261999987, 4885605.1021], [-416554.02800000086, 4885441.6608000025], [-417328.0254999995, 4885260.751699999], [-419815.85599999875, 4886270.179499999], [-420510.5703999996, 4887335.4032000005], [-420920.0665999986, 4889103.256399997], [-423000.1501000002, 4891458.444600001], [-423683.26209999993, 4891715.958800003], [-423747.43780000135, 4891724.0449], [-424200.78440000117, 4890628.643299997], [-425011.3458000012, 4890761.143799998], [-426698.01960000023, 4889523.199299999], [-427541.98530000076, 4889603.1565999985], [-428774.9362999983, 4890562.572700001], [-428954.6853, 4892039.044699997], [-430372.65129999816, 4893249.314499997], [-431510.30249999836, 4893769.173199996], [-432267.8872999996, 4893414.117700003], [-435491.0747000016, 4893640.206900001], [-436040.4565999992, 4893939.166000001], [-437039.15199999884, 4895175.603799999], [-437552.9334000014, 4895536.4463], [-438446.06340000033, 4895518.916599996], [-439551.8984999992, 4893922.342299998], [-439806.38760000095, 4894536.742799997], [-440412.85610000044, 4894917.416500002], [-440282.0557000004, 4895539.321900003], [-440116.1897, 4896022.575499997], [-440042.10660000145, 4896498.783], [-440031.0859999992, 4896913.642999999], [-442396.27760000154, 4896721.070100002], [-444360.75510000065, 4896561.123300001], [-446242.30590000004, 4898003.893600002], [-448082.9710999988, 4900231.115000002], [-448204.47309999913, 4901444.490500003], [-447934.32449999824, 4902182.467], [-448149.6163999997, 4902271.946599998], [-449920.48690000176, 4902290.469700001], [-451057.72679999843, 4902555.850900002], [-451607.58940000087, 4902908.828500003], [-452221.2380999997, 4903461.001100004], [-452631.060800001, 4904013.4234], [-453374.06280000135, 4904586.738399997], [-453650.24639999866, 4904551.2151999995], [-454215.8607000001, 4904803.818999998], [-454804.7408999987, 4903206.024899997], [-454959.92020000145, 4902953.6809], [-455856.9327000007, 4902006.354199998], [-456458.2806000002, 4901768.552299999], [-456650.9189000018, 4901377.332900003], [-456866.9343999997, 4901141.879500002], [-457639.9926000014, 4901499.910899997], [-457930.6477999985, 4901426.626400001], [-458700.81170000136, 4901411.604999997], [-459119.0390000008, 4901759.2183], [-459455.72480000183, 4901755.2075999975], [-459894.21229999885, 4902184.217200004], [-460077.0368000008, 4902103.127300002], [-461259.15630000085, 4901578.810800001], [-461961.8123999983, 4902231.516599998], [-461364.73699999973, 4904442.523000002], [-463672.90399999917, 4905512.079099998], [-464168.5808000006, 4907009.706900001], [-464460.3707999997, 4907891.315399997], [-465307.2639000006, 4908630.7729], [-466640.1341999993, 4909125.682099998], [-467961.51590000093, 4907604.138400003], [-467974.07079999894, 4907009.706900001], [-468014.04030000046, 4905117.299599998], [-468764.2837000005, 4905081.9103000015], [-469595.4919999987, 4905619.454700001], [-470439.22940000147, 4905234.7848000005], [-471027.49720000103, 4906223.057300001], [-473051.9651999995, 4905530.081100002], [-474252.7514999993, 4903308.804799996], [-474445.36939999834, 4902080.224799998], [-475336.3790999986, 4900278.010600001], [-477118.2212000005, 4899090.1611], [-478017.3029000014, 4897914.517999999], [-479369.9868000001, 4898329.585000001], [-479656.2683000006, 4899032.341799997], [-479414.86730000004, 4899683.776100002], [-479681.45650000125, 4899936.833700001], [-481140.1094000004, 4899072.146300003], [-482568.3354999982, 4900682.860399999], [-483308.88749999925, 4900864.937700003], [-484052.54560000077, 4900400.044699997], [-483760.8117999993, 4902757.444200002], [-485133.87739999965, 4906155.815399997], [-485097.4021999985, 4907009.706900001], [-484931.80260000005, 4910886.424599998], [-487572.6904999986, 4912305.297499999], [-487467.379900001, 4911782.423799999], [-488245.3110000007, 4909890.030199997], [-487964.8759999983, 4909424.337899998], [-488092.82840000093, 4907997.554899998], [-489544.88489999995, 4907306.1679000035], [-489808.1543000005, 4907009.706900001], [-492877.4715999998, 4903553.424400002], [-493684.2419000007, 4903686.006999999], [-493662.57820000127, 4901332.965099998], [-494003.78449999914, 4900573.066500001], [-495280.5175999999, 4899909.6065], [-498042.24909999967, 4899540.457500003], [-500640.5412000008, 4898193.681999996], [-502606.81060000136, 4897388.464400001], [-502877.0100999996, 4895838.199100003], [-503298.68360000104, 4895356.550300002], [-505022.7001999989, 4895001.428599998], [-506583.1096000001, 4895292.202], [-509138.2404999994, 4896027.373999998], [-509129.8381000012, 4896995.547700003], [-509740.4085999988, 4897554.990199998], [-509251.4081000015, 4897845.999499999], [-508277.44200000167, 4897762.3411], [-507707.5811999999, 4898585.713500001], [-507615.91220000014, 4900034.946900003], [-508379.54089999944, 4900950.944700003], [-508672.07550000027, 4903402.945299998], [-507181.8414000012, 4904692.7250000015], [-507086.99720000103, 4906249.685900003], [-506180.27650000155, 4907009.706900001], [-504239.09699999914, 4908636.819700003], [-505091.53770000115, 4911126.3059], [-505434.62629999965, 4913543.1598000005], [-505886.63919999823, 4914033.1413], [-506064.1937999986, 4915734.487599999], [-505266.0887000002, 4915539.511500001], [-504829.2710000016, 4915699.8006], [-504229.53720000014, 4916071.505900003], [-503900.47679999843, 4916179.733900003], [-503860.7619000003, 4915237.590899996], [-503252.561900001, 4914749.213100001], [-502327.01309999824, 4912720.1263], [-501510.30790000036, 4911952.899899997], [-500906.9686000012, 4911906.131399997], [-499658.8471999988, 4912657.755000003], [-497854.4926000014, 4912586.278800003], [-497276.96709999815, 4912577.956500001], [-497018.5388999991, 4912319.240599997], [-496613.0020000003, 4912444.290600002], [-495994.1213000007, 4912452.685800001], [-496039.5397000015, 4912668.333499998], [-495704.85759999976, 4913242.224799998], [-495696.00769999996, 4913943.4089], [-495777.2153000012, 4914459.3994999975], [-496571.6468000002, 4915537.028700002], [-496206.03990000114, 4916048.986500002], [-494650.79780000076, 4916587.7566], [-494204.95980000123, 4917115.193499997], [-494266.4673999995, 4921221.679200001], [-494534.75719999894, 4922222.631899998], [-492195.39930000156, 4925153.067100003], [-491256.8260000013, 4925682.671899997], [-490076.8728, 4925853.245899998], [-486107.8658000007, 4925286.517099999], [-484980.3847000003, 4925903.5757], [-483385.9957000017, 4925916.836199999], [-482148.0053000003, 4925513.867399998], [-481002.7254999988, 4925741.648400001], [-481523.0064000003, 4926352.812799998], [-481327.1660999991, 4926910.289899997], [-481442.0780999996, 4927615.623599999], [-482093.8792000003, 4927603.9498], [-483108.42080000043, 4928414.7754999995], [-483014.3242999986, 4928897.7233000025], [-483049.42920000106, 4929831.2119999975], [-482460.06969999894, 4930199.727499999], [-481991.7917999998, 4931286.939999998], [-480922.2025000006, 4931814.561399996], [-481465.09099999815, 4933023.759800002], [-480835.5590999983, 4932908.454000004], [-480530.4525000006, 4933718.479699999], [-481307.91429999843, 4935704.347599998], [-481245.9343999997, 4939158.625], [-481652.32770000026, 4940121.852499999], [-481108.08940000087, 4941377.385499999], [-481034.5375000015, 4942616.9388], [-480988.02910000086, 4943400.7355], [-481696.9787000008, 4943910.5198], [-481333.7340000011, 4945856.450900003], [-479765.85130000114, 4947238.333999999], [-477459.9270000011, 4948265.117899999], [-476613.37590000033, 4951771.789099999], [-476752.72199999914, 4952856.738700002], [-476318.1358000003, 4953842.089400001], [-477506.5795000009, 4954722.2531], [-477621.1176000014, 4957593.285499997], [-476726.5177000016, 4958036.7907000035], [-475566.50769999996, 4957754.427599996], [-474532.0736999996, 4954447.505900003], [-472483.5740999989, 4953881.010200001], [-469021.7718999982, 4954374.721900001], [-464924.9270000011, 4955916.0864999965], [-463202.57189999893, 4956954.0986], [-464439.56980000064, 4957957.1351], [-463955.03599999845, 4960540.200599998], [-464552.8707999997, 4964412.706200004], [-464269.6862999983, 4965424.183499999], [-463121.75400000066, 4966702.197800003], [-461458.14730000123, 4967536.775799997], [-460475.4833999984, 4970605.948399998], [-460077.0368000008, 4970989.133699998], [-459251.8988999985, 4971782.6674000025], [-459058.61670000106, 4972738.863399997], [-457708.6226999983, 4974465.963399999], [-456056.9737999998, 4975197.587800004], [-455768.71930000186, 4976426.0205999985], [-455891.62409999967, 4977787.288099997], [-454350.78180000186, 4979398.1445999965], [-453796.16230000183, 4981160.830700003], [-453062.64649999887, 4981984.987800002], [-451893.6805000007, 4981748.107799999], [-451216.63540000096, 4981502.779200003], [-450487.6596999988, 4981435.511500001], [-450324.85489999875, 4981249.737599999], [-449958.2241999991, 4980495.944899999], [-449663.11620000005, 4980551.223999999], [-449301.3278999999, 4980457.793700002], [-448866.7366000004, 4980175.229500003], [-447633.20529999956, 4980114.292499997], [-446948.92440000176, 4980379.433499999], [-446653.3154999986, 4980578.349100001], [-446112.0800999999, 4981101.679700002], [-445577.9134999998, 4981210.701300003], [-444119.23860000074, 4980743.527099997], [-443504.4210000001, 4980813.509900004], [-442997.7503999993, 4980608.782200001], [-442941.7010000013, 4980832.181900002], [-442824.48160000145, 4981029.783500001], [-442941.86300000176, 4982828.430100001], [-442396.27760000154, 4983653.554399997], [-441475.29459999874, 4985046.417099997], [-441100.2949000001, 4986175.862800002], [-441396.09109999985, 4988376.4016999975], [-439367.7023999989, 4992332.9602999985], [-438861.0689999983, 4995731.406199999], [-439856.50989999995, 4996684.420999996], [-439133.18290000036, 4998088.292599998], [-438248.9952000007, 5000088.352899998], [-438352.944600001, 5001600.026299998], [-437446.0247000009, 5001580.577799998], [-437174.8504999988, 5001668.685599998], [-436550.29250000045, 5002008.305699997], [-436352.03240000084, 5003176.512599997], [-434610.1050999984, 5005924.296499997], [-434393.5329999998, 5005986.205799997], [-433977.36510000005, 5006264.802199997], [-433591.53170000017, 5007251.1567], [-433050.6860000007, 5007741.349200003], [-432675.59490000084, 5008081.328699999], [-432295.71719999984, 5008093.270999998], [-431989.81120000035, 5008326.369099997], [-431931.4241000004, 5008569.646300003], [-430697.69629999995, 5008187.066299997], [-429565.3231999986, 5009205.922200002], [-428352.0315000005, 5009335.269100003], [-427951.25140000135, 5009731.563100003], [-427368.939199999, 5009962.783399999], [-426912.0282999985, 5010003.704700001], [-426235.4283999987, 5010366.842299998], [-425415.1997999996, 5010161.511500001], [-424052.6667999998, 5010580.575099997], [-420865.2296999991, 5012513.138700001], [-419777.5621000007, 5014146.490900002], [-419658.6728999987, 5014356.424400002], [-419356.2179000005, 5014691.766599998], [-419314.6400000006, 5015129.071500003], [-419202.819600001, 5015407.708700001], [-418438.2217000015, 5016328.736400001], [-418048.0469000004, 5016455.6391], [-417792.9582999982, 5017006.061700001], [-417236.36080000177, 5017745.713600002], [-417184.20760000125, 5017938.826399997], [-416968.41479999945, 5018320.783200003], [-416661.1730000004, 5019027.915299997], [-416206.48849999905, 5019670.518799998], [-416368.3471000008, 5020250.130900003], [-415267.7313000001, 5021399.272], [-414717.36769999936, 5021558.278700002], [-414249.71449999884, 5021931.888300002], [-413656.15900000185, 5022894.4366], [-412554.54129999876, 5023678.3955999985], [-411981.02329999954, 5024155.683300003], [-411357.24450000003, 5024540.764600001], [-410484.8892999999, 5024870.994199999], [-410092.5438000001, 5024880.446400002], [-409587.1532999985, 5024766.7993], [-409200.59640000015, 5025130.932300001], [-408767.2296000011, 5025914.481200002], [-408160.42709999904, 5026520.9811], [-407837.71189999953, 5026772.617299996], [-406934.52120000124, 5027786.688000001], [-406555.6453000009, 5028052.539999999], [-406416.8854999989, 5028242.829099998], [-406375.97560000047, 5028657.843800001], [-406158.6242999993, 5029277.148500003], [-405936.54190000147, 5029615.666299999], [-405886.503800001, 5029812.487800002], [-405895.0753999986, 5030054.1611], [-405744.7384000011, 5030241.6818], [-404553.7311999984, 5030889.166199997], [-404416.2355999984, 5032345.016000003], [-402959.80310000107, 5033473.031800002], [-402258.6015999988, 5034344.8464], [-401940.060899999, 5034434.212800004], [-401254.49980000034, 5034785.994599998], [-400933.12040000036, 5035143.8508], [-400738.53400000185, 5035280.609899998], [-400600.5535000004, 5035126.5528], [-400182.2148000002, 5035102.306000002], [-399755.74980000034, 5035171.350299999], [-399538.9550999999, 5035742.870099999], [-398809.8125, 5036173.3618], [-398351.4545000009, 5036001.5473000035], [-397303.9937000014, 5035890.5792], [-396060.6107000001, 5036613.484200001], [-395217.3654999994, 5036806.307400003], [-394489.05779999867, 5036827.527099997], [-394023.46400000155, 5036708.712399997], [-393687.55739999935, 5036048.566799998]], [[-376480.6810999997, 4957982.274099998], [-375322.3460999988, 4957292.607299998], [-374913.65630000085, 4958137.261500001], [-374457.2666000016, 4958308.5424000025], [-374490.0661999993, 4959064.973399997], [-375485.4037999995, 4959167.613700002], [-375552.5069999993, 4958688.465999998], [-376271.567400001, 4958331.893100001], [-376480.6810999997, 4957982.274099998]]], [[[-356332.9411999993, 4874597.9877], [-356798.21489999816, 4874587.896499999], [-357034.19260000065, 4874863.877300002], [-356845.62310000136, 4875044.825499997], [-356288.98889999837, 4874934.538900003], [-356332.9411999993, 4874597.9877]]], [[[-473628.4732999988, 4962635.336300001], [-473808.07400000095, 4961164.1127], [-477204.17540000007, 4961249.952], [-480827.1746000014, 4960500.806699999], [-481272.3761, 4961942.1897], [-480308.2212000005, 4963376.894900002], [-477363.71869999915, 4965344.618699998], [-475797.87139999866, 4964828.480300002], [-475113.7547999993, 4964445.448600002], [-473628.4732999988, 4962635.336300001]]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "Comunidad de Madrid", "CNTR_CODE": "ES", "NUTS_ID": "ES30", "NUTS_NAME": "Comunidad de Madrid", "LEVL_CODE": 2, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES4-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES4-region-20m-3035-2016.geojson new file mode 100644 index 00000000..5dba3057 --- /dev/null +++ b/vignettes/articles/artcache/ES4-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "MultiPolygon", "coordinates": [[[[3119952.0965, 2349559.6811999995], [3125001.4101, 2330449.2777999993], [3150300.8507000003, 2327782.3135], [3162283.3367999997, 2314443.0578000005], [3163653.3541, 2308938.1927000005], [3166500.6481999997, 2297553.6778999995], [3172460.7660000008, 2291846.463300001], [3175411.4093999993, 2291867.773499999], [3177367.3874999993, 2295483.9648], [3179988.7774, 2294987.7567999996], [3179180.033500001, 2291421.2546999995], [3192778.1324000005, 2293707.5615], [3189500.0430999994, 2304026.1525], [3187396.0602, 2310678.455], [3193779.3111000005, 2318292.9058999997], [3214481.3960999995, 2328317.7947000004], [3232789.2897999994, 2322638.6021999996], [3245936.8885999992, 2326401.1130999997], [3255442.84, 2321747.763699999], [3256755.159499999, 2303490.7809999995], [3260589.2171, 2300629.2070000004], [3249720.886600001, 2293031.0437000003], [3244989.3155000005, 2289733.8762], [3262169.4164000005, 2268634.2475000005], [3268897.3400999997, 2260428.375499999], [3255192.270300001, 2262449.0764000006], [3252208.2777999993, 2261013.1689], [3248354.4751999993, 2252463.9134], [3248847.259400001, 2242595.8125], [3241876.8972999994, 2214289.3730999995], [3253551.0661999993, 2193820.4492000006], [3265947.7237, 2198859.9618999995], [3280351.7048000004, 2188400.773], [3287270.8214, 2195094.202299999], [3290066.9048999995, 2197804.2820999995], [3301555.1323000006, 2198436.843699999], [3315555.7653, 2190964.2083], [3320153.2068000007, 2179318.8586], [3322602.5621000007, 2173140.0863000005], [3339164.6708000004, 2173247.9261000007], [3338191.2777999993, 2145215.0406], [3324325.0501000006, 2130880.3687999994], [3320573.4825999998, 2115289.217700001], [3311477.2315999996, 2115649.2814000007], [3306374.5276999995, 2109656.6722999997], [3306154.4099000003, 2085580.9211], [3309793.2765999995, 2085984.7526999991], [3327481.2235000003, 2077678.5802999996], [3342725.3554, 2058005.5736999996], [3342794.4805999994, 2020941.2387000006], [3331823.5679, 2017019.0307], [3318343.6432000007, 2000696.9396000002], [3344584.6417999994, 1968319.6502], [3348582.2419000007, 1955301.0374999996], [3353819.7498000003, 1952016.4002], [3366572.0955, 1949885.1067999993], [3367939.042300001, 1945405.4098000005], [3362101.130000001, 1943328.3509], [3359154.579500001, 1929332.7474000007], [3348713.0973000005, 1914676.1378000006], [3331946.3783, 1904357.960000001], [3328750.6482999995, 1889372.1570999995], [3353230.0163000003, 1870515.5622000005], [3347870.6827000007, 1845260.0708000008], [3354261.5317, 1832142.1460999995], [3368699.5085000005, 1828248.5932], [3368962.6042, 1812557.920499999], [3366765.9044000003, 1803229.7704000007], [3358646.9791, 1799734.674900001], [3350924.5186, 1807008.3871], [3346700.844900001, 1810997.3684999999], [3334171.8203999996, 1807491.1786000002], [3323293.3713000007, 1804112.5719000008], [3310379.528000001, 1772376.2208999991], [3300490.2179000005, 1770369.8378999997], [3291062.8440000005, 1777478.9824], [3264446.9527000003, 1773235.1347000003], [3259998.9529, 1769500.6363999993], [3234890.708799999, 1748534.0275999997], [3220614.2314, 1756235.5787000004], [3217566.8117999993, 1757885.6275999993], [3221546.0341999996, 1762521.2059000004], [3228810.0076, 1771628.5479000006], [3227472.9779000003, 1788518.5874000005], [3225938.4255999997, 1792090.2550000008], [3221092.6728000008, 1801230.3576999996], [3206655.1525999997, 1809949.3696999997], [3194153.8215999994, 1804160.2177000009], [3154922.7206999995, 1811506.1438999996], [3144236.5222999994, 1807140.0001999997], [3078882.6253999993, 1817254.1201000009], [3073284.0786000006, 1813057.6834999993], [3013685.8264000006, 1867697.3472000007], [3003395.8956000004, 1867807.2030999996], [2964939.6942, 1844685.6445000004], [2961596.3259999994, 1820278.8531], [2955595.16, 1812174.2807999998], [2945585.776799999, 1811047.9392000008], [2945194.9539, 1820031.4337000009], [2936049.9789000005, 1820688.7597000003], [2920347.6218999997, 1805736.9285000004], [2900309.0726999994, 1802349.4406000003], [2887446.4164000005, 1812045.2080000006], [2869323.0415000003, 1818984.7425999995], [2841367.7413999997, 1845643.4425000008], [2825810.8137, 1846890.8708999995], [2814683.6943999995, 1880101.0756], [2830219.0867999997, 1909755.1043999996], [2843821.144200001, 1917402.0711000003], [2856470.365599999, 1935613.6271000002], [2845052.7489, 1948555.6505999994], [2839691.3215999994, 1967475.0245999992], [2836695.3061999995, 1988343.2740000002], [2822316.5429, 2015259.6797000002], [2866332.3018999994, 2007702.5895000007], [2884980.7090000007, 2036259.3658000007], [2878534.2765999995, 2058737.0285999998], [2885229.647399999, 2068270.8232000005], [2892686.5370000005, 2068076.5185000002], [2900060.5025999993, 2076678.8945000004], [2909675.7776999995, 2128364.2321000006], [2904457.601, 2151677.7938], [2914970.0164, 2152224.6538999993], [2928114.7364000008, 2166294.6163], [2947304.8771, 2172124.7914000005], [2950367.1721, 2172482.1493999995], [2953674.0818000007, 2176456.5595999993], [2960288.4356999993, 2179024.3719999995], [2975581.5835999995, 2196387.298699999], [2969246.9417000003, 2208467.8521999996], [2953281.2358999997, 2217667.332800001], [2951485.3585, 2243667.4395000003], [2921462.8126999997, 2255028.6382999998], [2926620.4451, 2272296.880000001], [2941104.2640000004, 2280259.488500001], [2944189.9134, 2281962.3007999994], [2948850.6717000008, 2291380.4398999996], [2945643.7040999997, 2303861.4520999994], [2944719.5591, 2307475.7106999997], [2926589.3499999996, 2315020.3358999994], [2936043.7424, 2333131.239499999], [2956202.5001, 2354584.1778999995], [2980150.943, 2350072.215399999], [2994681.9268999994, 2359967.0779], [3001189.7097999994, 2357750.468699999], [3023674.524, 2356815.2456], [3038149.1797, 2342700.5812], [3048685.008199999, 2347782.8335999995], [3094136.622199999, 2345448.7804000005], [3114346.7486000005, 2355112.6822999995], [3119952.0965, 2349559.6811999995]], [[3082330.612400001, 2021947.4032000005], [3088533.8883999996, 2020064.3471000008], [3099761.3676999994, 2025696.8311], [3105096.5325000007, 2018719.5039000008], [3116661.3882, 2023000.7436999995], [3127465.6620000005, 2017649.447899999], [3160598.7853999995, 1995064.6379000004], [3159467.4145, 1989756.1532000005], [3150440.5073000006, 1983539.7216999996], [3151608.075099999, 1979255.4945999999], [3182657.6909, 1987089.0864000004], [3198669.207800001, 1983222.7755999994], [3208186.1379000004, 1992004.4617999997], [3202266.1798, 2008291.9937999994], [3205507.1086, 2019824.0485999994], [3202013.0601000004, 2033206.0689000003], [3184369.311899999, 2065861.6651000008], [3194938.7591999993, 2090932.0110999998], [3186712.0832, 2109110.6219999995], [3152614.7422, 2091351.5243999995], [3143259.5385999996, 2076570.5775000006], [3126360.241699999, 2066777.7544999998], [3111580.2049000002, 2054606.7230999991], [3106569.1263999995, 2040446.1953999996], [3082330.612400001, 2021947.4032000005]], [[3147811.1428999994, 1978511.5833], [3142664.294399999, 1984145.4758000001], [3136066.923800001, 1976893.6017000005], [3139456.127699999, 1970659.8823000006], [3147811.1428999994, 1978511.5833]]], [[[3292057.6103000008, 2262987.3589999992], [3290514.7684000004, 2258419.6279000007], [3276782.8600999992, 2262324.396299999], [3270083.6382999998, 2271642.5656000003], [3273671.9174000006, 2277245.969799999], [3281829.005999999, 2275583.3948], [3292781.291200001, 2267579.033], [3293444.5076, 2267095.6284999996], [3292057.6103000008, 2262987.3589999992]]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "CENTRO (ES)", "CNTR_CODE": "ES", "NUTS_ID": "ES4", "NUTS_NAME": "CENTRO (ES)", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES5-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES5-region-20m-3035-2016.geojson new file mode 100644 index 00000000..465c7420 --- /dev/null +++ b/vignettes/articles/artcache/ES5-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "MultiPolygon", "coordinates": [[[[3828319.8139999993, 1893178.9528], [3831755.3770000003, 1882079.5190999992], [3828465.2935000006, 1875906.8442000002], [3822952.3659000006, 1878160.8496000003], [3807677.7964999992, 1890013.6500000004], [3802365.5271000005, 1892303.5122999996], [3790516.319, 1892083.0294000003], [3791777.2917, 1899271.366800001], [3788810.6110999994, 1902174.6487000007], [3791675.4624000005, 1905573.8594000004], [3801432.8333, 1906062.5945999995], [3821612.3188000005, 1904373.9761999995], [3828319.8139999993, 1893178.9528]]], [[[3618228.6633, 2206417.9881999996], [3618482.1468, 2188579.036699999], [3640254.1414, 2192873.1951], [3640544.7918999996, 2191503.195699999], [3655306.1842, 2185601.0467000008], [3660408.1558999997, 2179076.1117000002], [3664048.0205000006, 2174432.645300001], [3673437.6285999995, 2177697.3172999993], [3681186.2612999994, 2180404.6229], [3686031.4689000007, 2177990.9366999995], [3690084.2576, 2175976.285], [3706422.2893000003, 2167894.0472999997], [3720277.7676999997, 2172970.581599999], [3734728.6498000007, 2178306.6994000003], [3758412.626, 2173293.2490999997], [3760245.7863, 2169221.2117999997], [3765805.9443999995, 2156838.3693000004], [3754819.1127000004, 2149590.1307999995], [3752079.1904000007, 2147787.9148999993], [3755477.5605999995, 2123462.0579000004], [3756493.969900001, 2116248.888800001], [3720866.591600001, 2091474.8175000008], [3718113.155200001, 2089575.7193999998], [3711867.5022, 2087138.4318000004], [3676073.1564000007, 2073323.0782999992], [3656494.624, 2056307.2821999993], [3618795.3077000007, 2049423.9584], [3560982.0867, 2037602.0504], [3554229.3936, 2031530.9179999996], [3537171.054199999, 2016267.8693000004], [3544879.4496999998, 2001026.2443000004], [3524875.188100001, 1995630.4362000003], [3515777.0196, 1986674.8182999995], [3490688.4773999993, 1958015.8791000005], [3464903.8198000006, 1928862.1249000002], [3445577.7430000007, 1906510.609099999], [3429656.689200001, 1874378.4091999996], [3435727.1776, 1836388.9971999992], [3447420.7983999997, 1813123.3479999993], [3462368.1602999996, 1804751.636], [3466165.0339, 1796319.357999999], [3442210.1094000004, 1781175.4536000006], [3400287.2178000007, 1756269.9427000005], [3370291.3166000005, 1707909.2694000006], [3351040.3910000008, 1737889.5098], [3357189.9453, 1757269.0326000005], [3350409.6777999997, 1772563.4497999996], [3359385.2633999996, 1792693.7478999998], [3358646.9791, 1799734.674900001], [3366765.9044000003, 1803229.7704000007], [3368962.6042, 1812557.920499999], [3368699.5085000005, 1828248.5932], [3354261.5317, 1832142.1460999995], [3347870.6827000007, 1845260.0708000008], [3353230.0163000003, 1870515.5622000005], [3328750.6482999995, 1889372.1570999995], [3331946.3783, 1904357.960000001], [3348713.0973000005, 1914676.1378000006], [3359154.579500001, 1929332.7474000007], [3362101.130000001, 1943328.3509], [3367939.042300001, 1945405.4098000005], [3381928.4350000005, 1942915.9730999991], [3389645.4748, 1931462.4814999998], [3395896.5285, 1931187.1455000006], [3392927.6007000003, 1938813.8468999993], [3413308.836100001, 1952055.6316], [3422811.5934999995, 1966295.9483000003], [3434512.3191, 1968204.7197999991], [3443278.191299999, 1977061.9713000003], [3447760.3978000004, 2000384.5781999994], [3444256.0562999994, 2011015.7123000007], [3460230.7227, 2021226.8385000005], [3479740.1206, 2011540.4266999997], [3489478.1235000007, 2013464.2942999993], [3498214.3501999993, 2025913.1195], [3498096.7468, 2050131.1634], [3502247.4944, 2055401.1425], [3514609.2875999995, 2071150.8484000005], [3512138.6203000005, 2085822.6787], [3520560.8320000004, 2100690.4952000007], [3518616.277899999, 2117218.7269], [3538345.1034999993, 2135019.659], [3554519.3172999993, 2172582.4569000006], [3558337.4133, 2181789.6730000004], [3557510.1657, 2190946.7178000007], [3556633.6624999996, 2200724.4694], [3561366.8620999996, 2212838.5025999993], [3559281.443600001, 2216650.5559], [3555449.739, 2223671.0808000006], [3557679.907400001, 2235782.8007999994], [3561960.8707999997, 2241030.5995000005], [3573288.5988999996, 2236521.7369], [3577063.0363999996, 2234734.1953], [3609712.7556999996, 2219408.9432999995], [3615953.851, 2209881.0535000004], [3618228.6633, 2206417.9881999996]]], [[[3726382.1261, 1896642.6159000006], [3730414.361300001, 1890315.9437000006], [3734295.412799999, 1894128.9180999994], [3737936.4693, 1891230.5271000005], [3731377.8333, 1880088.3672000002], [3740214.6385999992, 1874412.6218999997], [3748858.2051, 1880120.7009999994], [3757871.5316000003, 1874487.7173999995], [3757034.2985999994, 1864909.6042], [3752368.1094000004, 1862866.7530000005], [3751760.4185000006, 1857080.9583], [3741940.6074, 1848655.079500001], [3734931.4854000006, 1833876.3726000004], [3718623.4354, 1824912.047700001], [3711577.166200001, 1836179.3649000004], [3696827.7762, 1837746.7937000003], [3692296.5404000003, 1850647.1329999994], [3695026.5803999994, 1853492.8344999999], [3685234.5505999997, 1861479.3401999995], [3676974.029100001, 1857335.3907999992], [3674578.9212999996, 1850448.4477999993], [3668713.4066000003, 1858151.3190000001], [3659580.1798, 1865157.6975999996], [3682980.9891999997, 1878398.4638], [3690790.1624999996, 1885943.8128999993], [3700776.0917000007, 1891976.512], [3706405.869999999, 1892173.1590999998], [3715968.6772000007, 1897562.1942999996], [3726382.1261, 1896642.6159000006]]], [[[3575443.8762999997, 1800752.1850000005], [3571680.160599999, 1792466.805400001], [3566991.1586000007, 1796850.2526999991], [3558719.3058, 1796444.8714000005], [3554985.3797999993, 1807803.2934000008], [3564558.471999999, 1807908.0045999996], [3564367.691400001, 1814363.4134999998], [3570842.2831999995, 1818529.007099999], [3586342.479800001, 1821320.1421000008], [3590531.6637999993, 1818722.8866000008], [3591982.8380999994, 1811736.5110999998], [3583260.3137999997, 1803252.4629999995], [3575443.8762999997, 1800752.1850000005]]], [[[3574250.3324999996, 1783873.7968000006], [3580042.4294000007, 1775028.9561], [3585604.537799999, 1778976.4460000005], [3588318.3994999994, 1769651.0344999991], [3580120.9087000005, 1767306.3402999993], [3575790.3418000005, 1775014.3633999992], [3567513.3428000007, 1769872.3566999994], [3567540.7784, 1776018.0286999997], [3574250.3324999996, 1783873.7968000006]]], [[[3368902.2589, 1958422.3059999999], [3366572.0955, 1949885.1067999993], [3353819.7498000003, 1952016.4002], [3348582.2419000007, 1955301.0374999996], [3344584.6417999994, 1968319.6502], [3358878.972100001, 1969812.3660000004], [3368902.2589, 1958422.3059999999]]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "ESTE", "CNTR_CODE": "ES", "NUTS_ID": "ES5", "NUTS_NAME": "ESTE", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES6-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES6-region-20m-3035-2016.geojson new file mode 100644 index 00000000..7c38e7fd --- /dev/null +++ b/vignettes/articles/artcache/ES6-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "MultiPolygon", "coordinates": [[[[3350409.6777999997, 1772563.4497999996], [3357189.9453, 1757269.0326000005], [3351040.3910000008, 1737889.5098], [3370291.3166000005, 1707909.2694000006], [3361644.0722000003, 1695285.1344000008], [3369678.4376, 1687580.0744000003], [3367103.2623999994, 1680821.8453000002], [3334567.1905000005, 1682762.9673999995], [3317613.2021999992, 1683836.7769000009], [3287208.5506999996, 1667564.6730000004], [3268069.1746999994, 1649850.5820000004], [3255997.342599999, 1624571.2421000004], [3237192.907400001, 1609054.7042999994], [3232252.2766999993, 1604995.2162999995], [3214156.2095, 1618181.7508000005], [3200489.4114999995, 1619358.5001999997], [3193702.477499999, 1616416.4266999997], [3177464.678200001, 1609413.3413999993], [3144922.6086, 1621046.3414999992], [3116522.7334000003, 1620527.6883000005], [3087263.7814000007, 1629828.3533999994], [3032080.7731999997, 1637043.569599999], [3005452.5858999994, 1619652.3681000005], [2979256.8884999994, 1622253.4109000005], [2959122.3268999998, 1617990.6206999999], [2948813.8093, 1608501.5980999991], [2938041.8399, 1592776.9705999997], [2937628.382099999, 1592928.1324000005], [2936959.989499999, 1593056.5219], [2912435.436899999, 1583469.9605999999], [2877930.6107, 1609838.784], [2866078.421599999, 1635342.169399999], [2866474.3132000007, 1655183.3268], [2858686.7441000007, 1662786.0693999995], [2854846.4442999996, 1665692.8608999997], [2853140.5659999996, 1675704.5294000003], [2862160.9350000005, 1681571.7458999995], [2848806.7239999995, 1705528.4607999995], [2813537.6229, 1736579.7866999991], [2809582.509400001, 1739366.3706999999], [2801477.6225000005, 1741301.6706000008], [2784352.917300001, 1743262.5914999992], [2777974.267000001, 1743031.7994], [2776212.4310999997, 1783297.5351], [2809812.5754000004, 1825151.6280000005], [2830724.2676999997, 1828966.9100000001], [2841367.7413999997, 1845643.4425000008], [2869323.0415000003, 1818984.7425999995], [2887446.4164000005, 1812045.2080000006], [2900309.0726999994, 1802349.4406000003], [2920347.6218999997, 1805736.9285000004], [2936049.9789000005, 1820688.7597000003], [2945194.9539, 1820031.4337000009], [2945585.776799999, 1811047.9392000008], [2955595.16, 1812174.2807999998], [2961596.3259999994, 1820278.8531], [2964939.6942, 1844685.6445000004], [3003395.8956000004, 1867807.2030999996], [3013685.8264000006, 1867697.3472000007], [3073284.0786000006, 1813057.6834999993], [3078882.6253999993, 1817254.1201000009], [3144236.5222999994, 1807140.0001999997], [3154922.7206999995, 1811506.1438999996], [3194153.8215999994, 1804160.2177000009], [3206655.1525999997, 1809949.3696999997], [3221092.6728000008, 1801230.3576999996], [3225938.4255999997, 1792090.2550000008], [3227472.9779000003, 1788518.5874000005], [3228810.0076, 1771628.5479000006], [3221546.0341999996, 1762521.2059000004], [3217566.8117999993, 1757885.6275999993], [3220614.2314, 1756235.5787000004], [3234890.708799999, 1748534.0275999997], [3259998.9529, 1769500.6363999993], [3264446.9527000003, 1773235.1347000003], [3291062.8440000005, 1777478.9824], [3300490.2179000005, 1770369.8378999997], [3310379.528000001, 1772376.2208999991], [3323293.3713000007, 1804112.5719000008], [3334171.8203999996, 1807491.1786000002], [3346700.844900001, 1810997.3684999999], [3350924.5186, 1807008.3871], [3358646.9791, 1799734.674900001], [3359385.2633999996, 1792693.7478999998], [3350409.6777999997, 1772563.4497999996]]], [[[3137230.7940999996, 1462498.6922999993], [3138683.0117000006, 1457044.2984999996], [3135149.3269999996, 1459467.6845999993], [3137230.7940999996, 1462498.6922999993]]], [[[2932713.4832000006, 1562845.4328000005], [2932255.162799999, 1562345.8067000005], [2929629.6896, 1567615.6918000001], [2930066.1142999995, 1567858.0932999998], [2931211.384400001, 1567705.1435000002], [2932473.420600001, 1566453.7273999993], [2933031.2269, 1565434.2451000009], [2933225.5185000002, 1564928.4850999992], [2933290.7328999992, 1564373.4309], [2933221.7760000005, 1563811.3402999993], [2933024.2804000005, 1563288.3474000003], [2932713.4832000006, 1562845.4328000005]]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "SUR", "CNTR_CODE": "ES", "NUTS_ID": "ES6", "NUTS_NAME": "SUR", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/ES7-region-20m-3035-2016.geojson b/vignettes/articles/artcache/ES7-region-20m-3035-2016.geojson new file mode 100644 index 00000000..f5c67575 --- /dev/null +++ b/vignettes/articles/artcache/ES7-region-20m-3035-2016.geojson @@ -0,0 +1 @@ +{"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::3035"}}, "type": "FeatureCollection", "features": [{"geometry": {"type": "MultiPolygon", "coordinates": [[[[1998040.3348999992, 1014751.3992999997], [1991696.9590000007, 1009282.5897000004], [1984037.1174999997, 1017181.9223999996], [1990007.7983999997, 1020108.4546000008], [1992246.4934999999, 1028571.8091000002], [2001492.5550999995, 1033810.6579], [2017109.1686000004, 1035431.8351000007], [2024978.0397999994, 1034047.6021999996], [2028820.3071999997, 1045428.9396000002], [2031999.8692000005, 1045730.1615999993], [2036429.9461000003, 1037074.8133000005], [2030254.0311999992, 1030529.9069999997], [2027246.2971, 1018957.2367000002], [2018318.4441999998, 1014758.0012999997], [1998040.3348999992, 1014751.3992999997]]], [[[1932337.1305, 950700.2115000002], [1918620.9320999999, 941493.0229000002], [1911409.1393, 948476.8438000008], [1923305.833900001, 951768.6407999992], [1934667.0895000007, 957474.0110999998], [1938886.0385999996, 968020.7048000004], [1947082.8411999997, 977816.1395999994], [1952370.8268999998, 980387.5132999998], [1962098.517000001, 991190.4138999991], [1967046.4262000006, 1003390.6007000003], [1980375.6992000006, 1003979.1713999994], [1983838.8954000007, 999363.0675000008], [1982121.3235999998, 984370.1137000006], [1974923.9054000005, 973864.2598000001], [1974893.7883000001, 966925.2254000008], [1964337.4569000006, 951487.6756999996], [1953730.3254000004, 949131.0687000006], [1932337.1305, 950700.2115000002]]], [[[1806466.1815000009, 950629.7630000003], [1789591.9085000008, 948918.7536999993], [1783090.4672999997, 952772.1811999995], [1774627.3607, 965540.2515999991], [1772503.8549000006, 975054.1352999993], [1774148.9206000008, 981322.6526999995], [1789244.882099999, 989418.8194999993], [1792227.2828000002, 995796.8757000007], [1808546.7144000009, 990605.3351000007], [1817765.4977000002, 981331.2036000006], [1815962.4368999992, 975771.4385000002], [1818758.4514000006, 968574.1012999993], [1813382.0387999993, 954958.8173999991], [1806466.1815000009, 950629.7630000003]]], [[[1761525.2854999993, 1056870.0429999996], [1762852.8541, 1050012.635399999], [1751279.3203999996, 1048612.3894999996], [1736375.8902000003, 1041420.9564999994], [1733958.3795999996, 1033714.5425000004], [1725234.7040999997, 1025277.4053000007], [1723400.898, 1019709.2843999993], [1709107.1827000007, 1010816.2666999996], [1692774.8716000002, 1014204.5532000009], [1692119.0188999996, 1023366.5508999992], [1686531.8044000007, 1039270.1933999993], [1687766.202299999, 1044598.5004999992], [1684115.3105999995, 1056381.2500999998], [1692628.5780999996, 1058532.3400999997], [1699386.0545000006, 1053712.887599999], [1707520.2109999992, 1054138.6275999993], [1722176.3445999995, 1050943.3850999996], [1739061.0346000008, 1059872.259299999], [1745992.6389000006, 1061104.7149], [1754650.7434, 1056686.539999999], [1761525.2854999993, 1056870.0429999996]]], [[[1646746.4390999991, 1032028.4854000006], [1642341.3237999994, 1033209.1158000007], [1634856.2115000002, 1045437.9368999992], [1641143.4419, 1055642.9526000004], [1647006.9425000008, 1055051.6026000008], [1658656.5053000003, 1042946.3311], [1658779.9888000004, 1036148.9052000009], [1646746.4390999991, 1032028.4854000006]]], [[[1611376.0359000005, 1109280.6371999998], [1600838.7300000004, 1099674.9164000005], [1595324.489600001, 1126236.909], [1594687.4923, 1139043.1415999997], [1605241.9408999998, 1144581.5713], [1617907.5475999992, 1137752.5004999992], [1619829.0089999996, 1125647.0669999998], [1613552.614, 1120393.5055], [1611376.0359000005, 1109280.6371999998]]], [[[1576915.8542, 1033866.5909000002], [1566711.5781999994, 1026421.7804000005], [1560865.5655000005, 1018609.7665], [1556543.3588999994, 1026867.9671], [1546821.2238999996, 1034447.2379], [1551338.4686999992, 1038430.0156999994], [1556772.6711, 1034253.3534999993], [1574270.1664000005, 1039380.2324], [1576915.8542, 1033866.5909000002]]]]}, "type": "Feature", "properties": {"COAST_TYPE": 0, "MOUNT_TYPE": 0, "NAME_LATN": "CANARIAS", "CNTR_CODE": "ES", "NUTS_ID": "ES7", "NUTS_NAME": "CANARIAS", "LEVL_CODE": 1, "URBN_TYPE": 0}}]} \ No newline at end of file diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_770.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_770.png new file mode 100644 index 00000000..39864ab1 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_770.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_771.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_771.png new file mode 100644 index 00000000..2ead5205 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_771.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_772.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_772.png new file mode 100644 index 00000000..a8fac04b Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_772.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_773.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_773.png new file mode 100644 index 00000000..5435b95a Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1001_773.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_770.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_770.png new file mode 100644 index 00000000..88062202 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_770.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_771.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_771.png new file mode 100644 index 00000000..4a7bb6b1 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_771.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_772.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_772.png new file mode 100644 index 00000000..f8edb643 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_772.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_773.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_773.png new file mode 100644 index 00000000..80783dd4 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1002_773.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_770.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_770.png new file mode 100644 index 00000000..00e27271 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_770.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_771.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_771.png new file mode 100644 index 00000000..0f99eb8d Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_771.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_772.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_772.png new file mode 100644 index 00000000..16044b09 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_772.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_773.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_773.png new file mode 100644 index 00000000..0254b038 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1003_773.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_770.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_770.png new file mode 100644 index 00000000..20642563 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_770.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_771.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_771.png new file mode 100644 index 00000000..f0160603 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_771.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_772.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_772.png new file mode 100644 index 00000000..897754af Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_772.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_773.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_773.png new file mode 100644 index 00000000..954637b1 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_11_1004_773.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_191.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_191.png new file mode 100644 index 00000000..72d406c0 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_191.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_192.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_192.png new file mode 100644 index 00000000..17a4c915 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_192.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_193.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_193.png new file mode 100644 index 00000000..515bf1d3 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_193.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_194.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_194.png new file mode 100644 index 00000000..f403f4c9 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_249_194.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_191.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_191.png new file mode 100644 index 00000000..a066eee0 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_191.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_192.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_192.png new file mode 100644 index 00000000..c5e7334c Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_192.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_193.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_193.png new file mode 100644 index 00000000..1628aeae Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_193.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_194.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_194.png new file mode 100644 index 00000000..f281424c Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_250_194.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_191.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_191.png new file mode 100644 index 00000000..4abefe75 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_191.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_192.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_192.png new file mode 100644 index 00000000..f56fb3f4 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_192.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_193.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_193.png new file mode 100644 index 00000000..de5cdf08 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_193.png differ diff --git a/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_194.png b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_194.png new file mode 100644 index 00000000..7ad4e95e Binary files /dev/null and b/vignettes/articles/artcache/IDErioja.Claro/IDErioja.Claro_9_251_194.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_11_1009_756.png b/vignettes/articles/artcache/IDErioja/IDErioja_11_1009_756.png new file mode 100644 index 00000000..915f6fc1 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_11_1009_756.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_11_1009_757.png b/vignettes/articles/artcache/IDErioja/IDErioja_11_1009_757.png new file mode 100644 index 00000000..f953c5d9 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_11_1009_757.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_11_1010_756.png b/vignettes/articles/artcache/IDErioja/IDErioja_11_1010_756.png new file mode 100644 index 00000000..0ff4dd3c Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_11_1010_756.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_11_1010_757.png b/vignettes/articles/artcache/IDErioja/IDErioja_11_1010_757.png new file mode 100644 index 00000000..db87a94d Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_11_1010_757.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_251_188.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_251_188.png new file mode 100644 index 00000000..d7185ff5 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_251_188.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_251_189.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_251_189.png new file mode 100644 index 00000000..08bb87af Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_251_189.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_251_190.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_251_190.png new file mode 100644 index 00000000..9828f741 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_251_190.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_252_188.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_252_188.png new file mode 100644 index 00000000..272be617 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_252_188.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_252_189.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_252_189.png new file mode 100644 index 00000000..5a8eed5f Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_252_189.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_252_190.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_252_190.png new file mode 100644 index 00000000..ef36f36c Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_252_190.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_253_188.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_253_188.png new file mode 100644 index 00000000..b4bcef34 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_253_188.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_253_189.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_253_189.png new file mode 100644 index 00000000..5b781465 Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_253_189.png differ diff --git a/vignettes/articles/artcache/IDErioja/IDErioja_9_253_190.png b/vignettes/articles/artcache/IDErioja/IDErioja_9_253_190.png new file mode 100644 index 00000000..9fbf03cd Binary files /dev/null and b/vignettes/articles/artcache/IDErioja/IDErioja_9_253_190.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1952_1495.png b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1495.png new file mode 100644 index 00000000..a3f8a1d2 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1495.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1952_1496.png b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1496.png new file mode 100644 index 00000000..b25fdd49 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1496.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1952_1497.png b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1497.png new file mode 100644 index 00000000..e54fc5f7 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1497.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1952_1498.png b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1498.png new file mode 100644 index 00000000..32008606 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1952_1498.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1953_1495.png b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1495.png new file mode 100644 index 00000000..a80733f4 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1495.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1953_1496.png b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1496.png new file mode 100644 index 00000000..91790edc Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1496.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1953_1497.png b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1497.png new file mode 100644 index 00000000..2aaf45d5 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1497.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1953_1498.png b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1498.png new file mode 100644 index 00000000..c6b1bbf7 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1953_1498.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1954_1495.png b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1495.png new file mode 100644 index 00000000..bf94a37a Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1495.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1954_1496.png b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1496.png new file mode 100644 index 00000000..2383b7a3 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1496.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1954_1497.png b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1497.png new file mode 100644 index 00000000..21270f1a Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1497.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1954_1498.png b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1498.png new file mode 100644 index 00000000..ab2ec024 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1954_1498.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1955_1495.png b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1495.png new file mode 100644 index 00000000..3bb49188 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1495.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1955_1496.png b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1496.png new file mode 100644 index 00000000..fe5d5f80 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1496.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1955_1497.png b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1497.png new file mode 100644 index 00000000..6b777da4 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1497.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_12_1955_1498.png b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1498.png new file mode 100644 index 00000000..8de03580 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_12_1955_1498.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_249_191.png b/vignettes/articles/artcache/PNOA/PNOA_9_249_191.png new file mode 100644 index 00000000..7a857f58 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_249_191.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_249_192.png b/vignettes/articles/artcache/PNOA/PNOA_9_249_192.png new file mode 100644 index 00000000..faecfcb1 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_249_192.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_249_193.png b/vignettes/articles/artcache/PNOA/PNOA_9_249_193.png new file mode 100644 index 00000000..b81d80e1 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_249_193.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_249_194.png b/vignettes/articles/artcache/PNOA/PNOA_9_249_194.png new file mode 100644 index 00000000..434fc196 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_249_194.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_250_191.png b/vignettes/articles/artcache/PNOA/PNOA_9_250_191.png new file mode 100644 index 00000000..755744c4 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_250_191.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_250_192.png b/vignettes/articles/artcache/PNOA/PNOA_9_250_192.png new file mode 100644 index 00000000..c7e26682 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_250_192.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_250_193.png b/vignettes/articles/artcache/PNOA/PNOA_9_250_193.png new file mode 100644 index 00000000..0ca1fb35 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_250_193.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_250_194.png b/vignettes/articles/artcache/PNOA/PNOA_9_250_194.png new file mode 100644 index 00000000..520450de Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_250_194.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_188.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_188.png new file mode 100644 index 00000000..c13dce3d Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_188.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_189.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_189.png new file mode 100644 index 00000000..0e2c4827 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_189.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_190.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_190.png new file mode 100644 index 00000000..d6034e66 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_190.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_191.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_191.png new file mode 100644 index 00000000..6e9d0abb Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_191.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_192.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_192.png new file mode 100644 index 00000000..81efb4df Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_192.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_193.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_193.png new file mode 100644 index 00000000..0716494b Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_193.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_251_194.png b/vignettes/articles/artcache/PNOA/PNOA_9_251_194.png new file mode 100644 index 00000000..b2d944e5 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_251_194.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_252_188.png b/vignettes/articles/artcache/PNOA/PNOA_9_252_188.png new file mode 100644 index 00000000..213f9946 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_252_188.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_252_189.png b/vignettes/articles/artcache/PNOA/PNOA_9_252_189.png new file mode 100644 index 00000000..71be52ce Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_252_189.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_252_190.png b/vignettes/articles/artcache/PNOA/PNOA_9_252_190.png new file mode 100644 index 00000000..c4bd9b3c Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_252_190.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_253_188.png b/vignettes/articles/artcache/PNOA/PNOA_9_253_188.png new file mode 100644 index 00000000..245d5ae6 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_253_188.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_253_189.png b/vignettes/articles/artcache/PNOA/PNOA_9_253_189.png new file mode 100644 index 00000000..4d27bf09 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_253_189.png differ diff --git a/vignettes/articles/artcache/PNOA/PNOA_9_253_190.png b/vignettes/articles/artcache/PNOA/PNOA_9_253_190.png new file mode 100644 index 00000000..3ac188e6 Binary files /dev/null and b/vignettes/articles/artcache/PNOA/PNOA_9_253_190.png differ diff --git a/vignettes/articles/artcache/RedTransporte.Carreteras/59138810664d941888513648f7d6e490.png b/vignettes/articles/artcache/RedTransporte.Carreteras/59138810664d941888513648f7d6e490.png new file mode 100644 index 00000000..00dc1f15 Binary files /dev/null and b/vignettes/articles/artcache/RedTransporte.Carreteras/59138810664d941888513648f7d6e490.png differ diff --git a/vignettes/articles/artcache/se89_3_admin_muni_a_x.gpkg b/vignettes/articles/artcache/se89_3_admin_muni_a_x.gpkg new file mode 100644 index 00000000..61bb2672 Binary files /dev/null and b/vignettes/articles/artcache/se89_3_admin_muni_a_x.gpkg differ diff --git a/vignettes/articles/artcache/se89_3_admin_muni_a_y.gpkg b/vignettes/articles/artcache/se89_3_admin_muni_a_y.gpkg new file mode 100644 index 00000000..c954b227 Binary files /dev/null and b/vignettes/articles/artcache/se89_3_admin_muni_a_y.gpkg differ diff --git a/vignettes/articles/artcache/se89_3_admin_prov_a_x.gpkg b/vignettes/articles/artcache/se89_3_admin_prov_a_x.gpkg new file mode 100644 index 00000000..125692fb Binary files /dev/null and b/vignettes/articles/artcache/se89_3_admin_prov_a_x.gpkg differ diff --git a/vignettes/articles/artcache/se89_3_admin_prov_a_y.gpkg b/vignettes/articles/artcache/se89_3_admin_prov_a_y.gpkg new file mode 100644 index 00000000..99d99282 Binary files /dev/null and b/vignettes/articles/artcache/se89_3_admin_prov_a_y.gpkg differ diff --git a/vignettes/articles/artcache/se89_3_vias_ffcc_p_x.gpkg b/vignettes/articles/artcache/se89_3_vias_ffcc_p_x.gpkg new file mode 100644 index 00000000..2cd7d187 Binary files /dev/null and b/vignettes/articles/artcache/se89_3_vias_ffcc_p_x.gpkg differ diff --git a/vignettes/articles/gadm/gadm41_ESP_0_pk.rds b/vignettes/articles/gadm/gadm41_ESP_0_pk.rds new file mode 100644 index 00000000..bad97599 Binary files /dev/null and b/vignettes/articles/gadm/gadm41_ESP_0_pk.rds differ diff --git a/vignettes/articles/working_imagery.Rmd b/vignettes/articles/working_imagery.Rmd index bc2a9683..f6a7923c 100644 --- a/vignettes/articles/working_imagery.Rmd +++ b/vignettes/articles/working_imagery.Rmd @@ -1,13 +1,11 @@ --- title: "Working with imagery" -author: "Diego Hernangómez" -editor_options: - markdown: - wrap: 80 +author: Diego Hernangómez ORCID logo +description: > + Learn how to include images on your maps. --- ```{r, include = FALSE} - knitr::opts_chunk$set( collapse = TRUE, comment = "#>", @@ -15,12 +13,17 @@ knitr::opts_chunk$set( message = FALSE, dpi = 300, tidy = "styler", + dev = "ragg_png", out.width = "100%" ) -if (isFALSE(requireNamespace("reactable", quietly = TRUE))) { - install.packages("reactable") -} +# Cache for articles +library(mapSpain) +initcache <- mapSpain::esp_detect_cache_dir() + +cache_dir_here <- file.path(getwd(), "artcache") + +esp_set_cache_dir(cache_dir_here, verbose = FALSE) ``` **mapSpain** provides a powerful interface for working with imagery. @@ -44,71 +47,66 @@ here on layer provided by La Rioja's [Infraestructura de Datos Espaciales **When working with imagery, it is important to set `moveCAN = FALSE`, otherwise the images for the Canary Islands won't be accurate.** -```{r static1} - +```{r static1, fig.alt="Map of the limits of city of Logroño using a tile as a basemap"} library(mapSpain) library(sf) -library(tmap) +library(ggplot2) +library(tidyterra) # Logroño -LGN <- esp_get_munic(munic = "Logroño") +lgn_borders <- esp_get_munic_siane(munic = "Logroño") # Convert to Mercator (EPSG:3857) as a general advice when working with tiles -LGN <- st_transform(LGN, 3857) +lgn_borders <- st_transform(lgn_borders, 3857) -tile_LGN <- esp_getTiles(LGN, "IDErioja", bbox_expand = 0.5) +tile_lgn <- esp_getTiles(lgn_borders, "IDErioja", bbox_expand = 0.5) -tm_shape(tile_LGN, raster.downsample = FALSE) + - tm_rgb() + - # Mix with a sf polygon - tm_shape(LGN) + - tm_borders(lwd = 2, lty = "dotted") +ggplot(lgn_borders) + + geom_spatraster_rgb(data = tile_lgn) + + geom_sf(fill = NA, linewidth = 2, color = "blue") ``` - ### Alpha value on tiles Some tiles could be loaded with or without an alpha value, that controls the transparency of the object: -```{r static2, fig.asp=1} - -Madrid <- esp_get_ccaa("Madrid", epsg = 3857) +```{r static2, fig.alt="Map of the roads of Autonomous Communities surrouding Madrid"} +madrid <- esp_get_ccaa("Madrid", epsg = 3857) # Example without transparency -BG <- esp_getTiles(Madrid, "IGNBase.Gris", zoom = 9) -UA.opaque <- - esp_getTiles(Madrid, "UnidadesAdm.Limites", - transparent = FALSE - ) +basemap <- esp_getTiles(madrid, "IDErioja.Claro", + zoommin = 1, + crop = TRUE, bbox_expand = 0 +) +tile_opaque <- esp_getTiles(madrid, "RedTransporte.Carreteras", + transparent = FALSE, crop = TRUE, bbox_expand = 0 +) -tm_shape(BG, raster.downsample = FALSE) + - tm_rgb() + - tm_shape(UA.opaque, raster.downsample = FALSE) + - tm_rgb() +ggplot() + + geom_spatraster_rgb(data = basemap) + + geom_spatraster_rgb(data = tile_opaque) + + theme_void() ``` Now let's check the same code using the `tranparent = TRUE` option: -```{r static_transp, fig.asp=1} +```{r static_transp, fig.alt="Example on how to use alpha value for combining different types of basemaps."} # Example with transparency -UA.alpha <- esp_getTiles(Madrid, - "UnidadesAdm.Limites", - transparent = TRUE +tile_alpha <- esp_getTiles(madrid, "RedTransporte.Carreteras", + transparent = TRUE, crop = TRUE, bbox_expand = 0 ) # Same code than above for plotting - -tm_shape(BG, raster.downsample = FALSE) + - tm_rgb() + - tm_shape(UA.alpha, raster.downsample = FALSE) + - tm_rgb() +ggplot() + + geom_spatraster_rgb(data = basemap) + + geom_spatraster_rgb(data = tile_alpha) + + theme_void() ``` - Now the two tiles overlaps with the desired alpha value. ### Masking tiles @@ -116,62 +114,47 @@ Now the two tiles overlaps with the desired alpha value. Another nice feature is the ability of masking the tiles, so more advanced maps can be plotted: -```{r static3} - -LaRioja <- esp_get_prov("La Rioja", epsg = 3857) +```{r static3, fig.alt="Example of combining types of tiles by masking to a shapefile."} +rioja <- esp_get_prov("La Rioja", epsg = 3857) -Basemap <- esp_getTiles(LaRioja, bbox_expand = 0.1, zoom = 10) +basemap <- esp_getTiles(rioja, "PNOA", bbox_expand = 0.1, zoommin = 1) -Mask <- esp_getTiles(LaRioja, "PNOA", mask = TRUE, zoom = 10) +masked <- esp_getTiles(rioja, "IDErioja", mask = TRUE, zoommin = 1) -tm_shape(Basemap, raster.downsample = FALSE) + - tm_rgb() + - tm_shape(Mask, raster.downsample = FALSE) + - tm_rgb() +ggplot() + + geom_spatraster_rgb(data = basemap, maxcell = 10e6) + + geom_spatraster_rgb(data = masked, maxcell = 10e6) ``` ## Dynamic maps with Leaflet -**mapSpain** provides a plugin to be used with the `leaflet` package. Here you +**mapSpain** provides a plugin to be used with the **leaflet** package. Here you can find some quick examples: ### Earthquakes in Tenerife (last year) ```{r leaflet1} - library(leaflet) -Tenerife.leaf <- - esp_get_nuts( - region = "Tenerife", - epsg = 4326, - moveCAN = FALSE - ) +tenerife_leaf <- esp_get_nuts( + region = "Tenerife", epsg = 4326, + moveCAN = FALSE +) -bbox <- as.double(round( - st_bbox(Tenerife.leaf) + c(-1, -1, 1, 1), 2 -)) +bbox <- as.double(round(st_bbox(tenerife_leaf) + c(-1, -1, 1, 1), 2)) # Start leaflet -m <- leaflet(Tenerife.leaf, +m <- leaflet(tenerife_leaf, elementId = "tenerife-earthquakes", - width = "100%", - height = "60vh", - options = leafletOptions( - minZoom = 9, - maxZoom = 18 - ) + width = "100%", height = "60vh", + options = leafletOptions(minZoom = 9, maxZoom = 18) ) # Add layers m <- m %>% - addProviderEspTiles("MDT.Relieve") %>% - addPolygons( - color = NA, - fillColor = "red", - group = "Polygon" - ) %>% + addProviderEspTiles("IDErioja.Relieve") %>% + addPolygons(color = NA, fillColor = "red", group = "Polygon") %>% addProviderEspTiles("Geofisica.Terremotos365dias", group = "Earthquakes" ) @@ -190,7 +173,6 @@ m %>% A map showing the population density of Spain as of 2019: ```{r leaflet2} - munic <- esp_get_munic_siane( year = 2019, epsg = 4326, @@ -208,11 +190,10 @@ munic$area_km2 <- munic$st_area_sh * 10000 pop <- mapSpain::pobmun19 # Paste -munic_pop <- - merge(munic, pop[, c("cmun", "cpro", "pob19")], - by = c("cmun", "cpro"), - all.x = TRUE - ) +munic_pop <- merge(munic, pop[, c("cmun", "cpro", "pob19")], + by = c("cmun", "cpro"), + all.x = TRUE +) munic_pop$dens <- munic_pop$pob19 / munic_pop$area_km2 munic_pop$dens_label <- prettyNum(round(munic_pop$dens, 2), @@ -221,28 +202,10 @@ munic_pop$dens_label <- prettyNum(round(munic_pop$dens, 2), ) # Create leaflet +bins <- c(0, 10, 25, 100, 200, 500, 1000, 5000, 10000, Inf) -bins <- - c( - 0, - 10, - 25, - 100, - 200, - 500, - 1000, - 5000, - 10000, - Inf - ) - -pal <- - colorBin("inferno", - domain = munic_pop$dens, - bins = bins, - reverse = TRUE - ) +pal <- colorBin("inferno", domain = munic_pop$dens, bins = bins, reverse = TRUE) labels <- sprintf( "%s
%s
%s pers. / km2", @@ -252,14 +215,9 @@ labels <- sprintf( ) %>% lapply(htmltools::HTML) - leaflet(elementId = "SpainDemo", width = "100%", height = "60vh") %>% - setView( - lng = -3.684444, - lat = 40.308611, - zoom = 5 - ) %>% - addProviderEspTiles("IGNBase.Gris") %>% + setView(lng = -3.684444, lat = 40.308611, zoom = 5) %>% + addProviderEspTiles("IDErioja") %>% addPolygons( data = munic_pop, fillColor = ~ pal(dens), @@ -276,26 +234,52 @@ leaflet(elementId = "SpainDemo", width = "100%", height = "60vh") %>% popup = labels ) %>% addLegend( - pal = pal, - values = bins, - opacity = 0.7, title = "Pop. Density km2
(2019)", + pal = pal, values = bins, opacity = 0.7, + title = paste0( + "Pop. Density km2
", + "(2019)" + ), position = "bottomright" ) ``` ## Providers available -The data frame `leaflet.providersESP.df` includes the data of the available -providers you can use on functions described above. This data frame includes -all the parameters needed to replicate the API request. In this summary only -the parameter `url_static` is shown: +The list `esp_tiles_providers` includes the data of the available providers you +can use on functions described above. This list includes all the parameters +needed to replicate the API request. See the static url of each provider: ```{r providers, echo=FALSE} - library(reactable) -df <- leaflet.providersESP.df[leaflet.providersESP.df$field == "url_static", ] +prov_names <- names(esp_tiles_providers) + +urls <- vapply(esp_tiles_providers, function(x) { + # Create url + allpars <- x$static + q <- allpars$q + rest <- modifyList( + allpars, + list( + attribution = NULL, + q = NULL + ) + ) + rest_temp <- paste0(names(rest), "=", rest, collapse = "&") + templurl <- paste0(q, rest_temp) + + if (grepl("rioja", q, ignore.case = TRUE)) { + templurl <- q + } + templurl +}, FUN.VALUE = character(1)) + +df <- data.frame( + provider = prov_names, + static_url = urls +) +rownames(df) <- NULL reactable(df, filterable = TRUE, searchable = TRUE, @@ -305,3 +289,23 @@ reactable(df, elementId = "leaflet-prov-summ" ) ``` + +```{r message=FALSE, warning=FALSE, include=FALSE} +# Restore cache +esp_set_cache_dir(initcache, verbose = TRUE) +``` + +## Session info + +
+ +Details + +```{r session, echo=FALSE} +if (!require("sessioninfo")) { + install.packages("sessioninfo") +} +sessioninfo::session_info() +``` + +
diff --git a/vignettes/articles/x01_regioncodes.Rmd b/vignettes/articles/x01_regioncodes.Rmd index 4b529c7e..3a75ca9f 100644 --- a/vignettes/articles/x01_regioncodes.Rmd +++ b/vignettes/articles/x01_regioncodes.Rmd @@ -1,5 +1,7 @@ --- title: "Annex: Codes and names of the Spanish regions" +description: > + Interactive explorer of the data included in the package. --- ```{r knitropts, include=FALSE} @@ -7,24 +9,21 @@ knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, - message = FALSE + message = FALSE, + dpi = 300, + tidy = "styler", + dev = "ragg_png", + out.width = "100%" ) - -if (isFALSE(requireNamespace("reactable", quietly = TRUE))) { - install.packages("reactable") -} ``` - -This annex shows an interactive version of the `mapSpain::esp_codelist` -data frame. That dataset contains the Spanish region codes under different schemes, +This annex shows an interactive version of the `mapSpain::esp_codelist` data +frame. That dataset contains the Spanish region codes under different schemes, and different naming versions on several languages. ## Names and codes of the spanish regions - ```{r esp_codelist, echo=FALSE} - library(mapSpain) library(reactable) @@ -40,7 +39,3 @@ reactable(esp_codelist, elementId = "esp_codelist" ) ``` - - - - diff --git a/vignettes/articles/x02_mapasesp.Rmd b/vignettes/articles/x02_mapasesp.Rmd new file mode 100644 index 00000000..341a7c82 --- /dev/null +++ b/vignettes/articles/x02_mapasesp.Rmd @@ -0,0 +1,558 @@ +--- +title: "mapSpain: Mapas de España en R [Spanish]" +author: Diego Hernangómez ORCID logo +description: > + Mapas de España en R de manera rápida y sencilla. +output: + html_document: + toc: true + toc_depth: 2 +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + warning = FALSE, + message = FALSE, + dpi = 300, + tidy = "styler", + dev = "ragg_png", + out.width = "100%" +) + +# Cache for articles +library(mapSpain) +initcache <- mapSpain::esp_detect_cache_dir() + +cache_dir_here <- file.path(getwd(), "artcache") + +esp_set_cache_dir(cache_dir_here, verbose = FALSE) +``` + +## Bienvenidos a mapSpain + +### Motivación + +mapSpain-logo + +**mapSpain** facilita la creación de mapas de los diferentes niveles +administrativos de España. + +Además, proporciona también la posibilidad de usar imágenes de servicios +WMS/WMTS de manera estática (como imagen georeferenciada) o dinámica (en mapas +leaflet). + +Adicionalmente, **mapSpain** dispone de funciones que permiten normalizar +nombres de las CCAA y provincias, lo que facilita el proceso de manipulación y +transformación de datos (no necesariamente espaciales). + +Las **fuentes de información** empleadas en **mapSpain** son: + +- [GISCO](https://ec.europa.eu/eurostat/web/gisco) (Eurostat) via el paquete + [**giscoR**](https://ropengov.github.io/giscoR/). +- [Instituto Geografico Nacional](https://www.ign.es/) (IGN) +- Distintos organismos públicos de España que proporcionan servicios de + teselas WMTS/WMS (). + +Los objetos resultantes se proporcionan en formato `sf` (librería **sf)** o +`SpatRaster`(librería **terra**). + +Página web: + +### Instalación + +#### CRAN + +```{r instcran, eval=FALSE} +install.packages("mapSpain", dependencies = TRUE) +``` + +#### Dev version + +Usando el [r-universe](https://ropenspain.r-universe.dev/ui#builds): + +```{r instruniverse, eval=FALSE} +# Enable this universe +install.packages("mapSpain", + repos = c( + "https://ropenspain.r-universe.dev", + "https://cloud.r-project.org" + ), + dependencies = TRUE +) +``` + +#### Remotes + +```{r instremotes, eval=FALSE} +remotes::install_github("rOpenSpain/mapSpain", dependencies = TRUE) +``` + +### Un ejemplo rápido + +```{r intro, fig.alt="Mapa de los municipios de Galicia"} +library(mapSpain) +library(tidyverse) + +galicia <- esp_get_munic_siane(region = "Galicia") %>% + # Homogeinizo labels + mutate(Provincia = esp_dict_translate(ine.prov.name, "es")) + + +ggplot(galicia) + + geom_sf(aes(fill = Provincia), color = "grey70") + + labs(title = "Provincias de Galicia") + + scale_fill_discrete(type = hcl.colors(4, "Blues")) + + theme_bw() +``` + +Si exploramos el dataset: + +```{r galicia_data} +library(reactable) + +reactable(galicia, + searchable = TRUE, striped = TRUE, filterable = TRUE, height = 350, + elementId = "munis-galicia" +) +``` + +### Comparando mapSpain con otras alternativas + +Comparamos ahora **mapSpain** con otro paquete que proporciona objetos `sf` o +`SpatVector` de distintos paises: + +```{r compara, fig.alt="Comparación de la resolución de diferentes fuentes de mapas; se muestran bordes de los datos comparados con ortofoto de la Ria de Ferrol"} +library(sf) # manipulación de datos espaciales + +# rnaturalearth +library(rnaturalearth) +esp_rnat <- ne_countries("large", country = "Spain", returnclass = "sf") %>% + st_transform(3857) + +# mapSpain +esp_mapspain <- esp_get_country(epsg = 4326) %>% + st_transform(3857) + +# geodata (GADM) +library(geodata) +esp_geodata <- geodata::gadm("ES", path = ".", level = 0) %>% + # Convertimos de SpatVector a objecto sf + sf::st_as_sf() %>% + st_transform(3857) + +# Imagen Ria Ferrol +tile <- esp_get_munic_siane(munic = "Ferrol", epsg = 3857) %>% + esp_getTiles("PNOA", bbox_expand = 0.5, zoommin = 1) + +# Prepara el plot +library(tidyterra) + + +esp_all <- bind_rows(esp_rnat, esp_mapspain, esp_geodata) + +esp_all$source <- as_factor(c( + "rnaturalearth", + "mapSpain", "geodata (GADM)" +)) + +ggplot(esp_all) + + geom_spatraster_rgb(data = tile, maxcell = Inf, alpha = 0.5) + + geom_sf(aes(color = source, linetype = source), + fill = NA, show.legend = "line", + linewidth = 0.5, alpha = 0.7 + ) + + coord_sf( + crs = 4326, xlim = c(-8.384421, -8.154413), ylim = c(43.43201, 43.59545), + expand = FALSE + ) + + scale_color_manual(values = c("red", "black", "blue")) + + scale_linetype_manual(values = c("solid", "dotted", "dashed")) + + theme_void() + + labs(title = "Ría de Ferrol") +``` + +- **rnaturalearth**: No capta bien el contorno. +- **mapSpain**: Resultados satisfactorios. +- **GADM** (libería **geodata**): Resultados muy precisos. + +### Almacenamiento + +**mapSpain** es un paquete API que usa recursos web. El comportamiento por +defecto consiste en descargar archivos al directorio temporal `tempdir()` para +su uso posterior durante la sesión. + +La función `esp_set_cache_dir()` permite modificar este comportamiento, +estableciendo un directorio de descarga específico para el usuario. Para hacer +esta configuración persistente se puede emplear el parámetro `install = TRUE` + +``` r +esp_set_cache_dir("~/R/mapslib/mapSpain", install = TRUE, verbose = TRUE) + +#> mapSpain cache dir is: C:/Users/xxxxx/Documents/R/mapslib/mapSpain + +munic <- esp_get_munic_siane(verbose = TRUE) + +#> Cache dir is C:/Users/xxxxx/Documents/R/mapslib/mapSpain +#> Downloading file from https://github.com/rOpenSpain/mapSpain/raw/sianedata/dist/se89_3_admin_muni_a_x.gpkg + +#> See https://github.com/rOpenSpain/mapSpain/tree/sianedata/ for more info +#> trying URL 'https://github.com/rOpenSpain/mapSpain/raw/sianedata/dist/se89_3_admin_muni_a_x.gpkg' +#> Content type 'application/octet-stream' length 5570560 bytes (5.3 MB) +#> downloaded 5.3 MB + +#> Download succesful +#> Reading from local file #> C:/Users/xxxxx/Documents/R/mapslib/mapSpain/se89_3_admin_muni_a_x.gpkg +#> 5.3 Mb +``` + +## Diccionario + +### Funciones para trabajar con strings + +**mapSpain** proporciona dos funciones relacionadas para trabajar con textos y +códigos: + +- `esp_dict_region_code()` convierte textos en códigos de CCAA y provincias. + Esquemas de codificación soportados: + - ISO2 + - NUTS + - INE (codauto y cpro) +- `esp_dict_translate()` traduce textos a diferentes idiomas: + - Castellano + - Inglés + - Catalán + - Gallego + - Vasco + +Estas funciones pueden ser de utilidad en ámbitos más amplios que necesiten +homogeneizar códigos de CCAA y Provincias (Datos COVID ISCII, etc). + +#### `esp_dict_region_code()` + +```{r} +vals <- c("Errioxa", "Coruna", "Gerona", "Madrid") + +esp_dict_region_code(vals, destination = "nuts") +esp_dict_region_code(vals, destination = "cpro") +esp_dict_region_code(vals, destination = "iso2") + +# Desde ISO a otros códigos + +iso2vals <- c("ES-M", "ES-S", "ES-SG") +esp_dict_region_code(iso2vals, origin = "iso2") + +iso2vals <- c("ES-GA", "ES-CT", "ES-PV") + +esp_dict_region_code(iso2vals, origin = "iso2", destination = "nuts") + +# Soporta diferentes niveles +valsmix <- c("Centro", "Andalucia", "Seville", "Menorca") +esp_dict_region_code(valsmix, destination = "nuts") + +esp_dict_region_code(c("Murcia", "Las Palmas", "Aragón"), destination = "iso2") +``` + +#### `esp_dict_translate()` + +```{r} +vals <- c("La Rioja", "Sevilla", "Madrid", "Jaen", "Orense", "Baleares") + +esp_dict_translate(vals, lang = "en") +esp_dict_translate(vals, lang = "es") +esp_dict_translate(vals, lang = "ca") + + +esp_dict_translate(vals, lang = "eu") +esp_dict_translate(vals, lang = "ga") +``` + +## Límites políticos + +**mapSpain** contiene un set de funciones que permiten obtener límites políticos +a diferentes niveles: + +- Todo el país +- [NUTS](https://ec.europa.eu/eurostat/web/nuts/background) (Eurostat): + Clasificación estadística de Eurostat. Niveles 0 (país), 1, 2 (CCAA) y 3. +- CCAA +- Provincias +- Municipios + +Para CCAA, Provinicas y Municipios hay dos versiones: `esp_get_xxxx()` (fuente: +GISCO) y `esp_get_xxxx_siane()` (fuente: IGN). + +La información se proporciona en diferentes proyecciones y niveles de +resolución. + +```{r pais} +esp <- esp_get_country(moveCAN = FALSE) + +ggplot(esp) + + geom_sf(fill = "#f9cd94") + + theme_light() +``` + +### El caso Canarias + +Por defecto, **mapSpain** "desplaza" Canarias para una mejor visualización en la +mayoría de sus funciones. Este comportamiento se puede desactivar usando +`moveCAN = FALSE`(ver anterior ejemplo). + +Proporcionamos funciones adicionales que permiten representar lineas alrededor +de la inserción del mapa +([ejemplos](https://ropenspain.github.io/mapSpain/reference/esp_get_can_box.html#examples)). + +```{r can} +esp_can <- esp_get_country() +can_prov <- esp_get_can_provinces() +can_box <- esp_get_can_box() + +ggplot(esp_can) + + geom_sf() + + geom_sf(data = can_prov) + + geom_sf(data = can_box) +``` + +**Cuando se trabaja con imágenes, mapas interactivos o se desean realizar +analisis espaciales, se debe usar `moveCAN = FALSE`** + +### NUTS + +```{r nuts} +nuts1 <- esp_get_nuts(resolution = 20, epsg = 3035, nuts_level = 1) + +ggplot(nuts1) + + geom_sf() + + labs(title = "NUTS1: Baja Resolución") +``` + +```{r} +# Baleares NUTS3 +nuts3_baleares <- c("ES531", "ES532", "ES533") +paste(esp_dict_region_code(nuts3_baleares, "nuts"), collapse = ", ") + +nuts3_sf <- esp_get_nuts(region = nuts3_baleares) + +ggplot(nuts3_sf) + + geom_sf(aes(fill = NAME_LATN)) + + labs(fill = "Baleares: NUTS3") + + scale_fill_viridis_d() + + theme_minimal() +``` + +### CCAA + +```{r ccaa} +ccaa <- esp_get_ccaa(ccaa = c( + "Catalunya", "Comunidad Valenciana", "Aragón", + "Baleares" +)) + +ccaa <- ccaa %>% + mutate(ccaa_cat = esp_dict_translate(ine.ccaa.name, "ca")) + +ggplot(ccaa) + + geom_sf(aes(fill = ccaa_cat)) + + labs(fill = "Comunitats autònomes") + + theme_minimal() + + scale_fill_discrete(type = hcl.colors(4, "Plasma")) +``` + +### Provincias (usando versión `*_siane`) + +Si pasamos una entidad de orden superior (e.g. Andalucia) obtenemos todas las +provincias de esa entidad. + +```{r prov} +provs <- esp_get_prov_siane(c( + "Andalucía", "Ciudad Real", "Murcia", "Ceuta", + "Melilla" +)) + +ggplot(provs) + + geom_sf(aes(fill = prov.shortname.es), alpha = 0.9) + + scale_fill_discrete(type = hcl.colors(12, "Cividis")) + + theme_minimal() + + labs(fill = "Provincias") +``` + +### Municipios + +```{r munic} +munic <- esp_get_munic(region = "Segovia") %>% + # Datos de ejemplo: Población INE + left_join(mapSpain::pobmun19, by = c("cpro", "cmun")) + +ggplot(munic) + + geom_sf(aes(fill = pob19), alpha = 0.9, color = NA) + + scale_fill_gradientn( + colors = hcl.colors(100, "Inferno"), + n.breaks = 10, labels = scales::label_comma(), + guide = guide_legend() + ) + + labs( + fill = "Habitantes", title = "Población en Segovia", + subtitle = "Datos INE (2019)" + ) + + theme_void() + + theme( + plot.background = element_rect("grey80"), + text = element_text(face = "bold"), + plot.title = element_text(hjust = .5), + plot.subtitle = element_text(hjust = .5) + ) +``` + +### Hexbin maps + +Disponibles como cuadrados y hexágonos, para provincias y CCAA. + +```{r hex, out.width="50%", fig.show='hold'} +cuad <- esp_get_hex_ccaa() +hex <- esp_get_grid_prov() + +ggplot(cuad) + + geom_sf() + + geom_sf_text(aes(label = iso2.ccaa.code)) + + theme_void() + + + +ggplot(hex) + + geom_sf() + + geom_sf_text(aes(label = iso2.prov.code)) + + theme_void() +``` + +## Imágenes + +**mapSpain** permite usar también imágenes de mapas (satélite, mapas base, +carreteras, etc.) proporcionados por diferentes organísmos públicos +(). + +Las imágenes se pueden emplear para la creación de mapas estáticos (imágenes +obtenidas como capas ráster de 3 o 4 bandas) o como fondo de mapas dinámicos, a +través del paquete `leaflet`. + +Los proveedores se han extraido del plugin para leaflet +[leaflet-providerESP](https://dieghernan.github.io/leaflet-providersESP/). + +### Creación de mapas estáticos + +Tenemos varias opciones que podemos emplear para componer mapas base: + +```{r imagesestaticos} +madrid_munis <- esp_get_munic_siane(region = "Madrid", epsg = 3857) +base_pnoa <- esp_getTiles(madrid_munis, "PNOA", + bbox_expand = 0.1, + zoommin = 1 +) + +library(tidyterra) + +ggplot() + + geom_spatraster_rgb(data = base_pnoa) + + geom_sf( + data = madrid_munis, color = "blue", fill = "blue", + alpha = 0.25, linewidth = 0.5 + ) + + theme_minimal() + + labs(title = "Municipios en Madrid") + + +# Usando la opción mask +madrid <- esp_get_munic_siane(munic = "^Madrid$", epsg = 3857) + +madrid_mask <- esp_getTiles(madrid, "IDErioja.Claro", + mask = TRUE, crop = TRUE, zoommin = 2 +) + + +ggplot() + + geom_spatraster_rgb(data = madrid_mask) + + theme_void() + + labs( + title = "Mapa Base de Madrid", + caption = "CC BY 4.0 www.iderioja.org" + ) +``` + +### Mapas dinámicos usando mapSpain + +Estas capas se pueden usar también como fondo en mapas estáticos + +```{r leaflet} +stations <- esp_get_railway(spatialtype = "point", epsg = 4326) + +library(leaflet) +# Creamos icono + +iconurl <- paste0( + "https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/", + "Map_icons_by_Scott_de_Jonge_-_train-station.svg/480px-Map_", + "icons_by_Scott_de_Jonge_-_train-station.svg.png" +) + +train_icon <- makeIcon(iconurl, iconurl, 18, 18) + + +leaflet(stations, + elementId = "railway", + width = "100%", + height = "60vh" +) %>% + addProviderEspTiles("IDErioja.Claro", group = "Base") %>% + addProviderEspTiles("MTN", group = "MTN") %>% + addProviderEspTiles("RedTransporte.Carreteras", + group = "Carreteras" + ) %>% + addProviderEspTiles("RedTransporte.Ferroviario", + group = "Lineas Ferroviarias" + ) %>% + addMarkers( + icon = train_icon, + group = "Estaciones", + popup = sprintf( + "%s", + stations$rotulo + ) %>% + lapply(htmltools::HTML) + ) %>% + addLayersControl( + baseGroups = c("Base", "MTN"), + overlayGroups = c("Estaciones", "Lineas Ferroviarias", "Carreteras"), + options = layersControlOptions(collapsed = FALSE) + ) %>% + hideGroup(c("Lineas Ferroviarias", "Carreteras")) +``` + +## Otros recursos + +**mapSpain** incluye otras [funciones +adicionales](https://ropenspain.github.io/mapSpain/reference/index.html#section-natural) +que permiten extraer información sobre altitud, rios y cuencas hidrográficas de +España, así líneas y puntos de +[infraestructuras](https://ropenspain.github.io/mapSpain/reference/index.html#section-infrastructures) +de España, como carreteras y líneas ferroviarias. + +```{r message=FALSE, warning=FALSE, include=FALSE} +# Restore cache +esp_set_cache_dir(initcache, verbose = TRUE) +``` + +## Session info + +
+ +Details + +```{r session, echo=FALSE} +if (!require("sessioninfo")) { + install.packages("sessioninfo") +} +sessioninfo::session_info() +``` + +
diff --git a/vignettes/basic-1.png b/vignettes/basic-1.png index c0081024..9de48011 100644 Binary files a/vignettes/basic-1.png and b/vignettes/basic-1.png differ diff --git a/vignettes/basic-2.png b/vignettes/basic-2.png deleted file mode 100644 index 77bcf173..00000000 Binary files a/vignettes/basic-2.png and /dev/null differ diff --git a/vignettes/basic-3.png b/vignettes/basic-3.png deleted file mode 100644 index 644a4cf4..00000000 Binary files a/vignettes/basic-3.png and /dev/null differ diff --git a/vignettes/basic2-1.png b/vignettes/basic2-1.png new file mode 100644 index 00000000..430fd8f4 Binary files /dev/null and b/vignettes/basic2-1.png differ diff --git a/vignettes/basic3-1.png b/vignettes/basic3-1.png new file mode 100644 index 00000000..96ab8d07 Binary files /dev/null and b/vignettes/basic3-1.png differ diff --git a/vignettes/choro-1.png b/vignettes/choro-1.png index caf3f776..d32f4f9e 100644 Binary files a/vignettes/choro-1.png and b/vignettes/choro-1.png differ diff --git a/vignettes/giscoR-1.png b/vignettes/giscoR-1.png index 7b5c3f38..2465f0c6 100644 Binary files a/vignettes/giscoR-1.png and b/vignettes/giscoR-1.png differ diff --git a/vignettes/imagery.Rmd b/vignettes/imagery.Rmd new file mode 100644 index 00000000..c3343e33 --- /dev/null +++ b/vignettes/imagery.Rmd @@ -0,0 +1,25 @@ +--- +title: "Imagery and mapSpain" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Imagery and mapSpain} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +Visit for +learning how to download imagery of Spain. + +Note also that you would need a bunch of extra packages. Make sure that you +install the packages needed running: + +``` r +install.packages("mapSpain", dependencies = TRUE) +``` diff --git a/vignettes/mapSpain.Rmd b/vignettes/mapSpain.Rmd index 5213004c..872c2e54 100644 --- a/vignettes/mapSpain.Rmd +++ b/vignettes/mapSpain.Rmd @@ -1,16 +1,17 @@ --- title: "Get Started" -author: "Diego Hernangómez" +author: Diego Hernangómez ORCID logo +description: > + First steps with `mapSpain`. output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Get Started} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: - markdown: - wrap: 80 --- + + ## Introduction @@ -18,77 +19,88 @@ editor_options: **Full site with more examples and vignettes on ** -[**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package designed -to provide geographical information of Spain at different levels. +[**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package designed to +provide geographical information of Spain at different levels. **mapSpain** provides shapefiles of municipalities, provinces, autonomous communities and NUTS levels of Spain. It also provides hexbin shapefiles and other complementary shapes, as the usual lines around the Canary Islands. -**mapSpain** provides access to map tiles of public organisms of Spain, that -can be represented on static maps via `mapSpain::esp_getTiles()` or on a **R** -`leaflet` map using `mapSpain::addProviderEspTiles()`. +**mapSpain** provides access to map tiles of public organisms of Spain, that can +be represented on static maps via `mapSpain::esp_getTiles()` or on a **R** +**leaflet** map using `mapSpain::addProviderEspTiles()`. On top of that, **mapSpain** also has a powerful dictionary that translate provinces and other regions to English, Spanish, Catalan, Basque language or Galician, and also converts those names to different coding standards, as NUTS, -ISO2 or the coding system used by the INE, that is the official statistic -agency of Spain. +ISO2 or the coding system used by the INE, that is the official statistic agency +of Spain. ## Caching -**mapSpain** provides a dataset and tile caching capability, that could be set as: - +**mapSpain** provides a dataset and tile caching capability, that could be set +as: -```r +``` r esp_set_cache_dir("./path/to/location") ``` -**mapSpain** relies on [**giscoR**](https://dieghernan.github.io/giscoR/) for +**mapSpain** relies on [**giscoR**](https://ropengov.github.io/giscoR/) for downloading some files, and both packages are well synchronized. Setting the same caching directory on both would speed up the data load on your session. - ## Basic example Some examples of what **mapSpain** can do: -```r - +``` r library(mapSpain) -library(tmap) +library(ggplot2) country <- esp_get_country() lines <- esp_get_can_box() -tm_shape(country) + - tm_polygons() + - tm_shape(lines) + - tm_lines() + - tm_graticules(lines = FALSE) + - tm_style("classic") + - tm_layout(main.title = "Map of Spain") +ggplot(country) + + geom_sf(fill = "cornsilk", color = "#887e6a") + + labs(title = "Map of Spain") + + theme( + panel.background = element_rect(fill = "#fffff3"), + panel.border = element_rect( + colour = "#887e6a", + fill = NA, + ), + text = element_text( + family = "serif", + face = "bold" + ) + ) ``` -plot of chunk basic +
+Example: Map of Spain +

Example: Map of Spain

+
-```r +``` r # Plot provinces Andalucia <- esp_get_prov("Andalucia") -tm_shape(Andalucia) + - tm_polygons(col = "darkgreen", border.col = "white") + - tm_graticules(lines = FALSE) +ggplot(Andalucia) + + geom_sf(fill = "darkgreen", color = "white") + + theme_bw() ``` -plot of chunk basic +
+Example: Provinces of Andalucia +

Example: Provinces of Andalucia

+
-```r +``` r # Plot municipalities Euskadi_CCAA <- esp_get_ccaa("Euskadi") @@ -98,52 +110,50 @@ Euskadi <- esp_get_munic(region = "Euskadi") Euskadi$name_eu <- esp_dict_translate(Euskadi$ine.prov.name, lang = "eu") -tm_shape(Euskadi_CCAA) + - tm_fill("grey50") + - tm_shape(Euskadi) + - tm_polygons("name_eu", - palette = c("red2", "darkgreen", "ivory2"), - title = "" +ggplot(Euskadi_CCAA) + + geom_sf(fill = "grey50") + + geom_sf(data = Euskadi, aes(fill = name_eu)) + + scale_fill_manual(values = c("red2", "darkgreen", "ivory2")) + + labs( + fill = "", + title = "Euskal Autonomia Erkidegoko", + subtitle = "Probintziak" ) + - tm_layout( - main.title = paste0( - "Euskal Autonomia Erkidegoko", - "\n", - "Probintziak" - ), - main.title.size = 0.8, - main.title.fontface = "bold" + theme_void() + + theme( + plot.title = element_text(face = "bold"), + plot.subtitle = element_text(face = "italic") ) ``` -plot of chunk basic +
+Example: Municipalities of the Basque Country +

Example: Municipalities of the Basque Country

+
## Choropleth and label maps Let's analyze the distribution of women in each autonomous community with -`tmap`: - +`ggplot`: -```r +``` r census <- mapSpain::pobmun19 # Extract CCAA from base dataset codelist <- mapSpain::esp_codelist -census <- - unique(merge(census, codelist[, c("cpro", "codauto")], - all.x = TRUE - )) +census <- unique(merge(census, codelist[, c("cpro", "codauto")], all.x = TRUE)) # Summarize by CCAA -census_ccaa <- - aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum) +census_ccaa <- aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum) census_ccaa$porc_women <- census_ccaa$women / census_ccaa$pob19 -census_ccaa$porc_women_lab <- - paste0(round(100 * census_ccaa$porc_women, 2), "%") +census_ccaa$porc_women_lab <- paste0( + round(100 * census_ccaa$porc_women, 2), + "%" +) # Merge into spatial data @@ -151,44 +161,42 @@ CCAA_sf <- esp_get_ccaa() CCAA_sf <- merge(CCAA_sf, census_ccaa) Can <- esp_get_can_box() - -# Plot with tmap -tm_shape(CCAA_sf) + - tm_polygons( - "porc_women", - border.col = "grey70", - title = "Porc. women", - palette = "Blues", - alpha = 0.7, - legend.format = list( - fun = function(x) { - sprintf("%1.1f%%", 100 * x) - } - ) +ggplot(CCAA_sf) + + geom_sf(aes(fill = porc_women), + color = "grey70", + linewidth = .3 ) + - tm_shape(CCAA_sf, point.per = "feature") + - tm_text("porc_women_lab", remove.overlap = TRUE, shadow = TRUE) + - tm_shape(Can) + - tm_lines(col = "grey70") + - tm_layout( - legend.position = c("LEFT", "center"), - frame = FALSE - ) + geom_sf(data = Can, color = "grey70") + + geom_sf_label(aes(label = porc_women_lab), + fill = "white", alpha = 0.5, size = 3, label.size = 0 + ) + + scale_fill_gradientn( + colors = hcl.colors(10, "Blues", rev = TRUE), + n.breaks = 10, + labels = function(x) { + sprintf("%1.1f%%", 100 * x) + }, + guide = guide_legend(title = "Porc. women", position = "inside") + ) + + theme_void() + + theme(legend.position.inside = c(0.1, 0.6)) ``` -plot of chunk choro +
+Percentage of women by Autonomous Community (2019) +

Percentage of women by Autonomous Community (2019)

+
## Thematic maps This is an example on how **mapSpain** can be used to beautiful thematic maps. For plotting purposes we would use the -[**tmap**](https://github.com/r-tmap/tmap) -package, however any package that handles `sf` objects (e.g. `ggplot2`, `mapsf`, -`leaflet`, etc. could be used). - +[**ggplot**](https://ggplot2.tidyverse.org/) package, however any package that +handles `sf` objects (e.g. **tmap**, **mapsf**, **leaflet**, etc. could be +used). -```r +``` r # Population density of Spain library(sf) @@ -203,90 +211,86 @@ munic$area <- municarea munic.pop <- merge(munic, pop, all.x = TRUE, by = c("cpro", "cmun")) munic.pop$dens <- munic.pop$pob19 / munic.pop$area -br <- - c( - -Inf, - 10, - 25, - 100, - 200, - 500, - 1000, - 5000, - 10000, - Inf - ) +br <- c(-Inf, 10, 25, 100, 200, 500, 1000, 5000, 10000, Inf) + +munic.pop$cuts <- cut(munic.pop$dens, br) -tm_shape(munic.pop) + - tm_fill("dens", - breaks = br, - alpha = 0.9, - title = "Pop. per km2", - palette = c("black", hcl.colors(100, "Spectral")), - showNA = FALSE, - colorNA = "black" +ggplot(munic.pop) + + geom_sf(aes(fill = cuts), color = NA, linewidth = 0) + + scale_fill_manual( + values = c("grey5", hcl.colors(length(br) - 2, "Spectral")), + labels = prettyNum(c(0, br[-1]), big.mark = ","), + guide = guide_legend(title = "Pop. per km2", direction = "horizontal", nrow = 1) ) + - tm_layout( - bg.color = "black", - main.title = "Population density in Spain (2019)", - main.title.color = "white", - main.title.fontface = "bold", - outer.bg.color = "black", - legend.title.color = "white", - legend.text.color = "white", - legend.text.fontface = "bold", - legend.text.size = 1, - legend.position = c("LEFT", "center") + labs(title = "Population density in Spain (2019)") + + theme_void() + + theme( + plot.title = element_text(hjust = .5), + plot.background = element_rect(fill = "black"), + text = element_text(colour = "white"), + legend.position = "bottom", + legend.title.position = "top", + legend.text.position = "bottom", + legend.key.width = unit(30, "pt") ) ``` -plot of chunk thematic +
+Population density in Spain (2019) +

Population density in Spain (2019)

+
## mapSpain and giscoR If you need to plot Spain along with another countries, consider using -[**giscoR**](https://dieghernan.github.io/giscoR/) package, that is installed -as a dependency when you installed **mapSpain**. A basic example: +[**giscoR**](https://ropengov.github.io/giscoR/) package, that is installed as a +dependency when you installed **mapSpain**. A basic example: -```r - +``` r library(giscoR) # Set the same resolution for a perfect fit -res <- "03" +res <- "20" -# Same crs -target_crs <- 3035 +all_countries <- gisco_get_countries(resolution = res) |> + st_transform(3035) -all_countries <- gisco_get_countries( - resolution = res, - epsg = target_crs -) eu_countries <- gisco_get_countries( - resolution = res, region = "EU", - epsg = target_crs -) + resolution = res, region = "EU" +) |> + st_transform(3035) + ccaa <- esp_get_ccaa( - moveCAN = FALSE, resolution = res, - epsg = target_crs -) + moveCAN = FALSE, resolution = res +) |> + st_transform(3035) # Plot -library(tmap) - -tm_shape(all_countries, bbox = c(23, 14, 67, 54) * 10e4) + - tm_graticules(col = "#DFDFDF", alpha = 0.7) + - tm_fill("#DFDFDF") + - tm_shape(eu_countries) + - tm_polygons("#FDFBEA", border.col = "#656565") + - tm_shape(ccaa) + - tm_polygons("#C12838", border.col = "grey80", lwd = 0.1) +ggplot(all_countries) + + geom_sf(fill = "#DFDFDF", color = "#656565") + + geom_sf(data = eu_countries, fill = "#FDFBEA", color = "#656565") + + geom_sf(data = ccaa, fill = "#C12838", color = "grey80", linewidth = .1) + + # Center in Europe: EPSG 3035 + coord_sf( + xlim = c(2377294, 7453440), + ylim = c(1313597, 5628510) + ) + + theme( + panel.background = element_blank(), + panel.grid = element_line( + colour = "#DFDFDF", + linetype = "dotted" + ) + ) ``` -plot of chunk giscoR +
+mapSpain and giscoR example +

mapSpain and giscoR example

+
## Working with tiles @@ -299,34 +303,9 @@ the Web Map Service) and use them along your shapefiles. include several basemaps on your interactive maps. The services are implemented via the leaflet plugin -[leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/). You can -check a display of each provider on the previous link. +[leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/). You +can check a display of each provider on the previous link. **Note that** When working with imagery, it is important to set -`moveCAN = FALSE` on the `esp_get_*` functions. See -**Displacing the Canary Islands** on -`help("esp_get_ccaa", package = "mapSpain")`. - -An example of how you can include tiles and shapes to create a static map: - - -```r - -# Get Deltebre - Municipality -delt <- esp_get_munic(munic = "Deltebre") - -# Base PNOA - Satellite imagery -PNOA <- esp_getTiles(delt, - type = "PNOA", - zoom = 11, - bbox_expand = 1.5 -) - -tm_shape(PNOA) + - tm_rgb() + - # Mix with shape - tm_shape(delt) + - tm_fill("green3", alpha = 0.5) -``` - -plot of chunk tile +`moveCAN = FALSE` on the `esp_get_*` functions. See **Displacing the Canary +Islands** on `help("esp_get_ccaa", package = "mapSpain")`. diff --git a/vignettes/mapSpain.Rmd.orig b/vignettes/mapSpain.Rmd.orig index 1945048e..76fc0970 100644 --- a/vignettes/mapSpain.Rmd.orig +++ b/vignettes/mapSpain.Rmd.orig @@ -1,24 +1,27 @@ --- title: "Get Started" -author: "Diego Hernangómez" +author: Diego Hernangómez ORCID logo +description: > + First steps with `mapSpain`. output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Get Started} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: - markdown: - wrap: 80 --- + + ```{r, include = FALSE} +knitr::knit_hooks$set(crop = knitr::hook_pdfcrop) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE, tidy = "styler", - dpi = 90, + dev = "ragg_png", + dpi = 120, fig.path = "./", out.width = "100%" ) @@ -29,65 +32,74 @@ knitr::opts_chunk$set( **Full site with more examples and vignettes on ** -[**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package designed -to provide geographical information of Spain at different levels. +[**mapSpain**](https://ropenspain.github.io/mapSpain/) is a package designed to +provide geographical information of Spain at different levels. **mapSpain** provides shapefiles of municipalities, provinces, autonomous communities and NUTS levels of Spain. It also provides hexbin shapefiles and other complementary shapes, as the usual lines around the Canary Islands. -**mapSpain** provides access to map tiles of public organisms of Spain, that -can be represented on static maps via `mapSpain::esp_getTiles()` or on a **R** -`leaflet` map using `mapSpain::addProviderEspTiles()`. +**mapSpain** provides access to map tiles of public organisms of Spain, that can +be represented on static maps via `mapSpain::esp_getTiles()` or on a **R** +**leaflet** map using `mapSpain::addProviderEspTiles()`. On top of that, **mapSpain** also has a powerful dictionary that translate provinces and other regions to English, Spanish, Catalan, Basque language or Galician, and also converts those names to different coding standards, as NUTS, -ISO2 or the coding system used by the INE, that is the official statistic -agency of Spain. +ISO2 or the coding system used by the INE, that is the official statistic agency +of Spain. ## Caching -**mapSpain** provides a dataset and tile caching capability, that could be set as: +**mapSpain** provides a dataset and tile caching capability, that could be set +as: ```{r, eval=FALSE} - esp_set_cache_dir("./path/to/location") ``` -**mapSpain** relies on [**giscoR**](https://dieghernan.github.io/giscoR/) for +**mapSpain** relies on [**giscoR**](https://ropengov.github.io/giscoR/) for downloading some files, and both packages are well synchronized. Setting the same caching directory on both would speed up the data load on your session. - ## Basic example Some examples of what **mapSpain** can do: -```{r basic} - +```{r basic, fig.cap="Example: Map of Spain", fig.asp=0.7} library(mapSpain) -library(tmap) +library(ggplot2) country <- esp_get_country() lines <- esp_get_can_box() -tm_shape(country) + - tm_polygons() + - tm_shape(lines) + - tm_lines() + - tm_graticules(lines = FALSE) + - tm_style("classic") + - tm_layout(main.title = "Map of Spain") +ggplot(country) + + geom_sf(fill = "cornsilk", color = "#887e6a") + + labs(title = "Map of Spain") + + theme( + panel.background = element_rect(fill = "#fffff3"), + panel.border = element_rect( + colour = "#887e6a", + fill = NA, + ), + text = element_text( + family = "serif", + face = "bold" + ) + ) +``` +```{r basic2, fig.cap="Example: Provinces of Andalucia", fig.asp=0.55} # Plot provinces Andalucia <- esp_get_prov("Andalucia") -tm_shape(Andalucia) + - tm_polygons(col = "darkgreen", border.col = "white") + - tm_graticules(lines = FALSE) +ggplot(Andalucia) + + geom_sf(fill = "darkgreen", color = "white") + + theme_bw() +``` +```{r basic3, fig.cap="Example: Municipalities of the Basque Country", fig.asp=0.8} # Plot municipalities Euskadi_CCAA <- esp_get_ccaa("Euskadi") @@ -97,48 +109,44 @@ Euskadi <- esp_get_munic(region = "Euskadi") Euskadi$name_eu <- esp_dict_translate(Euskadi$ine.prov.name, lang = "eu") -tm_shape(Euskadi_CCAA) + - tm_fill("grey50") + - tm_shape(Euskadi) + - tm_polygons("name_eu", - palette = c("red2", "darkgreen", "ivory2"), - title = "" +ggplot(Euskadi_CCAA) + + geom_sf(fill = "grey50") + + geom_sf(data = Euskadi, aes(fill = name_eu)) + + scale_fill_manual(values = c("red2", "darkgreen", "ivory2")) + + labs( + fill = "", + title = "Euskal Autonomia Erkidegoko", + subtitle = "Probintziak" ) + - tm_layout( - main.title = paste0( - "Euskal Autonomia Erkidegoko", - "\n", - "Probintziak" - ), - main.title.size = 0.8, - main.title.fontface = "bold" + theme_void() + + theme( + plot.title = element_text(face = "bold"), + plot.subtitle = element_text(face = "italic") ) ``` ## Choropleth and label maps Let's analyze the distribution of women in each autonomous community with -`tmap`: - -```{r choro} +`ggplot`: +```{r choro, fig.cap="Percentage of women by Autonomous Community (2019)", fig.asp=0.7} census <- mapSpain::pobmun19 # Extract CCAA from base dataset codelist <- mapSpain::esp_codelist -census <- - unique(merge(census, codelist[, c("cpro", "codauto")], - all.x = TRUE)) +census <- unique(merge(census, codelist[, c("cpro", "codauto")], all.x = TRUE)) # Summarize by CCAA -census_ccaa <- - aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum) +census_ccaa <- aggregate(cbind(pob19, men, women) ~ codauto, data = census, sum) census_ccaa$porc_women <- census_ccaa$women / census_ccaa$pob19 -census_ccaa$porc_women_lab <- - paste0(round(100 * census_ccaa$porc_women, 2), "%") +census_ccaa$porc_women_lab <- paste0( + round(100 * census_ccaa$porc_women, 2), + "%" +) # Merge into spatial data @@ -146,39 +154,36 @@ CCAA_sf <- esp_get_ccaa() CCAA_sf <- merge(CCAA_sf, census_ccaa) Can <- esp_get_can_box() - -# Plot with tmap -tm_shape(CCAA_sf) + - tm_polygons( - "porc_women", - border.col = "grey70", - title = "Porc. women", - palette = "Blues", - alpha = 0.7, - legend.format = list( - fun = function(x) { - sprintf("%1.1f%%", 100 * x) - } - ) +ggplot(CCAA_sf) + + geom_sf(aes(fill = porc_women), + color = "grey70", + linewidth = .3 + ) + + geom_sf(data = Can, color = "grey70") + + geom_sf_label(aes(label = porc_women_lab), + fill = "white", alpha = 0.5, size = 3, label.size = 0 ) + - tm_shape(CCAA_sf, point.per = "feature") + - tm_text("porc_women_lab", remove.overlap = TRUE, shadow = TRUE) + - tm_shape(Can) + - tm_lines(col = "grey70") + - tm_layout(legend.position = c("LEFT", "center"), - frame = FALSE) + scale_fill_gradientn( + colors = hcl.colors(10, "Blues", rev = TRUE), + n.breaks = 10, + labels = function(x) { + sprintf("%1.1f%%", 100 * x) + }, + guide = guide_legend(title = "Porc. women", position = "inside") + ) + + theme_void() + + theme(legend.position.inside = c(0.1, 0.6)) ``` ## Thematic maps This is an example on how **mapSpain** can be used to beautiful thematic maps. For plotting purposes we would use the -[**tmap**](https://github.com/r-tmap/tmap) -package, however any package that handles `sf` objects (e.g. `ggplot2`, `mapsf`, -`leaflet`, etc. could be used). - -```{r thematic, fig.asp=0.7} +[**ggplot**](https://ggplot2.tidyverse.org/) package, however any package that +handles `sf` objects (e.g. **tmap**, **mapsf**, **leaflet**, etc. could be +used). +```{r thematic, fig.cap="Population density in Spain (2019)", crop=TRUE, dpi=120} # Population density of Spain library(sf) @@ -193,84 +198,74 @@ munic$area <- municarea munic.pop <- merge(munic, pop, all.x = TRUE, by = c("cpro", "cmun")) munic.pop$dens <- munic.pop$pob19 / munic.pop$area -br <- - c( - -Inf, - 10, - 25, - 100, - 200, - 500, - 1000, - 5000, - 10000, - Inf - ) +br <- c(-Inf, 10, 25, 100, 200, 500, 1000, 5000, 10000, Inf) + +munic.pop$cuts <- cut(munic.pop$dens, br) -tm_shape(munic.pop) + - tm_fill("dens", - breaks = br, - alpha = 0.9, - title = "Pop. per km2", - palette = c("black", hcl.colors(100,"Spectral")), - showNA = FALSE, - colorNA = "black" +ggplot(munic.pop) + + geom_sf(aes(fill = cuts), color = NA, linewidth = 0) + + scale_fill_manual( + values = c("grey5", hcl.colors(length(br) - 2, "Spectral")), + labels = prettyNum(c(0, br[-1]), big.mark = ","), + guide = guide_legend(title = "Pop. per km2", direction = "horizontal", nrow = 1) ) + - tm_layout(bg.color = "black", - main.title = "Population density in Spain (2019)", - main.title.color = "white", - main.title.fontface = "bold", - outer.bg.color = "black", - legend.title.color = "white", - legend.text.color = "white", - legend.text.fontface = "bold", - legend.text.size = 1, - legend.position = c("LEFT","center") -) + labs(title = "Population density in Spain (2019)") + + theme_void() + + theme( + plot.title = element_text(hjust = .5), + plot.background = element_rect(fill = "black"), + text = element_text(colour = "white"), + legend.position = "bottom", + legend.title.position = "top", + legend.text.position = "bottom", + legend.key.width = unit(30, "pt") + ) ``` ## mapSpain and giscoR If you need to plot Spain along with another countries, consider using -[**giscoR**](https://dieghernan.github.io/giscoR/) package, that is installed -as a dependency when you installed **mapSpain**. A basic example: - -```{r giscoR, fig.asp=1} +[**giscoR**](https://ropengov.github.io/giscoR/) package, that is installed as a +dependency when you installed **mapSpain**. A basic example: +```{r giscoR, fig.cap="mapSpain and giscoR example", fig.asp=0.9} library(giscoR) # Set the same resolution for a perfect fit -res <- "03" +res <- "20" -# Same crs -target_crs <- 3035 +all_countries <- gisco_get_countries(resolution = res) |> + st_transform(3035) -all_countries <- gisco_get_countries( - resolution = res, - epsg = target_crs -) eu_countries <- gisco_get_countries( - resolution = res, region = "EU", - epsg = target_crs -) + resolution = res, region = "EU" +) |> + st_transform(3035) + ccaa <- esp_get_ccaa( - moveCAN = FALSE, resolution = res, - epsg = target_crs -) + moveCAN = FALSE, resolution = res +) |> + st_transform(3035) # Plot -library(tmap) - -tm_shape(all_countries, bbox = c(23, 14, 67, 54) * 10e4) + - tm_graticules(col = "#DFDFDF", alpha = 0.7) + - tm_fill("#DFDFDF") + - tm_shape(eu_countries) + - tm_polygons("#FDFBEA", border.col = "#656565") + - tm_shape(ccaa) + - tm_polygons("#C12838", border.col = "grey80", lwd = 0.1) - +ggplot(all_countries) + + geom_sf(fill = "#DFDFDF", color = "#656565") + + geom_sf(data = eu_countries, fill = "#FDFBEA", color = "#656565") + + geom_sf(data = ccaa, fill = "#C12838", color = "grey80", linewidth = .1) + + # Center in Europe: EPSG 3035 + coord_sf( + xlim = c(2377294, 7453440), + ylim = c(1313597, 5628510) + ) + + theme( + panel.background = element_blank(), + panel.grid = element_line( + colour = "#DFDFDF", + linetype = "dotted" + ) + ) ``` ## Working with tiles @@ -284,31 +279,9 @@ the Web Map Service) and use them along your shapefiles. include several basemaps on your interactive maps. The services are implemented via the leaflet plugin -[leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/). You can -check a display of each provider on the previous link. +[leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/). You +can check a display of each provider on the previous link. **Note that** When working with imagery, it is important to set -`moveCAN = FALSE` on the `esp_get_*` functions. See -**Displacing the Canary Islands** on -`help("esp_get_ccaa", package = "mapSpain")`. - -An example of how you can include tiles and shapes to create a static map: - -```{r tile} - -# Get Deltebre - Municipality -delt <- esp_get_munic(munic = "Deltebre") - -# Base PNOA - Satellite imagery -PNOA <- esp_getTiles(delt, - type = "PNOA", - zoom = 11, - bbox_expand = 1.5 -) - -tm_shape(PNOA) + - tm_rgb() + - # Mix with shape - tm_shape(delt) + - tm_fill("green3", alpha = 0.5) -``` +`moveCAN = FALSE` on the `esp_get_*` functions. See **Displacing the Canary +Islands** on `help("esp_get_ccaa", package = "mapSpain")`. diff --git a/vignettes/thematic-1.png b/vignettes/thematic-1.png index 87f6f05c..ed7d0210 100644 Binary files a/vignettes/thematic-1.png and b/vignettes/thematic-1.png differ diff --git a/vignettes/tile-1.png b/vignettes/tile-1.png deleted file mode 100644 index 2ea16917..00000000 Binary files a/vignettes/tile-1.png and /dev/null differ