[gdal-dev] Help with color map for raster grid

windchaser dkaminski at gmail.com
Tue Feb 25 06:35:23 PST 2014


Chaitanya,

Thanks for your prompt reply. I think I would like to use display engine,
but I am still trying to figure out which function I need to use to 'load a
different color table'. I am using GDAL with C# in a VS2010 project. Below
is the function that opens the raster text file and returns the bitmap.

when trying to retrieve the color table using this statement "ColorTable ct
= band.GetRasterColorTable();" the color table returned is empty.

>From your post I understand that a VRT dataset needs to be created by
copying the source dataset and then this VRT dataset can be manipulated to
add more classes apply a color gradient to the classes.

Are there any C# examples of using VRT dataset?
Could you highlight the main steps that I need to take in order to achieve
this?

Thanks,

    public static Bitmap GetBitmap(string sFileName)
    {
        //**How to write manipulated raster values to ASCII grid with GDAL?
        //**
http://stackoverflow.com/questions/10635107/how-to-write-manipulated-raster-values-to-ascii-grid-with-gdal
        OSGeo.GDAL.Dataset ds = Gdal.Open(sFileName,
OSGeo.GDAL.Access.GA_ReadOnly);
        if (ds == null)
        {
            MessageBox.Show("Invalid File Format!");
            return null;
        }

        OSGeo.GDAL.Driver dr = ds.GetDriver();

        int nWidth = ds.RasterXSize;
        int nHeight = ds.RasterYSize;

        //** GDAL CSharp Guide gdal - Revision 26980:
/trunk/gdal/swig/csharp/apps
        //** http://svn.osgeo.org/gdal/trunk/gdal/swig/csharp/apps/

        // Creating a Bitmap to store the GDAL image in
        Bitmap bitmap = new Bitmap(nWidth, nHeight,
PixelFormat.Format8bppIndexed);
        // Obtaining the bitmap buffer
        BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, nWidth,
nHeight), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
        try
        {
            int stride = bitmapData.Stride;
            IntPtr buf = bitmapData.Scan0;
            Band band = ds.GetRasterBand(1);
            band.ReadRaster(0, 0, nWidth, nHeight, buf, nWidth, nHeight,
DataType.GDT_Byte, 1, stride);
        }
        finally
        {
            bitmap.UnlockBits(bitmapData);
        }

        return bitmap;
    }



*Daniel*
c: 1 (705) 499-2450


On Tue, Feb 25, 2014 at 12:01 AM, chaitanya_ch [via OSGeo.org] <
ml-node+s1560n5105703h0 at n6.nabble.com> wrote:

> Daniel,
>
> You can make changes in two places. In the data or the display engine. In
> the data, you can modify the colour table. This will be permanent. In the
> display, you just load a different color table based on the table of pixel
> values. If you don't like either, you can build a gdal vrt file and modify
> its colour table.
>
> http://www.gdal.org/gdalbuildvrt.html
> http://www.gdal.org/gdal_vrttut.html
>
> --
> Best regards,
> Chaitanya Kumar CH
> On 25-Feb-2014 9:26 am, "windchaser" <[hidden email]<http://user/SendEmail.jtp?type=node&node=5105703&i=0>>
> wrote:
>
>> Hi,
>> I am working with GDAL in a C# project. I need help figuring out how to
>> increase the colors displayed on a raster grid. Opening the file using
>> Gdal.Open("myfile", OSGeo.GDAL.Access.GA_ReadOnly); seems to offer some
>> colors but I would like to increase the number of colors for the raster
>> map,
>> specially for floating point raster.
>>
>> Here is an example of what i am trying to achieve using GDAL.
>>
>> http://screencast.com/t/LPjJ7pTk <http://screencast.com/t/LPjJ7pTk>
>>
>> Thanks for your help!
>>
>> Daniel
>>
>>
>>
>> --
>> View this message in context:
>> http://osgeo-org.1560.x6.nabble.com/Help-with-color-map-for-raster-grid-tp5105698.html
>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>> _______________________________________________
>> gdal-dev mailing list
>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5105703&i=1>
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=5105703&i=2>
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://osgeo-org.1560.x6.nabble.com/Help-with-color-map-for-raster-grid-tp5105698p5105703.html
>  To unsubscribe from Help with color map for raster grid, click here<http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5105698&code=ZGthbWluc2tpQGdtYWlsLmNvbXw1MTA1Njk4fDYwNTc3NjY1OA==>
> .
> NAML<http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Help-with-color-map-for-raster-grid-tp5105698p5105844.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140225/6a3b1d40/attachment-0001.html>


More information about the gdal-dev mailing list