cursor slow

1753
4
07-08-2016 01:23 PM
MKa
by
Occasional Contributor III

I want to get all features from a feature class and add them to a list.  And I have noticed that the iteration using the cursor is just so slow.  Does anyone have a better way of getting all values back and populating a list with them.  I want the list of all features, but the loop is just so slow.  It is taking like 8 seconds to populate the list with 300 features

List<IFeature> featureList = new List<IFeature>();

//Run the filter on the Feature class and get the intersection

IFeatureCursor fc = featureClass.Search(null, false);

IFeature feature;

//SLOW PART STARTS HERE

while ((feature = fc.NextFeature()) != null)

{

    featureList.Add(feature);

}

0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor

300 features is small and should be instant; my immediate question is what and where is the source of the data? Is it a shapefile on your C:\ drive or ArcServer on the other side of the planet?

MKa
by
Occasional Contributor III

It is not the searching that is the issue.  That is very quick.  It is the Looping through and getting values from each feature in the cursor that is slow.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Your searching is fast because you aren't actually searching for anything, i.e., the NULL you are passing will create a cursor with all records.  As you iterate through the cursor, the data will be retrieved from the data source, which is why Duncan asked about what and where is the source of data.  Also, how many columns are in the data source you are accessing?

0 Kudos
MKa
by
Occasional Contributor III

I am using a file geodatabase located on my local machines hard drive. 

I have also tried to narrow down the columns retrieved, to only the ones I want to retrieve, but it also seems to be slower than I expected.  Is there any way to just get all values?

               string subfields = "aaaaa, bbbbb, ccccc, ddddd, eeeee";

                IQueryFilter queryFilter = new QueryFilterClass();

                queryFilter.WhereClause = null;

                queryFilter.SubFields = subfields;

              IFeatureCursor fc = featureClass.Search(queryFilter, false);

              IFeature feature;

               

               List<AllLocalInfoItem> AllLocalInfoItemList = new List<AllLocalInfoItem>();

               while ((feature = fc.NextFeature()) != null)

                {

                        AllLocalInfoItem ali = new AllLocalInfoItem();

                        ali.aaaaa= xxxxxDbReadWrite.getTableValue(feature, "aaaaa");

                        ali.bbbbb= xxxxxDbReadWrite.getTableValue(feature, "bbbbb");

                        ali.ccccc= xxxxxDbReadWrite.getTableValue(feature, "ccccc");

                        ali.ddddd= xxxxxDbReadWrite.getTableValue(feature, "ddddd");

                        ali.eeeee= xxxxxDbReadWrite.getTableValue(feature, "eeeee");

                       AllLocalInfoItemList.Add(ali);

                }

0 Kudos