<div dir="ltr">thanks, <br>That does the trick. <br>Oz. <br><br><div class="gmail_quote">On Mon, Mar 30, 2009 at 7:02 PM, Even Rouault <span dir="ltr">&lt;<a href="mailto:even.rouault@mines-paris.org">even.rouault@mines-paris.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Oz,<br>
<br>
See the hereafter a correction to insert in your code that will hopefully fix<br>
your issue.<br>
<br>
Le Monday 30 March 2009 17:25:13 Oz Nahum, vous avez écrit :<br>
<div><div></div><div class="h5">&gt; Hi,<br>
&gt; I have encountered a weired problem with gdal_rasterize.<br>
&gt;<br>
&gt; when I run the script from here<br>
&gt; <a href="http://trac.osgeo.org/gdal/wiki/FAQRaster#HowcanIcreateablankrasterbasedona" target="_blank">http://trac.osgeo.org/gdal/wiki/FAQRaster#HowcanIcreateablankrasterbasedona</a><br>
&gt;vectorfilesextentsforusewithgdal_rasterize<br>
&gt;<br>
&gt; When I run:<br>
&gt; #!/usr/bin/env python<br>
&gt;<br>
&gt; from osgeo import gdal<br>
&gt; from osgeo import osr<br>
&gt; from osgeo import ogr<br>
&gt; import numpy<br>
&gt; #from numpy import ones<br>
&gt; import stat, sys, os, string, commands<br>
&gt;<br>
&gt; shp = &#39;AOI&#39;<br>
&gt; tiff = &#39;AOI.tif&#39;<br>
&gt; px = 1<br>
&gt; tiff_width = 80<br>
&gt; tiff_height = 80<br>
&gt;<br>
&gt; # Import vector shapefile<br>
&gt; vector = ogr.GetDriverByName(&#39;ESRI Shapefile&#39;)<br>
&gt; src_ds = vector.Open(shp +&#39;.shp&#39;)<br>
&gt; src_lyr = src_ds.GetLayerByIndex(index=0)<br>
&gt; src_extent = src_lyr.GetExtent()<br>
&gt;<br>
&gt; # Create new raster layer with 4 bands<br>
&gt; raster = gdal.GetDriverByName(&#39;GTiff&#39;)<br>
&gt; dst_ds = raster.Create( tiff, tiff_width, tiff_height, 1, gdal.GDT_Byte)<br>
&gt;<br>
&gt; # Create raster GeoTransform based on upper left corner and pixel<br>
&gt; resolution raster_transform = [src_extent[0], px, 0.0, src_extent[3], 0.0,<br>
&gt; -px] dst_ds.SetGeoTransform( raster_transform )<br>
&gt;<br>
&gt; # Get projection of shapefile and assigned to raster<br>
&gt; srs = osr.SpatialReference()<br>
&gt; srs.ImportFromWkt(src_lyr.GetSpatialRef().__str__())<br>
&gt; dst_ds.SetProjection( srs.ExportToWkt() )<br>
&gt;<br>
&gt; # Create blank raster with fully opaque alpha band<br>
&gt; zeros = numpy.zeros( (tiff_height, tiff_width), numpy.uint8 )<br>
&gt; dst_ds.GetRasterBand(1).WriteArray( zeros )<br>
<br>
</div></div># Properly close the dataset before calling gdal_rasterize, so that the TIF<br>
# file is properly written.<br>
dst_ds = None<br>
<div class="im"><br>
&gt;<br>
&gt; commandString =  &#39;gdal_rasterize -burn 255 -l AOI AOI.shp AOI.tif&#39;<br>
&gt; commandOutput = commands.getoutput(commandString)<br>
&gt; print commandOutput<br>
&gt; #end of code<br>
&gt;<br>
&gt; I get the error this error:<br>
&gt;<br>
&gt; augmented to the gdal_rasterize command I see this error. When I run it via<br>
&gt; a shell script, I don&#39;t see the error:<br>
&gt; ERROR 4: `AOI.tif&#39; not recognised as a supported file format.<br>
&gt;<br>
&gt;<br>
&gt; #!/bin/sh<br>
&gt; python create_empty_raster.py<br>
&gt; gdal_rasterize -burn 255 -l AOI AOI.shp AOI.tif<br>
&gt;<br>
&gt; Runs ok.<br>
<br>
</div>--&gt; This runs ok as at the end of the create_empty_raster.py script, the GDAL<br>
dataset is automatically closed.<br>
<div><div></div><div class="h5"><br>
&gt;<br>
&gt; So I am confused, why I can&#39;t call gdal_rasterize from python ?<br>
&gt; Thanks, for any help<br>
&gt;<br>
&gt; Oz Nahum<br>
&gt; Universtät Tuebingen<br>
&gt; Applied Environmental Sciences<br>
<br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><br>----<br>            Imagine there&#39;s no countries<br>            It isn&#39;t hard to do<br>            Nothing to kill or die for<br>            And no religion too<br>
            Imagine all the people<br>            Living life in peace <br>----<br>           You all must read &#39;The God Delusion&#39; <br>           <a href="http://en.wikipedia.org/wiki/The_God_Delusion">http://en.wikipedia.org/wiki/The_God_Delusion</a><br>
---<br>when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion.&quot;<br>Robert Pirsig, Zen and the Art of Motorcycle Maintenance<br><br>
</div>