GDALRasterLayer & FwTools on Webhost

Topics: General Topics
Feb 26, 2007 at 4:17 AM

I'm wanting to run SharpMap, using the GDALRasterLayer and FwTools on my web host, but I've followed Christian's instructions from and am finding FwTools won't open datasets. I am unable to install FwTools on my host, so I've just copied all the DLLs into my 'bin' directory. Has anyone else got this to work?

The basic functionality of SharpMap, such as loading geometries from a SQL database and doing various NTS-focussed queries, is all working okay, but the imagery/raster stuff is not. Any tips?

Thanks, Steve
Feb 26, 2007 at 5:43 AM
Hi Steve,

Have you copied all dll files into your bin folder.
There are round about 30 meg of dll files included into the FwTools. You have to copy
all of them even if they aren't managed dll's.

Don't forget to copy the bindings assemblies from the "csharp" folder of the FwTools.

Feb 26, 2007 at 10:46 AM
Hi Christian,

I've copied all the DLLs from the bin directory, and also all the bindings. The app works fine on my local machine, where I had previously installed FwTools, but then uninstalled it to simulate what the server would be like. When running from the web host, basic SharpMap stuff works fine, but when I try to add the GDALRasterLayer using this line of code:

GdalRasterLayer lyrImg = new GdalRasterLayer("Image", HttpContext.Current.Server.MapPath("~/App_Data/lsat.tif"));

I get the following exception:

Couldn't load dataset. TIFFOpen:c:\websites\essolutionsau163\\fis\App_Data\lsat.tif: No such file or directory

The file is certainly there and can be displayed by using the URL directly to it, but won't display in SharpMap (using the FwTools) for some reason. I just assumed it was because something wasn't set up correctly with FwTools. Are there any DLLs that have to be 'registered' on the server for this to work? I didn't need to register the SharpMap DLL to get it working, so I assumed that the FwTools binaries would be the same.


Thanks, Steve

Feb 26, 2007 at 4:38 PM
srweal -

A "No such file or directory" is almost surely a Windows error. It's probably just rethrown from GDAL's failure using Window's fopen(). Try pasting that local path into the Run dialog on the webserver and execute it. You say the URL exists, but it's trying to load it via a local path, not a URL.

If all else fails, try running ProcessMon and capture file requests to see if it is loaded.
Feb 26, 2007 at 10:23 PM
Okay, I just solved it. Finally!!

The call to in the GDALRasterLayer uses the call, 1). This tries to open the file in Update mode, rather than ReadOnly. If the second parameter is changed to 0 (or re-written as GDAL.gdalconst.GA_ReadOnly) then there are no problems on the host.

In summary, using the HttpContext.Current.Server.MapPath(virtual path) notation works well for getting the correct file reference on the server, but the write permissions on the server were causing the error to be thrown.

I think the default file access mode for GDALRasterLayer should be changed to ReadOnly in the source. I am not a developer of SharpMap, so I hope codekaizen or volleyknaller will do this.

Also, please change the following line in the GetPreview method of the GDALRasterLayer:

band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, (int)GT.HorizontalPixelResolution, (int)GT.VerticalPixelResolution);

The last two parameters should be zeroes. This problem only appears when the imagery has a pixel size greater than 1 (e.g. projected imagery), because in all other instances the (int) cast rounds the pixel resolution values (e.g. 0.0001 degrees) down to zero.

Thanks for your help,

Mar 1, 2007 at 5:05 PM
Hi Steve,

I have applied your suggestions.