-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPotentials_script.R
96 lines (69 loc) · 3.7 KB
/
Potentials_script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#' Stewart's Potentials
#'
#' Compute and plot Stewart's Potentials
#'
#' This function compute the potentials of spatial interaction as defined by J.Q. Stewart (1950) and plot the results.
#' It provides two kinds of outputs: a data.frame or a raster map (ggplot) representing potentials of interaction.
#'
#' @param knownpts, object of class sp (SpatialPointsDataFrame or SpatialPolygonsDataFrame).
#' @param mask, object of class sp (SpatialPolygonsDataFrame) to clip the final map of potentials.
#' @param opportgrid, output of the PointOpport() function. This object is a list containing a grid of unknown points,
#' a matrix of opportunities and a projection.
#' @param varname CHARACTER, name of the variable (in the attribute table) from which potentials are computed.
#' Quantitative variable with no negative values.
#' @param typedist CHARACTER, type of distance. Options are "euclidean" (default) or "orthodromic".
#' If the distance is euclidean, X and Y coordinates are expected. If orthodromic longitud and latitud are expected
#' in decimal degrees, in WGS84 reference system.)
#' @param typefct CHARACTER, spatial interaction function. Options are "pareto" (default) or "exponential".
#' If "pareto" the interaction is defined as: (1 + alpha * mDistance) ^ (-beta).
#' If "exponential" the interaction is defined as: exp(- alpha * mDistance ^ beta).
#' The alpha parameter is computed from parameters given by the user (beta and reach).
#' @param beta NUMERIC, impedance factor for the spatial interaction function.
#' @param span NUMERIC, distance where the density of probability of the spatial interaction function equals 0.5.
#' @param nbclass INTEGER, number of classes for the cartographic representation.
#' @param resolution INTEGER, resolution of the grid for raster representation.
#' @references Stewart J. Q., Demographic gravitation: evidence and applications, Sociometry, 11(1-2), 31-58.
# load packages ----
library(sp)
library(rgdal)
library(rgeos)
library(raster)
library(fields)
library(RColorBrewer)
# load functions ----
source("Potentials_functions.R")
# load data ----
spatPts <- readOGR(dsn = "DATA/parispc_pts.shp", layer = "parispc_pts", stringsAsFactors = FALSE)
spatUnits <- readOGR(dsn = "DATA/parispc_com.shp", layer = "parispc_com", stringsAsFactors = FALSE)
spatMask <- readOGR(dsn = "DATA/parispc_mask.shp", layer = "parispc_mask", stringsAsFactors = FALSE)
plot(spatMask)
plot(spatUnits)
plot(spatPts, pch = 20, add = T)
spatPts$POPULATION
# compute opportunities ----
opportunities <- PointsOpport(knownpts = spatPts,
varname = "POPULATION",
span = 1000,
beta = 2,
mask = spatMask,
resolution = 400)
# compute potentials ----
potentials <- OpportPotentials(opportgrid = opportunities,
nbclass = 8,
mask = spatMask)
# plot potentials ----
plot(potentials, col = plyr::mapvalues(potentials$layer,
from = potentials$layer,
to = brewer.pal(n = 8, name = "Reds")))
# compute Reilly catchment zones ----
reillyRast <- ComputeReilly(unknownpts = opportunities$UNKWPTS,
matopport = opportunities$OPPORT,
mask = spatMask,
myproj = opportunities$PROJ)
plot(reillyRast)
# compute Huff catchment zones ----
huffRast <- ComputeHuff(unknownpts = opportunities$UNKWPTS,
matopport = opportunities$OPPORT,
mask = spatMask,
myproj = opportunities$PROJ)
plot(huffRast)