Converting a spatial network to a graph Converting a spatial network

Converting a spatial network to a graph Converting
a spatial network to a graph
in R
Binbin Lu, Martin Charlton
National Centre for Geocomputation
National University of Ireland Maynooth
Maynooth, Co.Kildare, Ireland
Maynooth, Co.Kildare, Ireland
The R User Conference 2011
Contents
Motivation
Key points in the conversion
Key points in the conversion
R package “shp2graph”
Future work
Motivation Motivation
How should I get all the
shortest
h t t paths
th between
b t
any pair of points?
SANNET
pgRouting
……
Coding with Dijkstra
algorithm
g
But
I am an R user and
I am “lazy”
Search in R packages
Search in R packages…
maptools
graph
sp
igraph
RBGL
sp between()
sp.between()
Shape file
shortest.paths()
Solution: Converting a spatial network to a graph object
Key points for this conversion:
Key points for this conversion:
Modelling Road network with graph data model
Attribute heritage
g
Topology
Structure optimization
Integration of points into network
Graph data model
Graph data model
Edge
g ((Arc))
Node ((Vertex))
Node list
Edge list
NodeID1
NodeID2
…
ID
X
Y
…
Graph data model:
ID1
ID2
...

IDn
Matrix
A kind of data model to abstract away
 IDn
ID1 ID2 ...
geographical details and represent a
 0 or 1

aij   Edgelength



...
network as a graph, that is, as a finite
set of points called nodes (i.e. vertices)
and relations between these points
called
ll d edges
d
(i arcs).
(i.e.
)
Attributes inheritance and translation
Attributes inheritance and translation
• Geometry
 Spatial coordinates of nodes • Attributes




IDs of nodes and edges;
IDs
of nodes and edges;
Lengths of edges;
Orientation of edges
Orientation of edges
……
Topology errors
(a) Dangling arc
(c) Overshoot
(b) Undershoot
(d) Missing intersection
Connectivity Problem
Connectivity Problem
Solutions to correct topology errors
Solutions to correct topology errors
GIS software
Topology correction tools/functions
ArcGIS ArcInfo
Extend Polyline Tool, Intersect Polylines Tool, Remove Redundant Nodes
Tool and Clean Dangles Tool in ET Geo‐tools
Clean Polyline, Clean Dangling Nodes, Split Polylines(With a Layer) in ET
Geo Wizards
Clean {Coverage}, Validate Entire Topology tool, Fix Topology Error tool
GRASS
Cleaning
l
i tools
l in
i v.clean
l
Toolset:
l
b k rmdangle,
break,
d
l snap
AutoCAD Map
Creating a network topology, Editing Topologies
Over correction
Structure Optimization
Structure Optimization
2
3
4
1
2
14
13
12
11
9
10
8
15
16
17
7
18
5
6
Pseudo-node
Multiple-edge
Self-loop
Test on Ontario Road Network data
Test on Ontario Road Network data
Test on Ontario Road Network data
Test on Ontario Road Network data
Comparison between original ORN and optimized graph
Data
Number of nodes
Number of edges
Original vector data
37178
48765
Optimized graph
25928
11250
30%
36375
12300
25%
Integration of point data into network
Integration of point data into network
Two guidelines:
1 Find a representative node
1.
for each point
2. Add a new edge to
connect each point with
the network
i. M
Mapping each poiint to
the nea
arest node
e
ii. M
Mapping e
each Poin
nt to
the nearrest pointt
iiii. Add a new edg
ge betwee
en each
point and the nearest
n
n
node
iv. Add a new ed
dge betw
ween each
nt and the
e nearesst point
poin
Edge Reconstruction
Edge Reconstruction
Edge split
Functions for recalculating attributes
 New _ ai  A


li
New
_
a

A
i

L
Edge merge
 New _ a  max  Ai 

 New _ a  min  Ai 

 New _ a  sum  Ai 
 New _ a  mean A
 i

R package “shp2graph”
p
g
p g p
R package “shp2graph”
p
g
p g p
After conversion you can
After conversion, you can…
• compute the shortest paths
• visualize the graph with igraph, shp2graph,
pajek
• do
d networkk analysis
l i with
i h various
i
ki d off
kinds
methods available in graph, igraph, RBGL, etc
• ……
Future work
Future work
I was an R beginner when I started to develop
package,
g so… I make lots of mistakes!
this p
• Awkward parameter settings in functions
• Poor coding style
Topology correction functions will be developed
in the near future.
future
I will keep working on this, and welcome any , gg
contribution, suggestions or comments.
Acknowledgments
• To Centre for Research into Statistical Methodology
(CRISM) for funding me to attend this conference.
• Research presented in this paper is jointly funded by
a Strategic Research Cluster grant (07/SRC/I1168) by
Science Foundation Ireland under the National
Development Plan and China Scholarship Council
(CSC).
Any comments or questions?