[Gdal-dev] GDAL C# bindings freezing problem

Tamas Szekeres szekerest at gmail.com
Tue Apr 17 05:14:26 EDT 2007


Ben,

I've tested the code with FWTools1.2.3. The only problem I've found is
that TransformPoint requires an array with 3 elements, so it should be
initialized as:
point = New Double() {0.0, 0.0, 0.0}

Without this change I got an application error at the end of the
program, the code did not freeze though.

This is just another example that makes me personally frustrated
having array parameters instead of obvious structures and classes in
the GDAL/OGR API. This approach might be converient for the interface
creator in some of the bindings but it's totally confusing for the
users and for some other language implementations.

This issue might be treated locally for the C# interface, but it's not
the suggested way as it brings in additional diversity among the
various languages.

Best regards,

Tamas



2007/4/17, Ben Greene <bgreene at rapidmap.com.au>:
> I was originally using the latest FWTools 1.2.2 binaries (I think that makes it 1.4.0), and then I compiled from the 1.4.1 sources according to the instructions on this site.  When I compiled from sources, the debugger would step into the SWIG wrappers, but I still had the same problem.
>
> Here is the VB code I'm currently using, if you would like the C# code I can probably dig that up too, but the VB is basically a direct translation of it.
>
> Private Shared image As Dataset
>
> Public Shared Function GetGeoReference(ByVal Filename As String) As GeoReference
>
> If Not (Filename Is Nothing) Then
>
> 'Return Nothing
>
> 'if uncommented, the code will not crash
>
> End If
>
> GDAL.gdal.AllRegister()
>
> image = GDAL.gdal.Open(Filename, 0)
>
> If (image Is Nothing) Then
>
> Return Nothing
>
> End If
>
> Dim gr(6) As Double
>
> image.GetGeoTransform(gr)
>
> Dim topLeft() As Double = TransformWGS84(gr(0), gr(3))
>
> Dim bottomRight() As Double = TransformWGS84(gr(0) + gr(1) * image.RasterXSize, gr(3) + gr(5) * image.RasterXSize)
>
> If (topLeft.Length = 2 And bottomRight.Length = 2) Then
>
> Return New GeoReference(topLeft(0), topLeft(1), bottomRight(0), bottomRight(1))
>
> Else
>
> Return Nothing
>
> End If
>
> image.Dispose()
>
> End Function
>
> Public Shared Function TransformWGS84(ByVal px As Double, ByVal py As Double) As Double()
>
> Dim point() As Double
>
> point = New Double() {0.0, 0.0}
>
> Dim srWGS84 As New SpatialReference("")
>
> srWGS84.SetWellKnownGeogCS("WGS84")
>
> If (image.GetProjection() = "") Then
>
> Return New Double() {}
>
> End If
>
> Dim srCurrent As New SpatialReference(image.GetProjection())
>
> Dim transform As New CoordinateTransformation(srCurrent, srWGS84)
>
> If (transform Is Nothing) Then
>
> Return New Double() {}
>
> End If
>
> Try
>
> transform.TransformPoint(point, px, py, 0)
>
> Catch
>
> Return New Double() {}
>
> End Try
>
> Return point
>
> End Function
>
>
>
> I'm not sure how I can post the GeoTIFFs - is there free hosting somewhere that people generally use?
>
> Thanks,
>
> Ben
>
>         -----Original Message-----
>         From: Tamas Szekeres [mailto:szekerest at gmail.com]
>         Sent: Mon 4/16/2007 7:59 PM
>         To: Ben Greene
>         Cc: gdal-dev at lists.maptools.org
>         Subject: Re: [Gdal-dev] GDAL C# bindings freezing problem
>
>
>
>         Ben,
>
>         Could you post an example code and data to reproduce this problem?
>         Which version of the C# bindings you use?
>
>         Best regards,
>
>         Tamas
>
>
>         2007/4/16, Ben Greene <bgreene at rapidmap.com.au>:
>         > Hi,
>         >
>         > I've been trying to modify an existing program to be able to read the georeferencing and image data from geotiffs using GDAL.  The program is written in VB.Net, but for my initial attempt I wrote a library in C#, and used that as a go-between.  I was having frequent crashing issues when the program hit the functions that load the image, so I switched to another library for the image loading stuff (I was also having trouble with indexed images, and it crashed much more often with certain images).
>         >
>         > I was still having the crashing problems, so I removed the references to my library, and everything worked.  I tried converting my code to VB and integrating it into the original program, but I'm still having the same issue.
>         >
>         > When the program crashes, it just freezes, taking the debugger with it (when I try to break, the environment freezes.  I then have to kill the process, and the debugger unfreezes).  This happens at different lines throughout the program, and for some images very occasionally (one in 20 executions maybe) won't happen, but with others will work most of the time.  There doesn't seem to be any pattern to the compression used, but larger images seem to be slightly more likley to crash.
>         >
>         > Has anyone else had similar problems?
>         >
>         > Cheers
>         >
>         > _______________________________________________
>         > Gdal-dev mailing list
>         > Gdal-dev at lists.maptools.org
>         > http://lists.maptools.org/mailman/listinfo/gdal-dev
>         >
>
>
>
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
>



More information about the Gdal-dev mailing list