<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">On Tue, Jan 31, 2012 at 19:20, questions anon <span dir="ltr"><<a href="mailto:questions.anon@gmail.com">questions.anon@gmail.com</a>></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('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 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"><<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>_______________________________________________<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>