We may be entirely going about this the wrong way, but we currently store the 'state' of the FeatureLayer by storing several of its properties on a wrapper class and then serializing that class. So, for FeatureLayers we store the data path, name, renderer json, labelling info, and definition expression as just strings/bools. On deserialization we create a new layer from the path and set all those stored properties back on the layer. One thing that is missing from our setup is the selection state for features.
One idea we had was to:
The concerns for this setup are pretty minor, but worth mentioning:
So, with that said, is this the intended way of doing this? Or is there a much simpler option I missed?
Solved! Go to Solution.
I think your overall approach is reasonable, but you may be able to simplify it.
Rather than special-casing ArcGISFeatureTable, shapefiles, GeoPackages, etc., you can determine the ObjectID field from the table schema, then serialize the ObjectIDs of the selected features:
var objectIdField = featureTable.Fields.FirstOrDefault(f => f.FieldType == FieldType.OID);
long objectId = Convert.ToInt64(feature.GetAttributeValue(objectIdField.Name));
This has a couple of advantages:
Regarding the concern about large selections (100k+ features), any solution will need to persist enough information to identify those selected features. Storing ObjectIDs is about as compact as you can get, but the amount of data you save and restore will still scale with the size of the selection.
I think your overall approach is reasonable, but you may be able to simplify it.
Rather than special-casing ArcGISFeatureTable, shapefiles, GeoPackages, etc., you can determine the ObjectID field from the table schema, then serialize the ObjectIDs of the selected features:
var objectIdField = featureTable.Fields.FirstOrDefault(f => f.FieldType == FieldType.OID);
long objectId = Convert.ToInt64(feature.GetAttributeValue(objectIdField.Name));
This has a couple of advantages:
Regarding the concern about large selections (100k+ features), any solution will need to persist enough information to identify those selected features. Storing ObjectIDs is about as compact as you can get, but the amount of data you save and restore will still scale with the size of the selection.
Thanks Jennifer, that is exactly what I was looking for!