{"id":15051486,"url":"https://github.com/jeremygelb/spnetwork","last_synced_at":"2025-10-09T00:50:21.887Z","repository":{"id":46656049,"uuid":"254388670","full_name":"JeremyGelb/spNetwork","owner":"JeremyGelb","description":"An R package to perform spatial analysis on networks.","archived":false,"fork":false,"pushed_at":"2025-10-04T22:42:12.000Z","size":227340,"stargazers_count":37,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T19:48:52.009Z","etag":null,"topics":["cran","kernel","kernel-density-estimation","network","network-analysis","r","r-package","rstats","spatial","spatial-analysis","spatial-data-analysis"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JeremyGelb.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-09T14:08:03.000Z","updated_at":"2025-10-04T22:42:17.000Z","dependencies_parsed_at":"2025-09-08T16:05:57.015Z","dependency_job_id":null,"html_url":"https://github.com/JeremyGelb/spNetwork","commit_stats":{"total_commits":215,"total_committers":4,"mean_commits":53.75,"dds":0.3023255813953488,"last_synced_commit":"3cf0ad5f79d584091699dce8c80b5d7011ba7206"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JeremyGelb/spNetwork","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyGelb%2FspNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyGelb%2FspNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyGelb%2FspNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyGelb%2FspNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JeremyGelb","download_url":"https://codeload.github.com/JeremyGelb/spNetwork/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JeremyGelb%2FspNetwork/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000643,"owners_count":26082879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cran","kernel","kernel-density-estimation","network","network-analysis","r","r-package","rstats","spatial","spatial-analysis","spatial-data-analysis"],"created_at":"2024-09-24T21:35:57.106Z","updated_at":"2025-10-09T00:50:21.869Z","avatar_url":"https://github.com/JeremyGelb.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: rmarkdown::github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  message = FALSE,\n  fig.path = \"man/figures/\",\n  out.width = \"100%\"\n)\nlibrary(badger)\n```\n\n# spNetwork \u003cimg src='man/figures/spNetwork_logo.png' align=\"right\" style = 'height:138px;'/\u003e\n## A R package to perform spatial analysis on networks.\n\n\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/JeremyGelb/spNetwork/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/JeremyGelb/spNetwork/actions/workflows/R-CMD-check.yaml)\n\n```{r echo=FALSE, results='asis'}\nversion \u003c- packageVersion(\"spNetwork\")\n\ncat(\n  paste0(\"[![](https://img.shields.io/badge/devel%20version-\",version,\"-green.svg)](https://jeremygelb.github.io/spNetwork/)\"),\n  badge_cran_release(color = \"blue\"),\n  badge_cran_download(color = \"blue\", type = \"grand-total\"),\n  badge_cran_download(\"spNetwork\", \"last-month\", \"green\")\n)\n```\n\n[![Codecov test coverage](https://codecov.io/gh/JeremyGelb/spNetwork/branch/master/graph/badge.svg)](https://app.codecov.io/gh/JeremyGelb/spNetwork?branch=master)\n\u003c!-- badges: end --\u003e\n\nThe package's website is available [here](https://jeremygelb.github.io/spNetwork/)\n\n## Breaking news\n\n\n### Removing spatial_index\n\nIn versions previous 0.4.4, we exported a class using c++ to do spatial indexing. It caused bugs on CRAN server and was removed because it was not significantly faster than `sf::st_join`.\n\n### Rework of the K functions\n\nWe reworked (version 0.4.4) the functions to calculate K functions on network: `kfunctions`,`kfunctions.mc`,`cross_kfunctions`,`cross_kfunctions.mc`,`k_nt_functions` and `k_nt_functions.mc`. We are still working on the spatio-temporal version of the cross K functions. Also, the current implementation of the G function is quite literal and we will try to replace it by a more interesting one using kernel density for estimation.\n\n### Changes in bandwidths selection functions\n\nThe version 0.4.4 has modifications in the arguments of the functions `bw_cvl_calc`, `bw_cvl_calc.mc`, `bw_cv_likelihood_calc`, `bw_cv_likelihood_calc`,`bw_tnkde_cv_likelihood_calc.mc`. The parameters about bandwidths range and step were replaced by a unique parameter requiring and **ordered** vector of bandwidths. Code from previous version need to be modified accordingly.\n\n### Using cppRouting\n\nA very interesting package has been published with `cppRouting`. It allows for extremely fast shortest path calculation on network. We are slowly integrating it in `spNetwork`. The changes are not visible for the users\n\n\n### Moving to sf\n\nConsidering that `rgeos` and `maptools` will be deprecated soon, we are moving to sf! This requires some adjustment in the code and the documentation. The development version and the releases on CRAN are now using `sf`. Please, report any bug or error in the documentation.\n\nTo install the previous version using `sp`, `rgeos` and `maptools`, you can run the following command:\n\n```{r eval=FALSE}\ndevtools::install_github(\"JeremyGelb/spNetwork\", ref = \"a3bc982\")\n```\n\nNote that all the new developments will use `sf` and you should switch as soon as possible.\n\n### Removing gpkgs\n\nBecause of a new CRAN policy, it is not possible anymore to read data in gpkg if they are stored in the user library. On Debian systems, this library is now mounted as read-only for checking. All the datasets provided by spNetwork are now stored as .rda file, and can be loaded with the function `data`.\n\n## What is this package ?\n\nThis package can be used to perform several types of analysis on geographical networks. This type of network have spatial coordinates associated with their nodes. They can be directed or undirected. In the actual development version the implemented methods are: \n\n* Network Kernel Density Estimate, a method estimating density of a point pattern constrained on a network (see the vignettes [Network Kernel Density Estimate](https://jeremygelb.github.io/spNetwork/articles/NKDE.html) and [Details about NKDE](https://jeremygelb.github.io/spNetwork/articles/NKDEdetailed.html)).\n* Temporal Network Kernel Density Estimate, a temporal extension of the previous methods [Temporal Network Kernel Density Estimate](https://jeremygelb.github.io/spNetwork/articles/TNKDE.html).\n* Spatial weight matrices based on network distances, which can be used in a great number of traditional methods in spatial analysis (see the vignette [Spatial Weight Matrices](https://jeremygelb.github.io/spNetwork/articles/SpatialWeightMatrices.html)).\n* Network k Functions, used to investigate the spatial distribution of a set of points on a network at several scales (see the vignette [Network k Functions](https://jeremygelb.github.io/spNetwork/articles/KNetworkFunctions.html)).\n* K nearest neighbours, to calculate for each point on a network its K nearest neighbour (see the function `network_knn`).\n* Graph analysis, using the functions of the package **igraph** (see the vignette [Building graphs](https://jeremygelb.github.io/spNetwork/articles/NetworkBuilding.html))\n* Isochrones, to delineate accessible area around points localized on a network (see the vignette [Calculating isochrones](https://jeremygelb.github.io/spNetwork/articles/Isochrones.html))\n\nCalculation on network can be long, efforts were made to reduce computation time by implementing several functions with **Rcpp** and **RcppArmadillo** and by using multiprocessing when possible. \n\n## Installing\n\nyou can install the CRAN version of this package with the following code in R.\n\n\n```{r eval=FALSE}\ninstall.packages(\"spNetwork\")\n```\n\nTo use all the new features before they are available in the CRAN version, you can download the development version.\n\n```{r eval=FALSE}\ndevtools::install_github(\"JeremyGelb/spNetwork\")\n```\n\nThe packages uses mainly the following packages in its internal structure :\n\n* igraph\n* sf\n* future\n* future.apply\n* data.table\n* Rcpp\n* RcppArmadillo\n* BH\n\n## Some examples\n\nWe provide here some short examples of several features. Please, check the vignettes for more details.\n\n* realizing a kernel network density estimate\n\n```{r warning=FALSE, message=FALSE}\nlibrary(spNetwork)\nlibrary(tmap)\nlibrary(sf)\n\n# loading the dataset\ndata(mtl_network)\ndata(bike_accidents)\n\n\n# generating sampling points at the middle of lixels\nsamples \u003c- lines_points_along(mtl_network, 50)\n\n# calculating densities\ndensities \u003c- nkde(lines = mtl_network,\n                 events = bike_accidents,\n                 w = rep(1,nrow(bike_accidents)),\n                 samples = samples,\n                 kernel_name = \"quartic\",\n                 bw = 300, div= \"bw\",\n                 method = \"discontinuous\",\n                 digits = 2, tol =  0.1,\n                 grid_shape = c(1,1),\n                 max_depth = 8,\n                 agg = 5, sparse = TRUE,\n                 verbose = FALSE)\n\ndensities \u003c- densities*1000\nsamples$density \u003c- densities\n\ntm_shape(samples) + \n  tm_dots(col = \"density\", size = 0.05, palette = \"viridis\",\n          n = 7, style = \"kmeans\")\n\n```\n\nAn extension for spatio-temporal dataset is also available [Temporal Network Kernel Density Estimate](https://jeremygelb.github.io/spNetwork/articles/TNKDE.html)\n\n```{r echo=FALSE, fig.align='center', message=FALSE, warning=FALSE, out.width=\"75%\"}\nknitr::include_graphics(\"vignettes/images/animated_map.gif\")\n```\n\n* Building a spatial matrix based on network distance\n\n```{r eval = TRUE, warning = FALSE, message=FALSE}\nlibrary(spdep)\n\n# creating a spatial weight matrix for the accidents\nlistw \u003c- network_listw(bike_accidents,\n                       mtl_network,\n                       mindist = 10,\n                       maxdistance = 400,\n                       dist_func = \"squared inverse\",\n                       line_weight = 'length',\n                       matrice_type = 'W',\n                       grid_shape = c(1,1),\n                       verbose=FALSE)\n\n# using the matrix to find isolated accidents (more than 500m)\nno_link \u003c- sapply(listw$neighbours, function(n){\n  if(sum(n) == 0){\n    return(TRUE)\n  }else{\n    return(FALSE)\n  }\n})\n\nbike_accidents$isolated \u003c- as.factor(ifelse(no_link,\n                                  \"isolated\",\"not isolated\"))\n\ntm_shape(mtl_network) + \n  tm_lines(col = \"black\") +\n  tm_shape(bike_accidents) + \n  tm_dots(col = \"isolated\", size = 0.1,\n          palette = c(\"isolated\" = \"red\",\"not isolated\" = \"blue\"))\n\n```\n\nNote 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\n\n* Calculating k function\n\n```{r eval = TRUE, warning = FALSE, message=FALSE}\n# loading the data\ndata(main_network_mtl)\ndata(mtl_theatres)\n\n# calculating the k function\nkfun_theatre \u003c- kfunctions(main_network_mtl, mtl_theatres,\n                           start = 0, end = 5000, step = 50, \n                           width = 1000, nsim = 50, resolution = 50,\n                           verbose = FALSE, conf_int = 0.05)\nkfun_theatre$plotg\n\n```\n\n\n### Work in progress\n\nNew methods will be probably added in the future, but we will focus on performance for the next release. Do no hesitate to open an issue [here](https://github.com/JeremyGelb/spNetwork/issues) if you have suggestion or if you encounter a bug.\n\nFeatures that will be added to the package in the future: \n\n* temporal NKDE, a two dimensional kernel density estimation in network space and time\n* rework for using `sf` objects rather than `sp` (`rgeos` and `maptools` will be deprecated in 2023). This work is undergoing, please report any bug or error in the new documentation.\n\n## Reporting a bug\n\nIf you encounter a bug when using spNetwork, please open an *issue* [here](https://github.com/JeremyGelb/spNetwork/issues). To ensure that the problem is quickly identified, the issue should follow the following guidelines: \n\n1. Provide an informative title and do not copy-paste the error message as the title.\n2. Provide the ALL code which lead to the bug.\n3. Indicate the version of R and spNetwork.\n4. If possible, provide a sample of data and a reproductible example.\n\n## Authors\n\n* **Jeremy Gelb** - *Creator and maintainer*\n\n## Contribute\n\nTo contribute to `spNetwork`, please follow these [guidelines](https://github.com/JeremyGelb/spNetwork/blob/master/CONTRIBUTING.md).\n\nPlease note that the `spNetwork` project is released with a [Contributor Code of Conduct](https://github.com/JeremyGelb/spNetwork/blob/master/CONDUCT.md). By contributing to this project, you agree to abide by its terms.\n\n## Citation\n\nAn article presenting `spNetwork` and NKDE has been accepted in the RJournal!\n\nGelb Jérémy (2021). spNetwork, a package for network kernel density estimation. The R Journal. https://journal.r-project.org/archive/2021/RJ-2021-102/index.html.\n\nYou can also cite the package for other methods:\n\nGelb Jérémy (2021). spNetwork: Spatial Analysis on Network. https://jeremygelb.github.io/spNetwork/.\n\n## License\n\n`spNetwork` is licensed under [GPL2 License](https://github.com/JeremyGelb/spNetwork/blob/master/LICENSE.txt).\n\n## Acknowledgments\n\n* Hat tip to Philippe Apparicio for his support during the development\n* Hat tip to Hadley Wickham and his helpful book *R packages*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremygelb%2Fspnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeremygelb%2Fspnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeremygelb%2Fspnetwork/lists"}