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

Alternatives to OgrProvider & GdalRasterLayer?

Topics: Data Access, General Topics, SharpMap Project, SharpMap v0.9 / v1.x
Mar 28, 2012 at 9:39 AM

Hi All,

I'm looking for some advice on alternative ways to load MapInfo TAB files as well as ECW Raster files using SharpMap.

For the last few months I have been developing a desktop application using the SharpMap (Trunk) utilising the OgrProvider to load MapInfo TAB files and GdalRasterLayer, both of which I think are built on the GDAL library (correct me if I am wrong).

My problem is that when I use the OgrProvider I am not able to load MapInfo TAB files when I run my compiled EXE (both debug and release versions). The application just crashes. But here is the thing...  it works when run within VS2010! (details: work item 32248).

When loading a GdalRasterLayer all I get is a blank image when I run my EXE. Again it works within VS2010, but not when I run the EXE.

I have tracked the cause of the problem down to the GDAL libraries which are installed with FWTools, but have not been able to progress things beyond that.
I am looking for advice on:

  1. How to load MapInfo TAB files using the OgrProvide without my EXE crashing. There must be someone out there who is able to successfully loading MapInfo TAB files outside the VS2010 IDE?
  2. How to load ECW Raster files using the GdalRasterLayer class and have it work outside the VS2010 IDE.
  3. Alternative ways to successfully load MapInfo TAB files or ECW Raster files without using the GDAL library / FWTools.

Any help at all would be much appreciated.


Mar 30, 2012 at 5:57 AM

In case anyone else has the same problem...

Essentially I have found a solution to item 3 of my post.

I have successfully been able to use the OgrProvider (with some slight modifications) to load MapInfo TAB files (containing vector data) from an EXE without it crashing.

Additionally I have also worked out how to completely remove any dependency on FWTools. Some GDAL dll’s are needed, but FWTools does not need to be installed.

The ECW raster layer problem has not been solved, but I do understand why it was not working and have an alternative solution for raster layers within my application so this is no longer an issue for me.

I will try and document my findings within Work Item 32248 when time permits as I think this will help to close the work item.


Jul 18, 2012 at 9:56 AM

hi AAyre, 

I have the same problem, how did you solve it ? 

Jul 19, 2012 at 2:39 AM

Hi cdqrain,

My fix was to remove FWTools completely, then download and install the GDAL SDK binaries from "" and use files from this SDK rather than FWTools.

I am fairly sure that the GDAL SDK I downloaded was "" since I use VS2010.

There are some files (DLL's) I needed to copy from the GDAL SDK to the same directory as by EXE in order to get everything to run. Unfortunately I do not have a definitive list of files. I think I simply copied all the DLL files from the GDAL SDK to the same directory as by EXE.

The other change needed was to the SharpMap.Extensions project. I completely replaced the FWToolsHelper class with my own GDALHelper class (see code below). I still need to set the GDALPath string correctly rather than hard coding as shown below. The OgrProvider class also needs to be changed to call the new GDALHelper.SetEnvironmentVariables instead of the original FWTools.Configure.

I think that is everything.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpMap.Data
    class GDALHelper
        public static void SetEnvironmentVariables()
            string GDALPath = "C:\\Program Files (x86)\\GDAL\\";

            SetVariableValue("PATH", GDALPath + "GDAL", true);
            SetVariableValue("GDAL_DATA", GDALPath + "GDAL\\gdal-data", false);
            SetVariableValue("GDAL_DRIVER_PATH", GDALPath + "GDAL\\gdalplugins", false);
            SetVariableValue("PROJ_LIB", GDALPath + "GDAL\\projlib", false);
            SetVariableValue("PYTHONPATH", GDALPath + "GDAL\\python", false);

        private static void SetVariableValue(string VariableName, string Value, bool PrependValue)
            string lstrCurrentValue = Environment.GetEnvironmentVariable(VariableName);
            if (lstrCurrentValue == null)
                Environment.SetEnvironmentVariable(VariableName, Value);
                if (PrependValue)
                    if (!Value.EndsWith(";"))
                        Value = Value + ";";
                    lstrCurrentValue = Value + lstrCurrentValue;
                    Environment.SetEnvironmentVariable(VariableName, lstrCurrentValue);
                    //Just set value
                    Environment.SetEnvironmentVariable(VariableName, Value);


Jul 19, 2012 at 4:45 AM

hi AAyre, 

many thanks for your help. Should I need to get gdal-19-1600-core.msi and install it ? But it only has 6 folders (csharp, gdal-data, gdalplugins, java, license, projlib), there is no GDAL folder. So, in your code SetEnvironmentVariables(), the GDALPath: C:\\Program Files (x86)\\GDAL\\GDAL will not exist.

Or should I need to get, and run SDKShell.bat. then, how to install it ?

I have no idea. Could I trouble you to help me more. 

Jul 19, 2012 at 5:20 AM

Yes, install gdal-19-1600-core.msi.

The GDAL folder ("C:\Program Files (x86)\GDAL\") will be created when you install the gdal-19-1600-core.msi.

If you install in a different folder, change the path in the GDALHelper code to point to where you installed the MSI.

Just to clarify... I when to and found the MSI there (gdal-19-1600-core.msi). Sorry should have been more specific. in my previous reply.

By default this MSI on my system this installs into "C:\Program Files (x86)\GDAL\".

I'm not 100% sure, but I think the files I needed to copy where found in the "csharp" directory ("C:\Program Files (x86)\GDAL\csharp\"), plus I also needed to copy some, if not all, DLL's from "C:\Program Files (x86)\GDAL\"

All files which I copied from "C:\Program Files (x86)\GDAL\" or some path under that directory I copied to the directory containing my EXE (my desktop application which uses SharpMap and MapInfo TAB files).

Jul 19, 2012 at 10:22 AM
Edited Jul 19, 2012 at 10:23 AM

Hi AAyre, 

Thanks, it works. :-)

But It has the Unicode of charactor problem. I use OgrProvider to load DXF file, it contains chinese charactor which code is GB2312 or UTF-8. When i use FWTools, it encode normally, but now it occur this problem after using GDAL.

Jul 23, 2012 at 1:23 AM

Hi AAyre,

How to get gdal version of fwtools used from because when i use fwtools, it can display charactor normally.

Jul 24, 2012 at 1:50 AM

I don't know much about DXF files. I used the GDAL SDK from only for reading MapInfo TAB files so I don't need to have FWTools installed.

If you are able to open DXF files using the GDAL SDK but the only problem is with chinese characters from the DXF file, then perhaps there is a problem somewhere within the GDAL SDK since by the time the characters are passed to the OgrProvider it should already be a .NET string which should be Unicode and therefore support chinese character.

Have you had a look at the open source project from where the GDAL SDK originated? Perhaps someone there can help. It can be found at:

Sorry I can't help any more than that.

Jul 27, 2012 at 9:08 AM

Hi AAyre,

How do i get GDAL 1.6 installation from . I can't find the link.  The FWTools 2.4.7 is use 1.6 version. So, i think the GDAL 1.6 will help me.

Best regards.

Jul 30, 2012 at 1:37 AM

Hi cdqrain,

I don't have any experience with GDAL other than that mentioned above. Perhaps you would get a better response from the project.

Best regards,