Inserting, Deleting, and Updating Features

To change data in a feature source, create an MgFeatureCommandCollection object. This can contain commands to insert, delete, or update features in an FDO data source. The commands are executed sequentially. For FDO providers that support transaction processing, the commands can be treated as a single transaction.

Feature commands can be one of the following:

- MgDeleteFeatures
- MgInsertFeatures
- MgUpdateFeatures

To execute the commands, call MgFeatureService::UpdateFeatures(). The feature class name and property names in any of the feature commands must match the class name and property names in the feature source.

For example, to delete all features in a feature class with an identity property ID, execute the following:

    $commands = new MgFeatureCommandCollection();

    $deleteCommand = new MgDeleteFeatures($className, "ID like '%'");

    $commands->Add($deleteCommand);

    $featureService->UpdateFeatures($featureSource, $commands, false);

To insert features, create an MgPropertyCollection object that contains the properties of the new feature. Create an MgInsertFeatures object and add this to the MgFeatureCommandCollection object.

For example, to add a new feature with a single geometry property, execute the following:

    $commands = new MgFeatureCommandCollection();

    $properties = new MgPropertyCollection();

    $agfByteStream = $agfReaderWriter->Write($geometry);

    $geometryProperty = new MgGeometryProperty($propertyName,

       $agfByteStream);

    $properties->Add($geometryProperty);

    $insertCommand = new MgInsertFeatures($className, $properties);

    $commands->Add($insertCommand);

    $featureService->UpdateFeatures($featureSource, $commands, false);

To update existing features, create an MgPropertyCollection object that contains the new values for the properties and a filter expression that selects the correct feature or features. See Querying Feature Data for details about filter expressions.