<font><font face="courier new,monospace">Is &#39;myarray&#39; full of zeros?<br clear="all"></font></font><br><font face="courier new,monospace"><font>/**<br> *<br> * Kyle Shannon<br> * <a href="mailto:ksshannon@gmail.com" target="_blank">ksshannon@gmail.com</a><br>

 *<br> */</font></font><font><br></font><br>
<br><br><div class="gmail_quote">On Tue, Jan 31, 2012 at 19:20, questions anon <span dir="ltr">&lt;<a href="mailto:questions.anon@gmail.com">questions.anon@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

thanks Frank, following your instructions with:<div class="im"><br>src_ds=gdal_array.OpenArray(myarray)<br>dst_ds = gdal.GetDriverByName(&#39;GTiff&#39;).Create(&#39;E:/test/rasterise/mynewraster.tif&#39;,ncols, nrows, 1 ,gdal.GDT_Byte)<br>

</div>
dst_ds.SetGeoTransform(geotransform)<br>dst_ds.GetRasterBand(1).WriteArray(myarray)<br><br>I do not receive any error messages but the tiff produced are all just zeros. Is there a step I am missing?<br>thanks<div class="HOEnZb">

<div class="h5"><br><br><div class="gmail_quote">
On Wed, Feb 1, 2012 at 12:07 PM, Frank Warmerdam <span dir="ltr">&lt;<a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a>&gt;</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">


<div><div>On Tue, Jan 31, 2012 at 4:38 PM, questions anon<br>
&lt;<a href="mailto:questions.anon@gmail.com" target="_blank">questions.anon@gmail.com</a>&gt; wrote:<br>
&gt; I need to output my numpy array as a raster so that someone else can access<br>
&gt; the data in ArcGIS. So basically the steps I need are:<br>
&gt; read numpy array into gdal<br>
&gt; convert to raster<br>
&gt; use latitude and longitude and array size to set projection<br>
&gt;<br>
&gt; I am really struggling with gdal because I can&#39;t seem to find enough<br>
&gt; documentation about each step to understand what it is doing.<br>
&gt; Here are some of the steps I think I need:<br>
&gt;<br>
&gt; myarray=myarray<br>
&gt; #the extent and shape of my array<br>
&gt; xmin,ymin,xmax,ymax=[139.8,-39.2,150.0,-33.6]<br>
&gt; ncols,nrows=[193,106]<br>
&gt; xres=(xmax-xmin)/float(ncols)<br>
&gt; yres=(ymax-ymin)/float(nrows)<br>
&gt; geotransform=(xmin,xres,0,ymax,0, -yres)<br>
&gt;<br>
&gt; from osgeo import gdal<br>
&gt; from osgeo import gdal_array<br>
&gt;<br>
&gt; src_ds=gdal_array.OpenArray(myarray)<br>
&gt;<br>
&gt; dst_ds =<br>
&gt; gdal.GetDriverByName(&#39;GTiff&#39;).Create(&#39;E:/test/rasterise/mynewraster.tif&#39;,ncols,<br>
&gt; nrows, 1 ,gdal.GDT_Byte)<br>
&gt; dst_rb = dst_ds.GetRasterBand(0)<br>
&gt; dst_ds.SetGeoTransform(geotransform)<br>
&gt; output = gdal.RasterizeLayer(dst_ds)<br>
<br>
</div></div>Dear &quot;Questions Anon&quot;,<br>
<br>
There are a variety of Python related information at:<br>
<br>
  <a href="http://trac.osgeo.org/gdal/wiki/GdalOgrInPython" target="_blank">http://trac.osgeo.org/gdal/wiki/GdalOgrInPython</a><br>
<br>
One serious issue with the above is that &quot;gdal.RasterizeLayer()&quot; is used to<br>
turn vector data into raster data - for instance to rasterize polygon features<br>
into an existing raster file.  I think you want to write your array into a<br>
raster file.  I think you can just call &quot;dst_ds.WriteArray(myarray)&quot;.<br>
<br>
Alternatively if that method does not exist on the dataset, you<br>
can write the one band like:<br>
<br>
  dst_ds.GetRasterBand(1).WriteArray(myarray)<br>
<br>
Some of the samples referenced from the GdalOgrInPython should be<br>
helpful though I understand it can be hard to know where to look.<br>
<br>
Best regards,<br>
<span><font color="#888888">--<br>
---------------------------------------+--------------------------------------<br>
I set the clouds in motion - turn up   | Frank Warmerdam, <a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>
light and sound - activate the windows | <a href="http://pobox.com/%7Ewarmerdam" target="_blank">http://pobox.com/~warmerdam</a><br>
and watch the world go round - Rush    | Geospatial Software Developer<br>
</font></span></blockquote></div><br>
</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>