<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Antonio,<div><br></div><div>Thanks for the suggestion to check my numpy types. I dug into the various Gdal types and numpty types and saw that I'll have to be careful to keep sync.</div><div><br></div><div>However, with a little more digging I think I found the simple problem: my axis needed to be reversed when calling the numpy function.</div><div><br></div><div>This code below now works:</div><div><br></div><div><br></div><div># create a 4 band geotiff with RGB bands all zero and Alpha band fully non-transparent</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); "><font class="Apple-style-span" color="#4062C1"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); "><span style="color: #4062c1">from</span> osgeo <span style="color: #4062c1">import</span> gdal</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); "><span style="color: #4062c1">from</span> osgeo <span style="color: #4062c1">import</span> osr</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); "><span style="color: #4062c1">import</span> numpy</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); min-height: 15px; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">driver = gdal.GetDriverByName(<span style="color: #b46c24">'GTiff'</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds = driver.Create( <span style="color: #b4894a">"test.tif"</span>, <span style="color: #489798">7850</span>, <span style="color: #489798">3500</span>, <span style="color: #489798">4</span>, gdal.GDT_Byte)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds.SetGeoTransform( [-<span style="color: #489798">124.75</span>, <span style="color: #489798">.001</span>, <span style="color: #489798">0.0</span>, <span style="color: #489798">49.02</span>, <span style="color: #489798">0.0</span>, -<span style="color: #489798">.001</span>] )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">srs = osr.SpatialReference()</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">srs.ImportFromEPSG(<span style="color: #489798">4326</span>)</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds.SetProjection( srs.ExportToWkt() )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">zeros = numpy.zeros( (<span style="color: #489798">3500</span>, <span style="color: #489798">7850</span>), numpy.uint8 )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds.GetRasterBand(<span style="color: #489798">1</span>).WriteArray( zeros )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds.GetRasterBand(<span style="color: #489798">2</span>).WriteArray( zeros )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds.GetRasterBand(<span style="color: #489798">3</span>).WriteArray( zeros )</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">opaque = numpy.ones((<span style="color: #489798">3500</span>,<span style="color: #489798">7850</span>), numpy.uint8 )*<span style="color: #489798">255</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); ">dst_ds.GetRasterBand(<span style="color: #489798">4</span>).WriteArray( opaque )</div></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(69, 69, 27); "><br></div></div><div>Cheers,</div><div><br></div><div>Dane</div><div><br></div><div><br><div><div>On Jun 7, 2008, at 1:59 AM, Antonio Valentino wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Il giorno Fri, 6 Jun 2008 17:20:44 -0700<br>Dane Springmeyer &lt;<a href="mailto:blake@hailmail.net">blake@hailmail.net</a>> ha scritto:<br><br><blockquote type="cite">Hi list,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Im just starting to use the python bindings and have been &nbsp;<br></blockquote><blockquote type="cite">experimenting with gdal_rasterize which great results, effectively &nbsp;<br></blockquote><blockquote type="cite">burning in multiple different colors based on some related vector &nbsp;<br></blockquote><blockquote type="cite">shapefile attributes. &nbsp;The trick to getting started was that I did<br></blockquote><blockquote type="cite">not have any raster (at the right extent and resolution) to copy<br></blockquote><blockquote type="cite">from, so to get started I followed the api tutorial to create and new<br></blockquote><blockquote type="cite">Gtiff.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">This code works perfectly for my usecase:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">from osgeo import gdal<br></blockquote><blockquote type="cite">from osgeo import osr<br></blockquote><blockquote type="cite">import numpy<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">driver = gdal.GetDriverByName('GTiff')<br></blockquote><blockquote type="cite">dst_ds = driver.Create( "/Users/spring/projects/wind/data/processed/ <br></blockquote><blockquote type="cite">wpc_final.tif", 7850, 3500, 4, gdal.GDT_Byte)<br></blockquote><blockquote type="cite">dst_ds.SetGeoTransform( [-124.75, .001, 0.0, 49.02, 0.0, -.001] )<br></blockquote><blockquote type="cite">srs = osr.SpatialReference()<br></blockquote><blockquote type="cite">srs.ImportFromEPSG(4326)<br></blockquote><blockquote type="cite">dst_ds.SetProjection( srs.ExportToWkt() )<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">But the tutorial also has the step of writing zeros over the image &nbsp;<br></blockquote><blockquote type="cite">with numpy. Since I am already burning in the required values into<br></blockquote><blockquote type="cite">my raster with gdal_rasterize this seems not to matter, but I am<br></blockquote><blockquote type="cite">really curious for future uses how to get this step working. Starting<br></blockquote><blockquote type="cite">with zeros, or any default value would be useful.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">So, if I execute the following code block next:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">zeros = numpy.zeros( (7850, 3500) )<br></blockquote><br>Dane,<br>here you are getting a floating point array. Try to print zeros.dtype.<br>In my opinion the correct code should be<br><br>zeros = numpy.zeros( (7850, 3500), dtype=numpy.uint8 )<br><br>or something similar.<br><br><blockquote type="cite">dst_ds.GetRasterBand(1).WriteArray( zeros )<br></blockquote><blockquote type="cite">dst_ds.GetRasterBand(2).WriteArray( zeros )<br></blockquote><blockquote type="cite">dst_ds.GetRasterBand(3).WriteArray( zeros )<br></blockquote><blockquote type="cite">dst_ds.GetRasterBand(4).WriteArray( zeros )<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I get the error:<br></blockquote><blockquote type="cite">'ValueError: array larger than output file, or offset off edge'<br></blockquote><blockquote type="cite">which obviously means that I am writing the wrong size numpy array<br></blockquote><blockquote type="cite">into my raster.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">So, what do I need to know to figure out the right dimensions for<br></blockquote><blockquote type="cite">the numpy.zeros() function? Some slick fraction of my image size in<br></blockquote><blockquote type="cite">pixels and my geotransform?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Thanks,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Dane<br></blockquote><blockquote type="cite"><br></blockquote><br><br>-- <br>Antonio Valentino<br>_______________________________________________<br>gdal-dev mailing list<br><a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>http://lists.osgeo.org/mailman/listinfo/gdal-dev<br></div></blockquote></div><br></div></body></html>