Delete a Feature from MemoryProvider

Aug 1, 2011 at 3:15 PM

Hi,

i added a view features with a linestring to my memoryprovider. Now, i am trying to delete this features.

How can i do this. I try this:

        private void deleteAll(object sender, RoutedEventArgs e)
        {
            MemoryProvider mp = (MemoryProvider)layer.DataSource;
            foreach (var f in mp.Features)
            {
                if (f["type"] == "linestring")
                    mp.Features.Delete(f.Fields);
           }
        }

but i get an: "Primary key of Features was not set" in Features.cs line 93.

Can someone help? I dont know what i have to add to my feature to get this work.

Thank you :)

Sep 18, 2011 at 6:52 PM
Edited Sep 18, 2011 at 6:53 PM

Hi,

Obviously Features.Delete() was not implemented correctly yet, please have a look and vote for the issue: Bug in Features.Delete().

This method requires passing in the value of the "primary key" field of the underlying IFeature objects. Primary key field name is determined while instantiating Features, like this:

Features myFeatures = new Features("FeaturePrimaryKey");

Then, while adding a feature to myFeatures, set its primary key field value as in the following example:

Feature newFeature = new Feature();

newFeature["FeaturePrimaryKey"] = 1;

myFeatures.Add(newFeature);

Finally, if you want to delete newFeature from myFeatures, AFAIK you would do the following:

myFeatures.Delete(1);

However, this currently does not work.

P.S. Sorry for the code not highlighted, on my browser the 'insert code snippet' feature is not working somehow :(

Hope this helps,

dragger.