├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── check-standard.yaml │ └── test-coverage.yaml ├── .gitignore ├── CITATION.cff ├── DESCRIPTION ├── NAMESPACE ├── NEWS.md ├── R ├── create_grid.R ├── create_matrix.R ├── curv.R ├── equipotential.R ├── mcpotential.R ├── package.R ├── potential.R ├── testarrow.R └── utils.R ├── README.md ├── README.rmd ├── _pkgdown.yml ├── codemeta.json ├── data └── nuts3.RData ├── docs ├── 404.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── index.html │ ├── potential.html │ ├── potential_files │ │ └── figure-html │ │ │ ├── curve-1.png │ │ │ ├── setup-1.png │ │ │ ├── setup2-1.png │ │ │ ├── setup3-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ ├── unnamed-chunk-7-1.png │ │ │ └── unnamed-chunk-8-1.png │ ├── smooth-1.png │ └── web_only │ │ ├── exemple.html │ │ └── exemple_files │ │ └── figure-html │ │ ├── regionalmap-1.png │ │ ├── regionalmappot-1.png │ │ └── smoothmappot-1.png ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── link.svg ├── logo.png ├── news │ └── index.html ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── Rplot001.png │ ├── Rplot002.png │ ├── create_grid-1.png │ ├── create_grid.html │ ├── create_matrix.html │ ├── equipotential-1.png │ ├── equipotential.html │ ├── figures │ │ ├── demo-1.png │ │ ├── demox-1.png │ │ └── logo.png │ ├── index.html │ ├── mcpotential-1.png │ ├── mcpotential.html │ ├── n3_poly.html │ ├── n3_pt.html │ ├── plot_inter-1.png │ ├── plot_inter-2.png │ ├── plot_inter.html │ ├── potential-1.png │ ├── potential-package.html │ └── potential.html └── sitemap.xml ├── inst └── tinytest │ └── test_curv.R ├── man ├── create_grid.Rd ├── create_matrix.Rd ├── equipotential.Rd ├── figures │ ├── demo-1.png │ ├── demox-1.png │ └── logo.png ├── mcpotential.Rd ├── n3_poly.Rd ├── n3_pt.Rd ├── plot_inter.Rd ├── potential-package.Rd └── potential.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── potential.Rproj ├── tests └── tinytest.R └── vignettes ├── .gitignore ├── potential.Rmd ├── references.bib ├── smooth-1.png └── web_only └── exemple.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.travis\.yml$ 4 | ^inst/test\.R$ 5 | ^inst/test/$ 6 | .github 7 | README.rmd 8 | README_files 9 | ^doc$ 10 | ^Meta$ 11 | ^_pkgdown\.yml$ 12 | ^docs$ 13 | ^pkgdown$ 14 | ^codemeta\.json$ 15 | ^CITATION\.cff$ 16 | ^\.github$ 17 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/check-standard.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macOS-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v2 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: covr::codecov(quiet = FALSE) 31 | shell: Rscript {0} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | inst/doc 5 | 6 | vignettes/*.html 7 | doc 8 | Meta 9 | # docs 10 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------- 2 | # CITATION file created with {cffr} R package, v0.2.2 3 | # See also: https://docs.ropensci.org/cffr/ 4 | # ----------------------------------------------------------- 5 | 6 | cff-version: 1.2.0 7 | message: 'To cite package "potential" in publications use:' 8 | type: software 9 | license: GPL-3.0-only 10 | title: 'potential: Implementation of the Potential Model' 11 | version: 0.2.0 12 | abstract: Provides functions to compute the potential model as defined by Stewart 13 | (1941) . Several options are available to customize 14 | the model, such as the possibility to fine-tune the distance friction functions 15 | or to use custom distance matrices. Some computations are parallelized to improve 16 | their efficiency. 17 | authors: 18 | - family-names: Giraud 19 | given-names: Timothée 20 | email: timothee.giraud@cnrs.fr 21 | orcid: https://orcid.org/0000-0002-1932-3323 22 | - family-names: Commenges 23 | given-names: Hadrien 24 | email: hadrien.commenges@univ-paris1.fr 25 | preferred-citation: 26 | type: manual 27 | title: 'potential: Implementation of the Potential Model' 28 | authors: 29 | - family-names: Giraud 30 | given-names: Timothée 31 | email: timothee.giraud@cnrs.fr 32 | orcid: https://orcid.org/0000-0002-1932-3323 33 | - family-names: Commenges 34 | given-names: Hadrien 35 | email: hadrien.commenges@univ-paris1.fr 36 | version: 0.2.0 37 | abstract: Provides functions to compute the potential model as defined by Stewart 38 | (1941) . Several options are available to customize 39 | the model, such as the possibility to fine-tune the distance friction functions 40 | or to use custom distance matrices. Some computations are parallelized to improve 41 | their efficiency. 42 | repository: https://CRAN.R-project.org/package=potential 43 | repository-code: https://github.com/riatelab/potential 44 | url: https://github.com/riatelab/potential 45 | contact: 46 | - family-names: Giraud 47 | given-names: Timothée 48 | email: timothee.giraud@cnrs.fr 49 | orcid: https://orcid.org/0000-0002-1932-3323 50 | keywords: 51 | - rspatial 52 | - stewart 53 | license: GPL-3.0-only 54 | year: '2022' 55 | repository: https://CRAN.R-project.org/package=potential 56 | repository-code: https://github.com/riatelab/potential 57 | url: https://github.com/riatelab/potential 58 | contact: 59 | - family-names: Giraud 60 | given-names: Timothée 61 | email: timothee.giraud@cnrs.fr 62 | orcid: https://orcid.org/0000-0002-1932-3323 63 | keywords: 64 | - rspatial 65 | - stewart 66 | references: 67 | - type: software 68 | title: 'R: A Language and Environment for Statistical Computing' 69 | notes: Depends 70 | authors: 71 | - name: R Core Team 72 | location: 73 | name: Vienna, Austria 74 | year: '2022' 75 | url: https://www.R-project.org/ 76 | institution: 77 | name: R Foundation for Statistical Computing 78 | version: '>= 3.5.0' 79 | - type: software 80 | title: sf 81 | abstract: 'sf: Simple Features for R' 82 | notes: Imports 83 | authors: 84 | - family-names: Pebesma 85 | given-names: Edzer 86 | email: edzer.pebesma@uni-muenster.de 87 | orcid: https://orcid.org/0000-0001-8049-7069 88 | year: '2022' 89 | url: https://CRAN.R-project.org/package=sf 90 | - type: software 91 | title: graphics 92 | abstract: 'R: A Language and Environment for Statistical Computing' 93 | notes: Imports 94 | authors: 95 | - name: R Core Team 96 | location: 97 | name: Vienna, Austria 98 | year: '2022' 99 | url: https://www.R-project.org/ 100 | institution: 101 | name: R Foundation for Statistical Computing 102 | - type: software 103 | title: mapiso 104 | abstract: 'mapiso: Create Contour Polygons from Regular Grids' 105 | notes: Imports 106 | authors: 107 | - family-names: Giraud 108 | given-names: Timothée 109 | email: timothee.giraud@cnrs.fr 110 | orcid: https://orcid.org/0000-0002-1932-3323 111 | year: '2022' 112 | url: https://CRAN.R-project.org/package=mapiso 113 | - type: software 114 | title: parallel 115 | abstract: 'R: A Language and Environment for Statistical Computing' 116 | notes: Imports 117 | authors: 118 | - name: R Core Team 119 | location: 120 | name: Vienna, Austria 121 | year: '2022' 122 | url: https://www.R-project.org/ 123 | institution: 124 | name: R Foundation for Statistical Computing 125 | - type: software 126 | title: doParallel 127 | abstract: 'doParallel: Foreach Parallel Adaptor for the ''parallel'' Package' 128 | notes: Imports 129 | authors: 130 | - family-names: Corporation 131 | given-names: Microsoft 132 | - family-names: Weston 133 | given-names: Steve 134 | year: '2022' 135 | url: https://CRAN.R-project.org/package=doParallel 136 | - type: software 137 | title: foreach 138 | abstract: 'foreach: Provides Foreach Looping Construct' 139 | notes: Imports 140 | authors: 141 | - name: Microsoft 142 | - family-names: Weston 143 | given-names: Steve 144 | year: '2022' 145 | url: https://CRAN.R-project.org/package=foreach 146 | - type: software 147 | title: covr 148 | abstract: 'covr: Test Coverage for Packages' 149 | notes: Suggests 150 | authors: 151 | - family-names: Hester 152 | given-names: Jim 153 | email: james.f.hester@gmail.com 154 | year: '2022' 155 | url: https://CRAN.R-project.org/package=covr 156 | - type: software 157 | title: lwgeom 158 | abstract: 'lwgeom: Bindings to Selected ''liblwgeom'' Functions for Simple Features' 159 | notes: Suggests 160 | authors: 161 | - family-names: Pebesma 162 | given-names: Edzer 163 | email: edzer.pebesma@uni-muenster.de 164 | orcid: https://orcid.org/0000-0001-8049-7069 165 | year: '2022' 166 | url: https://CRAN.R-project.org/package=lwgeom 167 | - type: software 168 | title: eurostat 169 | abstract: 'eurostat: Tools for Eurostat Open Data' 170 | notes: Suggests 171 | authors: 172 | - family-names: Lahti 173 | given-names: Leo 174 | email: leo.lahti@iki.fi 175 | orcid: https://orcid.org/0000-0001-5537-637X 176 | - family-names: Huovari 177 | given-names: Janne 178 | - family-names: Kainu 179 | given-names: Markus 180 | - family-names: Biecek 181 | given-names: Przemyslaw 182 | year: '2022' 183 | url: https://CRAN.R-project.org/package=eurostat 184 | - type: software 185 | title: giscoR 186 | abstract: 'giscoR: Download Map Data from GISCO API - Eurostat' 187 | notes: Suggests 188 | authors: 189 | - family-names: Hernangómez 190 | given-names: Diego 191 | email: diego.hernangomezherrero@gmail.com 192 | orcid: https://orcid.org/0000-0001-8457-4658 193 | affiliation: rOpenGov 194 | year: '2022' 195 | url: https://CRAN.R-project.org/package=giscoR 196 | - type: software 197 | title: mapsf 198 | abstract: 'mapsf: Thematic Cartography' 199 | notes: Suggests 200 | authors: 201 | - family-names: Giraud 202 | given-names: Timothée 203 | email: timothee.giraud@cnrs.fr 204 | orcid: https://orcid.org/0000-0002-1932-3323 205 | year: '2022' 206 | url: https://CRAN.R-project.org/package=mapsf 207 | - type: software 208 | title: knitr 209 | abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R' 210 | notes: Suggests 211 | authors: 212 | - family-names: Xie 213 | given-names: Yihui 214 | email: xie@yihui.name 215 | orcid: https://orcid.org/0000-0003-0645-5666 216 | year: '2022' 217 | url: https://CRAN.R-project.org/package=knitr 218 | - type: software 219 | title: tinytest 220 | abstract: 'tinytest: Lightweight and Feature Complete Unit Testing Framework' 221 | notes: Suggests 222 | authors: 223 | - family-names: van der Loo 224 | given-names: Mark 225 | email: mark.vanderloo@gmail.com 226 | orcid: https://orcid.org/0000-0002-9807-4686 227 | year: '2022' 228 | url: https://CRAN.R-project.org/package=tinytest 229 | - type: software 230 | title: rmarkdown 231 | abstract: 'rmarkdown: Dynamic Documents for R' 232 | notes: Suggests 233 | authors: 234 | - family-names: Allaire 235 | given-names: JJ 236 | email: jj@rstudio.com 237 | - family-names: Xie 238 | given-names: Yihui 239 | email: xie@yihui.name 240 | orcid: https://orcid.org/0000-0003-0645-5666 241 | - family-names: McPherson 242 | given-names: Jonathan 243 | email: jonathan@rstudio.com 244 | - family-names: Luraschi 245 | given-names: Javier 246 | email: javier@rstudio.com 247 | - family-names: Ushey 248 | given-names: Kevin 249 | email: kevin@rstudio.com 250 | - family-names: Atkins 251 | given-names: Aron 252 | email: aron@rstudio.com 253 | - family-names: Wickham 254 | given-names: Hadley 255 | email: hadley@rstudio.com 256 | - family-names: Cheng 257 | given-names: Joe 258 | email: joe@rstudio.com 259 | - family-names: Chang 260 | given-names: Winston 261 | email: winston@rstudio.com 262 | - family-names: Iannone 263 | given-names: Richard 264 | email: rich@rstudio.com 265 | orcid: https://orcid.org/0000-0003-3925-190X 266 | year: '2022' 267 | url: https://CRAN.R-project.org/package=rmarkdown 268 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: potential 2 | Title: Implementation of the Potential Model 3 | Version: 0.3.0.0 4 | Authors@R: c( 5 | person("Timothée", "Giraud", email = "timothee.giraud@cnrs.fr", role = c("cre","aut"), 6 | comment = c(ORCID = "0000-0002-1932-3323")), 7 | person("Hadrien", "Commenges", email = "hadrien.commenges@univ-paris1.fr", role = c("aut"))) 8 | Description: Provides functions to compute the potential model as defined by 9 | Stewart (1941) . Several options are available 10 | to customize the model, such as the possibility to fine-tune the distance 11 | friction functions or to use custom distance matrices. Some computations are 12 | parallelized to improve their efficiency. 13 | Depends: R (>= 3.5.0) 14 | License: GPL-3 15 | LazyData: true 16 | Imports: 17 | sf, 18 | graphics, 19 | mapiso, 20 | parallel, 21 | doParallel, 22 | foreach 23 | Suggests: 24 | covr, 25 | lwgeom, 26 | eurostat, 27 | giscoR, 28 | mapsf, 29 | knitr, 30 | tinytest, 31 | rmarkdown 32 | URL: https://github.com/riatelab/potential 33 | BugReports: https://github.com/riatelab/potential/issues 34 | Encoding: UTF-8 35 | VignetteBuilder: knitr 36 | RoxygenNote: 7.2.3 37 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(create_grid) 4 | export(create_matrix) 5 | export(equipotential) 6 | export(mcpotential) 7 | export(plot_inter) 8 | export(potential) 9 | import(graphics) 10 | importFrom(mapiso,mapiso) 11 | importFrom(sf,"st_agr<-") 12 | importFrom(sf,"st_geometry<-") 13 | importFrom(sf,st_as_sf) 14 | importFrom(sf,st_bbox) 15 | importFrom(sf,st_buffer) 16 | importFrom(sf,st_cast) 17 | importFrom(sf,st_centroid) 18 | importFrom(sf,st_collection_extract) 19 | importFrom(sf,st_coordinates) 20 | importFrom(sf,st_crs) 21 | importFrom(sf,st_distance) 22 | importFrom(sf,st_drop_geometry) 23 | importFrom(sf,st_geometry) 24 | importFrom(sf,st_intersection) 25 | importFrom(sf,st_intersects) 26 | importFrom(sf,st_is) 27 | importFrom(sf,st_is_longlat) 28 | importFrom(sf,st_make_valid) 29 | importFrom(sf,st_sf) 30 | importFrom(sf,st_sfc) 31 | importFrom(sf,st_transform) 32 | importFrom(sf,st_union) 33 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # potential 0.2.0 2 | 3 | ## Minor changes 4 | - Change longlat arg default to FALSE in create_matrix() 5 | - Use mapsf instead of cartography in all examples 6 | - Use mapiso instead of isoband 7 | - In epquipotential "xcoords" and "ycoords" are not needed anymore -------------------------------------------------------------------------------- /R/create_grid.R: -------------------------------------------------------------------------------- 1 | #' @title Create a Regularly Spaced Points Grid 2 | #' @name create_grid 3 | #' @description This function creates a regular grid of points 4 | #' from the extent of a given spatial object and a given resolution. 5 | #' @param x an sf or sfc object, the spatial extent of this object is used to 6 | #' create the regular grid. 7 | #' @param res resolution of the grid (in map units). 8 | #' @return The output of the function is an sf object of regularly spaced 9 | #' points with the extent of x. 10 | #' @examples 11 | #' library(sf) 12 | #' g <- create_grid(x = n3_poly, res = 200000) 13 | #' plot(st_geometry(g)) 14 | #' plot(st_geometry(n3_poly), border = "red", add = TRUE) 15 | #' @importFrom sf st_as_sf st_crs st_bbox 16 | #' @export 17 | create_grid <- function(x, res) { 18 | 19 | if (!inherits(x = x, what = c("sfc", "sf"))) { 20 | stop("x is not an sf or an sfc object.", 21 | call. = FALSE) 22 | } 23 | 24 | 25 | bb <- st_bbox(x) 26 | rounder <- bb %% res 27 | bb[1:2] <- bb[1:2] - rounder[1:2] 28 | bb[3:4] <- bb[3:4] + res - rounder[3:4] 29 | cx <- seq(from = bb[1], to = bb[3], by = res) 30 | cy <- seq(from = bb[2], to = bb[4], by = res) 31 | 32 | g <- expand.grid(cx, cy) 33 | g <- data.frame( 34 | ID = 1:nrow(g), 35 | COORDX = g[, 1], 36 | COORDY = g[, 2] 37 | ) 38 | g <- st_as_sf(g, 39 | coords = c("COORDX", "COORDY"), 40 | crs = st_crs(x), remove = FALSE 41 | ) 42 | 43 | return(g) 44 | } 45 | -------------------------------------------------------------------------------- /R/create_matrix.R: -------------------------------------------------------------------------------- 1 | #' @title Create a Distance Matrix Between Two Spatial Objects 2 | #' @name create_matrix 3 | #' @description This function creates a distance matrix between two 4 | #' spatial objects. 5 | #' @param x an sf object (POINT), rows of the distance matrix, row names are 6 | #' used as row names of the matrix. 7 | #' @param y an sf object (POINT), columns of the distance matrix, row names 8 | #' are used as column names of the matrix. 9 | #' @param checksize if FALSE, bypass the distance matrix size control 10 | #' (see Details). 11 | #' @param longlat if FALSE, the Euclidean distance is used, if TRUE Great Circle 12 | #' (WGS84 ellipsoid) distance is used. 13 | #' @details The function returns a full matrix of distances in meters. 14 | #' If the matrix to compute is too large (more than 100,000,000 cells, more than 15 | #' 10,000,000 origins or more than 10,000,000 destinations) 16 | #' the function may sends a message to warn users about the amount of 17 | #' RAM mobilized. 18 | #' @return A distance matrix, row names are \code{x} row names, column 19 | #' names are \code{y} row names. 20 | #' @examples 21 | #' g <- create_grid(x = n3_poly, res = 200000) 22 | #' mat <- create_matrix(x = n3_pt, y = g) 23 | #' mat[1:5, 1:5] 24 | #' @importFrom sf st_centroid st_geometry st_geometry<- st_as_sf st_is_longlat 25 | #' st_distance st_transform st_is 26 | #' @export 27 | create_matrix <- function(x, y, checksize = TRUE, longlat = FALSE) { 28 | 29 | test_point(x, "x") 30 | test_point(y, "y") 31 | 32 | 33 | if (checksize) { 34 | nk <- nrow(x) 35 | nu <- nrow(y) 36 | if (nk * nu > 100000000 | nu > 10000000 | nk > 10000000) { 37 | stop(paste0( 38 | "Computation aborted. The distance matrix would probably ", 39 | "be too large. Use checksize = FALSE to bypass this control." 40 | ), 41 | call. = FALSE 42 | ) 43 | } 44 | } 45 | 46 | if (!st_is_longlat(x)) { 47 | if (longlat) { 48 | x <- st_transform(x, 4326) 49 | y <- st_transform(y, 4326) 50 | } 51 | } 52 | d <- st_distance(x, y) 53 | mat <- as.vector(d) 54 | dim(mat) <- dim(d) 55 | dimnames(mat) <- list(row.names(x), row.names(y)) 56 | return(mat) 57 | } 58 | -------------------------------------------------------------------------------- /R/curv.R: -------------------------------------------------------------------------------- 1 | #' @title Display a Spatial Interaction Function 2 | #' @description Display a spatial interaction function. 3 | #' @param fun spatial interaction function. Options are "p" 4 | #' (pareto, power law) or "e" (exponential). 5 | #' For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 6 | #' For "exponential" the interaction is defined as: 7 | #' exp(- alpha * mDistance ^ beta). 8 | #' The alpha parameter is computed from parameters given by the user 9 | #' (\code{beta} and \code{span}). 10 | #' @param span distance where the density of probability of the spatial 11 | #' interaction function equals 0.5. 12 | #' @param beta impedance factor for the spatial interaction function. 13 | #' @param limit maximum distance used to retrieved \code{x} points, in 14 | #' map units. 15 | #' @return a plot 16 | #' @import graphics 17 | #' @export 18 | #' 19 | #' @examples 20 | #' plot_inter(fun = "e", span = 2000, beta = 2, limit = 4000) 21 | #' plot_inter(fun = "p", span = 2000, beta = 2, limit = 20000) 22 | plot_inter <- function(fun = "e", span, beta, limit = span * 5) { 23 | if (fun == "e") { 24 | alpha <- log(2) / span^beta 25 | fric <- function(alpha, matdist, beta) { 26 | exp(-alpha * matdist^beta) 27 | } 28 | fna <- "Exponential" 29 | } 30 | if (fun == "p") { 31 | alpha <- (2^(1 / beta) - 1) / span 32 | fric <- function(alpha, matdist, beta) { 33 | (1 + alpha * matdist)^(-beta) 34 | } 35 | fna <- "Pareto" 36 | } 37 | 38 | d <- seq(0, limit, length.out = 100) 39 | inter <- fric(alpha, d, beta) 40 | dp <- seq(limit, limit + (limit / 4), length.out = 25) 41 | interp <- fric(alpha, dp, beta) 42 | 43 | plot.new() 44 | plot.window(xlim = c(0, limit + limit / 4), ylim = c(0, 1)) 45 | grid(ny = 4) 46 | 47 | points(d, inter, type = "l", lwd = 1.5) 48 | points(dp, interp, type = "l", col = "grey", lwd = 1.5) 49 | 50 | points(x = span, y = 0.5, pch = 21, bg = "red") 51 | text(x = span, y = 0.5, labels = "span", col = "grey40", pos = 4) 52 | 53 | points(x = limit, y = fric(alpha, limit, beta), pch = 21, bg = "red") 54 | text( 55 | x = limit, y = fric(alpha, limit, beta), labels = "limit", 56 | col = "grey40", pos = 3 57 | ) 58 | 59 | segments( 60 | x0 = 0, y0 = fric(alpha, limit, beta), 61 | x1 = limit, y1 = fric(alpha, limit, beta), 62 | lwd = .5, lty = 2, col = "grey40" 63 | ) 64 | text( 65 | x = 0, y = fric(alpha, limit, beta), 66 | labels = signif(fric(alpha, limit, beta), digits = 2), 67 | cex = .8, adj = c(0, 0), col = "grey40" 68 | ) 69 | 70 | 71 | axis(1, lwd = 0, font.axis = 2) 72 | axis(2, lwd = 0, font.axis = 2, at = seq(0, 1, length.out = 5)) 73 | 74 | title(xlab = "Distance", col.lab = "red3") 75 | title(ylab = "Interaction intensity", col.lab = "red3") 76 | title( 77 | main = "Density of Probability of the Spatial Interaction", 78 | col.main = "red3", adj = 0 79 | ) 80 | mtext( 81 | side = 1, line = 4, adj = 0, 82 | text = paste0( 83 | fna, " function: span = ", 84 | span, ", beta = ", beta, 85 | ", limit = ", limit 86 | ) 87 | ) 88 | } 89 | -------------------------------------------------------------------------------- /R/equipotential.R: -------------------------------------------------------------------------------- 1 | #' @title Create Polygons of Equipotential 2 | #' @name equipotential 3 | #' @description 4 | #' This function creates polygons of equipotential from a regular grid of 5 | #' potential points. 6 | #' @param x an sf object of regularly spaced points. 7 | #' @param nclass a number of class. 8 | #' @param breaks a vector of break values. 9 | #' @param mask an sf object of polygons or multipolygons. \code{mask} is used 10 | #' to clip polygons of contours equipotential. 11 | #' @param xcoords not used. 12 | #' @param ycoords not used. 13 | #' @param var name of the variable to use in \code{x}. 14 | #' @param buffer if set, a buffer is added to the mask in order to 15 | #' reach more precisely the number of breaks. The buffer is defined in 16 | #' \code{x} units. 17 | #' @return The output is an sf object (POLYGONS). The data frame contains four 18 | #' fields: id (id of each polygon), min and max (minimum and maximum breaks of 19 | #' the polygon) and center (central values of classes). 20 | #' @importFrom sf st_as_sf st_crs st_bbox st_cast st_sf st_sfc st_intersection 21 | #' st_union st_agr<- st_collection_extract st_make_valid st_buffer st_coordinates 22 | #' @importFrom mapiso mapiso 23 | #' @examples 24 | #' library(sf) 25 | #' y <- create_grid(x = n3_poly, res = 200000) 26 | #' d <- create_matrix(n3_pt, y) 27 | #' pot <- potential( 28 | #' x = n3_pt, y = y, d = d, var = "POP19", 29 | #' fun = "e", span = 200000, beta = 2 30 | #' ) 31 | #' y$OUTPUT <- pot 32 | #' equipot <- equipotential(y, var = "OUTPUT", mask = n3_poly) 33 | #' plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis")) 34 | #' @export 35 | equipotential <- function(x, 36 | var, 37 | nclass = 8, 38 | breaks, 39 | mask, 40 | buffer, 41 | xcoords, 42 | ycoords) { 43 | 44 | if (!inherits(x = x, what = "sf")) { 45 | stop("x is not an sf object.", 46 | call. = FALSE) 47 | } 48 | 49 | if (!missing(buffer)){ 50 | mask_b <- sf::st_buffer(mask, buffer) 51 | inter <- st_intersects(x = x, y = mask_b) 52 | inout <- sapply(inter, function(x)if(length(x)>0){1}else{NA}) 53 | x[[var]] <- inout * x[[var]] 54 | } 55 | 56 | iso <- mapiso(x = x, var = var, 57 | breaks = breaks, 58 | nbreaks = nclass, 59 | mask = mask) 60 | names(iso)[1:3] <- c("id", "min", "max") 61 | iso$center <- iso$min + (iso$max - iso$min) / 2 62 | 63 | return(iso) 64 | } 65 | -------------------------------------------------------------------------------- /R/mcpotential.R: -------------------------------------------------------------------------------- 1 | #' @title Compute the Potential Model using Parallelization 2 | #' @description This function computes the potential model with a cutoff 3 | #' distance and parallel 4 | #' computation. 5 | #' @param x an sf object (POINT), the set of known observations to estimate 6 | #' the potentials from. 7 | #' @param y an sf object (POINT), the set of unknown units for which the 8 | #' function computes the estimates. 9 | #' @param var names of the variables in \code{x} from which potentials are 10 | #' computed. Quantitative variables with no negative values. 11 | #' @param fun spatial interaction function. Options are "p" 12 | #' (pareto, power law) or "e" (exponential). 13 | #' For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 14 | #' For "exponential" the interaction is defined as: 15 | #' exp(- alpha * mDistance ^ beta). 16 | #' The alpha parameter is computed from parameters given by the user 17 | #' (\code{beta} and \code{span}). 18 | #' @param span distance where the density of probability of the spatial 19 | #' interaction function equals 0.5. 20 | #' @param beta impedance factor for the spatial interaction function. 21 | #' @param limit maximum distance used to retrieve \code{x} points, in map units. 22 | #' @param ncl number of clusters. \code{ncl} is set to 23 | #' \code{parallel::detectCores() - 1} by default. 24 | #' @param size \code{mcpotential} splits \code{y} in smaller chunks and 25 | #' dispatches the computation in \code{ncl} cores, \code{size} indicates the 26 | #' size of each chunks. 27 | #' @return If only one variable is computed a vector is returned, if more than 28 | #' one variable is computed a matrix is returned. 29 | #' @export 30 | #' @importFrom sf st_buffer st_centroid st_geometry st_intersects 31 | #' @examples 32 | #' \donttest{ 33 | #' library(sf) 34 | #' g <- create_grid(x = n3_poly, res = 20000) 35 | #' pot <- mcpotential( 36 | #' x = n3_pt, y = g, var = "POP19", 37 | #' fun = "e", span = 75000, beta = 2, 38 | #' limit = 300000, 39 | #' ncl = 2 40 | #' ) 41 | #' g$OUTPUT <- pot 42 | #' equipot <- equipotential(g, var = "OUTPUT", mask = n3_poly) 43 | #' plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis")) 44 | #' } 45 | mcpotential <- function(x, y, var, fun, 46 | span, beta, 47 | limit = 3 * span, 48 | ncl, size = 500) { 49 | 50 | test_point(x, "x") 51 | test_point(y, "y") 52 | 53 | # launch multiple cores 54 | if (missing(ncl)) { 55 | ncl <- parallel::detectCores(all.tests = FALSE, logical = FALSE) - 1 56 | if (is.na(ncl)) { 57 | ncl <- 1 58 | } 59 | if (ncl == 0) { 60 | ncl <- 1 61 | } 62 | } 63 | ## 64 | cl <- parallel::makeCluster(ncl, setup_strategy = "sequential") 65 | doParallel::registerDoParallel(cl) 66 | 67 | # data simplification 68 | xsfc <- st_geometry(x) 69 | kgeom <- matrix(unlist(xsfc), ncol = 2, byrow = TRUE) 70 | 71 | v <- as.matrix(x = x[, var, drop = TRUE]) 72 | 73 | ysfc <- st_geometry(y) 74 | 75 | # sequence to split unknowpts 76 | ny <- nrow(y) 77 | sequence <- unique(c(seq(1, ny, size), ny + 1)) 78 | lseq <- length(sequence) - 1 79 | 80 | # split unknownpts and put it on a list 81 | ml <- list() 82 | for (i in 1:lseq) { 83 | ml[[i]] <- ysfc[(sequence[i]):(sequence[i + 1] - 1)] 84 | } 85 | 86 | # dispatch 87 | pot <- foreach::`%dopar%`( 88 | foreach::foreach( 89 | ysfc = ml, 90 | .packages = "sf", 91 | .combine = c, 92 | .inorder = FALSE 93 | ), 94 | { 95 | # FUNS 96 | eucledian_simple <- function(from, to) { 97 | sqrt((from[1] - to[1])^2 + (from[2] - to[2])^2) 98 | } 99 | if (fun == "e") { 100 | alpha <- log(2) / span^beta 101 | fric <- function(alpha, matdist, beta) { 102 | exp(-alpha * matdist^beta) 103 | } 104 | } 105 | if (fun == "p") { 106 | alpha <- (2^(1 / beta) - 1) / span 107 | fric <- function(alpha, matdist, beta) { 108 | (1 + alpha * matdist)^(-beta) 109 | } 110 | } 111 | 112 | # Buffer limit 113 | gbuf <- st_buffer(ysfc, limit) 114 | inter <- st_intersects(gbuf, xsfc, prepared = TRUE) 115 | 116 | # data transformation 117 | ugeom <- matrix(unlist(ysfc), ncol = 2, byrow = TRUE) 118 | 119 | # go through each y 120 | l <- vector("list", nrow(ugeom)) 121 | for (i in seq_along(l)) { 122 | kindex <- unlist(inter[i]) 123 | kn <- kgeom[kindex, , drop = FALSE] 124 | un <- ugeom[i, ] 125 | matdist <- apply(kn, 1, eucledian_simple, un) 126 | un <- apply( 127 | X = v[kindex, , drop = FALSE], 128 | MARGIN = 2, 129 | FUN = function(x) { 130 | sum(x * fric(alpha, matdist, beta), na.rm = TRUE) 131 | } 132 | ) 133 | l[[i]] <- un 134 | } 135 | unlist(l) 136 | } 137 | ) 138 | # stop parralel 139 | parallel::stopCluster(cl) 140 | if (length(var) == 1) { 141 | pot <- as.numeric(pot) 142 | } else { 143 | pot <- matrix(pot, 144 | ncol = length(var), byrow = TRUE, 145 | dimnames = list(NULL, var) 146 | ) 147 | } 148 | 149 | return(pot) 150 | } 151 | -------------------------------------------------------------------------------- /R/package.R: -------------------------------------------------------------------------------- 1 | #' @title Implementation of the Potential Model 2 | #' @name potential-package 3 | #' @rdname potential-package 4 | #' @description This package provides functions to compute the potential model as 5 | #' defined by Stewart (1941) . Several options 6 | #' are available to customize the model, such as the possibility to fine-tune 7 | #' the distance friction functions or to use custom distance matrices. Some 8 | #' computations are parallelized to improve their efficiency. 9 | #' @docType package 10 | NULL 11 | 12 | 13 | 14 | #' @title Points and Polygons Layers of European Statistical Units (NUTS3) 15 | #' @description 16 | #' 17 | #' n3_pt (POINTS) and n3_poly (MULTIPOLYGONS) are sf objects of 18 | #' 1506 NUTS3 statistical units of continental Europe. 19 | #' 20 | #' Population dataset (2019 an 2018 total population) downloaded on the Eurostat 21 | #' website (05/10/2020) from the "demo_r_pjanaggr3" dataset 22 | #' (last update: 16/06/2020). 23 | #' 24 | #' Geometries are downloaded from the GISCO website 25 | #' (NUTS3 - 2016 - 1:60 Million) 26 | #' 27 | #' When data from this package is used in any printed or electronic 28 | #' publication, in addition to any other provisions applicable to the whole 29 | #' Eurostat website, data source will have to be acknowledged in the legend of 30 | #' the map and in the introductory page of the publication with the following 31 | #' copyright notice: 32 | #' "© EuroGeographics for the administrative boundaries and © Eurostat 33 | #' for data". 34 | #' 35 | #' @name n3_pt 36 | #' 37 | #' @usage data(nuts3) 38 | #' @docType data 39 | "n3_pt" 40 | 41 | 42 | #' @title Points and Polygons Layers of European Statistical Units (NUTS3) 43 | #' @description 44 | #' 45 | #' n3_pt (POINTS) and n3_poly (MULTIPOLYGONS) are sf objects of 46 | #' 1506 NUTS3 statistical units of continental Europe. 47 | #' 48 | #' Population dataset (2019 an 2018 total population) downloaded on the Eurostat 49 | #' website (05/10/2020) from the "demo_r_pjanaggr3" dataset 50 | #' (last update: 16/06/2020). 51 | #' 52 | #' Geometries are downloaded from the GISCO website 53 | #' (NUTS3 - 2016 - 1:60 Million) 54 | #' 55 | #' When data from this packgage is used in any printed or electronic 56 | #' publication, in addition to any other provisions applicable to the whole 57 | #' Eurostat website, data source will have to be acknowledged in the legend of 58 | #' the map and in the introductory page of the publication with the following 59 | #' copyright notice: 60 | #' "© EuroGeographics for the administrative boundaries and © Eurostat 61 | #' for data". 62 | #' 63 | #' @name n3_poly 64 | #' 65 | #' @usage data(nuts3) 66 | #' @docType data 67 | "n3_poly" 68 | -------------------------------------------------------------------------------- /R/potential.R: -------------------------------------------------------------------------------- 1 | #' @title Compute the Potential Model 2 | #' @name potential 3 | #' @description This function computes the potential model as defined 4 | #' by J.Q. Stewart (1941). 5 | #' @param x an sf object (POINT), the set of known observations to 6 | #' estimate the potentials from. 7 | #' @param y an sf object (POINT), the set of unknown units for which 8 | #' the function computes the estimates. 9 | #' @param d a distance matrix between known observations and unknown 10 | #' units for which the function computes the estimates. Row names match the row 11 | #' names of \code{x} and column names match the row names of 12 | #' \code{y}. \code{d} can contain any distance metric (time 13 | #' distance or euclidean distance for example). 14 | #' @param var names of the variables in \code{x} from which potentials are 15 | #' computed. Quantitative variables with no negative values. 16 | #' @param fun spatial interaction function. Options are "p" 17 | #' (pareto, power law) or "e" (exponential). 18 | #' For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 19 | #' For "exponential" the interaction is defined as: 20 | #' exp(- alpha * mDistance ^ beta). 21 | #' The alpha parameter is computed from parameters given by the user 22 | #' (\code{beta} and \code{span}). 23 | #' @param span distance where the density of probability of the spatial 24 | #' interaction function equals 0.5. 25 | #' @param beta impedance factor for the spatial interaction function. 26 | #' @return If only one variable is computed a vector is returned, if more than 27 | #' one variable is computed a matrix is returned. 28 | #' @examples 29 | #' library(sf) 30 | #' y <- create_grid(x = n3_poly, res = 200000) 31 | #' d <- create_matrix(n3_pt, y) 32 | #' pot <- potential( 33 | #' x = n3_pt, y = y, d = d, var = "POP19", 34 | #' fun = "e", span = 200000, beta = 2 35 | #' ) 36 | #' y$OUTPUT <- pot 37 | #' equipot <- equipotential(y, var = "OUTPUT", mask = n3_poly) 38 | #' plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis")) 39 | #' @references 40 | #' STEWART, JOHN Q. 1941. "An Inverse Distance Variation for Certain Social 41 | #' Influences." \emph{Science} 93 (2404): 89–90. 42 | #' \doi{10.1126/science.93.2404.89}. 43 | #' @importFrom sf st_as_sf 44 | #' @export 45 | potential <- function(x, y, d, var, fun, span, beta) { 46 | test_point(x, "x") 47 | test_point(y, "y") 48 | result <- prepare_data(x = x, y = y, d = d) 49 | matdens <- interact_density( 50 | d = result$d, 51 | fun = fun, beta = beta, span = span 52 | ) 53 | 54 | pot <- apply( 55 | X = result$x[, var, drop = FALSE], MARGIN = 2, 56 | FUN = compute_potentials, matdens 57 | ) 58 | 59 | if (length(var) == 1) { 60 | pot <- as.numeric(pot) 61 | } 62 | 63 | return(pot) 64 | } 65 | 66 | 67 | # Internal functions 68 | #' @importFrom sf st_drop_geometry 69 | prepare_data <- function(x, y, d) { 70 | d <- use_matrix(d = d, x = x, y = y) 71 | x <- st_drop_geometry(x) 72 | y <- st_drop_geometry(y) 73 | return(list(x = x, y = y, d = d)) 74 | } 75 | 76 | 77 | use_matrix <- function(d, x, y) { 78 | i <- factor(row.names(x), levels = row.names(x)) 79 | j <- factor(row.names(y), levels = row.names(y)) 80 | d <- d[levels(i), levels(j)] 81 | return(round(d, digits = 8)) 82 | } 83 | 84 | 85 | interact_density <- function(d, fun, beta, span) { 86 | if (fun == "p") { 87 | alpha <- (2^(1 / beta) - 1) / span 88 | matDens <- (1 + alpha * d)^(-beta) 89 | } else if (fun == "e") { 90 | alpha <- log(2) / span^beta 91 | matDens <- exp(-alpha * d^beta) 92 | } 93 | return(matDens) 94 | } 95 | 96 | compute_potentials <- function(x, matdens, var) { 97 | pot <- apply(x * matdens, 2, sum, na.rm = TRUE) 98 | } 99 | -------------------------------------------------------------------------------- /R/testarrow.R: -------------------------------------------------------------------------------- 1 | #' library(sf) 2 | #' library(potential) 3 | #' library(cartography) 4 | #' x <- n3_pt[substr(n3_pt$ID,1,3) %in% c( "FRJ"), ] 5 | #' x_poly <- n3_poly[substr(n3_poly$ID,1,3) %in% c( "FRJ"),] 6 | #' x$POP19 <- round(x$POP19 / 1000, 0) 7 | #' x <- n3_pt 8 | #' 9 | #' y <- create_grid(x = x, res = 5000) 10 | #' d <- create_matrix(x, y) 11 | #' r <- prepare_data2(x = x, y = y, d = d) 12 | #' matdens <- interact_density( 13 | #' d = r$d, 14 | #' fun = "e", beta = 2, span = 25000 15 | #' ) 16 | #' m2 <- matdens * r$x$POP19 17 | #' 18 | #' m <- matrix(data = NA, nrow = nrow(r$x), ncol = nrow(r$y)) 19 | #' for(i in 1:nrow(r$x)){ 20 | #' for (j in 1:nrow(r$y)){ 21 | #' m[i, j] <- get_angle(r$x[i,"xy"], r$y[j,"xy"]) 22 | #' } 23 | #' } 24 | #' 25 | #' get_angle <- function(x, y){ 26 | #' atan2(y = (y[2] - x[2]), x = (y[1] - x[1])) 27 | #' } 28 | #' 29 | #' 30 | #' ewv <- m2 * sin(m) 31 | #' nsv <- m2 * cos(m) 32 | #' 33 | #' ewvws <- colMeans(ewv) 34 | #' nsvws <- colMeans(nsv) 35 | #' 36 | #' intens <- sqrt(ewvws^2 + nsvws^2) 37 | #' 38 | #' int <- 2 * intens / max(intens) 39 | #' 40 | #' wwdr <- atan2(ewvws,nsvws) 41 | #' 42 | #' # wwdr[nsvws<0] <- wwdr[nsvws<0] + pi 43 | #' 44 | #' wwdd <- wwdr * 180 / pi 45 | #' 46 | #' y$an <- wwdd 47 | #' 48 | #' y$pot <- potential(x, y, d, "POP19", "e", 25000, 2 ) 49 | #' z <- equipotential(y, var = "pot", nclass = 20, mask =n3_poly) 50 | #' par(mar = c(0,0,0,0), family = "JetBrains Mono") 51 | #' mapsf::mp_map_t(z, "center", pal = "Reds", border = NA, leg_pos = NA) 52 | #' mapsf::mp_map_p(x, "POP19", col = NA, border = "white", leg_pos = NA) 53 | #' for(i in 1:nrow(y)){ 54 | #' text(x = y$COORDX[i], y = y$COORDY[i], 55 | #' labels = "<-", srt = y$an[i], cex = int[i]) 56 | #' } 57 | #' 58 | #' 59 | #' 60 | #' 61 | #' 62 | #' 63 | #' 64 | #' # Internal functions 65 | #' #' @importFrom sf st_drop_geometry 66 | #' prepare_data2 <- function(x, y, d) { 67 | #' d <- use_matrix(d = d, x = x, y = y) 68 | #' x$xy <- st_coordinates(x) 69 | #' y$xy <- st_coordinates(y) 70 | #' 71 | #' x <- st_drop_geometry(x) 72 | #' y <- st_drop_geometry(y) 73 | #' 74 | #' 75 | #' 76 | #' return(list(x = x, y = y, d = d)) 77 | #' } 78 | #' 79 | #' 80 | #' use_matrix <- function(d, x, y) { 81 | #' i <- factor(row.names(x), levels = row.names(x)) 82 | #' j <- factor(row.names(y), levels = row.names(y)) 83 | #' d <- d[levels(i), levels(j)] 84 | #' return(round(d, digits = 8)) 85 | #' } 86 | #' 87 | #' 88 | #' interact_density <- function(d, fun, beta, span) { 89 | #' if (fun == "p") { 90 | #' alpha <- (2^(1 / beta) - 1) / span 91 | #' matDens <- (1 + alpha * d)^(-beta) 92 | #' } else if (fun == "e") { 93 | #' alpha <- log(2) / span^beta 94 | #' matDens <- exp(-alpha * d^beta) 95 | #' } 96 | #' return(matDens) 97 | #' } 98 | #' 99 | #' compute_potentials <- function(x, matdens, var) { 100 | #' pot <- apply(x * matdens, 2, sum, na.rm = TRUE) 101 | #' } 102 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | test_point <- function(x, id){ 2 | 3 | if (!inherits(x = x, what = "sf")) { 4 | stop(paste0(id, " is not an sf object."), 5 | call. = FALSE) 6 | } 7 | 8 | type <- sf::st_geometry_type(x, by_geometry = FALSE) 9 | if (type != "POINT") { 10 | stop(paste0('"', id, '" geometry should be of type POINT.'), 11 | call. = FALSE) 12 | } 13 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # potential 3 | 4 | [![](https://www.r-pkg.org/badges/version/potential)](https://cran.r-project.org/package=potential) 5 | [![R-CMD-check](https://github.com/riatelab/potential/workflows/R-CMD-check/badge.svg)](https://github.com/riatelab/potential/actions) 6 | [![codecov](https://codecov.io/gh/riatelab/potential/branch/master/graph/badge.svg?token=G8MZTHC9KQ)](https://app.codecov.io/gh/riatelab/potential) 7 | [![Project Status: Active – The project has reached a stable, usable 8 | state and is being actively 9 | developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 10 | 11 | This package provides functions to compute the potential model as 12 | defined by Stewart (1941). Several options are available to customize 13 | the model, for example it is possible to fine-tune the distance friction 14 | functions or to use custom distance matrices. Some computations are 15 | parallelized to improve their efficiency. 16 | 17 | - [**Website**](https://riatelab.github.io/potential/) 18 | - [**Vignette**](https://riatelab.github.io/potential/articles/potential.html) 19 | - [**Blog post**](https://rgeomatic.hypotheses.org/2023) 20 | 21 | ## Installation 22 | 23 | You can install the released version of `potential` from 24 | [CRAN](https://CRAN.R-project.org/package=potential) with: 25 | 26 | ``` r 27 | install.packages("potential") 28 | ``` 29 | 30 | You can install the development version of `potential` from GitHub with: 31 | 32 | ``` r 33 | # install.packages("remotes") 34 | remotes::install_github("riatelab/potential") 35 | ``` 36 | 37 | ## Demo 38 | 39 | ``` r 40 | library(mapsf) 41 | library(potential) 42 | # Display the spatial interaction function 43 | plot_inter(fun = "e", span = 75000, beta = 2, limit = 250000) 44 | ``` 45 | 46 | ![](man/figures/demox-1.png) 47 | 48 | ``` r 49 | # create a regular grid 50 | y <- create_grid(x = n3_poly, res = 20000) 51 | # compute potentials 52 | pot <- mcpotential( 53 | x = n3_pt, y = y, 54 | var = "POP19", 55 | fun = "e", span = 75000, 56 | beta = 2, limit = 250000, 57 | ncl = 2 58 | ) 59 | # Define potential according to the maximum value 60 | y$pot <- pot / max(pot) * 100 61 | # create equipotential areas 62 | bks <- seq(0, 100, length.out = 11) 63 | equipot <- equipotential(y, var = "pot", breaks = bks, mask = n3_poly) 64 | # map potentials 65 | mf_theme("default") 66 | mf_map(x = equipot, var = "min", type = "choro", 67 | breaks = bks, 68 | pal = hcl.colors(10, 'Teal'), 69 | border = "#121725", 70 | leg_val_rnd = 0, 71 | lwd = .2, 72 | leg_pos = "topright", 73 | leg_title = "Potential Intensity") 74 | mf_title(txt = "Potentials of Population") 75 | mf_credits(txt = "© EuroGeographics for the administrative boundaries and © Eurostat for data") 76 | ``` 77 | 78 | ![](man/figures/demo-1.png) 79 | 80 | ## Note 81 | 82 | This package provides access to the revamped potential-related functions 83 | initially offered by 84 | [`SpatialPosition`](https://CRAN.R-project.org/package=SpatialPosition). 85 | 86 | ## References 87 | 88 |
89 | 90 |
91 | 92 | Stewart, John Q. 1941. “An Inverse Distance Variation for Certain Social 93 | Influences.” *Science* 93 (2404): 89–90. 94 | . 95 | 96 |
97 | 98 |
99 | -------------------------------------------------------------------------------- /README.rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | bibliography: "vignettes/references.bib" 4 | --- 5 | 6 | 7 | ```{r setup, include=FALSE} 8 | knitr::opts_chunk$set(echo = TRUE, fig.path = "man/figures/") 9 | ``` 10 | 11 | 12 | 13 | # potential 14 | 15 | [![](https://www.r-pkg.org/badges/version/potential)](https://cran.r-project.org/package=potential) 16 | [![R-CMD-check](https://github.com/riatelab/potential/workflows/R-CMD-check/badge.svg)](https://github.com/riatelab/potential/actions) 17 | [![codecov](https://codecov.io/gh/riatelab/potential/branch/master/graph/badge.svg?token=G8MZTHC9KQ)](https://app.codecov.io/gh/riatelab/potential) 18 | [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) 19 | 20 | This package provides functions to compute the potential model as 21 | defined by @STEWART41. Several options 22 | are available to customize the model, for example it is possible to fine-tune 23 | the distance friction functions or to use custom distance matrices. Some 24 | computations are parallelized to improve their efficiency. 25 | 26 | * [**Website**](https://riatelab.github.io/potential/) 27 | * [**Vignette**](https://riatelab.github.io/potential/articles/potential.html) 28 | * [**Blog post**](https://rgeomatic.hypotheses.org/2023) 29 | 30 | ## Installation 31 | 32 | You can install the released version of `potential` from 33 | [CRAN](https://CRAN.R-project.org/package=potential) with: 34 | 35 | ``` r 36 | install.packages("potential") 37 | ``` 38 | 39 | You can install the development version of `potential` from GitHub with: 40 | 41 | ``` r 42 | # install.packages("remotes") 43 | remotes::install_github("riatelab/potential") 44 | ``` 45 | 46 | ## Demo 47 | 48 | 49 | ```{r demox, fig.show='hold', message=FALSE} 50 | library(mapsf) 51 | library(potential) 52 | # Display the spatial interaction function 53 | plot_inter(fun = "e", span = 75000, beta = 2, limit = 250000) 54 | ``` 55 | 56 | 57 | ```{r demo, fig.width = 7, fig.height= 6, fig.show='hold'} 58 | # create a regular grid 59 | y <- create_grid(x = n3_poly, res = 20000) 60 | # compute potentials 61 | pot <- mcpotential( 62 | x = n3_pt, y = y, 63 | var = "POP19", 64 | fun = "e", span = 75000, 65 | beta = 2, limit = 250000, 66 | ncl = 2 67 | ) 68 | # Define potential according to the maximum value 69 | y$pot <- pot / max(pot) * 100 70 | # create equipotential areas 71 | bks <- seq(0, 100, length.out = 11) 72 | equipot <- equipotential(y, var = "pot", breaks = bks, mask = n3_poly) 73 | # map potentials 74 | mf_theme("default") 75 | mf_map(x = equipot, var = "min", type = "choro", 76 | breaks = bks, 77 | pal = hcl.colors(10, 'Teal'), 78 | border = "#121725", 79 | leg_val_rnd = 0, 80 | lwd = .2, 81 | leg_pos = "topright", 82 | leg_title = "Potential Intensity") 83 | mf_title(txt = "Potentials of Population") 84 | mf_credits(txt = "© EuroGeographics for the administrative boundaries and © Eurostat for data") 85 | ``` 86 | 87 | 88 | 89 | ## Note 90 | 91 | This package provides access to the revamped potential-related functions 92 | initially offered by 93 | [`SpatialPosition`](https://CRAN.R-project.org/package=SpatialPosition). 94 | 95 | ## References 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/_pkgdown.yml -------------------------------------------------------------------------------- /codemeta.json: -------------------------------------------------------------------------------- 1 | { 2 | "@context": "https://doi.org/10.5063/schema/codemeta-2.0", 3 | "@type": "SoftwareSourceCode", 4 | "identifier": "potential", 5 | "description": "Provides functions to compute the potential model as defined by Stewart (1941) . Several options are available to customize the model, such as the possibility to fine-tune the distance friction functions or to use custom distance matrices. Some computations are parallelized to improve their efficiency.", 6 | "name": "potential: Implementation of the Potential Model", 7 | "codeRepository": "https://github.com/riatelab/potential", 8 | "issueTracker": "https://github.com/riatelab/potential/issues", 9 | "license": "https://spdx.org/licenses/GPL-3.0", 10 | "version": "0.2.0", 11 | "programmingLanguage": { 12 | "@type": "ComputerLanguage", 13 | "name": "R", 14 | "url": "https://r-project.org" 15 | }, 16 | "runtimePlatform": "R version 4.2.1 (2022-06-23)", 17 | "provider": { 18 | "@id": "https://cran.r-project.org", 19 | "@type": "Organization", 20 | "name": "Comprehensive R Archive Network (CRAN)", 21 | "url": "https://cran.r-project.org" 22 | }, 23 | "author": [ 24 | { 25 | "@type": "Person", 26 | "givenName": "Timothée", 27 | "familyName": "Giraud", 28 | "email": "timothee.giraud@cnrs.fr", 29 | "@id": "https://orcid.org/0000-0002-1932-3323" 30 | }, 31 | { 32 | "@type": "Person", 33 | "givenName": "Hadrien", 34 | "familyName": "Commenges", 35 | "email": "hadrien.commenges@univ-paris1.fr" 36 | } 37 | ], 38 | "maintainer": [ 39 | { 40 | "@type": "Person", 41 | "givenName": "Timothée", 42 | "familyName": "Giraud", 43 | "email": "timothee.giraud@cnrs.fr", 44 | "@id": "https://orcid.org/0000-0002-1932-3323" 45 | } 46 | ], 47 | "softwareSuggestions": [ 48 | { 49 | "@type": "SoftwareApplication", 50 | "identifier": "covr", 51 | "name": "covr", 52 | "provider": { 53 | "@id": "https://cran.r-project.org", 54 | "@type": "Organization", 55 | "name": "Comprehensive R Archive Network (CRAN)", 56 | "url": "https://cran.r-project.org" 57 | }, 58 | "sameAs": "https://CRAN.R-project.org/package=covr" 59 | }, 60 | { 61 | "@type": "SoftwareApplication", 62 | "identifier": "lwgeom", 63 | "name": "lwgeom", 64 | "provider": { 65 | "@id": "https://cran.r-project.org", 66 | "@type": "Organization", 67 | "name": "Comprehensive R Archive Network (CRAN)", 68 | "url": "https://cran.r-project.org" 69 | }, 70 | "sameAs": "https://CRAN.R-project.org/package=lwgeom" 71 | }, 72 | { 73 | "@type": "SoftwareApplication", 74 | "identifier": "eurostat", 75 | "name": "eurostat", 76 | "provider": { 77 | "@id": "https://cran.r-project.org", 78 | "@type": "Organization", 79 | "name": "Comprehensive R Archive Network (CRAN)", 80 | "url": "https://cran.r-project.org" 81 | }, 82 | "sameAs": "https://CRAN.R-project.org/package=eurostat" 83 | }, 84 | { 85 | "@type": "SoftwareApplication", 86 | "identifier": "giscoR", 87 | "name": "giscoR", 88 | "provider": { 89 | "@id": "https://cran.r-project.org", 90 | "@type": "Organization", 91 | "name": "Comprehensive R Archive Network (CRAN)", 92 | "url": "https://cran.r-project.org" 93 | }, 94 | "sameAs": "https://CRAN.R-project.org/package=giscoR" 95 | }, 96 | { 97 | "@type": "SoftwareApplication", 98 | "identifier": "mapsf", 99 | "name": "mapsf", 100 | "provider": { 101 | "@id": "https://cran.r-project.org", 102 | "@type": "Organization", 103 | "name": "Comprehensive R Archive Network (CRAN)", 104 | "url": "https://cran.r-project.org" 105 | }, 106 | "sameAs": "https://CRAN.R-project.org/package=mapsf" 107 | }, 108 | { 109 | "@type": "SoftwareApplication", 110 | "identifier": "knitr", 111 | "name": "knitr", 112 | "provider": { 113 | "@id": "https://cran.r-project.org", 114 | "@type": "Organization", 115 | "name": "Comprehensive R Archive Network (CRAN)", 116 | "url": "https://cran.r-project.org" 117 | }, 118 | "sameAs": "https://CRAN.R-project.org/package=knitr" 119 | }, 120 | { 121 | "@type": "SoftwareApplication", 122 | "identifier": "tinytest", 123 | "name": "tinytest", 124 | "provider": { 125 | "@id": "https://cran.r-project.org", 126 | "@type": "Organization", 127 | "name": "Comprehensive R Archive Network (CRAN)", 128 | "url": "https://cran.r-project.org" 129 | }, 130 | "sameAs": "https://CRAN.R-project.org/package=tinytest" 131 | }, 132 | { 133 | "@type": "SoftwareApplication", 134 | "identifier": "rmarkdown", 135 | "name": "rmarkdown", 136 | "provider": { 137 | "@id": "https://cran.r-project.org", 138 | "@type": "Organization", 139 | "name": "Comprehensive R Archive Network (CRAN)", 140 | "url": "https://cran.r-project.org" 141 | }, 142 | "sameAs": "https://CRAN.R-project.org/package=rmarkdown" 143 | } 144 | ], 145 | "softwareRequirements": { 146 | "1": { 147 | "@type": "SoftwareApplication", 148 | "identifier": "R", 149 | "name": "R", 150 | "version": ">= 3.5.0" 151 | }, 152 | "2": { 153 | "@type": "SoftwareApplication", 154 | "identifier": "sf", 155 | "name": "sf", 156 | "provider": { 157 | "@id": "https://cran.r-project.org", 158 | "@type": "Organization", 159 | "name": "Comprehensive R Archive Network (CRAN)", 160 | "url": "https://cran.r-project.org" 161 | }, 162 | "sameAs": "https://CRAN.R-project.org/package=sf" 163 | }, 164 | "3": { 165 | "@type": "SoftwareApplication", 166 | "identifier": "graphics", 167 | "name": "graphics" 168 | }, 169 | "4": { 170 | "@type": "SoftwareApplication", 171 | "identifier": "mapiso", 172 | "name": "mapiso", 173 | "provider": { 174 | "@id": "https://cran.r-project.org", 175 | "@type": "Organization", 176 | "name": "Comprehensive R Archive Network (CRAN)", 177 | "url": "https://cran.r-project.org" 178 | }, 179 | "sameAs": "https://CRAN.R-project.org/package=mapiso" 180 | }, 181 | "5": { 182 | "@type": "SoftwareApplication", 183 | "identifier": "parallel", 184 | "name": "parallel" 185 | }, 186 | "6": { 187 | "@type": "SoftwareApplication", 188 | "identifier": "doParallel", 189 | "name": "doParallel", 190 | "provider": { 191 | "@id": "https://cran.r-project.org", 192 | "@type": "Organization", 193 | "name": "Comprehensive R Archive Network (CRAN)", 194 | "url": "https://cran.r-project.org" 195 | }, 196 | "sameAs": "https://CRAN.R-project.org/package=doParallel" 197 | }, 198 | "7": { 199 | "@type": "SoftwareApplication", 200 | "identifier": "foreach", 201 | "name": "foreach", 202 | "provider": { 203 | "@id": "https://cran.r-project.org", 204 | "@type": "Organization", 205 | "name": "Comprehensive R Archive Network (CRAN)", 206 | "url": "https://cran.r-project.org" 207 | }, 208 | "sameAs": "https://CRAN.R-project.org/package=foreach" 209 | }, 210 | "SystemRequirements": null 211 | }, 212 | "fileSize": "1732.97KB", 213 | "releaseNotes": "https://github.com/riatelab/potential/blob/master/NEWS.md", 214 | "readme": "https://github.com/riatelab/potential/blob/master/README.md", 215 | "contIntegration": ["https://github.com/riatelab/potential/actions", "https://app.codecov.io/gh/riatelab/potential"], 216 | "developmentStatus": "https://www.repostatus.org/#active", 217 | "keywords": ["stewart", "rspatial"] 218 | } 219 | -------------------------------------------------------------------------------- /data/nuts3.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/data/nuts3.RData -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • potential 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 |
31 |
83 | 84 | 85 | 86 | 87 |
88 |
89 | 92 | 93 | Content not found. Please use links in the navbar. 94 | 95 |
96 | 97 | 101 | 102 |
103 | 104 | 105 | 106 |
110 | 111 |
112 |

113 |

Site built with pkgdown 2.0.5.

114 |
115 | 116 |
117 |
118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/index.html: -------------------------------------------------------------------------------- 1 | 2 | Articles • potential 6 | 7 | 8 |
9 |
53 | 54 | 55 | 56 |
57 |
58 | 61 | 62 |
63 |

All vignettes

64 |

65 | 66 |
potential
67 |
68 |
Stewart Potentials: a Use Case
69 |
70 |
71 |
72 |
73 | 74 | 75 |
78 | 79 |
80 |

Site built with pkgdown 2.0.5.

81 |
82 | 83 |
84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/curve-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/curve-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/setup-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/setup-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/setup2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/setup2-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/setup3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/setup3-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/potential_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/potential_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/smooth-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/smooth-1.png -------------------------------------------------------------------------------- /docs/articles/web_only/exemple_files/figure-html/regionalmap-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/web_only/exemple_files/figure-html/regionalmap-1.png -------------------------------------------------------------------------------- /docs/articles/web_only/exemple_files/figure-html/regionalmappot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/web_only/exemple_files/figure-html/regionalmappot-1.png -------------------------------------------------------------------------------- /docs/articles/web_only/exemple_files/figure-html/smoothmappot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/articles/web_only/exemple_files/figure-html/smoothmappot-1.png -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • potential 6 | 7 | 8 |
9 |
53 | 54 | 55 | 56 |
57 |
58 |
59 | 62 | 63 | 64 |
  • 65 |

    Timothée Giraud. Maintainer, author. 66 |

    67 |
  • 68 |
  • 69 |

    Hadrien Commenges. Author. 70 |

    71 |
  • 72 |
73 |
74 |
75 |

Citation

76 | Source: DESCRIPTION 77 |
78 |
79 | 80 | 81 |

Giraud T, Commenges H (2022). 82 | potential: Implementation of the Potential Model. 83 | R package version 0.2.0, https://github.com/riatelab/potential. 84 |

85 |
@Manual{,
 86 |   title = {potential: Implementation of the Potential Model},
 87 |   author = {Timothée Giraud and Hadrien Commenges},
 88 |   year = {2022},
 89 |   note = {R package version 0.2.0},
 90 |   url = {https://github.com/riatelab/potential},
 91 | }
92 | 93 |
94 | 95 |
96 | 97 | 98 | 99 |
102 | 103 |
104 |

Site built with pkgdown 2.0.5.

105 |
106 | 107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/favicon.ico -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/logo.png -------------------------------------------------------------------------------- /docs/news/index.html: -------------------------------------------------------------------------------- 1 | 2 | Changelog • potential 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 62 | 63 |
    64 | 65 |
    66 |

    Minor changes

    67 |
    • Change longlat arg default to FALSE in create_matrix()
    • 68 |
    • Use mapsf instead of cartography in all examples
    • 69 |
    • Use mapiso instead of isoband
    • 70 |
    • In epquipotential “xcoords” and “ycoords” are not needed anymore
    • 71 |
    72 |
    73 |
    74 | 75 | 78 | 79 |
    80 | 81 | 82 |
    85 | 86 |
    87 |

    Site built with pkgdown 2.0.5.

    88 |
    89 | 90 |
    91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | /* Ensure in-page images don't run outside their container */ 60 | .contents img { 61 | max-width: 100%; 62 | height: auto; 63 | } 64 | 65 | /* Fix bug in bootstrap (only seen in firefox) */ 66 | summary { 67 | display: list-item; 68 | } 69 | 70 | /* Typographic tweaking ---------------------------------*/ 71 | 72 | .contents .page-header { 73 | margin-top: calc(-60px + 1em); 74 | } 75 | 76 | dd { 77 | margin-left: 3em; 78 | } 79 | 80 | /* Section anchors ---------------------------------*/ 81 | 82 | a.anchor { 83 | display: none; 84 | margin-left: 5px; 85 | width: 20px; 86 | height: 20px; 87 | 88 | background-image: url(./link.svg); 89 | background-repeat: no-repeat; 90 | background-size: 20px 20px; 91 | background-position: center center; 92 | } 93 | 94 | h1:hover .anchor, 95 | h2:hover .anchor, 96 | h3:hover .anchor, 97 | h4:hover .anchor, 98 | h5:hover .anchor, 99 | h6:hover .anchor { 100 | display: inline-block; 101 | } 102 | 103 | /* Fixes for fixed navbar --------------------------*/ 104 | 105 | .contents h1, .contents h2, .contents h3, .contents h4 { 106 | padding-top: 60px; 107 | margin-top: -40px; 108 | } 109 | 110 | /* Navbar submenu --------------------------*/ 111 | 112 | .dropdown-submenu { 113 | position: relative; 114 | } 115 | 116 | .dropdown-submenu>.dropdown-menu { 117 | top: 0; 118 | left: 100%; 119 | margin-top: -6px; 120 | margin-left: -1px; 121 | border-radius: 0 6px 6px 6px; 122 | } 123 | 124 | .dropdown-submenu:hover>.dropdown-menu { 125 | display: block; 126 | } 127 | 128 | .dropdown-submenu>a:after { 129 | display: block; 130 | content: " "; 131 | float: right; 132 | width: 0; 133 | height: 0; 134 | border-color: transparent; 135 | border-style: solid; 136 | border-width: 5px 0 5px 5px; 137 | border-left-color: #cccccc; 138 | margin-top: 5px; 139 | margin-right: -10px; 140 | } 141 | 142 | .dropdown-submenu:hover>a:after { 143 | border-left-color: #ffffff; 144 | } 145 | 146 | .dropdown-submenu.pull-left { 147 | float: none; 148 | } 149 | 150 | .dropdown-submenu.pull-left>.dropdown-menu { 151 | left: -100%; 152 | margin-left: 10px; 153 | border-radius: 6px 0 6px 6px; 154 | } 155 | 156 | /* Sidebar --------------------------*/ 157 | 158 | #pkgdown-sidebar { 159 | margin-top: 30px; 160 | position: -webkit-sticky; 161 | position: sticky; 162 | top: 70px; 163 | } 164 | 165 | #pkgdown-sidebar h2 { 166 | font-size: 1.5em; 167 | margin-top: 1em; 168 | } 169 | 170 | #pkgdown-sidebar h2:first-child { 171 | margin-top: 0; 172 | } 173 | 174 | #pkgdown-sidebar .list-unstyled li { 175 | margin-bottom: 0.5em; 176 | } 177 | 178 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 179 | 180 | /* All levels of nav */ 181 | 182 | nav[data-toggle='toc'] .nav > li > a { 183 | padding: 4px 20px 4px 6px; 184 | font-size: 1.5rem; 185 | font-weight: 400; 186 | color: inherit; 187 | } 188 | 189 | nav[data-toggle='toc'] .nav > li > a:hover, 190 | nav[data-toggle='toc'] .nav > li > a:focus { 191 | padding-left: 5px; 192 | color: inherit; 193 | border-left: 1px solid #878787; 194 | } 195 | 196 | nav[data-toggle='toc'] .nav > .active > a, 197 | nav[data-toggle='toc'] .nav > .active:hover > a, 198 | nav[data-toggle='toc'] .nav > .active:focus > a { 199 | padding-left: 5px; 200 | font-size: 1.5rem; 201 | font-weight: 400; 202 | color: inherit; 203 | border-left: 2px solid #878787; 204 | } 205 | 206 | /* Nav: second level (shown on .active) */ 207 | 208 | nav[data-toggle='toc'] .nav .nav { 209 | display: none; /* Hide by default, but at >768px, show it */ 210 | padding-bottom: 10px; 211 | } 212 | 213 | nav[data-toggle='toc'] .nav .nav > li > a { 214 | padding-left: 16px; 215 | font-size: 1.35rem; 216 | } 217 | 218 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 219 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 220 | padding-left: 15px; 221 | } 222 | 223 | nav[data-toggle='toc'] .nav .nav > .active > a, 224 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 226 | padding-left: 15px; 227 | font-weight: 500; 228 | font-size: 1.35rem; 229 | } 230 | 231 | /* orcid ------------------------------------------------------------------- */ 232 | 233 | .orcid { 234 | font-size: 16px; 235 | color: #A6CE39; 236 | /* margins are required by official ORCID trademark and display guidelines */ 237 | margin-left:4px; 238 | margin-right:4px; 239 | vertical-align: middle; 240 | } 241 | 242 | /* Reference index & topics ----------------------------------------------- */ 243 | 244 | .ref-index th {font-weight: normal;} 245 | 246 | .ref-index td {vertical-align: top; min-width: 100px} 247 | .ref-index .icon {width: 40px;} 248 | .ref-index .alias {width: 40%;} 249 | .ref-index-icons .alias {width: calc(40% - 40px);} 250 | .ref-index .title {width: 60%;} 251 | 252 | .ref-arguments th {text-align: right; padding-right: 10px;} 253 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 254 | .ref-arguments .name {width: 20%;} 255 | .ref-arguments .desc {width: 80%;} 256 | 257 | /* Nice scrolling for wide elements --------------------------------------- */ 258 | 259 | table { 260 | display: block; 261 | overflow: auto; 262 | } 263 | 264 | /* Syntax highlighting ---------------------------------------------------- */ 265 | 266 | pre, code, pre code { 267 | background-color: #f8f8f8; 268 | color: #333; 269 | } 270 | pre, pre code { 271 | white-space: pre-wrap; 272 | word-break: break-all; 273 | overflow-wrap: break-word; 274 | } 275 | 276 | pre { 277 | border: 1px solid #eee; 278 | } 279 | 280 | pre .img, pre .r-plt { 281 | margin: 5px 0; 282 | } 283 | 284 | pre .img img, pre .r-plt img { 285 | background-color: #fff; 286 | } 287 | 288 | code a, pre a { 289 | color: #375f84; 290 | } 291 | 292 | a.sourceLine:hover { 293 | text-decoration: none; 294 | } 295 | 296 | .fl {color: #1514b5;} 297 | .fu {color: #000000;} /* function */ 298 | .ch,.st {color: #036a07;} /* string */ 299 | .kw {color: #264D66;} /* keyword */ 300 | .co {color: #888888;} /* comment */ 301 | 302 | .error {font-weight: bolder;} 303 | .warning {font-weight: bolder;} 304 | 305 | /* Clipboard --------------------------*/ 306 | 307 | .hasCopyButton { 308 | position: relative; 309 | } 310 | 311 | .btn-copy-ex { 312 | position: absolute; 313 | right: 0; 314 | top: 0; 315 | visibility: hidden; 316 | } 317 | 318 | .hasCopyButton:hover button.btn-copy-ex { 319 | visibility: visible; 320 | } 321 | 322 | /* headroom.js ------------------------ */ 323 | 324 | .headroom { 325 | will-change: transform; 326 | transition: transform 200ms linear; 327 | } 328 | .headroom--pinned { 329 | transform: translateY(0%); 330 | } 331 | .headroom--unpinned { 332 | transform: translateY(-100%); 333 | } 334 | 335 | /* mark.js ----------------------------*/ 336 | 337 | mark { 338 | background-color: rgba(255, 255, 51, 0.5); 339 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 340 | padding: 1px; 341 | } 342 | 343 | /* vertical spacing after htmlwidgets */ 344 | .html-widget { 345 | margin-bottom: 10px; 346 | } 347 | 348 | /* fontawesome ------------------------ */ 349 | 350 | .fab { 351 | font-family: "Font Awesome 5 Brands" !important; 352 | } 353 | 354 | /* don't display links in code chunks when printing */ 355 | /* source: https://stackoverflow.com/a/10781533 */ 356 | @media print { 357 | code a:link:after, code a:visited:after { 358 | content: ""; 359 | } 360 | } 361 | 362 | /* Section anchors --------------------------------- 363 | Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 364 | */ 365 | 366 | div.csl-bib-body { } 367 | div.csl-entry { 368 | clear: both; 369 | } 370 | .hanging-indent div.csl-entry { 371 | margin-left:2em; 372 | text-indent:-2em; 373 | } 374 | div.csl-left-margin { 375 | min-width:2em; 376 | float:left; 377 | } 378 | div.csl-right-inline { 379 | margin-left:2em; 380 | padding-left:1em; 381 | } 382 | div.csl-indent { 383 | margin-left: 2em; 384 | } 385 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.17.1.1 2 | pkgdown: 2.0.5 3 | pkgdown_sha: ~ 4 | articles: 5 | potential: potential.html 6 | exemple: web_only/exemple.html 7 | last_built: 2022-07-04T12:28Z 8 | 9 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/Rplot002.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/Rplot002.png -------------------------------------------------------------------------------- /docs/reference/create_grid-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/create_grid-1.png -------------------------------------------------------------------------------- /docs/reference/create_grid.html: -------------------------------------------------------------------------------- 1 | 2 | Create a Regularly Spaced Points Grid — create_grid • potential 7 | 8 | 9 |
    10 |
    54 | 55 | 56 | 57 |
    58 |
    59 | 64 | 65 |
    66 |

    This function creates a regular grid of points 67 | from the extent of a given spatial object and a given resolution.

    68 |
    69 | 70 |
    71 |
    create_grid(x, res)
    72 |
    73 | 74 |
    75 |

    Arguments

    76 |
    x
    77 |

    an sf object, the spatial extent of this object is used to 78 | create the regular grid.

    79 | 80 | 81 |
    res
    82 |

    resolution of the grid (in map units).

    83 | 84 |
    85 |
    86 |

    Value

    87 | 88 | 89 |

    The output of the function is an sf object of regularly spaced 90 | points with the extent of x.

    91 |
    92 | 93 |
    94 |

    Examples

    95 |
    library(sf)
     96 | #> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE
     97 | g <- create_grid(x = n3_poly, res = 200000)
     98 | plot(st_geometry(g))
     99 | plot(st_geometry(n3_poly), border = "red", add = TRUE)
    100 | 
    101 | 
    102 |
    103 |
    104 | 107 |
    108 | 109 | 110 |
    113 | 114 |
    115 |

    Site built with pkgdown 2.0.5.

    116 |
    117 | 118 |
    119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/reference/create_matrix.html: -------------------------------------------------------------------------------- 1 | 2 | Create a Distance Matrix Between Two Spatial Objects — create_matrix • potential 7 | 8 | 9 |
    10 |
    54 | 55 | 56 | 57 |
    58 |
    59 | 64 | 65 |
    66 |

    This function creates a distance matrix between two 67 | spatial objects.

    68 |
    69 | 70 |
    71 |
    create_matrix(x, y, checksize = TRUE, longlat = FALSE)
    72 |
    73 | 74 |
    75 |

    Arguments

    76 |
    x
    77 |

    an sf object (POINT), rows of the distance matrix, row names are 78 | used as 79 | row names of the matrix.

    80 | 81 | 82 |
    y
    83 |

    an sf object (POINT), columns of the distance matrix, row names 84 | are used 85 | as column names of the matrix.

    86 | 87 | 88 |
    checksize
    89 |

    if FALSE, bypass the distance matrix size control 90 | (see Details).

    91 | 92 | 93 |
    longlat
    94 |

    if FALSE, the Euclidean distance is used, if TRUE Great Circle 95 | (WGS84 ellipsoid) distance is used.

    96 | 97 |
    98 |
    99 |

    Value

    100 | 101 | 102 |

    A distance matrix, row names are x row names, column 103 | names are y row names.

    104 |
    105 |
    106 |

    Details

    107 |

    The function returns a full matrix of distances in meters. 108 | If the matrix to compute is too large (more than 100,000,000 cells, more than 109 | 10,000,000 origins or more than 10,000,000 destinations) 110 | the function may sends a message to warn users about the amount of 111 | RAM mobilized.

    112 |
    113 | 114 |
    115 |

    Examples

    116 |
    g <- create_grid(x = n3_poly, res = 200000)
    117 | mat <- create_matrix(x = n3_pt, y = g)
    118 | mat[1:5, 1:5]
    119 | #>         1       2       3       4       5
    120 | #> 1 2674796 2482621 2291785 2102653 1915730
    121 | #> 2 2622868 2430532 2239539 2050264 1863231
    122 | #> 3 2682813 2492081 2302922 2115758 1931170
    123 | #> 4 2643075 2451462 2261302 2072995 1887096
    124 | #> 5 2638427 2447799 2258792 2071850 1887586
    125 | 
    126 |
    127 |
    128 | 131 |
    132 | 133 | 134 |
    137 | 138 |
    139 |

    Site built with pkgdown 2.0.5.

    140 |
    141 | 142 |
    143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /docs/reference/equipotential-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/equipotential-1.png -------------------------------------------------------------------------------- /docs/reference/equipotential.html: -------------------------------------------------------------------------------- 1 | 2 | Create Polygons of Equipotential — equipotential • potential 7 | 8 | 9 |
    10 |
    54 | 55 | 56 | 57 |
    58 |
    59 | 64 | 65 |
    66 |

    This function creates polygons of equipotential from a regular grid of 67 | potential points.

    68 |
    69 | 70 |
    71 |
    equipotential(x, var, nclass = 8, breaks, mask, buffer, xcoords, ycoords)
    72 |
    73 | 74 |
    75 |

    Arguments

    76 |
    x
    77 |

    an sf object of regularly spaced points.

    78 | 79 | 80 |
    var
    81 |

    name of the variable to use in x.

    82 | 83 | 84 |
    nclass
    85 |

    a number of class.

    86 | 87 | 88 |
    breaks
    89 |

    a vector of break values.

    90 | 91 | 92 |
    mask
    93 |

    an sf object of polygons or multipolygons. mask is used 94 | to clip polygons of contours equipotential.

    95 | 96 | 97 |
    buffer
    98 |

    if set, a buffer is added to the mask in order to 99 | reach more precisely the number of breaks. The buffer is defined in 100 | x units.

    101 | 102 | 103 |
    xcoords
    104 |

    not used.

    105 | 106 | 107 |
    ycoords
    108 |

    not used.

    109 | 110 |
    111 |
    112 |

    Value

    113 | 114 | 115 |

    The output is an sf object (POLYGONS). The data frame contains four 116 | fields: id (id of each polygon), min and max (minimum and maximum breaks of 117 | the polygon) and center (central values of classes).

    118 |
    119 | 120 |
    121 |

    Examples

    122 |
    library(sf)
    123 | y <- create_grid(x = n3_poly, res = 200000)
    124 | d <- create_matrix(n3_pt, y)
    125 | pot <- potential(
    126 |   x = n3_pt, y = y, d = d, var = "POP19",
    127 |   fun = "e", span = 200000, beta = 2
    128 | )
    129 | y$OUTPUT <- pot
    130 | equipot <- equipotential(y, var = "OUTPUT", mask = n3_poly)
    131 | plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis"))
    132 | 
    133 | 
    134 |
    135 |
    136 | 139 |
    140 | 141 | 142 |
    145 | 146 |
    147 |

    Site built with pkgdown 2.0.5.

    148 |
    149 | 150 |
    151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /docs/reference/figures/demo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/figures/demo-1.png -------------------------------------------------------------------------------- /docs/reference/figures/demox-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/figures/demox-1.png -------------------------------------------------------------------------------- /docs/reference/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/figures/logo.png -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Function reference • potential 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 61 | 62 | 66 | 69 | 70 | 73 | 74 | 77 | 78 | 81 | 82 | 85 | 86 | 89 | 90 | 93 | 94 | 97 | 98 | 101 | 102 |
    63 |

    All functions

    64 |

    65 |
    67 |

    create_grid()

    68 |

    Create a Regularly Spaced Points Grid

    71 |

    create_matrix()

    72 |

    Create a Distance Matrix Between Two Spatial Objects

    75 |

    equipotential()

    76 |

    Create Polygons of Equipotential

    79 |

    mcpotential()

    80 |

    Compute the Potential Model using Parallelization

    83 |

    nuts3

    84 |

    Points and Polygons Layers of European Statistical Units (NUTS3)

    87 |

    nuts3

    88 |

    Points and Polygons Layers of European Statistical Units (NUTS3)

    91 |

    plot_inter()

    92 |

    Display a Spatial Interaction Function

    95 |

    potential-package

    96 |

    Implementation of the Potential Model

    99 |

    potential()

    100 |

    Compute the Potential Model

    103 | 104 | 107 |
    108 | 109 | 110 |
    113 | 114 |
    115 |

    Site built with pkgdown 2.0.5.

    116 |
    117 | 118 |
    119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/reference/mcpotential-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/mcpotential-1.png -------------------------------------------------------------------------------- /docs/reference/n3_poly.html: -------------------------------------------------------------------------------- 1 | 2 | Points and Polygons Layers of European Statistical Units (NUTS3) — n3_poly • potential 19 | 20 | 21 |
    22 |
    66 | 67 | 68 | 69 |
    70 |
    71 | 76 | 77 |
    78 |

    n3_pt (POINTS) and n3_poly (MULTIPOLYGONS) are sf objects of 79 | 1506 NUTS3 statistical units of continental Europe.

    80 |

    Population dataset (2019 an 2018 total population) downloaded on the Eurostat 81 | website (05/10/2020) from the "demo_r_pjanaggr3" dataset 82 | (last update: 16/06/2020).

    83 |

    Geometries are downloaded from the GISCO website 84 | (NUTS3 - 2016 - 1:60 Million)

    85 |

    When data from this packgage is used in any printed or electronic 86 | publication, in addition to any other provisions applicable to the whole 87 | Eurostat website, data source will have to be acknowledged in the legend of 88 | the map and in the introductory page of the publication with the following 89 | copyright notice: 90 | "© EuroGeographics for the administrative boundaries and © Eurostat 91 | for data".

    92 |
    93 | 94 |
    95 |
    data(nuts3)
    96 |
    97 | 98 |
    99 |

    Format

    100 |

    An object of class sf (inherits from data.frame) with 1506 rows and 4 columns.

    101 |
    102 | 103 |
    104 | 107 |
    108 | 109 | 110 |
    113 | 114 |
    115 |

    Site built with pkgdown 2.0.5.

    116 |
    117 | 118 |
    119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/reference/n3_pt.html: -------------------------------------------------------------------------------- 1 | 2 | Points and Polygons Layers of European Statistical Units (NUTS3) — n3_pt • potential 19 | 20 | 21 |
    22 |
    66 | 67 | 68 | 69 |
    70 |
    71 | 76 | 77 |
    78 |

    n3_pt (POINTS) and n3_poly (MULTIPOLYGONS) are sf objects of 79 | 1506 NUTS3 statistical units of continental Europe.

    80 |

    Population dataset (2019 an 2018 total population) downloaded on the Eurostat 81 | website (05/10/2020) from the "demo_r_pjanaggr3" dataset 82 | (last update: 16/06/2020).

    83 |

    Geometries are downloaded from the GISCO website 84 | (NUTS3 - 2016 - 1:60 Million)

    85 |

    When data from this package is used in any printed or electronic 86 | publication, in addition to any other provisions applicable to the whole 87 | Eurostat website, data source will have to be acknowledged in the legend of 88 | the map and in the introductory page of the publication with the following 89 | copyright notice: 90 | "© EuroGeographics for the administrative boundaries and © Eurostat 91 | for data".

    92 |
    93 | 94 |
    95 |
    data(nuts3)
    96 |
    97 | 98 |
    99 |

    Format

    100 |

    An object of class sf (inherits from data.frame) with 1506 rows and 4 columns.

    101 |
    102 | 103 |
    104 | 107 |
    108 | 109 | 110 |
    113 | 114 |
    115 |

    Site built with pkgdown 2.0.5.

    116 |
    117 | 118 |
    119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /docs/reference/plot_inter-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/plot_inter-1.png -------------------------------------------------------------------------------- /docs/reference/plot_inter-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/plot_inter-2.png -------------------------------------------------------------------------------- /docs/reference/plot_inter.html: -------------------------------------------------------------------------------- 1 | 2 | Display a Spatial Interaction Function — plot_inter • potential 6 | 7 | 8 |
    9 |
    53 | 54 | 55 | 56 |
    57 |
    58 | 63 | 64 |
    65 |

    Display a spatial interaction function.

    66 |
    67 | 68 |
    69 |
    plot_inter(fun = "e", span, beta, limit = span * 5)
    70 |
    71 | 72 |
    73 |

    Arguments

    74 |
    fun
    75 |

    spatial interaction function. Options are "p" 76 | (pareto, power law) or "e" (exponential). 77 | For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 78 | For "exponential" the interaction is defined as: 79 | exp(- alpha * mDistance ^ beta). 80 | The alpha parameter is computed from parameters given by the user 81 | (beta and span).

    82 | 83 | 84 |
    span
    85 |

    distance where the density of probability of the spatial 86 | interaction function equals 0.5.

    87 | 88 | 89 |
    beta
    90 |

    impedance factor for the spatial interaction function.

    91 | 92 | 93 |
    limit
    94 |

    maximum distance used to retrieved x points, in 95 | map units.

    96 | 97 |
    98 |
    99 |

    Value

    100 | 101 | 102 |

    a plot

    103 |
    104 | 105 |
    106 |

    Examples

    107 |
    plot_inter(fun = "e", span = 2000, beta = 2, limit = 4000)
    108 | 
    109 | plot_inter(fun = "p", span = 2000, beta = 2, limit = 20000)
    110 | 
    111 | 
    112 |
    113 |
    114 | 117 |
    118 | 119 | 120 |
    123 | 124 |
    125 |

    Site built with pkgdown 2.0.5.

    126 |
    127 | 128 |
    129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/reference/potential-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/docs/reference/potential-1.png -------------------------------------------------------------------------------- /docs/reference/potential-package.html: -------------------------------------------------------------------------------- 1 | 2 | Implementation of the Potential Model — potential-package • potential 10 | 11 | 12 |
    13 |
    57 | 58 | 59 | 60 |
    61 |
    62 | 67 | 68 |
    69 |

    This package provides functions to compute the potential model as 70 | defined by Stewart (1941) <doi:10.1126/science.93.2404.89>. Several options 71 | are available to customize the model, such as the possibility to fine-tune 72 | the distance friction functions or to use custom distance matrices. Some 73 | computations are parallelized to improve their efficiency.

    74 |
    75 | 76 | 77 | 78 |
    79 | 82 |
    83 | 84 | 85 |
    88 | 89 |
    90 |

    Site built with pkgdown 2.0.5.

    91 |
    92 | 93 |
    94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /docs/sitemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /404.html 5 | 6 | 7 | /articles/index.html 8 | 9 | 10 | /articles/potential.html 11 | 12 | 13 | /articles/web_only/exemple.html 14 | 15 | 16 | /authors.html 17 | 18 | 19 | /index.html 20 | 21 | 22 | /news/index.html 23 | 24 | 25 | /reference/create_grid.html 26 | 27 | 28 | /reference/create_matrix.html 29 | 30 | 31 | /reference/equipotential.html 32 | 33 | 34 | /reference/index.html 35 | 36 | 37 | /reference/mcpotential.html 38 | 39 | 40 | /reference/n3_poly.html 41 | 42 | 43 | /reference/n3_pt.html 44 | 45 | 46 | /reference/plot_inter.html 47 | 48 | 49 | /reference/potential-package.html 50 | 51 | 52 | /reference/potential.html 53 | 54 | 55 | -------------------------------------------------------------------------------- /inst/tinytest/test_curv.R: -------------------------------------------------------------------------------- 1 | suppressPackageStartupMessages(library(sf)) 2 | 3 | 4 | # test plot_inter 5 | expect_silent(plot_inter(fun="e", span = 2000, beta = 2)) 6 | expect_silent(plot_inter(fun="p", span = 2000, beta = 2)) 7 | 8 | # test create_grid 9 | expect_silent(create_grid(x = n3_poly, res = 300000)) 10 | 11 | # test create_matrix 12 | g <- create_grid(x = n3_poly, res = 300000) 13 | expect_silent(create_matrix(x = g, y = g, checksize = TRUE, 14 | longlat = FALSE)) 15 | 16 | if (sf::sf_extSoftVersion()[["GDAL"]] >= "3.0.4") { 17 | expect_silent(create_matrix(x = g, y = g, longlat = TRUE)) 18 | } 19 | expect_silent(create_matrix(x = g, y = g, checksize = FALSE, 20 | longlat = TRUE)) 21 | huge <- do.call(rbind, 22 | list(n3_pt, n3_pt, n3_pt, n3_pt, n3_pt, 23 | n3_pt, n3_pt, n3_pt, n3_pt, 24 | n3_pt, n3_pt, n3_pt, n3_pt, 25 | n3_pt, n3_pt, n3_pt)) 26 | expect_error(create_matrix(x = huge, 27 | y = huge, 28 | checksize = TRUE, 29 | longlat = FALSE)) 30 | # test potential 31 | d <- create_matrix(n3_pt, g) 32 | expect_silent(potential(x = n3_pt, y = g, d = d, var = "POP19", 33 | fun = "e", span = 100000, beta = 2)) 34 | 35 | expect_silent(potential(x = n3_pt, y = g, d = d, var = "POP19", 36 | fun = "p", span = 100000, beta = 2)) 37 | 38 | # test equipotential 39 | pot <- potential( 40 | x = n3_pt, y = g, d = d, var = "POP19", 41 | fun = "e", span = 200000, beta = 2) 42 | g$OUTPUT <- pot 43 | 44 | expect_silent(equipotential(g, var = "OUTPUT", mask = n3_poly)) 45 | expect_silent(equipotential(g, var = "OUTPUT", mask = n3_poly)) 46 | expect_silent(equipotential(g, var = "OUTPUT")) 47 | expect_silent(equipotential(g, var = "OUTPUT", 48 | breaks = c(0,1000,1000000,40000000))) 49 | expect_silent(equipotential(g[,-c(2,3)], var = "OUTPUT", mask = n3_poly)) 50 | expect_silent(equipotential(g[,-c(2,3)], var = "OUTPUT", 51 | mask = n3_poly, buffer = 100000)) 52 | 53 | 54 | # test mcpotential 55 | home <- length(unclass(packageVersion("potential"))[[1]]) == 4 56 | if(home){ 57 | expect_silent(mcpotential( 58 | x = n3_pt, y = g, var = "POP19", 59 | fun = "e", span = 200000, beta = 2)) 60 | expect_silent(mcpotential( 61 | x = n3_pt, y = g, var = c("POP19", "POP18"), 62 | fun = "e", span = 200000, beta = 2)) 63 | expect_silent(mcpotential( 64 | x = n3_pt, y = g, var = "POP19", 65 | fun = "p", span = 200000, beta = 2, ncl = 1)) 66 | } 67 | 68 | 69 | 70 | expect_error(create_grid(x = 3, res = 100)) 71 | 72 | expect_error(potential:::test_point(3, "E")) 73 | 74 | expect_silent(potential:::test_point(g, "E")) 75 | 76 | -------------------------------------------------------------------------------- /man/create_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create_grid.R 3 | \name{create_grid} 4 | \alias{create_grid} 5 | \title{Create a Regularly Spaced Points Grid} 6 | \usage{ 7 | create_grid(x, res) 8 | } 9 | \arguments{ 10 | \item{x}{an sf or sfc object, the spatial extent of this object is used to 11 | create the regular grid.} 12 | 13 | \item{res}{resolution of the grid (in map units).} 14 | } 15 | \value{ 16 | The output of the function is an sf object of regularly spaced 17 | points with the extent of x. 18 | } 19 | \description{ 20 | This function creates a regular grid of points 21 | from the extent of a given spatial object and a given resolution. 22 | } 23 | \examples{ 24 | library(sf) 25 | g <- create_grid(x = n3_poly, res = 200000) 26 | plot(st_geometry(g)) 27 | plot(st_geometry(n3_poly), border = "red", add = TRUE) 28 | } 29 | -------------------------------------------------------------------------------- /man/create_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/create_matrix.R 3 | \name{create_matrix} 4 | \alias{create_matrix} 5 | \title{Create a Distance Matrix Between Two Spatial Objects} 6 | \usage{ 7 | create_matrix(x, y, checksize = TRUE, longlat = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{an sf object (POINT), rows of the distance matrix, row names are 11 | used as row names of the matrix.} 12 | 13 | \item{y}{an sf object (POINT), columns of the distance matrix, row names 14 | are used as column names of the matrix.} 15 | 16 | \item{checksize}{if FALSE, bypass the distance matrix size control 17 | (see Details).} 18 | 19 | \item{longlat}{if FALSE, the Euclidean distance is used, if TRUE Great Circle 20 | (WGS84 ellipsoid) distance is used.} 21 | } 22 | \value{ 23 | A distance matrix, row names are \code{x} row names, column 24 | names are \code{y} row names. 25 | } 26 | \description{ 27 | This function creates a distance matrix between two 28 | spatial objects. 29 | } 30 | \details{ 31 | The function returns a full matrix of distances in meters. 32 | If the matrix to compute is too large (more than 100,000,000 cells, more than 33 | 10,000,000 origins or more than 10,000,000 destinations) 34 | the function may sends a message to warn users about the amount of 35 | RAM mobilized. 36 | } 37 | \examples{ 38 | g <- create_grid(x = n3_poly, res = 200000) 39 | mat <- create_matrix(x = n3_pt, y = g) 40 | mat[1:5, 1:5] 41 | } 42 | -------------------------------------------------------------------------------- /man/equipotential.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/equipotential.R 3 | \name{equipotential} 4 | \alias{equipotential} 5 | \title{Create Polygons of Equipotential} 6 | \usage{ 7 | equipotential(x, var, nclass = 8, breaks, mask, buffer, xcoords, ycoords) 8 | } 9 | \arguments{ 10 | \item{x}{an sf object of regularly spaced points.} 11 | 12 | \item{var}{name of the variable to use in \code{x}.} 13 | 14 | \item{nclass}{a number of class.} 15 | 16 | \item{breaks}{a vector of break values.} 17 | 18 | \item{mask}{an sf object of polygons or multipolygons. \code{mask} is used 19 | to clip polygons of contours equipotential.} 20 | 21 | \item{buffer}{if set, a buffer is added to the mask in order to 22 | reach more precisely the number of breaks. The buffer is defined in 23 | \code{x} units.} 24 | 25 | \item{xcoords}{not used.} 26 | 27 | \item{ycoords}{not used.} 28 | } 29 | \value{ 30 | The output is an sf object (POLYGONS). The data frame contains four 31 | fields: id (id of each polygon), min and max (minimum and maximum breaks of 32 | the polygon) and center (central values of classes). 33 | } 34 | \description{ 35 | This function creates polygons of equipotential from a regular grid of 36 | potential points. 37 | } 38 | \examples{ 39 | library(sf) 40 | y <- create_grid(x = n3_poly, res = 200000) 41 | d <- create_matrix(n3_pt, y) 42 | pot <- potential( 43 | x = n3_pt, y = y, d = d, var = "POP19", 44 | fun = "e", span = 200000, beta = 2 45 | ) 46 | y$OUTPUT <- pot 47 | equipot <- equipotential(y, var = "OUTPUT", mask = n3_poly) 48 | plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis")) 49 | } 50 | -------------------------------------------------------------------------------- /man/figures/demo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/man/figures/demo-1.png -------------------------------------------------------------------------------- /man/figures/demox-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/man/figures/demox-1.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/man/figures/logo.png -------------------------------------------------------------------------------- /man/mcpotential.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mcpotential.R 3 | \name{mcpotential} 4 | \alias{mcpotential} 5 | \title{Compute the Potential Model using Parallelization} 6 | \usage{ 7 | mcpotential(x, y, var, fun, span, beta, limit = 3 * span, ncl, size = 500) 8 | } 9 | \arguments{ 10 | \item{x}{an sf object (POINT), the set of known observations to estimate 11 | the potentials from.} 12 | 13 | \item{y}{an sf object (POINT), the set of unknown units for which the 14 | function computes the estimates.} 15 | 16 | \item{var}{names of the variables in \code{x} from which potentials are 17 | computed. Quantitative variables with no negative values.} 18 | 19 | \item{fun}{spatial interaction function. Options are "p" 20 | (pareto, power law) or "e" (exponential). 21 | For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 22 | For "exponential" the interaction is defined as: 23 | exp(- alpha * mDistance ^ beta). 24 | The alpha parameter is computed from parameters given by the user 25 | (\code{beta} and \code{span}).} 26 | 27 | \item{span}{distance where the density of probability of the spatial 28 | interaction function equals 0.5.} 29 | 30 | \item{beta}{impedance factor for the spatial interaction function.} 31 | 32 | \item{limit}{maximum distance used to retrieve \code{x} points, in map units.} 33 | 34 | \item{ncl}{number of clusters. \code{ncl} is set to 35 | \code{parallel::detectCores() - 1} by default.} 36 | 37 | \item{size}{\code{mcpotential} splits \code{y} in smaller chunks and 38 | dispatches the computation in \code{ncl} cores, \code{size} indicates the 39 | size of each chunks.} 40 | } 41 | \value{ 42 | If only one variable is computed a vector is returned, if more than 43 | one variable is computed a matrix is returned. 44 | } 45 | \description{ 46 | This function computes the potential model with a cutoff 47 | distance and parallel 48 | computation. 49 | } 50 | \examples{ 51 | \donttest{ 52 | library(sf) 53 | g <- create_grid(x = n3_poly, res = 20000) 54 | pot <- mcpotential( 55 | x = n3_pt, y = g, var = "POP19", 56 | fun = "e", span = 75000, beta = 2, 57 | limit = 300000, 58 | ncl = 2 59 | ) 60 | g$OUTPUT <- pot 61 | equipot <- equipotential(g, var = "OUTPUT", mask = n3_poly) 62 | plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis")) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /man/n3_poly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{data} 4 | \name{n3_poly} 5 | \alias{n3_poly} 6 | \title{Points and Polygons Layers of European Statistical Units (NUTS3)} 7 | \format{ 8 | An object of class \code{sf} (inherits from \code{data.frame}) with 1506 rows and 4 columns. 9 | } 10 | \usage{ 11 | data(nuts3) 12 | } 13 | \description{ 14 | n3_pt (POINTS) and n3_poly (MULTIPOLYGONS) are sf objects of 15 | 1506 NUTS3 statistical units of continental Europe. 16 | 17 | Population dataset (2019 an 2018 total population) downloaded on the Eurostat 18 | website (05/10/2020) from the "demo_r_pjanaggr3" dataset 19 | (last update: 16/06/2020). 20 | 21 | Geometries are downloaded from the GISCO website 22 | (NUTS3 - 2016 - 1:60 Million) 23 | 24 | When data from this packgage is used in any printed or electronic 25 | publication, in addition to any other provisions applicable to the whole 26 | Eurostat website, data source will have to be acknowledged in the legend of 27 | the map and in the introductory page of the publication with the following 28 | copyright notice: 29 | "© EuroGeographics for the administrative boundaries and © Eurostat 30 | for data". 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/n3_pt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{data} 4 | \name{n3_pt} 5 | \alias{n3_pt} 6 | \title{Points and Polygons Layers of European Statistical Units (NUTS3)} 7 | \format{ 8 | An object of class \code{sf} (inherits from \code{data.frame}) with 1506 rows and 4 columns. 9 | } 10 | \usage{ 11 | data(nuts3) 12 | } 13 | \description{ 14 | n3_pt (POINTS) and n3_poly (MULTIPOLYGONS) are sf objects of 15 | 1506 NUTS3 statistical units of continental Europe. 16 | 17 | Population dataset (2019 an 2018 total population) downloaded on the Eurostat 18 | website (05/10/2020) from the "demo_r_pjanaggr3" dataset 19 | (last update: 16/06/2020). 20 | 21 | Geometries are downloaded from the GISCO website 22 | (NUTS3 - 2016 - 1:60 Million) 23 | 24 | When data from this package is used in any printed or electronic 25 | publication, in addition to any other provisions applicable to the whole 26 | Eurostat website, data source will have to be acknowledged in the legend of 27 | the map and in the introductory page of the publication with the following 28 | copyright notice: 29 | "© EuroGeographics for the administrative boundaries and © Eurostat 30 | for data". 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/plot_inter.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/curv.R 3 | \name{plot_inter} 4 | \alias{plot_inter} 5 | \title{Display a Spatial Interaction Function} 6 | \usage{ 7 | plot_inter(fun = "e", span, beta, limit = span * 5) 8 | } 9 | \arguments{ 10 | \item{fun}{spatial interaction function. Options are "p" 11 | (pareto, power law) or "e" (exponential). 12 | For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 13 | For "exponential" the interaction is defined as: 14 | exp(- alpha * mDistance ^ beta). 15 | The alpha parameter is computed from parameters given by the user 16 | (\code{beta} and \code{span}).} 17 | 18 | \item{span}{distance where the density of probability of the spatial 19 | interaction function equals 0.5.} 20 | 21 | \item{beta}{impedance factor for the spatial interaction function.} 22 | 23 | \item{limit}{maximum distance used to retrieved \code{x} points, in 24 | map units.} 25 | } 26 | \value{ 27 | a plot 28 | } 29 | \description{ 30 | Display a spatial interaction function. 31 | } 32 | \examples{ 33 | plot_inter(fun = "e", span = 2000, beta = 2, limit = 4000) 34 | plot_inter(fun = "p", span = 2000, beta = 2, limit = 20000) 35 | } 36 | -------------------------------------------------------------------------------- /man/potential-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/package.R 3 | \docType{package} 4 | \name{potential-package} 5 | \alias{potential-package} 6 | \title{Implementation of the Potential Model} 7 | \description{ 8 | This package provides functions to compute the potential model as 9 | defined by Stewart (1941) . Several options 10 | are available to customize the model, such as the possibility to fine-tune 11 | the distance friction functions or to use custom distance matrices. Some 12 | computations are parallelized to improve their efficiency. 13 | } 14 | -------------------------------------------------------------------------------- /man/potential.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/potential.R 3 | \name{potential} 4 | \alias{potential} 5 | \title{Compute the Potential Model} 6 | \usage{ 7 | potential(x, y, d, var, fun, span, beta) 8 | } 9 | \arguments{ 10 | \item{x}{an sf object (POINT), the set of known observations to 11 | estimate the potentials from.} 12 | 13 | \item{y}{an sf object (POINT), the set of unknown units for which 14 | the function computes the estimates.} 15 | 16 | \item{d}{a distance matrix between known observations and unknown 17 | units for which the function computes the estimates. Row names match the row 18 | names of \code{x} and column names match the row names of 19 | \code{y}. \code{d} can contain any distance metric (time 20 | distance or euclidean distance for example).} 21 | 22 | \item{var}{names of the variables in \code{x} from which potentials are 23 | computed. Quantitative variables with no negative values.} 24 | 25 | \item{fun}{spatial interaction function. Options are "p" 26 | (pareto, power law) or "e" (exponential). 27 | For pareto the interaction is defined as: (1 + alpha * mDistance) ^ (-beta). 28 | For "exponential" the interaction is defined as: 29 | exp(- alpha * mDistance ^ beta). 30 | The alpha parameter is computed from parameters given by the user 31 | (\code{beta} and \code{span}).} 32 | 33 | \item{span}{distance where the density of probability of the spatial 34 | interaction function equals 0.5.} 35 | 36 | \item{beta}{impedance factor for the spatial interaction function.} 37 | } 38 | \value{ 39 | If only one variable is computed a vector is returned, if more than 40 | one variable is computed a matrix is returned. 41 | } 42 | \description{ 43 | This function computes the potential model as defined 44 | by J.Q. Stewart (1941). 45 | } 46 | \examples{ 47 | library(sf) 48 | y <- create_grid(x = n3_poly, res = 200000) 49 | d <- create_matrix(n3_pt, y) 50 | pot <- potential( 51 | x = n3_pt, y = y, d = d, var = "POP19", 52 | fun = "e", span = 200000, beta = 2 53 | ) 54 | y$OUTPUT <- pot 55 | equipot <- equipotential(y, var = "OUTPUT", mask = n3_poly) 56 | plot(equipot["center"], pal = hcl.colors(nrow(equipot), "cividis")) 57 | } 58 | \references{ 59 | STEWART, JOHN Q. 1941. "An Inverse Distance Variation for Certain Social 60 | Influences." \emph{Science} 93 (2404): 89–90. 61 | \doi{10.1126/science.93.2404.89}. 62 | } 63 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /potential.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: No 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-multiarch --with-keep.source 17 | PackageRoxygenize: rd,collate,namespace,vignette 18 | -------------------------------------------------------------------------------- /tests/tinytest.R: -------------------------------------------------------------------------------- 1 | 2 | if (requireNamespace("tinytest", quietly = TRUE)) { 3 | tinytest::test_package("potential") 4 | } 5 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/references.bib: -------------------------------------------------------------------------------- 1 | @article {STEWART41, 2 | author = {Stewart, John Q}, 3 | title = {An Inverse Distance Variation for Certain Social Influences}, 4 | volume = {93}, 5 | number = {2404}, 6 | pages = {89--90}, 7 | year = {1941}, 8 | doi = {10.1126/science.93.2404.89}, 9 | publisher = {American Association for the Advancement of Science}, 10 | issn = {0036-8075}, 11 | URL = {https://science.sciencemag.org/content/93/2404/89}, 12 | eprint = {https://science.sciencemag.org/content/93/2404/89.full.pdf}, 13 | journal = {Science} 14 | } 15 | 16 | 17 | @book{fotheringham1989spatial, 18 | title={Spatial interaction models: formulations and applications}, 19 | author={Fotheringham, A Stewart and O'Kelly, Morton E}, 20 | volume={1}, 21 | year={1989}, 22 | publisher={Kluwer Academic Publishers Dordrecht} 23 | } 24 | 25 | 26 | @article{rodrigue2013spatial, 27 | title={Spatial Interactions and the Gravity Model}, 28 | author={Rodrigue, Jean-Paul and Comtois, Claude and Slack, Brian}, 29 | journal={The geography of transport systems.}, 30 | year={2013}, 31 | URL = {https://transportgeography.org/contents/methods/spatial-interactions-gravity-model/} 32 | } 33 | 34 | 35 | @article{rich1980potential, 36 | title={Potential Models in Human Geography.}, 37 | author={Rich, David C}, 38 | journal={CATMOG 26}, 39 | volume={38}, 40 | year={1980} 41 | } 42 | -------------------------------------------------------------------------------- /vignettes/smooth-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riatelab/potential/3dc649b6661a2595754d3b848198305a5f3c3fd6/vignettes/smooth-1.png -------------------------------------------------------------------------------- /vignettes/web_only/exemple.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Stewart Potentials: a Use Case" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Stewart Potentials: a Use Case} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | 12 | knitr::opts_chunk$set( 13 | message = FALSE, 14 | warning = FALSE, 15 | collapse = TRUE, 16 | comment = "#>", 17 | fig.width = 7, 18 | fig.height = 9 19 | ) 20 | 21 | ``` 22 | 23 | 24 | The Stewart model is a spatial interaction modeling approach which aims to compute indicators based on stock values weighted by distance. These indicators have two main interests: 25 | 26 | 1. they produce understandable maps by smoothing complex spatial patterns; 27 | 2. they enrich stock variables with contextual spatial information. 28 | 29 | This functional semantic simplification may help to show a smoothed context-aware picture of the localized socio-economic activities. 30 | 31 | In this vignette, we show a use case of these potentials on the regional GDP per capita in Italy with three maps: 32 | 33 | * a regional map of the GDP per capita; 34 | * a regional map of the potential GDP per capita; 35 | * a smoothed map of the GDP per capita. 36 | 37 | ## Data preparation 38 | 39 | ```{r init} 40 | library(eurostat) 41 | library(giscoR) 42 | library(potential) 43 | library(mapsf) 44 | library(sf) 45 | # Data download from Eurostat 46 | gdp_raw <- get_eurostat('nama_10r_3gdp') 47 | pop_raw <- get_eurostat('nama_10r_3popgdp') 48 | 49 | # Selection of the relevant rows and columns 50 | pop <- pop_raw[nchar(pop_raw$geo)==5 & 51 | pop_raw$time == "2018-01-01", ] 52 | names(pop)[4] <- "pop" 53 | pop$pop <- pop$pop * 1000 54 | gdp <- gdp_raw[nchar(gdp_raw$geo)==5 & 55 | gdp_raw$time == "2018-01-01" & 56 | gdp_raw$unit == "MIO_EUR", ] 57 | names(gdp)[4] <- "gdp" 58 | gdp$gdp <- gdp$gdp * 1000000 59 | 60 | # Base maps download from GISCO 61 | countries <- gisco_get_countries() 62 | nuts_raw <- gisco_nuts 63 | nuts <- nuts_raw[nuts_raw$LEVL_CODE == 3 & 64 | nuts_raw$CNTR_CODE == "IT", ] 65 | nuts <- st_transform(nuts, 3035) 66 | countries <- st_transform(countries, 3035) 67 | 68 | # Join between base map and dataset 69 | nuts <- merge(nuts, pop[,c("geo", "pop")], by.x = "NUTS_ID", by.y = "geo", all.x = T) 70 | nuts <- merge(nuts, gdp[,c("geo", "gdp")], by.x = "NUTS_ID", by.y = "geo", all.x = T) 71 | ``` 72 | 73 | 74 | ## Regional Map of the GDP per Capita 75 | 76 | ```{r regionalmap, fig.width=7, fig.height=9, fig.show='hold'} 77 | # Compute the GDP per capita 78 | nuts$gdp_hab <- nuts$gdp / nuts$pop 79 | # Set Breaks 80 | bv <- quantile(nuts$gdp_hab, seq(from = 0, to = 1, length.out = 9), na.rm = T) 81 | # Set a color palette 82 | pal <- mf_get_pal(n = 9, palette = "Burg", rev = TRUE) 83 | # Set the credit text 84 | cred <- paste0("© EuroGeographics for the administrative boundaries\n", 85 | "© Eurostat, 2021 (nama_10r_3gdp and nama_10r_3popgdp tables)\n", 86 | "T. Giraud, 2022") 87 | # Draw the basemap 88 | mf_theme(bg = "#cdd2d4", mar = c(0,0,1.2,0), tab = FALSE) 89 | mf_init(nuts) 90 | mf_map(countries, col = "#f5f5f3ff", border = "#a9b3b4ff", add = TRUE) 91 | # Map the regional GDP per capita 92 | mf_map(x = nuts, var = "gdp_hab", type = "choro", 93 | leg_pos = "topright", 94 | breaks = bv, 95 | pal = pal, 96 | border = NA, 97 | leg_frame = TRUE, 98 | leg_title = "GDP per Capita\n(in euros, 2018)", 99 | leg_val_rnd = -2, 100 | col_na = "grey60", 101 | add = TRUE) 102 | mf_map(countries[countries$ISO3_CODE == "ITA", ], 103 | col = NA, border = "#a9b3b4ff", add = TRUE) 104 | # Set a layout 105 | mf_arrow("topleft") 106 | mf_title(txt = "GDP per Capita Inequalities in Italy") 107 | mf_scale(100) 108 | mf_credits(txt = cred, bg = "#ffffff80") 109 | ``` 110 | 111 | 112 | ## Regional Map of the Potential GDP per Capita 113 | 114 | We compute the potentials of GDP for each spatial unit. 115 | The computed value takes into account the spatial distribution of the stock variable and return a sum weighted by distance, 116 | according a specific spatial interaction and fully customizable function. 117 | 118 | ```{r regionalmappot, fig.width=7, fig.height=9, fig.show='hold' } 119 | # Create a distance matrix between units 120 | nuts_pt <- nuts 121 | st_geometry(nuts_pt) <- st_centroid(st_geometry(nuts_pt)) 122 | d <- create_matrix(nuts_pt, nuts_pt) 123 | # Compute the potentials of population and GDP per units 124 | # function = exponential, beta = 2, span = 100 km 125 | pot <- potential(x = nuts_pt, 126 | y = nuts_pt, 127 | d = d, 128 | var = c("pop", "gdp"), 129 | fun = "e", 130 | beta = 2, 131 | span = 100000) 132 | # Compute the potential GDP per capita 133 | nuts$gdp_hab_pot <- pot[, 2] / pot[, 1] 134 | # Exclude regions with No Data 135 | nuts$gdp_hab_pot[is.na(nuts$gdp_hab)] <- NA 136 | # Set breaks 137 | bv2 <- c(min(nuts$gdp_hab_pot, na.rm = TRUE), 138 | bv[2:8], 139 | max(nuts$gdp_hab_pot, na.rm = TRUE)) 140 | 141 | # Draw the basemap 142 | mf_init(nuts) 143 | mf_map(countries, col = "#f5f5f3ff", border = "#a9b3b4ff", add = TRUE) 144 | # Map the regional GDP per capita 145 | mf_map(x = nuts, var = "gdp_hab_pot", type = "choro", 146 | leg_pos = "topright", 147 | breaks = bv2, 148 | pal = pal, 149 | border = NA, 150 | leg_title = "Potential\nGDP per Capita\n(in euros, 2018)", 151 | leg_frame = TRUE, 152 | leg_val_rnd = -2, 153 | col_na = "grey60", 154 | add = TRUE) 155 | mf_map(countries[countries$ISO3_CODE == "ITA", ], 156 | col = NA, border = "#a9b3b4ff", add = TRUE) 157 | # Set a layout 158 | mf_arrow("topleft") 159 | mf_title(txt = "GDP per Capita Inequalities in Italy") 160 | mf_scale(100) 161 | mf_credits(txt = cred, bg = "#ffffff80") 162 | # Set a text to explicit the function parameters 163 | text(x = 4873429, y = 2258495, xpd = TRUE, 164 | labels = paste0("Distance function:\n", 165 | "- type = exponential\n", 166 | "- beta = 2\n", 167 | "- span = 100 km"), 168 | cex = 0.8, adj = 0, font = 3) 169 | ``` 170 | 171 | This map gives a smoothed picture of the spatial patterns of GDP per capita in Italy while keeping the original spatial units as interpretive framework. 172 | Hence, the map reader can still rely on a known territorial division to develop its analyses. 173 | 174 | 175 | ## Smoothed Map of the GDP per Capita 176 | 177 | In this case, the potential GDP per capita is computed on a regular grid. 178 | 179 | ```{r smoothmappot, fig.width=7, fig.height=9, fig.show='hold' } 180 | # Compute the potentials of population on a regular grid (10km resolution) 181 | g <- create_grid(x = nuts, res = 10000) 182 | d <- create_matrix(nuts_pt, g) 183 | # function = exponential, beta = 2, span = 75 km 184 | pot2 <- potential(x = nuts_pt, 185 | y = g, 186 | d = d, 187 | var = c("pop", "gdp"), 188 | fun = "e", 189 | beta = 2, 190 | span = 100000) 191 | # Create the ratio variable 192 | g$gdp_hab_pot <- pot2[, 2] / pot2[, 1] 193 | 194 | # Set breaks 195 | bv3 <- c(min(g$gdp_hab_pot, na.rm = TRUE), 196 | bv[2:8], 197 | max(g$gdp_hab_pot, na.rm = TRUE)) 198 | 199 | # Create an isopleth layer 200 | equipot <- equipotential(x = g, var = "gdp_hab_pot", breaks = bv3, 201 | mask = nuts[!is.na(nuts$gdp_hab),]) 202 | 203 | # Draw the basemap 204 | mf_init(nuts) 205 | mf_map(countries, col = "#f5f5f3ff", border = "#a9b3b4ff", add = TRUE) 206 | # Map the regional GDP per capita 207 | mf_map(x = equipot, var = "min", type = "choro", 208 | leg_pos = "topright", 209 | breaks = bv3, 210 | pal = pal, 211 | border = NA, 212 | leg_title = "Potential\nGDP per Capita\n(in euros, 2018)", 213 | leg_frame = TRUE, 214 | leg_val_rnd = -2, 215 | add = TRUE) 216 | mf_map(countries[countries$ISO3_CODE == "ITA", ], 217 | col = NA, border = "#a9b3b4ff", add = TRUE) 218 | # Set a layout 219 | mf_arrow("topleft") 220 | mf_title(txt = "GDP per Capita Inequalities in Italy") 221 | mf_scale(100) 222 | mf_credits(txt = cred, bg = "#ffffff80") 223 | # Set a text to explicit the function parameters 224 | text(x = 4873429, y = 2308495, xpd = TRUE, 225 | labels = paste0("Distance function:\n", 226 | "- type = exponential\n", 227 | "- beta = 2\n", 228 | "- span = 100 km"), 229 | cex = 0.8, adj = 0, font = 3) 230 | ``` 231 | 232 | Unlike the previous maps, this one doesn't keep the initial territorial division to give a smoothed picture of the spatial patterns of GDP per capita in Italy. 233 | The result is easy to read and can be considered as a bypassing of the Modifiable Areal Unit Problem (MAUP). 234 | --------------------------------------------------------------------------------