3

I have a bus line with bus stops along the route. enter image description here

The sample data looks like this:

LINESTRING (-70.57243474999999933 -33.37452829000000065, -70.57308152999999606 -33.37470645999999874, -70.57543062999999961 -33.37539473999999728, -70.57551596999999788 -33.3754228700000013, -70.57676012999999671 -33.37580358000000302, -70.57838608999999508 -33.37581671000000227, -70.5790643100000068 -33.37582045999999991, -70.58024559999999781 -33.37582420999999755, -70.58068577000000232 -33.37587485000000243, -70.5810989999999947 -33.37592361000000096, -70.58192544999999996 -33.3760173800000004, -70.58280580000000271 -33.37611865000000222)

POINT(-70.58176091969386334 -33.37599871220383818)
POINT(-70.58081166577235877 -33.37588970535671251)
POINT(-70.5789007062584659 -33.37581955540557743)
POINT(-70.57517086297514197 -33.3753186292262285)
POINT(-70.57426670966613358 -33.37505371514445329)

How can I order (add an order ID) the bus stops along the route?

Any Open Source Software is welcome. Preferably something that can be automated (QGIS, Python, PostGIS).

3
  • 4
    Which software?
    – dassouki
    Mar 12, 2015 at 17:50
  • Related: QGIS calculate distance of point along a line
    – Jake
    Mar 12, 2015 at 18:23
  • @dassouki I updated my question and added software. However I also appreciate general ideas/algorithms on how to solve it that are software independent.
    – ustroetz
    Mar 12, 2015 at 21:11

1 Answer 1

5

If using PostGIS, you can order the bus stops according to their value returned for an ST_Line_Locate_point() call.


This is how it looks if I apply it to the linestring and points you supplied:

SELECT  
  ST_Line_Locate_Point(line.f1, ST_GeomFromText('POINT(-70.58176091969386334 -33.37599871220383818)')) as A,
  ST_Line_Locate_Point(line.f1, ST_GeomFromText('POINT(-70.58081166577235877 -33.37588970535671251)')) as B,
  ST_Line_Locate_Point(line.f1, ST_GeomFromText('POINT(-70.5789007062584659 -33.37581955540557743)')) as C,
  ST_Line_Locate_Point(line.f1, ST_GeomFromText('POINT(-70.57517086297514197 -33.3753186292262285)')) as D,
  ST_Line_Locate_Point(line.f1, ST_GeomFromText('POINT(-70.57426670966613358 -33.37505371514445329)')) as E
  FROM
  (
    SELECT 
      ST_GeomFromText('LINESTRING (-70.57243474999999933 -33.37452829000000065, -70.57308152999999606 -33.37470645999999874, -70.57543062999999961 -33.37539473999999728, -70.57551596999999788 -33.3754228700000013, -70.57676012999999671 -33.37580358000000302, -70.57838608999999508 -33.37581671000000227, -70.5790643100000068 -33.37582045999999991, -70.58024559999999781 -33.37582420999999755, -70.58068577000000232 -33.37587485000000243, -70.5810989999999947 -33.37592361000000096, -70.58192544999999996 -33.3760173800000004, -70.58280580000000271 -33.37611865000000222)') 
        as f1
  ) as line;

-----------------------------------------------------------------------------------------
   A              | B               | C               | D               | E
0.900519204659061;0.810142121650764;0.629032670938557;0.269386835869428;0.180270638952756
-----------------------------------------------------------------------------------------

And a pic, just in case that helps..

enter image description here

0

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.