[Gdal-dev] Create Images with GDAL in C#

Jean Michel PIERRET jmp at geosys.com
Tue Nov 14 02:55:10 EST 2006


Hi,

I'm using the CVS of 2006.11.09 and it's doesn't work with your new version
of code, but with the CVS of this morning (2006.11.13) it's ok, my images
are good and I can read these with arcview.        

Thanks a lot, for your reactivity and efficiency.

PIERRET Jean michel

-----Message d'origine-----
De : Tamas Szekeres [mailto:szekerest at gmail.com] 
Envoyé : lundi 13 novembre 2006 23:35
À : Jean Michel PIERRET
Cc : gdal-dev at lists.maptools.org
Objet : Re: [Gdal-dev] Create Images with GDAL in C#

I've tested the following code with success:

public static void Main(string[] args)
{
          create(args[0]);
}

public static void create(string file)
    {
        Driver dv;
        Dataset ds;
        Band ba;

        int bXSize, bYSize;
        int w, h;

        string [] options;

        w = 100;
        h = 100;

        bXSize = w;
        bYSize = 1;

        gdal.AllRegister();

        dv = gdal.GetDriverByName("GTiff");
        options = new string [] {"BLOCKXSIZE=" + bXSize, "BLOCKYSIZE="
+ bYSize};

        ds = dv.Create(file, w, h, 1, gdalconst.GDT_Byte, options);

        ba = ds.GetRasterBand(1);

        float [] buffer;

        buffer = new float [w * h];

        for (int i = 0; i < buffer.Length; i++)

            buffer[i] = i*256/buffer.Length;

        ba.WriteRaster(0, 0, w, h, buffer, w, h, 0, 0);

        ba.FlushCache();
        ds.FlushCache();

        ba.Dispose();
        ds.Dispose();
    }


Are you using the latest CVS version?

Best Regards,

Tamas Szekeres




2006/11/13, Jean Michel PIERRET <jmp at geosys.com>:
>
>
>
>
> Hi,
>
>
> I've just tried to use the GDAL C#, it's ok to read images,
>
> But i have problem to create images, all my created images are empty.
>
>
>
> public static void create(string file)
>
> {
>
> Driver dv;
>
>       Dataset ds;
>
>       Band ba;
>
>
>
>       int bXSize, bYSize;
>
>       int w, h;
>
>
>
>       string [] options;
>
>
>
>       w = 100;
>
>       h = 100;
>
>
>
>       bXSize = w;
>
>       bYSize = 1;
>
>
>
>       dv = gdal.GetDriverByName("GTiff");
>
>       options = new string [] {"BLOCKXSIZE=" + bXSize, "BLOCKYSIZE=" +
> bYSize};
>
>
>
>       ds = dv.Create(file, w, h, 1, gdalconst.GDT_Float32, options);
>
>       ba = ds.GetRasterBand(1);
>
>
>
>       float [] buffer;
>
>       buffer = new float [w * h];
>
>       for (int i = 0; i < buffer.Length; i++)
>
>             buffer[i] = i;
>
>
>
>       b.WriteRaster(0, 0, w, h, buffer, w, h, 0, 0);
>
>
>
>       b.FlushCache();
>
>       d.FlushCache();
>
>
>
>       b.Dispose();
>
>       d.Dispose();
>
> }
>
>
>
> Thanks for your help and all your work on c# bindings.
>
>
>
> 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