By Daniel Du
Firstly what is feature class and non-feature class? Generally speaking, a Feature Class is a class with associated geometry, so that it is possible to create a layer in Map 3D or AIMS. A non-feature class just contains non-spatial data that can be used as a standalone or contained class has not geometry field. Geospatial Plat for API, which uses FDO, can manipulate both feature class and non feature class.
let’s say we have a feature schema as below, which is a SDF data source, there are two classes in the schema, one is feature class with Geometry field, another is non-feature class, just attribute fields.
If you connect to this data source in Map 3D, you will notice that the non-feature class is gray out as it cannot be added to map as layer.
Now let’s add some data into this non-feature class with Geospatial platform API. The important thing is to get the resource identifier of the data source, since it is connected to Map 3D and add a layer, I use following code to demo how to get the resource ID:
[CommandMethod("InsertNonFeatureClass")]
public void InsertNonFeatureClass()
{
const string LAYERNAME = "River";
MgFeatureService featuerSvc = AcMapServiceFactory
.GetService(MgServiceType.FeatureService)
as MgFeatureService;
//This is just for demonstration of the format of FeatureSourceId
AcMapMap currentMap = AcMapMap.GetCurrentMap();
MgLayerBase layer = null;
MgLayerCollection allLayers = currentMap.GetLayers();
foreach (MgLayerBase lyr in allLayers)
{
if (lyr.Name == LAYERNAME)
{
layer = lyr;
break;
}
}
//Just to demonstrate the format of FeatureSource
string resId = layer.FeatureSourceId;
System.Windows.Forms.MessageBox.Show(resId);
//---------------------------
//Library://River.FeatureSource
//---------------------------
//OK
//---------------------------
// Insert into non-feature class
MgResourceIdentifier featureSourceId = new MgResourceIdentifier(resId);
string className = "DefaultSchema:RiverAttributes"; //feature class name
MgPropertyCollection properities = new MgPropertyCollection();
//ID is auto generated
properities.Add(
new MgStringProperty("Name",
"Yangzi River"));
properities.Add(
new MgStringProperty("Desciption",
"The longest river in China"));
MgInsertFeatures insFeature =
new MgInsertFeatures(className, properities);
MgFeatureCommandCollection commands = new MgFeatureCommandCollection();
commands.Add(insFeature);
featuerSvc.UpdateFeatures(featureSourceId, commands, false);
}
here is the result in Data table:
From the code snippet, it is exactly the same as operating a feature class, with feature service. Actually for a feature class has been added to map as layer, there is a simple way, that is :
"Layer.UpdateFeatures() "
This method actually call underlay feature service to update features. But if you want to update a non-feature class, that does not have a corresponding layer, you have to use the lower lever API - featureService.UpdateFeatures() as demoed in ditto code snippet. Please note that this concept also applies to AIMS as well, The code can be migrated to AIMS with only minor changes.
Hope this helps.