Updating Features

AutoCAD Map 3D Geospatial Platform API

Updating Features

All updates to features in a feature source are performed using an MgFeatureCommandCollection. The feature command collection can contain commands to add new features, delete existing features, update existing features, lock features, or unlock features.

To add a new feature, create an MgInsertFeatures object. MgInsertFeatures has two constructors. One has an MgPropertyCollection parameter and is used to insert a single feature. The other has an MgBatchPropertyCollection parameter and is used to insert multiple features in a single command.

The MgPropertyCollection contains values for the feature properties, including the feature geometry property. Create an empty MgPropertyCollection, then add properties using MgPropertyCollection.Add(). The different property types, such as MgGeometryProperty or MgInt32Property, are all derived from the base class MgProperty.

Most feature classes will require a geometry property, which is used to display the feature. To create a geometry property, start with an MgGeometry object.

Convert the MgGeometry to binary AGF format suitable for FDO.

MgByteReader geometryStream;
MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter;
geometryStream = agfReaderWriter.Write(geometry);

Create a property collection to contain the feature properties. Add the geometry property. Add any other required properties. The property names are case sensitive and must match the names defined in the feature class.

MgPropertyCollection properties = new MgPropertyCollection();
MgGeometryProperty geomProp;
geomProp = new MgGeometryProperty( "SHPGEOM", geometryStream);

Create a feature command to insert the feature, and add it to a feature command collection.

MgFeatureCommandCollection commands = 
  new MgFeatureCommandCollection();
MgInsertFeatures insertCommand;
insertCommand = new MgInsertFeatures(className, properties);

Call AcMapLayer.UpdateFeatures() to add the new feature.


Deleting and updating features is similar. The constructors for MgDeleteFeatures and MgUpdateFeatures require different parameters, but the feature commands can be added to the same MgFeatureCommandCollection.