Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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: gis.stackexchange.com/questions/74845/… – SASS_Shooter Oct 24 '13 at 12:25
up vote 1 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)
continue;
if (geometry is IPolycurve)
((IPolycurve)geometry).Densify(0, -1);
Polyline shape = geometry as Polyline;
share|improve this answer
    
I had the exactly same problem, but it did not help much in my case. I mean the resulting polyline is in fact only a segment of the true cost path. What is more, mine GemetryCollection contsins a single geometry object too. Did you tackle this issue, or was it working in your case? – Konrad Mar 10 at 12:18

Your Answer

 
discard

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.