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.14.tar.gz (1.4 MB 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.14-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snapy-toolbox-0.2.14.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • 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.14.tar.gz
Algorithm Hash digest
SHA256 8bb88af93814ae7e00339dfc5cf4cfbeb5462365bf3d910ac2a65671f7b16523
MD5 06fd63157e0b60545e52b2952510307c
BLAKE2b-256 cbb4df126587199427677c2e07c61aa845d1c1a8e0aabbf3677e1b7e3c5fea1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: snapy_toolbox-0.2.14-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 66c475a5e38b0045606e682ffe3c40458100a6864b0831a299d9ab1ff43d195b
MD5 f0d4cd0d0aa8c93f64dbc00e24cdc03e
BLAKE2b-256 63691519be1f7a4c358e5a25310c151bc3d86a9225da1ff713a689d86028b9e0

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