Accessing a plug-in data source programmatically
One of the advantages of plug-in data sources is that once implemented, they can be accessed by client developers using the normal geodatabase ArcObjects application programming interface (API). Only the interfaces with names starting with IPlugIn must be used when implementing the data source.
One problem that can be encountered is that no type library information will be available for the workspace factory, so late binding must be used to create the object via its ProgID.
The ProgID of a workspace factory can be found by using the Component Category Manager tool to inspect the ESRI Workspace Factories category. The ProgID is derived from the return value of the DataSourceName property of the IPlugInWorkspaceFactoryHelper interface and is given in the following format:
- ProgID = esriGeoDatabase.<DataSourceName>WorkspaceFactory
For example, if the returning DataSourceName property of PlugInWorkspaceFactoryHelper is SimplePointPlugin, the plug-in ProgID will be as follows:
- esriGeoDatabase.SimplePointPluginWorkspaceFactory
The following code example shows how to access a plug-in data source programmatically and add a feature class to the map:
[C#]
//Get the type using the ProgID.
Type t = Type.GetTypeFromProgID("esriGeoDatabase.SimplePointPluginWorkspaceFactory");
//Use activator to create an instance of the workspace factory.
IWorkspaceFactory workspaceFactory = Activator.CreateInstance(t)as IWorkspaceFactory;
//Open the workspace.
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)
workspaceFactory.OpenFromFile(@"C:\Data\Data", 0);
//Get a feature class from the workspace.
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("points");
//Create a feature layer and add it to the map.
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.Name = featureClass.AliasName;
featureLayer.FeatureClass = featureClass;
m_hookHelper.FocusMap.AddLayer((ILayer)featureLayer);
[VB.NET]
'Get the type using the ProgID.
Dim t As Type = Type.GetTypeFromProgID("esriGeoDatabase.SimplePointPluginWorkspaceFactory")
'Use activator to create an instance of the workspace factory.
Dim workspaceFactory As IWorkspaceFactory = TryCast(Activator.CreateInstance(t), IWorkspaceFactory)
'Open the workspace.
Dim featureWorkspace As IFeatureWorkspace = CType(workspaceFactory.OpenFromFile("C:\Data\Data", 0), IFeatureWorkspace)
'Get a feature class from the workspace.
Dim featureClass As IFeatureClass = featureWorkspace.OpenFeatureClass("points")
'Create a feature layer and add it to the map.
Dim featureLayer As IFeatureLayer = New FeatureLayerClass()
featureLayer.Name = featureClass.AliasName
featureLayer.FeatureClass = featureClass
m_hookHelper.FocusMap.AddLayer(CType(featureLayer, ILayer))
You can also open the workspace with IWorkspaceFactory.Open. In this case, supply a property set with a single property of DATABASE and the appropriate workspace string. Another way of opening the workspace is to use a WorkspaceName object; set the WorkspaceFactoryProgID and PathName properties, then call IName.Open.
See Also:
Plug-in data sourcesCreating a plug-in data source
Sample: Simple point plug-in data source
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine Runtime |
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |