Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the CostPathAsPolyline method which returns the Polyline as an IGeometryCollection. I now need to get this converted back into a polyline. But it seems to be more complex than just a cast.

Can someone please help me? I cannot find anything online.

share|improve this question
Is this an ArcGIS related question? Which language are you trying to use? – BradHards Oct 22 '13 at 20:00
This is an ArcObjects question and it is C#. – SASS_Shooter Oct 25 '13 at 20:51
Did you want to put that in the question or the tags? – BradHards Oct 25 '13 at 23:37

Wouldn't you just do something like this?

IGeometryCollection collection = x.CostPathAsPolyline(y, z, zz);
IPolyline polyline = (IPolyline)collection;
share|improve this answer
When I do this it runs. But the object has no length. When I set it to be returned in a response set, it says there is not enough spatial information to create a geometry (or something like that) See this:… – SASS_Shooter Oct 24 '13 at 12:25
up vote 0 down vote accepted

This took quite a while to find the correct answer. Believe it or not, when I told ESRI support that it returned only 1 point she asked what was wrong with that! This is the final code to actually get a line out of the code following an undocumented process:

IGeometryCollection result = distanceComputer.CostPathAsPolyline(points, costSets[0], costSets[1]);
geometry = result.get_Geometry(location);
if (geometry == null)
if (geometry is IPolycurve)
((IPolycurve)geometry).Densify(0, -1);
Polyline shape = geometry as Polyline;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.