<span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">Patrik,<br><br>The code you mentioned did't appear to do correct mashaling with the buffer passed to gdal.<br>You might want to use the following readraster signature instead:<br>
<br>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)<br><br>which would implicitly do something like:<br><br><br> GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);<br>
try {<br> retval = ReadRaster(xOff, yOff, xSize, ySize, handle.AddrOfPinnedObject(), buf_xSize, buf_ySize, DataType.GDT_Int16, pixelSpace, lineSpace);<br> } finally {<br> handle.Free();<br> }<br>
GC.KeepAlive(this);<br><br><br><br>Best regards,<br><br>Tamas<br><br><br></span><br><div class="gmail_quote">2009/11/29 patsv <span dir="ltr"><<a href="mailto:patsv@bredband.net">patsv@bredband.net</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="SV">
<div>
<p class="MsoNormal"><span lang="EN-US">Hi, I am trying to read GDEM data
from the ASTER dataset.</span></p>
<p class="MsoNormal"><span lang="EN-US">But all I get is a buffer with zeroes, is
there something wrong with my code or is it something with the readraster
function.</span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US">Part of my code:</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
<span style="color: rgb(43, 145, 175);">Band</span> band = ds.GetRasterBand(1);</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
<span style="color: blue;">short</span>[] DEM = <span style="color: blue;">new</span>
<span style="color: blue;">short</span>[band.XSize * band.YSize];</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
<span style="color: rgb(43, 145, 175);">CPLErr</span> Ret = band.ReadRaster(0, 0,
band.XSize,band.YSize, DEM, band.XSize, band.YSize, 2, band.XSize * 2);</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
<span style="color: blue;">if</span> (Ret != <span style="color: rgb(43, 145, 175);">CPLErr</span>.CE_None)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
{</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
<span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Exception</span>(<span style="color: rgb(163, 21, 21);">"Read
error "</span> + Ret.ToString());</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">
</span><span style="font-size: 10pt; font-family: "Courier New";">}</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">As mentioned above all I get
is a buffer filled with Zeroes.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">Thanks for a good library.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">Regards</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US">Patrik Svensson</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
</div>
</div>
<br>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></blockquote></div><br>