This project has moved and is read-only. For the latest updates, please go here.

GDAL Raster (.ecw) problem

Topics: Algorithms, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0
Oct 21, 2011 at 6:23 PM

Hi all, I have a urgent problem. I configured my application to load a .ecw raster layer and visualize it. I installed FWtools 2.4.7 and everything to make this work.

The application works in debug mode (from visual studio->debug)

But when I try to execute the application by double clicking it, freezes.

That's my stupid example:


GdalRasterLayer G = new GdalRasterLayer("Try1", @"C:\Foo.ecw");

Map M = new Map(pictureBox1.Size);



pictureBox1.Image = M.GetMap();


The application freezes in the GDAL constructor. 

Stepping into the behind code, I noted that there is an error in GdalRasterLayer.cs:

in public GdalRasterLayer(string strLayerName, string imageFilename)





_gdalDataset = Gdal.OpenShared(_Filename, Access.GA_ReadOnly);


Here the application freezes. There's no way to understand the error... 

Help me!

Oct 21, 2011 at 8:10 PM

Check that the sharpmap release version is targeted at x86 platform.

Hth FObermaier

Oct 21, 2011 at 9:04 PM

yes, it is. All projects are targeted at x86

Oct 22, 2011 at 6:28 PM
Edited Oct 22, 2011 at 6:29 PM

If it can help:
- I'm using Visual Studio 2010
-I tried on both x64 and x86 machines, and on windows7, xp and 2003 server
-Both Gdal.OpenShared and Gdal.Open make freeze the application
-Debugging mode does work, but in few days I have to do a demonstration, and I'm quite worried
-.ecw file is quite big (5.5GB)

Next steps will be:
build SharpMap in vs2005
try to understand the source code of Gdal.OpenShared

Oct 23, 2011 at 10:09 AM
Edited Oct 23, 2011 at 10:19 AM

I was wrong. I extrapolated the code that calls GdalRasterLayer constructor and the problem seems to be here

_projectionWkt = _gdalDataset.GetProjectionRef();


I tried to temporarily comment all parts that the variable _projectionWkt was needed and now the project seems work fine. Can this create any other problem? I apologize for being pedantic, but tomorrow I have an important demonstration :-)

Oct 23, 2011 at 7:27 PM

To me it seems that there is some native library reference missing. Please check that with

If you want to, I'll take a look at your *.csproj files to see if all is matching. on the managed side. Are the settings in app.config right, do they differ somehow?

All the best for your presentation tomorrow

Hth FObermaier

Oct 23, 2011 at 8:08 PM

I temporanely resolved by commenting in public GdalRasterLayer(string strLayerName, string imageFilename)

//_projectionWkt = _gdalDataset.GetProjectionRef();


if you want to check my .csproj file, maybe the part of your interest is this:

    <Reference Include="gdal_csharp, Version=1.0.3671.21225, Culture=neutral, PublicKeyToken=db5a52b08dc5b321">
    <Reference Include="ProjNET, Version=1.2.3882.19088, Culture=neutral, PublicKeyToken=a1f5bdcd9c6f5740, processorArchitecture=MSIL">
    <Reference Include="SharpMap">
    <Reference Include="SharpMap.Extensions">
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />

Thank you as always for the help :) you guys are the best

Oct 24, 2011 at 7:45 AM

Sound to me like a problem when GDAL tries to initialize projection EPSG and gsv files from the GDAL data-dir.


Make sure you have them accessible in the path or that you have set the environmen variable GDAL_DATA.



Oct 26, 2011 at 10:05 PM

I set all variables correctly, the weird is that the program works in debug mode without touching the code


btw, thank you all for the support, the demonstration was perfect :)