# FME - Calculate distance of point along a line

I have created an FME workspace which inputs a pipeline as well as other linear features which cross it (waterways, roads, railways, fences, other pipelines, etc). The output is a point file which contains the crossing type. What I would like to do is calculate the distance along the pipe from the start of the pipeline for each intersection. So, as you travel along the pipeline, the distance attribute will increase.

I'm thinking that I'll need to use some of the linear referencing tools like MeasureGenerator, MeasureExtractor, or something like that, but I'm not sure how to do so.

Does anyone have an idea of how to do this?

-

I believe you can use `LengthToPointCalculator` transformer. But you have to do some additional preparations:

1. Extract point coordinates to attributes with `CoordinateExtractor`.
2. Merge line feature with points (`FeatureMerger`). You need to receive one feature for each point with line geometry and original point's coordinates in the attributes. Use `GeometryExtractor`/`GeometryReplacer`.

Model will be similar to:

-
Alex, thanks for that, it worked perfectly. – Fezter Aug 1 '12 at 0:25

So, you want to find the distance along the pipe at which the intersection occurs?

If you use the MeasureGenerator before you do the intersection, then the intersection process will cause a new measure to be created at the point of intersection. Then you could turn it into a point (if necessary) by using a Chopper.

The intersection part can be done by either the LineOnLineOverlayer or the Intersector transformer, e.g.

-
Thanks Mark, while this makes sense to me, it doesn't seem to do what I need. I am not outputting the "Intersected" but rather the nodes as I only want the points of intersection. I've eliminated the endpoints elsewhere (possible feature request for this transformer to mention to the FME developers, perhaps?) – Fezter Aug 1 '12 at 0:28

The MeasureGenerator will assign a measure value to vertices along the line so may not actually accomplish what you need, or will require a bit more processing after the MeasureGenerator transformer to get the distance value assigned to the point.

To achieve what you want you can use the ShortestPathFinder. The idea being that if you get the start point of the pipeline and then calculate the shortest path to each intersection point along the pipeline then that will give you the segments of the line for each intersection - then you can just use LengthCalculator to get the distance for each segment. The rough workflow I would adopt is:

1. Use CoordinateExtractor to get the X and Y of the pipeline's first (0) coordinate
2. Use the 2DPointReplacer to turn the extracted coordinates into a point
3. Use the ShortestPathFinder and put the pipeline feature into the LINE port, the generated start point of the pipeline into the SOURCE port, and the intersection points into the DESTINATION port
4. Use LengthCalculator on the output PATH features to get the distance
5. Join the distance attribute from the PATH to the original intersection point using the FeatureMerger (you will need to make sure you have some form of unique ID on your intersection points)

That should get you to where you need to be, this is the approach I used in a similar task. An alternative approach would be to look at the PointOnLineOverlayer transformer.

-