[Gdal-dev] Create Images with GDAL in C#
Tamas Szekeres
szekerest at gmail.com
Mon Nov 13 17:34:59 EST 2006
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