I need to do some operation with every combinations of features in two FeatureClasses. The "for" iterating operator is very very slow-working, so I decided to try "while" operator and using FeatureCursor. So nested iteration I have like below:
IFeatureCursor fcur1 = fclayer1fc1.Search(null, false);
IFeatureCursor fcur2 = fclayer2fc2.Search(null, false);
IFeature f1 = fcur1.NextFeature();
IFeature f2 = fcur2.NextFeature();
while (f1 != null)
{
//external cycle code
MessageBox.Show("external cycle FID " + fSTRf1.Value[0].ToString());
while (f2 != null)
{
//internal cycle code
MessageBox.Show("internal cycle FID " + f1.Value[0].ToString());
f2 = fcur2.NextFeature();
}
f1 = fcur1.NextFeature();
}
The problem is: the f1 feature goes to internal cycle once only. ForFor example, there are 3 features in each FeatureClass f1fc1 and f2fc2.
I use a MessageBoxes to show FID of feature f1 to understand what happens in external and internal iterations.
The expected order of MessageBoxes is:
external cycle FID 0
internal cycle FID 0
internal cycle FID 0
internal cycle FID 0
external cycle FID 1
internal cycle FID 1
internal cycle FID 1
internal cycle FID 1
external cycle FID 2
internal cycle FID 2
internal cycle FID 2
internal cycle FID 2
But result of my code is:
external cycle FID 0
internal cycle FID 0
internal cycle FID 0
internal cycle FID 0
external cycle FID 1
external cycle FID 2
So, external cycle operates with every feature f1, but internal cycle getgets the first feature f1 only. Why another features f1 doesn't go to internal cycle?