I noticed that when using FeatureSource.GetFeaturesNearestTo() the features returned no longer had column values other than ID.
Playing around I found that these columnvalues seem to get lost right after they’ve been added to a featuresource.
I have a Feature feat with several column values, which is added to the internal features of TrackShapeLayer, and then immediately afterwards I try to obtain this feature with all of its columnsvalues
MyFeatureOverlay.TrackShapeLayer.InternalFeatures.Add(feat);
Feature testfeature = MyFeatureOverlay.TrackShapeLayer.FeatureSource.GetFeatureById(feat.Id, ReturningColumnsType.AllColumns);
In this example testfeature doesn’t have any columnvalues.
How can I make sure that the columnvalues stay with the features, so that when I obtain the feature nearest to a user click, it still has its columnvalues?
Column values lost in featuresource
Hi,
I guess it is caused by there is no columns defined in the TrackShapeLayer. Actually, the TrackShapeLayer is an inmemoryFeaturelayer without any columns. So, we need to add the columns in the layer before using it. Some codes like the below:
winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.Open();
winformsMap1.TrackOverlay.TrackShapeLayer.Columns.Add(new FeatureSourceColumn("Edit"));
winformsMap1.TrackOverlay.TrackShapeLayer.Columns.Add(new FeatureSourceColumn("sid"));
Feature rectangle = new Feature(new RectangleShape(-48, 0, 52, -40));
rectangle.ColumnValues.Add("sid", "123");
rectangle.Tag = "NotOk";
// Set the value of column "Edit" to "rectangle", so this shape will be editing by custom way.
rectangle.ColumnValues.Add("Edit", "rectangle");
Feature testFeature = winformsMap1.TrackOverlay.TrackShapeLayer.FeatureSource.GetFeatureById(rectangle.Id, ReturningColumnsType.AllColumns);
Hope it helps.
Regards,
Troy
Hi again,
Thanks for
shedding some light.
Your answer
made me wonder why I didn't have a problem with editing rectangles as in my
code these indeed are taken from the TrackShapeLayer and have to have a Edit
column.
Turns out
that in the relevant piece of code I didn't get the right feature by using GetFeatureById, but by
looping through the Internal features and checking the Ids.
Collection<Feature>
features = MyFeatureOverlay.TrackShapeLayer.FeatureSource.GetFeaturesNearestTo(...);
Feature feature1 = features[0];
Feature feature2 = null;
foreach (Feature f in MyFeatureOverlay.TrackShapeLayer.InternalFeatures)
{
if
(f.Id == feature1.Id) {
feature2 = f;
break;
}
}
In this
case feature2 has all its original columns, which is not the case for feature3:
Collection<Feature>
features = MyFeatureOverlay.TrackShapeLayer.FeatureSource.GetFeaturesNearestTo(...);
Feature feature3 = MyFeatureOverlay.TrackShapeLayer.FeatureSource.GetFeatureById(features[0].Id,
ReturningColumnsType.AllColumns);
So the
columns are in the InternalFeatures, but not in the FeatureSource. Manually
defining columns as you suggested is not a very good option for me as I have
many different features taken from different tables that therefore have
different columns.
I guess
I'll just have to loop over the InternalFeatures whenever I want to grab a
feature with its columns. Please let me know if you can think of something
that's more elegant.
Hi,
Sorry to say I can’t think out a good way except adding the columns in TrackShapeLayer or loop though the InternalFeatures.
In Map Suite, only the layer including the columns then we can get the feature’s column by the FeatureSource methods like “GetAllFeature”,“GetFeatureById” etc. The reason why we can get the feature with its columns in the TrackShapeLayer.InternalFeatures is because the “InternalFeatures” is just a collection property for temporary.
So, I guess the TrackShapeLayer.FeatureSource.GetFeatureById is not fit for you.
Regards,
Troy
Thanks for clarifying.
Where can I find some more information on the difference between FeatureSource, and the InternalFeatures collection? I have noticed that updating a feature in the FeatureSource does not necessarily affect the InternalFeatures.
Hi,
Yes, modifying the feature from FeatureSource would not affect the InternalFeatures, as the features returned from FeatureSource are cloned with the InternalFeatures.
As for the relationship between the FeatureSource and InternalFeatures, let me do another explanation: Actually, all the features returned by the FeatureSource methods like GetAllFeatures are from the copy of InternalFeatures. Besides,as the reason why those returned features doesn’t include the columns from InternalFeatures, is because we will filter the columns and only the columns defined in the FeatureSource will be filled into the returned features.
I guess the above can explain the two questions you’ve encountered.
Hope it helps.
Regards,
Troy
Thanks, that clears things up :)
Hi,
Good to hear it helps.
If any other questions, don’t hesitate to let us know.
Regards,
Troy