ThinkGeo.com    |     Documentation    |     Premium Support

InternalFeatures.Remove not working with key

I am trying to remove a specific feature by its id/key in an InMemoryFeatureLayer by simply doing:

if (layer.InternalFeatures.Count > 0)
{
    layer.InternalFeatures.Remove("sampleId");
}

However, the feature is not removed. I have verified the feature within the internal features also has an id of “sampleId”.

The feature is being added like:

layer.InternalFeatures.Add(feature.Id, feature); // feature.Id is "sampleId"

Why would the remove not work in this case?

If I get the index of the feature and do layer.InternalFeatures.RemoveAt(index) it works.

layer.InternalFeatures.RemoveAll(feature => string.Equals(feature.Id, "sampleId", StringComparison.OrdinalIgnoreCase)); also works.

Using version 12.0 of your products.

Hi Dan,

I’ve tested this several different ways and I’ve found that as long as I pass a string in the first parameter of the Add function I can always remove the feature by name later. So, your code above seems to me like it should work.

Is it possible for you to put together a very simple .sln and attach the .zip to this ticket? That will confirm we are on the exact same build and confirm that we are adding and removing the features in the same way.

Thansk,
John

I’m trying to track down what is happening, because after some more testing it only happens sometimes and I can’t quite pinpoint why. I will update if I find out, but thanks for the reply!

Thanks for the update @Dan_Weaver. Just let me know if you can recreate it and we’ll take another look.

Thanks,
John