[Gdal-dev] ColorTable in C#

Jean Michel PIERRET jmp at geosys.com
Wed Nov 22 02:48:45 EST 2006


Hi,

It works very well, thanks.

Best Regards,

PIERRET Jean michel


-----Message d'origine-----
De : Tamas Szekeres [mailto:szekerest at gmail.com] 
Envoyé : mardi 21 novembre 2006 22:42
À : Jean Michel PIERRET
Cc : gdal-dev at lists.maptools.org
Objet : Re: RE : [Gdal-dev] ColorTable in C#

Hi,

When constructing the ColorTable you have to use the GDALPaletteInterp
constants as the parameter like:

ct_out = new ColorTable(gdalconst.GPI_RGB);

Here is the complete code:

public static void test(string file, string file_out)
    {
        gdal.AllRegister();

        Driver dv = null;
        Dataset ds = null, ds_out = null;
        Band ba = null, ba_out = null;
        ColorTable ct = null, ct_out = null;
        byte [] buffer;

        ds = gdal.Open(file, gdalconst.GA_ReadOnly);
        ba = ds.GetRasterBand(1);
        ct = ba.GetRasterColorTable();

        buffer = new byte [ds.RasterXSize * ds.RasterYSize];
        ba.ReadRaster(0, 0, ds.RasterXSize, ds.RasterYSize, buffer,
            ds.RasterXSize, ds.RasterYSize, 0, 0);

        dv = gdal.GetDriverByName("GTiff");

        ds_out = dv.Create(file_out, ds.RasterXSize, ds.RasterYSize,
            ds.RasterCount, ba.DataType, new string [] {});
        ba_out = ds_out.GetRasterBand(1);
        ct_out = new ColorTable(gdalconst.GPI_RGB);

        ba_out.WriteRaster(0, 0, ds.RasterXSize, ds.RasterYSize, buffer,
            ds.RasterXSize, ds.RasterYSize, 0, 0);

        for (int i = 0; i < ct.GetCount(); i++)
        {
            ColorEntry ce = null, ce_out = null;

            ce = ct.GetColorEntry(i);
            ce_out = new ColorEntry();

            ce_out.c1 = ce.c1;
            ce_out.c2 = ce.c2;
            ce_out.c3 = ce.c3;
            ce_out.c4 = ce.c4

            ct_out.SetColorEntry(i, ce_out);

            ce.Dispose();
            ce_out.Dispose();
        }

        ba_out.SetRasterColorTable(ct_out);
    }


Best Regards,

Tamas Szekeres







2006/11/21, Jean Michel PIERRET <jmp at geosys.com>:
>
> Hi,
>
> I'm using the CVS : "gdal-cvs-2006.11.21.tar.gz", I see well the new Class
> ColorEntry, but I still can't create a new ColorTable with 256 ColorEntry.
>
>
> public static void test(string file, string file_out)
> {
>         Driver dv = null;
>         Dataset ds = null, ds_out = null;
>         Band ba = null, ba_out = null;
>         ColorTable ct = null, ct_out = null;
>         byte [] buffer;
>
>         ds = gdal.Open(file, gdalconst.GA_ReadOnly);
>         ba = ds.GetRasterBand(1);
>         ct = ba.GetRasterColorTable();
>
>         buffer = new byte [ds.RasterXSize * ds.RasterYSize];
>         ba.ReadRaster(0, 0, ds.RasterXSize, ds.RasterYSize, buffer,
> ds.RasterXSize, ds.RasterYSize, 0, 0);
>
>         dv = gdal.GetDriverByName("GTiff");
>
>         ds_out = dv.Create(file_out, ds.RasterXSize, ds.RasterYSize,
> ds.RasterCount, ba.DataType, new string [] {});
>         ba_out = ds_out.GetRasterBand(1);
>     ct_out = new ColorTable(ct.GetCount());
>
>         ba_out.WriteRaster(0, 0, ds.RasterXSize, ds.RasterYSize, buffer,
> ds.RasterXSize, ds.RasterYSize, 0, 0);
>
>         for (int i = 0; i < ct.GetCount(); i++)
>         {
>                 ColorEntry ce = null, ce_out = null;
>
>                 ce = ct.GetColorEntry(i);
>                 ce_out = new ColorEntry();
>
>                 ce_out.c1 = ce.c1;
>                 ce_out.c2 = ce.c2;
>                 ce_out.c3 = ce.c3;
>                 ce_out.c4 = ce.c4;
>
>                 ct_out.SetColorEntry(i, ce_out);
>
>                 ce.Dispose();
>                 ce_out.Dispose();
>         }
>
>         ba_out.SetRasterColorTable(ct_out);
>
>         ct_out.Dispose();
>         ba_out.Dispose();
>         ds_out.Dispose();
>
>         ct.Dispose();
>         ba.Dispose();
>         ds.Dispose();
> }
>
> -----Message d'origine-----
> De: Tamas Szekeres [mailto:szekerest at gmail.com]
> Envoyé: lundi 20 novembre 2006 14:06
> Ŕ: Jean Michel PIERRET
> Cc: gdal-dev at lists.maptools.org
> Objet: Re: [Gdal-dev] ColorTable in C#
>
> Hi,
>
> I've just added the ColorEntry struct for the SWIG C# interface. Now you can
> use
>
> the ColorTable and ColorEntry classes along with
> Band.SetRasterColorTable and Band.GetRasterColorTable.
>
> Checkout the latest CVS and notify me how it works.
>
>
> Best Regards,
>
> Tamas Szekeres
>
>
>
> 2006/11/20, Jean Michel PIERRET <jmp at geosys.com>:
> >
> >
> >
> >
> > Hi,
> >
> >
> >
> > How can I create a new ColorTable in C# for a new image.
> >
> >
> >
> > Thank.
> >
> >
> >
> > PIERRET Jean michel.
> >
> >
> >
> >
> > _______________________________________________
> > Gdal-dev mailing list
> > Gdal-dev at lists.maptools.org
> > http://lists.maptools.org/mailman/listinfo/gdal-dev
> >
> >
>
>





More information about the Gdal-dev mailing list