no I quickly checked that!<br>myarray is:<br>[[ 16.15035553 16.14380074 16.15581551 ..., 18.06388149 18.08930645<br> 18.08825245]<br> [ 16.2154911 16.21180592 16.23977184 ..., 18.1085537 18.12040272<br> 18.12342682]<br>
[ 16.32851467 16.29202938 16.28964043 ..., 18.16753635 18.14905453<br> 18.16632977]<br> ..., <br> [ 30.50812759 30.58384018 30.66707535 ..., 26.31020527 26.47789459<br> 27.11495361]<br> [ 30.76499577 30.76497536 30.79138317 ..., 26.45928288 26.64059887<br>
27.03641129]<br> [ 31.01263275 30.96269417 30.9933857 ..., 26.78247185 26.77845631<br> 26.97975636]]<br><br><div class="gmail_quote">On Wed, Feb 1, 2012 at 1:25 PM, Kyle Shannon <span dir="ltr"><<a href="mailto:ksshannon@gmail.com">ksshannon@gmail.com</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"><font><font face="courier new,monospace">Is 'myarray' 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"><div><div class="h5">On Tue, Jan 31, 2012 at 19:20, questions anon <span dir="ltr"><<a href="mailto:questions.anon@gmail.com" target="_blank">questions.anon@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5">
thanks Frank, following your instructions with:<div><br>src_ds=gdal_array.OpenArray(myarray)<br>dst_ds = gdal.GetDriverByName('GTiff').Create('E:/test/rasterise/mynewraster.tif',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>
<div><br><br><div class="gmail_quote">
On Wed, Feb 1, 2012 at 12:07 PM, Frank Warmerdam <span dir="ltr"><<a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</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">
<div><div>On Tue, Jan 31, 2012 at 4:38 PM, questions anon<br>
<<a href="mailto:questions.anon@gmail.com" target="_blank">questions.anon@gmail.com</a>> wrote:<br>
> I need to output my numpy array as a raster so that someone else can access<br>
> the data in ArcGIS. So basically the steps I need are:<br>
> read numpy array into gdal<br>
> convert to raster<br>
> use latitude and longitude and array size to set projection<br>
><br>
> I am really struggling with gdal because I can't seem to find enough<br>
> documentation about each step to understand what it is doing.<br>
> Here are some of the steps I think I need:<br>
><br>
> myarray=myarray<br>
> #the extent and shape of my array<br>
> xmin,ymin,xmax,ymax=[139.8,-39.2,150.0,-33.6]<br>
> ncols,nrows=[193,106]<br>
> xres=(xmax-xmin)/float(ncols)<br>
> yres=(ymax-ymin)/float(nrows)<br>
> geotransform=(xmin,xres,0,ymax,0, -yres)<br>
><br>
> from osgeo import gdal<br>
> from osgeo import gdal_array<br>
><br>
> src_ds=gdal_array.OpenArray(myarray)<br>
><br>
> dst_ds =<br>
> gdal.GetDriverByName('GTiff').Create('E:/test/rasterise/mynewraster.tif',ncols,<br>
> nrows, 1 ,gdal.GDT_Byte)<br>
> dst_rb = dst_ds.GetRasterBand(0)<br>
> dst_ds.SetGeoTransform(geotransform)<br>
> output = gdal.RasterizeLayer(dst_ds)<br>
<br>
</div></div>Dear "Questions Anon",<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 "gdal.RasterizeLayer()" 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 "dst_ds.WriteArray(myarray)".<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></div></div>_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">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>
</blockquote></div><br>