Select to view content in your preferred language

Process IFeatureCursor results many times without re-applying query/filter

857
2
05-07-2013 06:26 PM
RobEllis
Deactivated User
I have a spatial filter performing as I want it to, returning me an IFeatureCursor object that I can loop through. I want to be able to loop through the IFeatureCursor object more than once without re-applying the filter, the spatial filtering can take some time to apply in large data sets. Is there a method available for this, like 'IFeature.FirstFeature()' rather than having to re-apply the filter and start wiith 'IFeature.NextFeature()' again? Code below.

Thanks

Rob

Dictionary<int, Dictionary<int, string>> FIDs = new Dictionary<int, Dictionary<int, string>>();
while ((pFeat = pFeatCursor.NextFeature()) != null)
{
 int thisFID = (int)pFeat.Value[fidIdx];
 FIDs.Add(thisFID, new Dictionary<int, string>());


 ISpatialFilter SPF = new SpatialFilter();
 SPF.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;
 SPF.Geometry = pFeat.ShapeCopy;


 IFeatureCursor IFC2 = resultFeatLay.Search(SPF, false);
 IFeature IF2;

 int theCount = 1;
 while ((IF2 = IFC2.NextFeature()) != null)
 {
  FIDs[thisFID].Add((int)IF2.Value[fidIdx], (string)IF2.Value[splitIdx]);
  theCount += 1;
 }

 //THIS IS MY ATTEMPT AT STARTING THE LOOP AGAIN, TO NO AVAIL
 while ((IF2 = IFC2.NextFeature()) != null)
 {
  string stophere = "";
 }

}
0 Kudos
2 Replies
LeoDonahue
Deactivated User
Is there a method available for this, like 'IFeature.FirstFeature()'...


No.

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#Cursors


Cursors and selection sets       Cursors provide a way to sequentially step through a series of records. The following are the types of class cursors:
      

  •            Search cursors�??Inspect and edit rows.

  •            Update cursors�??Edit and delete rows.

  •            Insert cursors�??Add new rows to the table.

       To determine whether to use a search cursor or an update cursor during editing, see Updating features. Cursors can be created from many interfaces, including ITable, IFeatureClass, ISelectionSet, and IQueryDef.
       Cursors allow records to be iterated through only once, in  one direction. They do not support behavior such as, resetting, moving  backwards, or making multiple passes (create cursors to make multiple  passes).


0 Kudos
DuncanHornby
MVP Notable Contributor
Rob,

Move the line that creates the spatialfilter object out of your looping code and place it above, you only need to create this object once.

So move these line above the beginning of your loop

ISpatialFilter SPF = new SpatialFilter();
SPF.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin;


Duncan
0 Kudos