I am new to gis and am struck. I have a network of rivers which is made up of small linestrings (polylines). In a different shapefile, i have locations of several stations on a river. I need to find distance along the river from each station till the end of river.

The problem is that I don't have one complete linestring of river. And there is no common attribute I can use to union or merge the linestrings. Also, some stations are on tributaries.

enter image description here

So the bottom line is I need to make a large network of rivers including tributaries and perform liner referencing. But I don't know how to do this. Any help is deeply appreciated. Please explain as clearly as possible.

Please comment if you need more information.

  • 3
    What software platform are you using?
    – TheSteve0
    Jul 20, 2011 at 10:48
  • i tried arcmap arcinfo . But it was overwhleming information about linear referencing. Then I moved to pgRouting and QGIS. Still struggling.
    – Naresh
    Jul 20, 2011 at 13:21
  • Do you have access to ArcGIS Network Analyst extension? I think it'd be possible to build network dataset using your rivers, and then finding shortest distances should be realtively easy.
    – user173
    Jul 21, 2011 at 11:07

2 Answers 2


I would agree with BWill. Your main problem is to define the origin of each polyline. What constitutes a 'river'? Ι would make the assumption that a tributary is an standalone "route" starting from 0-> length of the tributary. Then I would the same for the main rivers, but in this case I would create a merged polyline from all the constituent polylines. I think once you have that you are 'almost' there. Then: Convert all your merged polylines to Measured polylines (PolylineM) -including the tributaries. You then have your 'route network'. From then on its a matter of finding the distance along your route for each station. I guess the station locations are defined in XYs? Also- another guess- they dont fall exactly on top of the river, do they? In any case you will need a way of finding the distance of the station from the beginning of each river or triburary. In theory, if a station is on the intersection of the river and the tributary it may have 2 locations (one for each).

To find this location you can use ArcMap tools but haven't use them for a while so cant remember of the top of my head. On the other hand if you import your shapefiles (?) into PostGIS you could use the ST_Line_Locate_Point. This function:

Returns a float between 0 and 1 representing the location of the closest point on LineString to the given Point, as a fraction of total 2d line length.

Which means you can then find the location along the river multiplying what you find with the (merged) river length. A final note- If you use PostGIS you dont have to go through the step of creating the PolylineM- only ArcGIS requires this for linear referencing.

Hope this makes sense!

  • my stations are exactly on the tributaries or river. Stupid thing is, there is no one big river, just small segments of lines. I can see a the big river bt the data itself doesnt have any common attribute to make a full river . Also, i have coordinates in degrees, so when i create routes in arcmap, i get length in degrees? I think that doesnt make sense. I got to convert the coordinates from wgs84 to some other projection. And yes, i imported shapefiles in PostGIS.
    – Naresh
    Jul 20, 2011 at 18:29

From my question of the same nature,

How to create a point along a line given distance

the following useful links came up.

I don't not complete my task through lack of effort. I believe the tedium you will experience is nominating the origin of each polyline.

  • 2
    i made some progress. I can find shortest path using pGrouting but i need to update "nodes". Right now I create a node table in postgresql and use that to create a network that i feed to pgrouting. But I need to add custom nodes in table which are not at end nodes.Stupid way is to split my polylines at the stations so they become nodes automatically. Still working. Update soon.
    – Naresh
    Jul 20, 2011 at 13:50

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.