Select to view content in your preferred language

Adding a raster to ArcMap problem in VB.net

887
2
08-12-2011 09:47 AM
nhu_NgaLe
Deactivated User
I can add a raster to ArcMap via VB.net but the added raster doesnt show up any thing on the ArcMap. Please see two figures attached here: (1) the raster data opened directly in the ArcMap, (2) the raster data opened through VB.net codes.

I could not find the problem in my codes (I am using ArcGIS Desktop 9.3.1, W7, VS2008).


Private Sub addRaster2ArcMap()
        Dim m_pDoc As IDocument = New ESRI.ArcGIS.ArcMapUI.MxDocument()
        Dim m_pApp As IApplication

        ' Get a reference to the application
        m_pApp = m_pDoc.Parent
      
        'Create a raster layer
        Dim dsFolder As String = "D:\TT-Hue\01_GIS\NgapLut VN2000\"
        Dim rasterName As String = "d100y"
      
        Dim pRasterLy As IRasterLayer = New RasterLayer()
        pRasterLy.CreateFromFilePath(dsFolder & rasterName)

        'Add the raster layer to ArcMap
        Dim mxDoc As IMxDocument = CType(m_pApp.Document, IMxDocument)
        Dim map As IMap = mxDoc.FocusMap
        map.AddLayer(CType(pRasterLy, ILayer))
        mxDoc.ActiveView.Refresh()
        mxDoc.UpdateContents()


    End Sub


I am looking forwards to seeing your solution soon.

Regards

Nga Le
0 Kudos
2 Replies
NeilClemmons
Honored Contributor
It looks like your code is opening ArcMap (as opposed to running inside of ArcMap).  When you do this, you cannot create new instances of any ArcObjects classes using the New keyword.  You must use IObjectFactory to create these instances.
0 Kudos
nhu_NgaLe
Deactivated User
Dear Neil,
 
Thank you very much for your advice. Yes, "IObjectFactory to create these instances" has solved my problem.

Best Regards

Nga Le
0 Kudos