2

How do I add a GeoPackage layer to ArcGIS Desktop using ArcObjects code (preferably c#)?

From the ESRI documentation:

The WorkspaceFactoryProgID identifies the ProgID of the WorkspaceFactory object that is used to open that particular workspace.

Here is a list of some of the possible WorkspaceFactoryProgIDs:

esriDataSourcesGDB.AccessWorkspaceFactory
esriDataSourcesFile.ArcInfoWorkspaceFactory
esriDataSourcesFile.CadWorkspaceFactory 
esriDataSourcesGDB.FileGDBWorkspaceFactory
esriDataSourcesOleDB.OLEDBWorkspaceFactory
esriDataSourcesFile.PCCoverageWorkspaceFactory
esriDataSourcesRaster.RasterWorkspaceFactory
esriDataSourcesGDB.SdeWorkspaceFactory
esriDataSourcesFile.ShapefileWorkspaceFactory
esriDataSourcesOleDB.TextFileWorkspaceFactory
esriDataSourcesFile.TinWorkspaceFactory
esriDataSourcesFile.VpfWorkspaceFactory

The use of the word "some" makes me think that there might be more factories available. You can certainly add GeoPackage layers using the AddData button in ArcMap.

1 Answer 1

3

Below is some VBA code that would load a FeatureClass in a geoPackage into a map in ArcMap. You need to access it through SqlWorkspaceFactory.

Public Sub AddDataToMap()
    ' Path to geopackage
    Dim sPath As String
    Let sPath = "C:\Scratch\test.gpkg"
    
    ' Create workspace factory
    Dim pWSFac As IWorkspaceFactory2
    Set pWSFac = New esriDataSourcesGDB.SqlWorkspaceFactory
    
    ' Open workspace
    Dim pWS As IWorkspace
    Set pWS = pWSFac.OpenFromFile(sPath, 0)
    
    ' cast into Featureworkspace
    Dim pFWS As IFeatureWorkspace
    Set pFWS = pWS
    
    ' open FeatureClass
    Dim pFC As IFeatureClass
    Set pFC = pFWS.OpenFeatureClass("main.fcLines")
    
    ' Create layer
    Dim pFl As IFeatureLayer
    Set pFl = New FeatureLayer
    Set pFl.FeatureClass = pFC
    pFl.Name = "Lines dataset"
    
    ' Add to current map and refresh
    Dim pmxd As IMxDocument
    Set pmxd = ThisDocument
    pmxd.FocusMap.AddLayer pFl
    pmxd.ActiveView.Refresh
    pmxd.UpdateContents        
End Sub
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.