Learn R Programming

⚠️There's a newer version (0.4.4.6) of this package.Take me there.

spNetwork

A R package to perform spatial analysis on networks.

Getting Started

A good start point for this package is the vignettes. They present the main features of the package

Installing

you can install this package with the following code in R. The packages use mainly the following packages in its internal structure :

  • igraph
  • sp
  • rgeos
  • maptools
  • raster
  • future
  • future.apply
  • dplyr
  • tidyR
  • Rcpp
  • RcppArmadillo
devtools::install_github("JeremyGelb/spNetwork")

Examples

We provide here some short examples of the main features

  • realizing a kernel network density estimate
library(spNetwork)
data(mtl_network)
data(bike_accidents)
lixels <- lixelize_lines(mtl_network,200,mindist = 50)
samples <- lines_center(lixels)
densities <- nkde(mtl_network,
                 events = bike_accidents,
                 w = rep(1,nrow(bike_accidents)),
                 samples = samples,
                 kernel_name = "quartic",
                 bw = 300, div= "bw",
                 method = "discontinuous", digits = 1, tol = 1,
                 grid_shape = c(1,1),
                 verbose=FALSE)
  • Building a spatial matrix based on network distance and use it to calculate the Moran I with spdep.
library(spNetwork)
library(spdep)
data(mtl_network)

conv_function <- function(x){
  if(x<=500){
    return(1/x**2)
  }else{
    return(0)
  }
}

listw <- line_ext_listw_gridded(mtl_network,maxdistance=500,
       dist_func = conv_function, matrice_type='W',
       grid_shape = c(5,5),
       mindist = 10)

moran.test(mtl_network$nbAccident,listw, zero.policy = T)

Note that you can use this in every spatial analysis you would like to perform. With the converter function of spdep (like listw2mat), you can convert the listw object into regular matrix if needed

Work in progress

Currently, functions to calculate K-function and cross-K-function for sets of points are available but still experimental.

Authors

  • Jeremy Gelb - Creator and maintainer

License

This project is licensed under the GPL2 License

Acknowledgments

  • Hat tip to Philippe Apparicio for its support during the development
  • Hat tip to Hadley Wickham and its helpful book R packages

Copy Link

Version

Install

install.packages('spNetwork')

Monthly Downloads

559

Version

0.1.1

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Jeremy Gelb

Last Published

January 21st, 2021

Functions in spNetwork (0.1.1)

build_graph_directed

Directed network generation
build_grid

Spatial grid
adaptive_bw

Adaptive bandwidth
add_vertices_lines

Add vertices to a SpatialLinesDataFrame
adaptive_bw.mc

Adaptive bandwidth (multicore)
add_vertices

Add vertices to a single line
build_graph

Network generation
aggregate_points

Events aggregation
closest_points

Find closest points
add_center_lines

Add center vertex to lines
continuousWorker_int

The worker function to calculate continuous NKDE (with ARMADILLO and Integer matrix)
add_center_lines.mc

Add center vertex to lines (multicore)
graph_checking

Topological error
corrfactor_discontinuous

A function to calculate the necessary informations to apply the Diggle correction factor with a discontinuous method
corrfactor_continuous_sparse

A function to calculate the necessary information to apply the Diggle correction factor with a continuous method (sparse)
gm_mean

Geometric mean
cosine_kernel

Cosine kernel
gaussian_kernel_scaled

Scaled gaussian kernel
kfunctions.mc

Network k and g functions (multicore, experimental)
build_quadtree

Build a quadtree
gfunc

Base g-function
cross_gfun

Base cross g-function
correction_factor

Border correction for NKDE
prepare_data

Prior data preparation
continuousWorker_sparse

The worker function to calculate continuous NKDE (with ARMADILLO and sparse matrix)
continuousfunction

The main function to calculate continuous NKDE (with ARMADILO and sparse matrix)
corrfactor_discontinuous_sparse

A function to calculate the necessary information to apply the Diggle correction factor with a discontinuous method (sparse)
plot_graph

Plot graph
lines_center

Center points of lines
network_listw

Network distance listw
network_listw.mc

Network distance listw (multicore)
split_border

Split boundary of polygon
cross_kfunctions.mc

Network cross k and g functions (multicore, experimental)
calc_gamma

Gamma parameter for Abramson<U+2019>s adaptive bandwidth
discontinuousWorker_int

The worker function to calculate discontinuous NKDE (with ARMADILLO and Integer matrix)
direct_lines

Make a network directed
discontinuousWorker_sparse

The worker function to calculate discontinuous NKDE (with ARMADILLO and sparse matrix)
corrfactor_simple

Simple NKDE border correction
lixelize_lines.mc

Cut lines into lixels (multicore)
discontinuousfunction

The main function to calculate discontinuous NKDE (ARMA and sparse matrix)
kfunctions

Network k and g functions (experimental)
kfunc

Base k-function
corrfactor_continuous

A function to calculate the necessary information to apply the Diggle correction factor with a continuous method
clean_events

Clean events geometries
nearest

Nearest feature
dist_mat_dupl

Distance matrix with dupicated
check_geometries

Geometry sanity check
epanechnikov_kernel

Epanechnikov kernel
cross_kfunc

Base cross k-function
nkde.mc

Network Kernel density estimate (multicore)
split_by_grid

Split data with a grid
nkde_worker

NKDE worker
remove_loop_lines

Remove loops
cross_kfunctions

Network cross k and g functions (experimental)
gaussian_kernel

Gaussian kernel
ess_kernel

Worker for simple NKDE algorithm
find_vertices

Match nodes and points
lines_points_along

Points along lines
lixelize_lines

Cut lines into lixels
network_listw_worker

network_listw worker
nkde

Network Kernel density estimate
quartic_kernel

Quartic kernel
prepare_elements_netlistw

Data preparation for network_listw
select_dist_function

Select the distance to weight function
triweight_kernel

Triweight kernel
randomize_distmatrix2

Points on network randomization simplified
randomize_distmatrix

Points on network randomization
split_by_grid_abw

Split data with a grid for the adaptive bw function
split_by_grid.mc

Split data with a grid (multicore)
spatial_request

Spatial request
sp_char_index

Coordinates to unique character vector
snapPointsToLines2

Snap points to lines
uniform_kernel

Uniform kernel
simple_nkde

Simple NKDE algorithm
lines_direction

Unify lines direction
lines_extremities

Get lines extremities
nearestPointOnLine

Nearest point on Line
nearestPointOnSegment

Nearest point on segment
simple_lines

LineString to simple Line
select_kernel

Select kernel function
split_by_grid_abw.mc

Split data with a grid for the adaptive bw function (multicore)
surrounding_points

Points along polygon boundary
triangle_kernel

triangle kernel
tricube_kernel

Tricube kernel