You would like to programmatically modify / update the Feature Object's fields i.e. it's attribute data using Geospatial Platform API in Map 3D.
In the screenshot below, we can see a Feature Object with ID = 10 and its Length property = 10.1234; using API we will update it’s value to 12.0.
Here is a VB.NET code snippet which demonstrates how to programmatically modify / update the Feature Object's fields i.e. it's attribute data using Geospatial Platform API in Map 3D :
Try
Dim map As AcMapMap = AcMapMap.GetCurrentMap()
Dim resId As MgResourceIdentifier = Nothing
Dim layerName As String = "API_Poly_Objects"
Dim className As String = ""
' Get the resource Id and class name of the layer on which we want to update
Dim layers As MgLayerCollection = map.GetLayers()
Dim layer As MgLayerBase = Nothing
Dim iCount As Integer = Nothing
For iCount = 0 To (layers.Count)
If (layers.GetItem(iCount).Name.ToLower() = layerName.ToLower()) Then
layer = layers.GetItem(iCount)
resId = New MgResourceIdentifier(layer.GetFeatureSourceId().ToString())
Exit For
End If
Next iCount
If layer Is Nothing Then
ed.WriteMessage(vbCrLf + "Layer Not Found ! ")
Exit Sub
End If
' Create a new Property colleaction Object
Dim propColl As MgPropertyCollection = New MgPropertyCollection()
' Create STNAME prop to Update it
Dim lengthProp As MgDoubleProperty = New MgDoubleProperty("Length", 12.0)
'Add the length property to property collection
propColl.Add(lengthProp)
' Define a filter to get the object whose property we want to update
'' Feature ID = 10 is specific to a sample SDF
Dim filterText As String = "ID=10"
'Create the UpdateFeatures object for the update
Dim updateFeatures As MgUpdateFeatures = New MgUpdateFeatures(layer.FeatureClassName, propColl, filterText)
' Create a command collection for the update
Dim commands As MgFeatureCommandCollection = New MgFeatureCommandCollection()
commands.Add(updateFeatures)
' Commit the Update
fs.UpdateFeatures(resId, commands, True)
layer.ForceRefresh()
trans.Commit()
Catch ex As MgException
ed.WriteMessage(ex.Message.ToString())
Finally
trans.Dispose()
End Try