Skip to main content

Spatial Network Analysis Python Module

Project description

SNAPy (Spatial Network Analysis Python Module)

A package of spatial network analysis tools based on Geopandas dataframe and networkx pathfinding. Developed for regional scale spatial network analysis in Python environment for efficiency and better documentation. With capabilities of multithreading using multiprocessing.pool. Most functions and tools are based from Urban Network Analysis Toolbox by MIT City Form Lab, but there are some (Reach, Betweeness Patronage) that have different mathematical expression which is elaborated on the documentation in this repository.

Documentation can be accesed with this link

Authorship

made by kevinsutjijadi @2023 Jakarta, Indonesia
Last updated at 2023/09/18

Installation

Module haven't been added to Pypi. installation by running package installation locally through clone or download the repository.

Requirements

  • pandas >= 1.5.2
  • geopandas >= 0.9.0
  • networkx >= 2.7.1
  • scipy >= 1.10.0
  • numpy >= 1.24.1
  • shapely >= 2.0.0

How to Use

As Spatial Network Analysis is a derivative development of the Social Science Network Analysis, the conceptualization of the network is adjusted where in the object, path network as the medium is supplemented by end nodes that represents buildings, activity points, or Point of interest of the movement. Note that the polygon data of the network pathway is required to be segmented at each intersection, with maximum inaccuracy tollarance of 1e-3 on junctions, further than that distance will not be detected as a junction. Entrance data are not required to be located on the network lines, as there are built in functions to map entrance points into the network. Per Function documentation can be accessed in Documentation Most analysis tools included will require a network, consisting of polygon geometry pathway networks, and point geometry entrances in any GIS format readable by geopandas. Some testdata is provided in this repository, which contains a part of Jakarta's network line obtained by OSM API, as the following:

to use library, load data into geopandas geodataframe format, and use Graphsims to load the network information. It will compile and also append how the entrances connect to the network data.

import geopandas as gpd
import SNAPy as sna

dfNetwork = gpd.read_file('NetworkClean.shp') # network dataframe
dfEntries = gpd.read_file('Features.gpkg', layer='Features') # entrance dataframe

nwSim = sna.GraphSims(dfNetwork, dfEntries) # main class for loading network data

to save the projected entries data, or access both network data or entrance data, both dataframes can be called and used as a normal Geopandas geodataframe

nwSim.EntriesDf.to_file("file.gpkg", layer="entries", driver="GPKG", crs="EPSG:32748") # saving entries dataframe
nwSim.NetworkDf.to_file("file.gpkg", layer="network", driver="GPKG", crs="EPSG:32748") # saving network dataframe

Example analysis and result of the betweenness Patronage

nwSim.BetweenessPatronage(OriWgt='Capacity', DestWgt='Weight', DetourR=1.2, SearchDist=1200, AlphaExp=0.1, RsltAttr='BtwnP')

with the resulting nwSim.Gdf (can be displayed directly in conjunction with folium) as displayed below

Performance is designed to be RAM efficient, and more faster and reliable than former counterparts, but undeniably there are still a lot of room for development and streamlining process. Current build spends 90% to 99% (on larger networks) of runtime within the networkx functions; Such as has_path, shortest_path, and path iterators. Upon trial, using all cores of multithreading, process can be 2-10x faster than UNA Toolbox on Rhino and ArcGIS with the cost of multiple cores used. However single threading is slower. for example the following simulation of betweenness patronage of 279 origins and destinations permutaion, with search distance of 1200m and 1.2 detour ratio took 3'14" of multithread process on a i7-13700K without overclocking. Multiple paths may also cause significant time cost, as the same input with 1.0 detour ratio took only 9" to complete (21x faster).

References

  • Sevtsuk, A., & Mekonnen, M. (2012). Urban Network Analysis Toolbox. International Journal of Geomatics and Spatial Analysis, 22(2), 287–305.
  • Sevtsuk, A. (2014). Networks of the built environment. In D. Ofenhuber & C. Ratti (Eds.), Decoding the City: Urbanism in the Age of Big Data (p. 192). Birkhäuser.
  • Barrat, A., et al. (2004) The architecture of complex weighted networks
  • Haggett, P., & Chorley, J. C. (1969) Network Analysis in Geography. London: Butler & Tanner Ltd.
  • Freeman, Linton (1977) A set of measures of centrality based on betweenness, Sociometry.
  • Sevtsuk, A (2010) Path and Place: A Study of Urban Geometry and Retail Activity in Cambridge and Somerville, MA.
  • Dijkstra, E W (1959) A note on two problems in connexion with graphs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snapy-toolbox-0.2.11.tar.gz (677.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snapy_toolbox-0.2.11-py3-none-any.whl (700.8 kB view details)

Uploaded Python 3

File details

Details for the file snapy-toolbox-0.2.11.tar.gz.

File metadata

  • Download URL: snapy-toolbox-0.2.11.tar.gz
  • Upload date:
  • Size: 677.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for snapy-toolbox-0.2.11.tar.gz
Algorithm Hash digest
SHA256 51377a78ea4ca92b83f8073e5fb3aec44b39ec8a40cf6e15a9a564a9e0922095
MD5 6be7a34a418b599c221cc3517a300fb9
BLAKE2b-256 6b9ca8850715af55fa0252173903aa64593e96d08d2ba084afa1d4d3000b23b4

See more details on using hashes here.

File details

Details for the file snapy_toolbox-0.2.11-py3-none-any.whl.

File metadata

  • Download URL: snapy_toolbox-0.2.11-py3-none-any.whl
  • Upload date:
  • Size: 700.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for snapy_toolbox-0.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 fc6bb2cf557f18bac7e578a6028fb67738623b7ba6b0a4d6c966a415eddb0aff
MD5 472bd4d41fc26c9ece65636f8632b464
BLAKE2b-256 5decf59492d90d55bda866a9b76c462283ca78f6403879d5065118e22da17320

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page