Selecting Feature Data

AutoCAD Map 3D Geospatial Platform API

 
Selecting Feature Data
 
 
 

Individual features within a feature source are identified by unique feature IDs. The form of the ID depends on the feature source. Call MgFeatureService.GetClassDefinition() to get the feature class definition. Call MgClassDefinition.GetIdentityProperties() to get a list of all properties that are identity properties.

To get the currently selected features for a map, call AcMapMap.GetFeatureSelection(). This returns an MgSelectionBase object. A single selection can contain features from multiple layers and classes. Call MgSelectionBase.GetLayers() to get all layers containing selected objects, or select an individual layer.

For example, to find selected features on the Parcels layer,

AcMapMap currentMap = AcMapMap.GetCurrentMap();
MgFeatureService fs =
  AcMapServiceFactory.GetService(MgServiceType.FeatureService) 
  as MgFeatureService;
 
MgLayerCollection layers = currentMap.GetLayers();
MgLayerBase parcelsLayer = layers.GetItem("Parcels");
string fcName = parcelsLayer.GetFeatureClassName();
 
MgSelectionBase selection = currentMap.GetFeatureSelection();
string selectionFilter = selection.GenerateFilter(parcelsLayer, 
  fcName );
 
MgFeatureQueryOptions queryOpts = new MgFeatureQueryOptions();
queryOpts.SetFilter(selectionFilter);
MgFeatureReader featureReader;
 
MgResourceIdentifier fsId = new
  MgResourceIdentifier(parcelsLayer.GetFeatureSourceId());
featureReader = fs.SelectFeatures(fsId, fcName, queryOpts);

A selection consists of one or more feature IDs. To process the features in a selection, create an MgFeatureReader that contains the selected features, then call MgFeatureReader.ReadNext() to advance through the feature reader. To create the MgFeatureReader() for the selected features in a layer, call MgSelectionBase.GenerateFilter(), which creates a filter to select the features. Then create and initialize an MgFeatureQueryOptions object. Finally, call AcMapFeatureService.SelectFeatures().

An MgFeatureReader iterates through a list of features from a single feature source. To advance to the next feature in the reader, call MgFeatureReader.ReadNext().