GdalRasterLayer usage with NASA GDEM tiff

Topics: Algorithms, Data Access, General Topics, SharpMap v0.9 / v1.x
Dec 18, 2013 at 12:03 PM

I am trying to display relief using GdalRasterLayer.

Original data are tiff from NASA (search on aster gdem).
I have used gdal_contour to import them into postgresql for contours.

I am trying to use them as datasource for GdalRasterLayer.
First, I had a coordinate transformation problem. I think this workaround works.

Then, I would like to recolor the image.
As far as I have seen using debugger, the source images contains only 1 band, with color interpretation equal to ColorInterp.GCI_GrayIndex.

I know that actual source of GdalRasterLayer can't do this, but I don't know what may be the best way to achieve this. Any idea ?
Dec 18, 2013 at 12:33 PM
I know that actual source of GdalRasterLayer can't do this, but I don't know what may be the best way to achieve this. Any idea ?
The raster is not displayed at all? Is it displayed with some strange colors? If so, try applying a different colorblend.
Dec 18, 2013 at 2:09 PM
Raster seams to be drawn, but it is full white.

I am debugging step by step, since I have ColorInterp.GCI_GrayIndex, the ColorBlend is not used at all.

Some of the values contained in intermediateValue for a single generated tile seams to be in range 400-600.

The only correction that can be applied is when ColorCorrect is true (and maybe histogram functions). Anyway, all values are capped to 255, so the only way I can reduce image values is by using Gain array.

Code I have :
private static Layer AddRelief(Map map, string layer_name)
            LayerGroup layerGroup = new LayerGroup(layer_name);
            string dataPath = @"J:\PostgreSQL\ASTGTM2\030294510916196\extract";
            DirectoryInfo di = new System.IO.DirectoryInfo(dataPath);
            FileInfo[] files = di.GetFiles("*dem.tif");
            foreach (System.IO.FileInfo fi in files)
                GdalRasterLayer layer = new GdalRasterLayer(Path.GetFileNameWithoutExtension(fi.Name), fi.FullName);

                layer.ColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow7;

            layerGroup.SRID = 900913;
            return layerGroup;
Dec 18, 2013 at 2:41 PM
Edited Dec 18, 2013 at 2:43 PM
I hope you are comfortable with gdal command line utilities.
  • use gdalbuildvrt to build a virtual raster from your tif files
  • use gdalinfo on the created virtual raster to gather information abount min/max values of the raster band
  • use text editor to modify settings according to (see complexsource, LUT)
  • load the virtual raster instead of the set of other rasters
Dec 18, 2013 at 3:20 PM
I have tried another approach, using this.
I have converted the original tiles to color relief, and they are displaying well.

Sometimes, it seams that I have AccessViolationException raised. I think this is due to the big amount of data to work on. I didn't managed yet to catch the stacktrace.

Do you think it can be possible to chain gdal tools/functions (with result caching in a second time) to obtain same result ?
Dec 18, 2013 at 3:42 PM
If you ge one step beyond and build an mbtiles file, you can use Tile(Async)Layer with a mbtiles provider.
Won't get any faster than that.
Dec 18, 2013 at 3:56 PM
Ok, I will try to generate mbtiles.

Thanks :)