16
pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

Embed Size (px)

Citation preview

Page 1: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

pgRouting with the ITN and OpenRoads Official

PGROUTING WITH THE ITN AND OS

OPENROADS Ian Bennett

GI Consultant May 2016

Page 2: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

INTRODUCTION

•  Demonstrate how to load OS OpenRoads into PostGreSQL and create a network using pgRouting.

•  This will include: •  Ordnance Survey network data sets •  Options for data loading •  Adding indexes and keys to improve performance •  Setting up the network data set •  Building the network •  Using the network in QGIS •  Examples •  Resources

pgRouting with the ITN and OpenRoads Official

Page 3: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

WHAT IS ROUTING?

The choice of roads taken to get to a place. That choice can get pretty complicated though!

•  Mode of transport •  Roadworks/diversions •  Time of day •  Road speeds •  Via points

Official pgRouting with the ITN and OpenRoads

Page 4: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

ORDNANCE SURVEY NETWORK DATA SETS OS MasterMap ITN Layer OS MasterMap Highways – ITN and NSG combined OS OpenRoads – Generalised Geometry but no routing information OS MasterMap Water Network and OS Open Water

pgRouting with the ITN and OpenRoads Official

Page 5: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

WHY PGROUTING?

•  Number of tools for network applications •  pgRouting is an extension to PostGreSQL •  OpenSource •  Gives user control of the network

pgRouting with the ITN and OpenRoads Official

Page 6: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

AND THE CON’S..

•  Building the network can take some time, (although once you’ve written the code once, you can just leave it as a standard process over a weekend)

•  Limited documentation and support

•  Doesn’t hook up to any kind of LIVE traffic info, its purely an offline routing tool

•  •  Won’t work on mobile devices, although the routes it creates can be

converted to gpx for satnavs using QGIS

•  Can be a bit tricky to get to grips with - a user group it might work out better

Page 7: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

OPTIONS FOR DATA LOADING

1.  GML – easiest to use Astun Loader from GitHub https://github.com/AstunTechnology/Loader 2. Setup a loader file 3. Alternative for OpenRoads is to use the PostGIS shape file loader

Remember to set the projection (27700 for BNG) and schema

pgRouting with the ITN and OpenRoads Official

Page 8: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

IMPROVING PERFORMANCE

1.  If not already present add unique id to each table as SERIAL 2.  Indexes

•  Shapefile loader will create spatial indexes however with the Astun loader you will need to create these

•  CREATE INDEX road_geom_idx ON openroads.road USING gist (geom); •  Add index for the column containing unique ids •  CREATE INDEX rlink_fid_idx ON openroads.roadlink USING btree (fid);

3.  Primary Keys Add these for each of the column containing unique id ALTER TABLE openroads.motorwayjunction ADD CONSTRAINT mjunc_id_pk PRIMARY KEY("ard-id"); ALTER TABLE openroads.roadlink ADD CONSTRAINT rlink_fid_pk PRIMARY KEY(fid); ALTER TABLE openroads.roadnode ADD CONSTRAINT rnode_fid_pk PRIMARY KEY(fid);

Official pgRouting with the ITN and OpenRoads

Page 9: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

SETTING UP THE NETWORK DATA

For use in pgRouting you will need to add the following columns to the table containing the road links •  source (integer) – Contains the value of the start node for each link •  target (integer) - Contains the value of the end node for each link •  cost (double precision) – Cost value for traversing along the link •  rcost (double precision) – Reverse cost value for traversing along the link

Official pgRouting with the ITN and OpenRoads

Page 10: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

BUILDING THE NETWORK

Either de-duplicate the data and use built in functions which creates a node table or Populate the source and target fields with the unique ID of each road node. As the ids in the table are text values an integer must be created for each, however the unique id added to the data can be used.

•  UPDATE openroads.road SET source = n.gid FROM openroads.roadnode n WHERE openroads.road.startnode = n.identifier;

Then calculate cost values, these can simply be the length of the link or based on rad class.

•  UPDATE openroads.roadlink SET cost = Length;

Official pgRouting with the ITN and OpenRoads

Page 11: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

USING THE NETWORK IN QGIS

Add the pgRouting Layer Plugin to QGIS In the dialog set edge_table = schema.roadtable geometry = name of geometry column (geom) id = road table unique id source = source target = target cost = cost reverse_cost = rcost Check the has_reverse_cost box

pgRouting with the ITN and OpenRoads Official

Page 12: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

GOING FURTHER

•  Using OS MasterMap ITN Layer (or Highways) •  One Ways •  Restrictions •  Handling grade separation

pgRouting with the ITN and OpenRoads

Official

Page 13: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

EXAMPLES

Official pgRouting with the ITN and OpenRoads

Page 14: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

ACCESS TO SERVICES

Ross McDonald – Angus Council •  Mapped Location of Defibrillators (AED) •  Created drive times •  Combined to generate catchment areas •  Create custom function using Alpha shape and driving distance

Official pgRouting with the ITN and OpenRoads

Page 15: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

ROUTES TO SCHOOL Steven Gardiner – City and County of Swansea Cut down time spent verifying school walking routes Used pgr_trsp as it returns lengths and allows start mid section of a link

Official pgRouting with the ITN and OpenRoads

Pgr_driving_distances used to create walking distance isochrones

Page 16: PGROUTING WITH THE ITN AND OS OPENROADS - … · pgRouting with the ITN and OpenRoads Official PGROUTING WITH THE ITN AND OS OPENROADS Ian Bennett GI Consultant May 2016

RESOURCES

For creating a more detailed network https://github.com/AstunTechnology/Loader/tree/master/extras/ordnancesurvey/osopen/roads http://www.slideshare.net/RossMcDonald1/ross-mc-donaldpgroutinginqgis Forum - https://www.ordnancesurvey.co.uk/forums/categories/public-sector Webinar - https://www.youtube.com/watch?v=WBUpBXeDJVc&feature=youtu.be pgRouting website - http://pgrouting.org/index.html

Official pgRouting with the ITN and OpenRoads