Determine DataSource in VB.NET

1496
5
Jump to solution
06-05-2013 11:56 AM
MichaelVolz
Esteemed Contributor
To All GIS VB.NET Developers:

What object of ILayer (layer in an mxd) can I use to determine if the layer is sourced from an SDE database?

In the past if I had a raster layer from SDE I used the RasterLayer.FilePath object which provides the path to where the SDE layer was created.  This did not work when I copied a raster SDE layer from one mxd to another.  In this case it showed the path to the SDE layer but did not include the .sde connection.

Any help or hints are greatly appreciated.
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
You can do something like this

If TypeOf layer Is ESRI.ArcGIS.Geodatabase.IDataset Then     Dim dataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(layer, ESRI.ArcGIS.Geodatabase.IDataset)     GetCategory(dataset.Workspace) End If

View solution in original post

0 Kudos
5 Replies
MichaelVolz
Esteemed Contributor
I am now trying to use the following code to determine data source, but it is crashing ArcMap:

pDataLayer = pLayer

pDatasetName2 = pDataLayer.DataSourceName - Intellisense provides DataSourceName as an member of pDataLayer but this is where the code crashes ArcMap

I would then like to use

pDatasetName2.Category to determine if the data is "SDE Feature Class"

Does anyone know what I am doing wrong here?
0 Kudos
KenBuja
MVP Esteemed Contributor
If you get the workspace of the dataset, you can use this code to get the type of data source

    Public Function GetCategory(ByVal pWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace) As String

        Dim sClassID As String
        sClassID = pWorkspace.WorkspaceFactory.GetClassID.Value

        Select Case sClassID
            Case "{DD48C96A-D92A-11D1-AA81-00C04FA33A15}" ' pGDB
                GetCategory = "Personal Geodatabase Database"

            Case "{71FE75F0-EA0C-4406-873E-B7D53748AE7E}" ' fGDB
                GetCategory = "File Geodatabase"          '

            Case "{D9B4FA40-D6D9-11D1-AA81-00C04FA33A15}" ' GDB
                GetCategory = "SDE Database"

            Case "{A06ADB96-D95C-11D1-AA81-00C04FA33A15}" ' Shape
                GetCategory = "Shapefile Workspace"

            Case "{34DAE34F-DBE2-409C-8F85-DDBB46138011}" ' SDC
                GetCategory = "SDC Workspace"

            Case "{1D887452-D9F2-11D1-AA81-00C04FA33A15}" ' Coverage
                GetCategory = "ArcInfo Coverage Workspace"

            Case "{7F2BC55C-B902-43D0-A566-AA47EA9FDA2C}" ' InMemory
                GetCategory = "InMemory Workspace"

            Case "{59158055-3171-11D2-AA94-00C04FA37849}" 'OLEDB Workspace
                GetCategory = "OLEDB Workspace"

            Case Else
                GetCategory = "Unknown Workspace Category"
        End Select
    End Function
0 Kudos
MichaelVolz
Esteemed Contributor
Ken:

Do you know what objects I need to expose to go from the ILayer object to IWorkspace object?
0 Kudos
KenBuja
MVP Esteemed Contributor
You can do something like this

If TypeOf layer Is ESRI.ArcGIS.Geodatabase.IDataset Then     Dim dataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(layer, ESRI.ArcGIS.Geodatabase.IDataset)     GetCategory(dataset.Workspace) End If
0 Kudos
MichaelVolz
Esteemed Contributor
Thank you Ken.

The combination of your 2 posts allowed me to trap if the raster layer originated from an SDE database.
0 Kudos