v0.10
This library provides tools to generate and examine spatial graphs, i.e. graphs that are embedded into space. It includes a reference implementation of the Scale-Invariant Spatial Graph (SISG) Model. In addition to spatial graphs, the generation of some non-spatial graph models is supported.
The functionality is, in parts, based on research conducted by the author. In particular, the definition of the Scale-Invariant Spatial Graph Model is contained in the following paper:
Franz-Benjamin Mocnik, Andrew U. Frank: Modelling Spatial Structures
Proceedings of the 12th Conference on Spatial Information Theory (COSIT), 2015
You find more information on http://www.mocnik-science.net
A demo of the functionality can be found at: http://projects.mocnik-science.net/spatial-graphs
The library can be used online in a browser or by node.js.
A new graph can be created as an instance of Graph
:
var g = new Graph();
This graph can be modified by executing operations on the graph. These operations return the graph, allowing to execute some operations in a row. For example, we can write:
g.addNodesRandom(100, [51, 52], [0, 8]).addEdgesSISGModel(1.5);
The functions getNodes
and getEdges
return the nodes resp. the edges of the graph:
g.getNodes();
g.getEdges();
You can add nodes to the graph by using the function addNodes
:
g.addNodes([{coordinates: [52, 8]}, {coordinates: [51, 0]}])
The nodes are assumed to be objects containing the key coordinates
with associated value a list consisting of the values for the latitude and longitude.
The edges can be removed from the graph by writing:
g.clearEdges();
The nodes and edges can be removed by writing:
g.clearGraph();
You can ensure that the nodes and edges are unique by executing the functions nubNodes
and nubEdges
; double nodes and edges are removed.
g.nubNodes();
g.nubEdges();
Many edge generation algorithms of this library remove double edges automatically.
You can add n
random nodes with latitude and longitude in given intervals like follows:
g.addNodesRandom(n, latInterval, lonInterval);
The intervals are of the form [a, b]
.
You can load points from a GeoJSON file into the graph:
g.addNodesGeoJSON(JSON.parse(...));
In a similar way, you can load data from a CSV file into the graph:
g.addNodesGeoCSV(...);
The first column of the file is assumed to contain the latitude, the second one the longitude. If a third column is provided, it is assumed to contain a label for the node.
Edges can be added to a graph according to the SISG model (see literature) using the function addEdgesSISGModel
. It assumes that the graph already contains a number of nodes. The density parameter k
is given as the only parameter:
g.addEdgesSISGModel(k);
Edges can be added according to the Gilbert model with given probability p
as follows:
g.addEdgesGilbert(p);
The graph can be exported in the CSV format (comma-separated values) as well as in the TGF format (trivial graph format). A string containing the data is returned.
g.csv();
g.tgf();
Copyright (c) 2015 by Franz-Benjamin Mocnik
The library is free to use for non-commercial projects.
Copys of the library must always contain this license.