2

Using pgRouting I wish to run an analysis from a location's nearest point on the network. This question seems to have been asked and discussed in several locations on the web including here and in the comments sections by Daniel Kastl here but I cannot find an actual written, implementable solution.

I understand that I need to:

  1. locate the point on the closest edge in the network and

  2. split the edge to create a node to run the analysis from

but I do not know how to implement this. Can I do this on the fly with an already built network? If so, could I have the implementable code?

2
  • possible duplicate of How to create more networking osm
    – Jendrusk
    Commented Aug 18, 2014 at 8:16
  • It basically is but that duplicate question is oddly phrased which is why I probably missed it in my searches. I think it is worth keeping this thread! Commented Aug 18, 2014 at 8:24

2 Answers 2

2

I've answered similar question here. I think this could be what you're looking for.

1

OK inspired by Jendrusk's answer I have come up with what I believe is a simpler method -- code wise. Jendrusk creates 'driveways' to connect an address to the network before processing it as a network as illustrated:enter image description here

The code I used was:

CREATE TABLE driveways AS
WITH index_query AS
(
  SELECT addr.address, road.name, 
  ST_Distance(road.wkb_geometry, addr.wkb_geometry) AS distance, 
  ST_MakeLINE(ST_ClosestPoint(road.wkb_geometry, addr.wkb_geometry), addr.wkb_geometry) AS geometry
  FROM addresses addr, roads road
  WHERE ST_DWithin(addr.wkb_geometry, road.wkb_geometry, 200) = True
  ORDER BY addr.wkb_geometry <-> road.wkb_geometry
)
SELECT DISTINCT ON(address)* FROM index_query ORDER BY address, distance;

Drawn on by this example.

1
  • 1
    Hi @Phil Donovan - little misunderstanding - I'm not creating driveways cause adding one line to network graph per every address will increase number of nodes to count route many times so will slow down query. This lines from address and crossing roads are used to cut the line since postgis have problem with cutting line with point.
    – Jendrusk
    Commented Aug 20, 2014 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.