Hello all,

I'm trying to build a command line application in VB.NET that extracts parts from a NetCDF file. For this I'm using the C# API as supplied with FWTools version 2.4.7. It's supposed to support VB.NET as well; am I right?

However, the application already crashes at the line Call GDAL.Registerall()
Here's the code:

Imports System
Imports OSGeo.GDAL
Imports OSGeo.OGR

Module MeteoBase

  'Copyright Siebe Bosch Hydroconsult, 2012
  'Lulofsstraat 55, unit 47 Den Haag, The Netherlands
  'this program creates subsets from precipitation data in NetCDF-files
  'as requested by the user. The program is designed to be called from
  'a PHP-script.

  Dim FileName As String
  Dim ds As Dataset

  Sub Main()
    Dim DebugMode As Boolean

    Console.WriteLine("This program extracts data from a NetCDF file")
    Console.WriteLine("Path to the NetCDF file (*.cn)")
    DebugMode = True

    'start reading the command line arguments
    If DebugMode Then
      FileName = "c:\GDAL\PM\1990\EVAP_PM_19901231.nc"
    Else
      If My.Application.CommandLineArgs.Count = 0 Then
        Console.WriteLine("Enter the path to the NetCDF-file:")
        FileName = Console.ReadLine()
      ElseIf My.Application.CommandLineArgs.Count <> 1 Then
        Console.WriteLine("Error: incorrect number of arguments presented")
      Else
        FileName = My.Application.CommandLineArgs(0)
      End If
    End If

    Try
      'start reading the NetCDF File
      Call Gdal.AllRegister()
      ds = Gdal.Open(FileName, Access.GA_ReadOnly)
      If ds Is Nothing Then
        Console.WriteLine("Cannot open NetCDF file: " & FileName)
        Throw New Exception
      Else
        Console.WriteLine("Raster dataset parameters:")
        Console.WriteLine("  Projection: " + ds.GetProjectionRef())
        Console.WriteLine("  RasterCount: " + ds.RasterCount)
Console.WriteLine(" RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")")
      End If
    Catch ex As Exception
      Console.WriteLine("Error in sub Main of Meteobase")
    End Try

  End Sub

End Module

_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to