Ah, thanks. This solved the problem.<br>I however face the problem that I don't know which data type the image has. So I can't hardcode the array to unsigned short, since it might sometimes be a int32 or even a float. So is there a way to do this in a generic way?<br>
<br>Chris<br><br><div class="gmail_quote">On Fri, Jun 3, 2011 at 12:21 PM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Le vendredi 03 juin 2011 12:13:41, Goo Creations a écrit :<br>
<div><div></div><div class="h5">> Hi all<br>
><br>
> I have a strange problem when writing to a GDAL dataset. I'm currently<br>
> doing the following:<br>
><br>
> *GDALDataset *mInputDataset = (GDALDataset*) GDALOpen("in.tif",<br>
> GA_ReadOnly);<br>
> GDALDataType type = mInputDataset->GetRasterBand(1)->GetRasterDataType();<br>
> int mWidth = mInputDataset->GetRasterXSize();<br>
> int mHeight = mInputDataset->GetRasterYSize();<br>
><br>
> GDALDataset *mOutputDataset = mInputDataset->GetDriver()->Create("out.tif",<br>
> mWidth, mHeight, mBands, type, 0);<br>
><br>
> int *data = <<get data for entire band>><br>
> mOutputDataset->GetRasterBand(1)->RasterIO(GF_Write, 0, 0, aligner.width(),<br>
> aligner.height(), data, aligner.width(), aligner.height(), type, 0, 0);<br>
> mOutputDataset->FlushCache();<br>
> *<br>
><br>
> The input image provided has a datatype of UINT16. When I hardcode all<br>
> "type" variables in the above example to GDT_Int32, then the image is<br>
> correctly created, but when I leave the example as is (hence with<br>
> GDT_UInt16 assigned to "type"), then I get a strange problem that every<br>
> second column has a value of 0. So every odd column has the correct values<br>
> in, but every even column has values of 0. I've checked the data array,<br>
> and all the values in there are correct.<br>
><br>
> Does anyone know why this is happening?<br>
<br>
</div></div>Yes, the type parameter must be consistent with the C type of the data array,<br>
otherwise weird things can happen, including crashes.<br>
<br>
In your exemple data is of type int*, so type must be set to GDT_Int32.<br>
If you want to write GDT_UInt16, then data must be declared as being of type<br>
unsigned short*<br>
<br>
</blockquote></div><br>