Given a polyline L and a point P which belongs to this polyline but that also is not necessarily one of the polyline's vertices, I'd like to measure the length from the start of the polyline L till P.

I got P using an identify task with zero tolerance, so I can assume for right that the point belongs to the polyline.

To reach my goals, I create a fake polyline L' that contains the points P and P', where P'=(Xp + Delta, Yp + Delta). Then I use L' to cut L and get two new polylines L1 and L2. Finally I use one geometry service to get the length I want.

The code snippet to create the fake polyline, cut L and measure the length:

private void IdentifyCompleted(object sender, IdentifyEventArgs e)
    if (e.IdentifyResults.Count <= 0)

    var geometryService = new GeometryService(
    MapPoint pLine = new MapPoint();
    // Some workaround here: creating and 'arbitrary' line starting with P
    pLine.X = p.X + 0.1;
    pLine.Y = p.X + 0.3;

    PointCollection pointCollection = new PointCollection();
    pointCollection .Add(p);
    pointCollection .Add(pLine);

    Polyline cutter = new Polyline();
    cutter.SpatialReference = Mapa.SpatialReference;

    // Transform the polilyne returned from the identify task in a list
    List<Graphic> polylineL = new List<Graphic>();
    foreach (var result in e.IdentifyResults)

    geometryService.CutCompleted += geometryService_CutCompleted;
    geometryService..CutAsync(listaResultado, tesoura);

private void geometryService_CutCompleted(object sender, CutEventArgs e)
    if (e.CutIndexes.Length == 2)
        // Magically figured out what are the first geometry. It
        // is out of the scope of this question
        Polyline first = getFirstGeometry();
        int theLengthIWant = first.Length();
        // We got it ! ! !

I guess is too overload execute one identify task and then one cut operation.

So my question is: is there a simpler to do this? I mean, is there a straight forward way to get the length from the start of one polyline till an arbitrary point on it?


I found a lot of people using IHitTest to do what I want. Unfortunately, this interface belongs to ArcObjects API which is not available to me right now.

  • I have used IHitTest to work out which part and segment the point falls closest to, then iterate through the points until segment index is reached then insert the new point. It's hard to tell from your question what your question actually is but I'm thinking you want a better way to achieve the same... is that right? – Michael Stimson Jul 23 '14 at 21:16
  • @MichaelMiles-Stimson, you're right. Sorry for the obscured question. I edited to be more clear regarding what I want. In addiction, your solution seems to be what I'm looking for. Can you answer with a code snippet? – Plinio.Santos Jul 24 '14 at 12:27
  • @MichaelMiles-Stimson besides of that, I could not find the class ESRI.ArcGIS.Geometry.IHitTest in arcgis 10.2 :( – Plinio.Santos Jul 24 '14 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.