[Gdal-dev] RE: Any tips for VB .NET?
Holywhippet
amills at frogtech.com.au
Tue Mar 21 19:51:07 EST 2006
Thanks, this comes very close to solving my problem. I basically just want
to extract the data from a Raster for the time being. At the end of my
message is the code I've written in VB .NET. It all works ok up to the
GDALRasterIO part. At that point everything falls apart. I'm not sure what
kind of variable to send in for the data or how to initialise it. I'm not
100% proficient in .NET so I'm not sure if I'm overlooking something
obvious. When it fails it tells me : "Object reference not set to an
instance of an object." so I'm guessing I'm not initialising the data
variable correctly or something. I'm not sure if I declared the function
correctly though since it returned the CPLERR type. I've changed all the
HandleRef types to IntPtr as well Any ideas?
Imports System.IO
Imports System.Runtime.InteropServices
Module mainModule
Sub main()
Dim tool As New ExtractRaster
tool.RunExtract()
' tool.Convert()
End Sub
End Module
Public Class ExtractRaster
Declare Function SetWindowLong Lib "USER32.DLL" Alias "SetWindowLongA"
(ByVal hwnd As Integer, ByVal attr As Integer, ByVal lVal As Integer) As
Integer
' Declare Function GDALOpen Lib "C:\Program
Files\FWTools1.0.0a7\bin\gdal_fw.dll" ()
' Declare Function GDALGetRasterBand Lib "C:\Program
Files\FWTools1.0.0a7\bin\gdal_fw.dll" ()
' Declare Sub GDALAllRegister Lib "C:\Program
Files\FWTools1.0.0a7\bin\gdal_fw.dll" Alias "GDALGetRasterBand" ()
' Declare Function GDALGetRasterXSize Lib "C:\Program
Files\FWTools1.0.0a7\bin\gdal_fw.dll" ()
' Declare Function GDALGetRasterYSize Lib "C:\Program
Files\FWTools1.0.0a7\bin\gdal_fw.dll" ()
' Declare Function GDALReadRaster Lib "C:\Program
Files\FWTools1.0.0a7\bin\gdal_fw.dll" ()
<DllImport("gdal_fw.dll", EntryPoint:="CPLGetLastErrorMsg")> _
Private Shared Function CPLGetLastErrorMsgExt() As IntPtr
End Function
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALOpen(<MarshalAs(UnmanagedType.LPStr)> ByVal
pszFilename As String, ByVal eAccess As Integer) As IntPtr
End Function
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterXSize(ByVal hDataset As IntPtr) As
Integer
End Function
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterYSize(ByVal hDataset As IntPtr) As
Integer
End Function
<DllImport("gdal_fw.dll")> _
Friend Shared Sub GDALAllRegister()
End Sub
<DllImport("gdal_fw.dll")> _
Friend Shared Sub GDALClose(ByVal hDriver As IntPtr)
End Sub
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterBand(ByVal hDataset As IntPtr, ByVal
index As Integer) As IntPtr
End Function
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALRasterIO(ByVal hBand As IntPtr, ByVal _
flag As Integer, ByVal xOff As Integer, ByVal yOff As Integer, ByVal
xSize As _
Integer, ByVal ySize As Integer, ByVal data As IntPtr, ByVal bufXSize As
_
Integer, ByVal bufYSize As Integer, ByVal type As Integer, ByVal _
pixelStride As Integer, ByVal lineStride As Integer) As IntPtr
End Function
' Fields
Private Const gdalDll As String = "gdal_fw.dll"
Public Sub RunExtract()
Try
GDALAllRegister()
Dim raster As IntPtr = GDALOpen("c:\FrogTech\seabed_g.img", 0)
Dim rasBand As IntPtr = GDALGetRasterBand(raster, 1)
Dim xSize As Integer = GDALGetRasterXSize(raster)
Dim ySize As Integer = GDALGetRasterYSize(raster)
MsgBox(xSize & " " & ySize)
' Dim rBand As String = GDALReadRaster(rasBand, 0, 0, xSize,
ySize, xSize, ySize, 6)
Dim rasData As String = New String(" "c, xSize & ySize) 'IntPtr
'
Dim errResult As IntPtr = GDALRasterIO(rasBand, 0, 0, 0, xSize,
ySize, New IntPtr(rasData.GetHashCode), xSize, ySize, 6, 0, 0)
' MsgBox(rBand)
GDALClose(raster)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
--
View this message in context: http://www.nabble.com/Any-tips-for-VB-.NET--t1315468.html#a3524371
Sent from the GDAL - Dev forum at Nabble.com.
More information about the Gdal-dev
mailing list