Select to view content in your preferred language

Get Raster Layer from Path

722
3
Jump to solution
08-26-2012 09:31 AM
StanStas
Deactivated User
Hi,

I need advise. I have raster data stored in File Geodatabase. I'd like to access raster layer. I've done this for vector layer in same GDB, but don't know how to access raster data.

    Public Function GetLayer(ByVal path As String) As IFeatureLayer          Dim strOutputFileName As String = System.IO.Path.GetFileName(path)          Dim strOutputFolderName1 As String = System.IO.Path.GetDirectoryName(path)          Dim strOutputFolderName As String = strOutputFolderName1.Remove(strOutputFolderName1.Length - 1)          Dim pWorkspaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass         Dim pFeatureWorkspace As IFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strOutputFolderName, 0)          Dim pFLayer As IFeatureLayer = New FeatureLayer         pFLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(strOutputFileName)          Return pFLayer      End Function


Easy, but I'm stuck. Thanks for help!
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
Stan,

It's the IRasterWorkspaceEx Interface you need to be using, search help on this and you will find an example.

Duncan

View solution in original post

0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor
Stan,

It's the IRasterWorkspaceEx Interface you need to be using, search help on this and you will find an example.

Duncan
0 Kudos
StanStas
Deactivated User
Thanks Duncan, it's working.

    Public Function GetFGDBRasterLayer(ByVal path As String) As IRasterLayer

        Dim workspaceFactory As IWorkspaceFactory2 = New FileGDBWorkspaceFactoryClass()
        Dim rasterWorkspace As IRasterWorkspaceEx = CType(workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(path), 0), IRasterWorkspaceEx)
        Dim rasterDataset As IRasterDataset = rasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(path))
        Dim rasterLayer As ESRI.ArcGIS.Carto.IRasterLayer = New ESRI.ArcGIS.Carto.RasterLayerClass
        rasterLayer.CreateFromDataset(rasterDataset)
        Return rasterLayer

    End Function
0 Kudos
StanStas
Deactivated User
One more question, which is close to the first one 🙂

Before I will get layer from path, I'd like to know, if data source (in File GDB) is raster or vector. How to do that? 🙂

Thanks
0 Kudos