how to enumerate through a Polyline

1538
7
Jump to solution
10-10-2013 03:58 AM
MichaelEber
Occasional Contributor
I have two points on a hydrography layer which we want the distance.  Originally it was a simple call in the Military layer but since that was pulled in 10.1 I'm taking this approach:

I'm planning on using one of the spatial functions passing the start point and end point.  The one function I found returns a PolyLine with the line having a 'value of 3 if it is a single connection'.

I want to "walk" through that polyline adding up the connections to get the total distance.  I'm new to ArcGIS and their lack of documentation for developers.  How do I enumerate through that polyline to a) find that line and b) is it correct to assume that once I know the resolution that adding up the number of cells with the value of 3 will give me the distance via n*res.  If I can pull out the collection of points can I use the lat/long to compute this?
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
Maybe I'm missing something but IPolyline has a Length property that returns the length of the line.  Is this not what you're looking for?

View solution in original post

0 Kudos
7 Replies
DuncanHornby
MVP Notable Contributor
Mike,

I'm not really understanding your question, may be you could upload an image sketching out what you are asking? Anyway if you are asking to "walk" along a polyline a segment at a time then you would cast your polyline into an ISegmentCollection interface and then enumerate the segments. If you have a bunch of points that you want to know the distance along a polyline they are the IPolyline has a method QueryPointAndDistance.

Duncan
0 Kudos
MichaelEber
Occasional Contributor
Given the following scenario (see attached image) I think it is called the CostDistance which returns the PolyLine.
(assumed to be represented by the red line in the drawing)

What I need to do is basically "walk" along that polyline to compute the nautical miles between the two points that the PolyLine represents.  We have a raster that represents the hydrography so that we only look at water.  And since we are on water all paths have the same weight, thus we should get only one path in the PolyLine.

This will serve as a utility for future tools.  Our current one isn't much, a grid of starting station, all known targets, and then once this service is called it will populate with the nautical miles between the station and each target.  (we can then use nautical maps to confirm the NM calculation before we go to the next level of use.

The polyline seemed the best method to call since a) it should return a single line as an answer  b) it should be easier to compute the actual length which I will probably make as an Extension Method to the PolyLine class   c) gives us the future option to then draw that line on the map to represent Response Force movement to a target.

On the other hand if QueryPointAndDistance does the trick for me, then my job just got a whole heck of a lot easier, given the situation.  I am assuming, though, that due to the nature of the raster we are likely to get an answer that contains multiple points along the line, but I just want the distance from start to end, not each waypoint inbetween.

Reading the documentation it looks like I would call my service, get back a PolyLineArray of PolyLines (one station to multiple target distances) and then :

    for (int index = 0; index < responseArray.Length; index++)
    {
          ICurve temp = responseArray[index] as ICurve;
          distance[index] = temp.QueryPointAndDistance(station, .., targets[index], distanceToTarget, ..
);
     }
0 Kudos
NeilClemmons
Regular Contributor III
Maybe I'm missing something but IPolyline has a Length property that returns the length of the line.  Is this not what you're looking for?
0 Kudos
AlexanderGray
Occasional Contributor III
The length of the polyline depends on the coordinate system distortion.  The length reported is the length in that coordinate system with distortion, not the length along a geodetic great circle.  Use the wrong coordinate system a path of 200kM becomes 300...  Assuming the distance is large enough to make a difference, to get real length you nee a geodesic operation.  IGeoPolyline exists in 10.1 as part of defenseSolutions library.  The polyline has a ISegmentCollention interface which has an enumSegments.   Segments have a from and to point...
0 Kudos
MichaelEber
Occasional Contributor
The length of the polyline depends on the coordinate system distortion.  The length reported is the length in that coordinate system with distortion, not the length along a geodetic great circle.  Use the wrong coordinate system a path of 200kM becomes 300...  Assuming the distance is large enough to make a difference, to get real length you nee a geodesic operation.  IGeoPolyline exists in 10.1 as part of defenseSolutions library.  The polyline has a ISegmentCollention interface which has an enumSegments.   Segments have a from and to point...


I thought they dropped support for Defense Solutions with 10.1.  At least that is what I gathered from all of the mixed messages coming out of ESRI.  But if I can use this, what do I call to get an IGeoPolyline?
0 Kudos
MichaelEber
Occasional Contributor
Maybe I'm missing something but IPolyline has a Length property that returns the length of the line.  Is this not what you're looking for?


The documentation for Polyline only lists a ton of interfaces.  It does not show a property of length in the SDK!  And since we are under a tight schedule I do not want to write a ton of code only to find I've gone down a wrong path.  So lot's of questions at this moment.
0 Kudos
AlexanderGray
Occasional Contributor III
The documentation for Polyline only lists a ton of interfaces.  It does not show a property of length in the SDK!  And since we are under a tight schedule I do not want to write a ton of code only to find I've gone down a wrong path.  So lot's of questions at this moment.


Neil said the IPolyline had a length field, not Polyline.  IPolyline is an interface on Polyline.  PolylineClass has about 50 interfaces and 5 or 6 of which I regularly use.   Reading the documentation is much more efficient than writing a ton of code, but you have to spend the time up front to understand this difficult API...
0 Kudos