[Gdal-dev] VB6 Bindings for GDAL

Frank Warmerdam fwarmerdam at gmail.com
Thu Mar 17 01:59:26 EST 2005


Folks,

On behalf of UN FAO I have completed a preliminary implementation
of Visual Basic 6 bindings for GDAL.   If anyone else is interested
in using these, feel free to contact me for details.  

The following is an example of a VB6 script that uses GDAL. 

Private Sub mnuCreate_Click()
    Dim SrcFilename As String, DstFilename As String
    Dim Drv As GDALDriver
    Dim SrcDS As GDALDataset, DstDS As GDALDataset
        
    SrcFilename = "BV02021.CA"
    DstFilename = "out_create.tif"
    
    Call GDALCore.GDALAllRegister
    Set SrcDS = GDAL.OpenDS(SrcFilename, GDAL.GA_ReadOnly)
    
    Set Drv = GDAL.GetDriverByName("GTiff")
    Set DstDS = Drv.Create(DstFilename, SrcDS.XSize, SrcDS.YSize, _
                           SrcDS.BandCount, GDAL.GDT_Byte, Nothing)
    If DstDS.IsValid() Then
        Print "Create Succeeded"
    Else
        Print "Create Failed: " & GDAL.GetLastErrorMsg()
    End If
    
    ' Copy geotransform
    Dim gt(6) As Double
    
    Call SrcDS.GetGeoTransform(gt)
    Call DstDS.SetGeoTransform(gt)
    
    ' Copy projection
    Call DstDS.SetProjection(SrcDS.GetProjection())
    
    ' Copy metadata.
    Call DstDS.SetMetadata(SrcDS.GetMetadata(""), "")
    
    ' Copy band info
    Dim Scanline() As Double
    ReDim Scanline(SrcDS.XSize) As Double
   
    For iBand = 1 To SrcDS.BandCount
        Dim SrcBand As GDALRasterBand, DstBand As GDALRasterBand
        
        Set SrcBand = SrcDS.GetRasterBand(iBand)
        Set DstBand = DstDS.GetRasterBand(iBand)
        
        Call DstBand.SetMetadata(SrcBand.GetMetadata(""), "")
        Call DstBand.SetOffset(SrcBand.GetOffset())
        Call DstBand.SetScale(SrcBand.GetScale())
        
        Dim NoDataValue As Double, Success As Long
        
        NoDataValue = SrcBand.GetNoDataValue(Success)
        If Success <> 0 Then
            Call DstBand.SetNoDataValue(NoDataValue)
        End If
        
        ' Copy band raster data.
        For iLine = 0 To SrcDS.YSize - 1
            Call SrcBand.RasterIO(GDAL.GF_Read, 0, iLine, SrcDS.XSize,
1, Scanline)
            Call DstBand.RasterIO(GDAL.GF_Write, 0, iLine,
SrcDS.XSize, 1, Scanline)
        Next iLine
    Next iBand
    
    Call DstDS.CloseDS
    Call SrcDS.CloseDS
    
    Print "Copy seems to have completed."
End Sub

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Gdal-dev mailing list