ThinkGeo.com    |     Documentation    |     Premium Support

Clarification on adding features info via blogpost

In the following link

it says if using InternalFeatures to add, the feature should be in the external projection when adding. This doesn’t seem to be correct, but I just want to clarify. Should the features be in the internal projection instead?

Also, in my app there are some derived types from Feature, but when using the Add/Update transaction, or using a projection converter, the functions always return Feature, not the original type, and thus I’m losing some extra properties. This is why I’d like the clarification.

Also, if using InternalFeatures, is there anything else that needs to be done besides calling BuildIndex() after?

Thanks,
Dan

Hi Dan,

Good Catch! You are right it should be using the internal projection for InMemoryFeatureLayer.InternalFeatures. We’ve updated that blog, please refresh and check it out. Thanks for letting us know!

Here below is a quick example how you can do the reprojection for a CustomFeature. You can just update the WKB to accomplish the reprojection while keeping the other attributes. Both of the SetWellKnownBinary() and GetWellKnownBinary are fast.

        CustomFeature a = new CustomFeature();
        var b = ProjectionConverter.Convert(4326, 3857, a);
        a.SetWellKnownBinary(b.GetWellKnownBinary());

You don’t need to do anything other than BuildIndex() after updating InternalFeatures. You don’t actually need to call BuildIndex() if there’re less than 100 features as it will be fast anyway.

Thanks,
Ben

1 Like

Thanks Ben! Didn’t know about the setwellknownbinary, good to know.

Sure! Again, thanks for letting us know the issue in the blog!

Hi Ben, I tried removing BuildIndex() after adding features via InternalFeatures.Add. However, those features do not appear on the map unless I call some function which ends up calling BuildIndex(). Is this a bug in the 13.1.2 version?

I’m simply doing this:
((InMemoryFeatureLayer)TestMap.FindFeatureLayer("TestLayer")).InternalFeatures.Add(feature.Id.ToUpper(), feature);

But if I do this after the add:
((InMemoryFeatureLayer)TestMap.FindFeatureLayer("TestLayer")).BuildIndex();
it appears fine.

I should mention that the feature does still appear in the InternalFeatures collection.

Hi Dan, yes, that’s expected behavior. Once you’ve called BuildIndex() , the InMemoryFeatureLayer starts using the spatial index for queries instead of scanning all features directly. That means any subsequent modifications to InternalFeatures —such as adding or removing features—will not be reflected until the index is rebuilt.

If you never call BuildIndex() (or any method like AddFeature() that internally triggers it), the layer will always loop through all features for spatial queries, so you wouldn’t need to rebuild anything manually.

In short:

  • If you’ve built an index, rebuild it after every feature change.
  • If you never build one, changes are reflected automatically (but queries may be slower if you have many features in the collection).

Thanks for the response Ben. Will BuildIndex() have any noticeable performance hit if it’s just a few features in the layer being added/modified?

It always re-adds every feature from the InternalFeatures collection to the index, so the operation is generally heavy. If the collection is small and you need to modify it frequently, it might be better not to use the index.