GDAL Problem

Topics: Data Access, WinForms Controls
Jul 6, 2012 at 3:40 AM

I am having a lot of success with using Sharpmap V 0.9 in my application. However, I hit another problem. Trying to load any kind of Gdal layer throws an exception

"The type initializer for 'SharpMap.Layers.GdalRasterLayer' threw an exception"

So I go back to the source (98572) and run the WinForms Sample and I get the same error when I select GDAL- Geotif

Any ideas?

Jul 7, 2012 at 4:29 PM

The problem in both cases was that the FW tools settings were either missing or wrong. I put this section into my app.config

<appSettings>
    <add key="FWToolsBinPath" value="C:\Program Files\FWTools2.4.7\bin"/>
    <add key="FWToolsProjLib" value="C:\Program Files\FWTools2.4.7\proj_lib"/>
    <add key="FWToolsGeoTiffCsv" value="C:\Program Files\FWTools2.4.7\data"/>
    <add key="FWToolsGdalData" value="C:\Program Files\FWTools2.4.7\data"/>
    <add key="FWToolsGdalDriver" value="C:\Program Files\FWTools2.4.7\plugins"/>
  </appSettings>

Don't put them under
<applicationSettings>

In the WinForms Sample, the path was to "C:\Program Files (x86) \FWTools2.4.7\bin" for a 64-bit OS and my development machine is 32-bit
Jul 8, 2012 at 1:18 AM

OK, I can load and display a digital elevation model file just fine. The bitmap is shaded by the heights, but I can't find anyway to get that elevation data. I found this post http://sharpmap.codeplex.com/discussions/19480 which discusses an elevation layer, but it doesn't seem to be in the code now.

How can I get the elevations data?

Build 98572 with VS2010

Coordinator
Jul 8, 2012 at 9:32 PM

Glad you made your way to setting up GDAL. It should be simpler in a little while, since we are working on some NuGet package to resolve this.

If I understand you question right, you want to click on the map and know the elevation value(s)? If so, you need to set the MapBox's query layer index to the GDAL raster layer, select the query tool and click on the map. Upon handling the MapQueried event you'll get a FeatureDataTable that has x- and y-ordinates and additional raster values for each band.

Hth FObermaier

Jul 9, 2012 at 1:05 AM

I don't get any reaction to a mouse click. Works fine on other layers, but not this one. I tested "IsQueryEnabled " on that layer and it said yes, but no response to a mouse click. Also, the MouseMove event gives me X and Y values, but no Z

Jul 9, 2012 at 2:53 AM

More information. With the Gdal raster layer active, a click on it does not fire MapBox1.MapQueried

Coordinator
Jul 9, 2012 at 11:14 AM

I see two pitfalls:

  • did you assign your GDAL layer to the BackgroundLayers collection? If so, those are not queried at all.
  • Do you use some sort of reprojection?

FObermaier

Jul 9, 2012 at 2:44 PM

I put it on Layer 0 to keep it behind the other layers. The layer is a USGS Digital Elevation Model in Arc/Info Binary Grid format and is in NAD 83 like the other layers.

    Private Sub loadTerrain_Click(sender As System.Object, e As System.EventArgsHandles B_loadTerrain.Click
        elevationlayer = New SharpMap.Layers.GdalRasterLayer("AIG", terrainPath)
 
        Elevationlayer.SRID = 4269
        Elevationlayer.LayerName = "Elevation Layer"
 
' this puts the elevation layer in the background
        If MapBox1.Map.Layers.Count = 0 Then              MapBox1.Map.Layers.Add(Elevationlayer)         Else             MapBox1.Map.Layers.Insert(0, Elevationlayer)         End If
        MapBox1.Map.ZoomToBox(SiteLayer.Envelope)         MapBox1.Map.Zoom *= 1.2         MapBox1.Refresh()     End Sub
Coordinator
Jul 10, 2012 at 7:58 AM

Have you tried the WinFormSamplesProject with some GDAL sample data. Does that work for you?

Have you set up a coordinate transformation for any of your layers?

Jul 11, 2012 at 10:17 PM

OK, I removed all references to sharpmap in my application. Then i download the pre-compiled dll's and the extensions. The map is working fine now. The only thing I had to change was that Worldpos changed from a GeoAPi coordinate to a Sharpmap.Point.

Thanks for your help.