GDAL with SharpMap

Topics: General Topics, SharpMap v0.9 / v1.x
Feb 10, 2009 at 1:03 AM

Have been using SharpMap 0.9 successfully for a while now for many different apps.  I have also been using the GDALRasterLayer provider for displaying ECW imagery behind my VectorLayers on my Map object.  However, I have been having intermittent issues with GDAL crashing.  No specific error message, but the process that the website is running under on my server crashes.  Recycling the app gets it back running again, but this crashing is most certainly due to the raster stuff (as it doesn't occur when imagery is not being displayed).  So I have a few questions:

1. Can anyone suggest what might be going wrong?  This is running under IIS7 (in WOW 32-bit mode) on a Windows Server 2008 machine.  No issues unless GDAL is being used for dispalying imagery.
2. Can anyone suggest an alternate way of gettign imagery into my SharpMap map?
3. I'm thinking about using OpenLayers for the mapping instead.  Will I still need SharpMap to act as a WMS server for displaying raster layers, or are there good alternatives?

The basic requirement is to display the vector spatial data from a SQL database on top of raster layers provideed from ECW files on the server.  Thanks for any guidance/advice.

Feb 10, 2009 at 9:08 AM
Hi Steve, when GDAL crashes is anything recorded in the system event log?
There are several other popular wms servers such as UMN MapServer (C) and GeoServer (Java) but I suspect they all use GDAL under the covers. Have you tried updating to the latest GDAL?
When you build the project do you build for 'any cpu'? if so, try building x86 only.
With openlayers you could create a TMS server by cookie cutting the ecw data up-front at specified resolutions.. hth jd
Feb 11, 2009 at 7:15 AM
Edited Feb 11, 2009 at 7:21 AM
Hi's not been long that i got to know about SharpMap and using it, its quite interesting. Well i also intend to do the same as steve but with a little difference that is displaying raster data which is ERDAS imagine .img format and on this raster data i want to display designing a desktop application using c# not a web one...any hints plz!!!!
Feb 12, 2009 at 1:14 AM
I've got some useful output for you to diagnose here JohnDiss.  Let's see if you can make sense of what is happening with this crash, as I'm having difficulty understanding it.

Here is the log from running Process Monitor on the Windows Server 2008 machine:

In this log, I have recorded the activity on the w3wp.exe*32 process that was running (PID7740).  Have filtered out some stuff, but the bulk is here.  

To set the scene, I have a web app that has an image button control that works as my map.  When the user clicks on this, I have a class called Mapping.cs that generates the various layers and makes up the rendered map.  This is stored in the Session using a GUID.  When the page reloads after the image button click, the updated map is populated by using a handler called GetMap (which gets passed the GUID, renders the image and clears the session variable).  The Map contains VectorLayers and sometimes GDALRasterLayers also. 

In this log, I have got a map displaying and functioning as expected, with some shapefiles being displayed on top of a raster layer.  In line 1 of the log, I click on the map to pan it.  Everything works fine and my new map is shown.  In line 41, I click again to pan the map again.  This time, it ends up crashing (line 64).  At line 65, the applicaiton pool that the process is running in has recycled, so it closes all files down and the process ends.  The web app then starts up in a new worker process, but has timed out and lost its session state.

Any ideas about how I might get beyond this problem?  I'm not sure where to go for more help, as I can't get into the source beyond the call to GDAL raster layer.

Feb 12, 2009 at 1:21 AM
In terms of the other ideas JohnDiss, I have not changed the Build For CPU option at any stage. 

I had a bit of a play with OpenLayers yesterday and had SharpMap producing the tiles for it, but it seems to run particularly slow (all set up on localhost).  Do you have any useful resources or sample apps that have this set up and running that I might look through to better understand how it works.  If so, you could email me at: srweal @

I don't understand much about the TMS stuff in OpenLayers, but will look into that in the future and do the tiling of the raster scenes that way.  Any idea if they support ECW?  I couldn't find details of file formats.

Feb 12, 2009 at 1:51 AM
Oh, and this is the event log from the crash event I've captured in the earlier post:

Exception information:
    Exception type: Exception
    Exception message: Couldn't load d:\site\\Imagery\imagefile.ecw

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Feb 12, 2009 at 9:21 AM
Edited Feb 12, 2009 at 9:21 AM
Hi Steve, do you have a static instance of the map or layer? Perhaps you could try a remote debugging session with throw on all exceptions set (in vs Debug Menu >> Exceptions>> check all relevant)?

With TMS you have a set of jpegs/pngs etc extracted on a grid (like google maps etc) so you would preprocess your ecw files. OpenLayers will generally accept an array of urls in place of a single url (e.g for wms/tms host) when it recieves the array it will 'round robin' requests (you can use this and some extra dns host names to get around the limitation in some browers where the browser will not allow more than 2 concurrent requests to the same host - a possible cause of slowness). Other things you can do include putting a wms-c server in front of the webserver (if the data doesn't change) hth jd
Feb 12, 2009 at 10:01 PM
John, what do you mean by 'a static instance of the map'?

I am trying to set up remote debugging now to see how it works and whether I can get deeper into the SharpMap GDALRasterLayer code to see what GDLA request it fails on. 

So you know, I got this post response back from Frank Warmerdam (the FW in FWTools) about GDAL and ECW:

"I have experienced intermittent hangs and crashes with the ecw sdk from time to time - more often on linux or when having built the ECW SDK myself from source.  You might want to test with a non-ecw image and see if that works reliably.  If so, the issue is either the ecw sdk or the GDAL ECW driver.  However, it is not at all clear how those issues might be fixed.  I advise converting ecw images to geotiff when problems are encountered."

Thanks for the tips about TMS tiling.  Where coudl I find the specs about how these tiles have to get created/named?

Ta, Steve
Feb 13, 2009 at 9:07 AM
Hi Steve, by static instance I meant a map that is 'reused' through multiple requests by holding it as a static field on some object. I thought perhaps two concurrent requests may be using the same map and causing issues - but it seems it is more likely to be the ecw provider part of GDAL itself..
For the TMS spec look at 
hth jd