Skip to main content
Tweeted twitter.com/StackGIS/status/907731217092620290
fixed mistake
Source Link
Alex
  • 169
  • 10

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.

enter image description here

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?

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 = fclayer1.Search(null, false);
    IFeatureCursor fcur2 = fclayer2.Search(null, false);

    IFeature f1 = fcur1.NextFeature();
    IFeature f2 = fcur2.NextFeature();

        while (f1 != null)
        {
            //external cycle code
            MessageBox.Show("external cycle FID " + fSTR.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. For example, there are 3 features in each FeatureClass f1 and f2.

enter image description here

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 get the first feature f1 only. Why another features doesn't go to internal cycle?

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 = fc1.Search(null, false);
    IFeatureCursor fcur2 = fc2.Search(null, false);

    IFeature f1 = fcur1.NextFeature();
    IFeature f2 = fcur2.NextFeature();

        while (f1 != null)
        {
            //external cycle code
            MessageBox.Show("external cycle FID " + f1.Value[0].ToString());

            while (f2 != null)
            {
                //internal cycle code
                MessageBox.Show("internal cycle FID " + f1.Value[0].ToString());
                f2 = fcur2.NextFeature();
            }
            f1 = fcur1.NextFeature();
        }

For example, there are 3 features in each FeatureClass fc1 and fc2.

enter image description here

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 gets the first feature f1 only. Why another features f1 doesn't go to internal cycle?

Source Link
Alex
  • 169
  • 10

Can't iterate feature in while nested iteration

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 = fclayer1.Search(null, false);
    IFeatureCursor fcur2 = fclayer2.Search(null, false);

    IFeature f1 = fcur1.NextFeature();
    IFeature f2 = fcur2.NextFeature();

        while (f1 != null)
        {
            //external cycle code
            MessageBox.Show("external cycle FID " + fSTR.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. For example, there are 3 features in each FeatureClass f1 and f2.

enter image description here

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 get the first feature f1 only. Why another features doesn't go to internal cycle?