Creating AutoCAD SelectionSet from FDO Features

By Partha Sarkar

Many a times I have come across a question : How do I create an AutoCAD selection set from the Geospatial Platform selection set (MgSelectionBase) containing FDO features ?

 

Here is a C# code snippet demonstrating the steps - 

AcMapMap currentMap = AcMapMap.GetCurrentMap();
MgLayerCollection layers = currentMap.GetLayers();
MgLayerBase layer = layers.GetItem("Parcels");
MgFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) as MgFeatureService;
 
string fsId = layer.GetFeatureSourceId();
string className = layer.GetFeatureClassName();
MgFeatureQueryOptions query = new MgFeatureQueryOptions();
// Parcels.shp file is used
query.SetFilter("FeatId = 166");
MgResourceIdentifier resId = new MgResourceIdentifier(fsId);
MgFeatureReader featureReader = fs.SelectFeatures(resId, className, query);
 
MgSelectionBase selectionSet = new MgSelectionBase(currentMap);
 
//Add all features in the feature reader to the newly constructed selection set
selectionSet.AddFeatures(layer, featureReader, 0);
 
AcMapFeatureEntityService.HighlightFeatures(selectionSet);
 
// create an AutoCAD selection
SelectionSet acadSelSet = AcMapFeatureEntityService.AddFeaturesToSelectionSet(null, selectionSet);

Hope this is useful to you!


Comments

2 responses to “Creating AutoCAD SelectionSet from FDO Features”

  1. Tom DiVittis Avatar
    Tom DiVittis

    Where is the MgFeatureService?!?

  2. Hi Tom,
    MgFeatureService is part of OSGeo.MapGuide namespace in OSGeo.MapGuide.PlatformBase.dll
    Thanks,
    Partha

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading