Select to view content in your preferred language

ESRI code does not process my additional points

579
0
12-11-2013 10:48 AM
MichaelEber
Deactivated User
Associated with my previous post I have a list of target points that I need to get the distance to.  In all cases I have a single origin and multiple targets.  I am getting the distance by creating a distance and backlink array and calling CostDistanceWithPolyline

The problem is that with each successive call all I get is the polyline from the origin to the first target.  Why????

My code:

                for (int index = 0; index < targets.Count; index++)
                {
                    IFeatureClass targetClass = (IFeatureClass) targets[index].Class;
                    IPoint targetPoint = (IPoint) targets[index].ShapeCopy;
                    if (!GPUtilities.CheckCoincidence(targetPoint, holdLayer, messages))
                    {
                        messages.AddMessage("Target is not coincident with the waterways and will be relocated.");
                        IFeature targetFeature = targets[index];
                        if (!RelocateToWaterway(ref targetFeature, rasterDataset, messages))
                        {
                            CreatePlaceholder(outputCursor, outputClass, messages);
                            continue;
                        }
                        targets[index] = targetFeature;
                        targetClass = (IFeatureClass)targetFeature.Class;
                        targetPoint = (IPoint) targetClass;
                    }
                    messages.AddMessage("Target is coincident with the hydrography map.");

                    IGeoDataset[] costSets = ComputeFullRaster(
                        targetClass, (RasterDataset) rasterDataset, messages);

                    // **  Temporary code for adding cost array to the map TOC
                    IApplication baseApp = (IApplication)Activator.CreateInstance(Type.GetTypeFromProgID("esriFramework.AppRef"));
                    IMxDocument doc = (IMxDocument) (baseApp.Document);

                    IMap activeMap = doc.ActiveView.FocusMap;
                    RasterLayer layer = new RasterLayerClass();
                    IRaster ds = (IRaster) costSets[0];
                    layer.CreateFromRaster(ds);
                    layer.Name = "Cost Array";
                    layer.Visible = true;
                    activeMap.AddLayer(layer);


                    IPointCollection points = new MultipointClass();
                    points.AddPoint(origin);
                    points.AddPoint(targetPoint);

                    messages.AddMessage(string.Format("Computing distance from origin to target {0}", index + 1));
                    IGeometryCollection result = distanceComputer.CostPathAsPolyline(points, costSets[0], costSets[1]);             
                    if (result == null)
                    {
                        messages.AddMessage("No result was returned for this target.");
                        CreatePlaceholder(outputCursor, outputClass, messages);
                        continue;
                    }
                    for (int subindex = 0; subindex < result.GeometryCount; subindex++)
                    {
                        Polyline data = (Polyline) result.Geometry[subindex];
                        IPolyline idata = (IPolyline) data;
                        
                        messages.AddMessage(string.Format("Their are {0} points on geometry {1} with length of {2}", data.PointCount, subindex, idata.Length));
                        messages.AddMessage("Saving geometry as new feature.");
                        IFeatureBuffer featureBuffer = outputClass.CreateFeatureBuffer();
                        IFeatureCursor cursor = outputClass.Insert(true);
                        featureBuffer.Shape = result.Geometry[subindex];
                        cursor.InsertFeature(featureBuffer);
                        cursor.Flush();
                        Marshal.FinalReleaseComObject(cursor);
                    }
                    
                }
0 Kudos
0 Replies