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.13.tar.gz (832.3 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.13-py3-none-any.whl (859.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snapy-toolbox-0.2.13.tar.gz
  • Upload date:
  • Size: 832.3 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.13.tar.gz
Algorithm Hash digest
SHA256 616e6b1cae814d15d078b2408e149d76f5484d920f7895e7e98b3d6ce0db7f1a
MD5 f7749ad00061f3de65b16eca21503f3c
BLAKE2b-256 c51d8ff8a74d44fb40eec10a3503c718932e5556ecabec3ea9bcb4c9233bab13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: snapy_toolbox-0.2.13-py3-none-any.whl
  • Upload date:
  • Size: 859.0 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 e55478f05d050e7dd5a044fd945898ce41b8d1f8cf856674d15b95f01bc456bb
MD5 5986e57084d2b7232c41cea1084f9e21
BLAKE2b-256 c05b795e46a4f3357d5b5352c514d3a905a2f861a69479745683deb26a98c5de

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