[gdal-dev] Problem with readraster in C#
Tamas Szekeres
szekerest at gmail.com
Fri Dec 4 16:26:36 EST 2009
Patrik,
The code you mentioned did't appear to do correct mashaling with the buffer
passed to gdal.
You might want to use the following readraster signature instead:
public OSGeo.GDAL.CPLErr ReadRaster(int xOff, int yOff, int xSize, int
ySize, short[] buffer, int buf_xSize, int buf_ySize, int pixelSpace, int
lineSpace)
which would implicitly do something like:
GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try {
retval = ReadRaster(xOff, yOff, xSize, ySize,
handle.AddrOfPinnedObject(), buf_xSize, buf_ySize, DataType.GDT_Int16,
pixelSpace, lineSpace);
} finally {
handle.Free();
}
GC.KeepAlive(this);
Best regards,
Tamas
2009/11/29 patsv <patsv at bredband.net>
> Hi, I am trying to read GDEM data from the ASTER dataset.
>
> But all I get is a buffer with zeroes, is there something wrong with my
> code or is it something with the readraster function.
>
>
>
> Part of my code:
>
> Band band = ds.GetRasterBand(1);
>
> short[] DEM = new short[band.XSize * band.YSize];
>
>
>
> CPLErr Ret = band.ReadRaster(0, 0, band.XSize,band.YSize, DEM,
> band.XSize, band.YSize, 2, band.XSize * 2);
>
> if (Ret != CPLErr.CE_None)
>
> {
>
> throw new Exception("Read error " + Ret.ToString());
>
> }
>
>
>
> As mentioned above all I get is a buffer filled with Zeroes.
>
>
>
> Thanks for a good library.
>
>
>
> Regards
>
> Patrik Svensson
>
>
>
>
>
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20091204/9542f51f/attachment.html
More information about the gdal-dev
mailing list