<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; " class=""><div class="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(218, 217, 84); "><font class="Apple-style-span" color="#4062C1"><div class="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; "><div class="" 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="#000000" face="Helvetica">Hi list,</font></div><div class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">Im just starting to use the python bindings and have been experimenting with gdal_rasterize which great results, effectively burning in multiple different colors based on some related vector shapefile attributes. The trick to getting started was that I did not have any raster (at the right extent and resolution) to copy from, so to get started I followed the api tutorial to create and new Gtiff.</font></div><div class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">This code works perfectly for my usecase:</font></div><div class="" 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="#030788"><b><br></b></font></div><div class="" 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: #030788"><b>from</b></span> osgeo <span style="color: #030788"><b>import</b></span> gdal</div><div class="" 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: #030788"><b>from</b></span> osgeo <span style="color: #030788"><b>import</b></span> osr</div><div class="" 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: #030788"><b>import</b></span> numpy</div><div class="" 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 class="" style=""></div><div class="" 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 class="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 12px/normal 'Lucida Grande'; color: rgb(180, 137, 74); "><span style="color: #45451b">dst_ds = driver.Create( </span>"/Users/spring/projects/wind/data/processed/wpc_final.tif"<span style="color: #45451b">, </span><span style="color: #489798">7850</span><span style="color: #45451b">, </span><span style="color: #489798">3500</span><span style="color: #45451b">, </span><span style="color: #489798">4</span><span style="color: #45451b">, gdal.GDT_Byte)</span></div><div class="" 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 class="" 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 class="" 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 class="" 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 class="" 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 class="" 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 class="" 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="#000000" face="Helvetica">But the tutorial also has the step of writing zeros over the image with numpy. Since I am already burning in the required values into my raster with gdal_rasterize this seems not to matter, but I am really curious for future uses how to get this step working. Starting with zeros, or any default value would be useful.</font></div><div class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">So, if I execute the following code block next:</font></div><div class="" 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 class="" 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 class="Apple-style-span" style="color: rgb(180, 137, 74); "><span style="color: rgb(72, 151, 152); ">7850</span><span style="color: rgb(69, 69, 27); ">, </span><span style="color: rgb(72, 151, 152); ">3500</span></span>) )</div><div class="" 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 class="" 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 class="" 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 class="" 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( zeros )</div><div class="" 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 class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">I get the error:</font></div><div class="" 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="#000000" face="Helvetica">'ValueError: array larger than output file, or offset off edge' which obviously means that I am writing the wrong size numpy array into my raster. </font></div><div class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">So, what do I need to know to figure out the right dimensions for the numpy.zeros() function? Some slick fraction of my image size in pixels and my geotransform?</font></div><div class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">Thanks,</font></div><div class="" 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="#000000" face="Helvetica"><br></font></div><div class="" 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="#000000" face="Helvetica">Dane</font></div><div class="" 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="#000000" face="Helvetica"><br></font></div></div></font></div></body></html>