Problems using GdalRasterLayer

Topics: General Topics
Feb 26, 2007 at 8:05 PM
I'm having problems correctly rendering an image using GdalRasterLayer.

I'm using SharpMap (change set 18222) in a simple winform, displaying image in a PictureBox control. The source is a b/w GeoTiff image. The rendered image is colored with 0,0,0 and 1,1,1 colors which makes it appear black.

Also using various GeoTiff images almost randomly throws memory exceptions

eg: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt...
at: GDAL.gdalPINVOKE.Band_ReadRaster(HandleRef jarg1, Int32 jarg2, Int32 jarg3, Int32 jarg4, Int32 jarg5, IntPtr jarg6, Int32 jarg7, Int32 jarg8, Int32 jarg9, Int32 jarg10, Int32 jarg11")
around: GetPreview method
line: band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, (int)GT.HorizontalPixelResolution, (int)GT.VerticalPixelResolution);)

I'm looking for any suggestions.

Goran
Coordinator
Feb 26, 2007 at 8:52 PM
Hi,

The gdal raster extension doesn't handle all colour types correctly.
We hope to fix this issue soon.

regards
Christian
Feb 26, 2007 at 10:50 PM
Thanks!

Btw. codekaizer is looking to contact you :)

Goran
Feb 26, 2007 at 10:57 PM
Goran,

You can solve this problem by recompiling your SharpMap.Extensions project after making the following change to the source. In the ReadRaster method in the GDALRasterLayer.cs file, change the line:

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

to:

band.ReadRaster(x1, y1, x1width, y1height, buffer, size.Width, size.Height, 0, 0);

This simply takes the last two parameters and makes them zero. If you look up the GDAL reference material on the web, you'll find that this is the default values anyway. The reason that the layer has been working for some of your GeoTIFFs is because their pixel resolution values are < 1, thereby rounding down to 0 anyway!

I've asked for this to be changed in the source, so hopefully this won't be an ongoing issue. Also note that the constructor the for GDALRasterLayer opens the file in Update mode. This causes problems when run on a web host, so you might want to change the mode to ReadOnly (i.e. change the 1 to 0 in the GDAL.open call).

Steve
Feb 27, 2007 at 3:30 PM
Edited Feb 27, 2007 at 3:55 PM
srweal,

Going through my references I've noticed an incorrect reference.Your suggestion works now so a big thank you :)

Gorn

P.S. the rendered image is still the wrong color.
Coordinator
Mar 1, 2007 at 5:08 PM
Hi Goran,

I' knowing of the colour issue and I'm still working on it.

regards
Christian
Mar 1, 2007 at 6:52 PM
Hi!

Great and thanks!

Goran