[gdal-dev] ERROR 4: `AOI.tif' not recognised as a supported file format.

Oz Nahum nahumoz at gmail.com
Mon Mar 30 11:25:13 EDT 2009


Hi,
I have encountered a weired problem with gdal_rasterize.

when I run the script from here
http://trac.osgeo.org/gdal/wiki/FAQRaster#HowcanIcreateablankrasterbasedonavectorfilesextentsforusewithgdal_rasterize

When I run:
#!/usr/bin/env python

from osgeo import gdal
from osgeo import osr
from osgeo import ogr
import numpy
#from numpy import ones
import stat, sys, os, string, commands

shp = 'AOI'
tiff = 'AOI.tif'
px = 1
tiff_width = 80
tiff_height = 80

# Import vector shapefile
vector = ogr.GetDriverByName('ESRI Shapefile')
src_ds = vector.Open(shp +'.shp')
src_lyr = src_ds.GetLayerByIndex(index=0)
src_extent = src_lyr.GetExtent()

# Create new raster layer with 4 bands
raster = gdal.GetDriverByName('GTiff')
dst_ds = raster.Create( tiff, tiff_width, tiff_height, 1, gdal.GDT_Byte)

# Create raster GeoTransform based on upper left corner and pixel resolution
raster_transform = [src_extent[0], px, 0.0, src_extent[3], 0.0, -px]
dst_ds.SetGeoTransform( raster_transform )

# Get projection of shapefile and assigned to raster
srs = osr.SpatialReference()
srs.ImportFromWkt(src_lyr.GetSpatialRef().__str__())
dst_ds.SetProjection( srs.ExportToWkt() )

# Create blank raster with fully opaque alpha band
zeros = numpy.zeros( (tiff_height, tiff_width), numpy.uint8 )
dst_ds.GetRasterBand(1).WriteArray( zeros )

commandString =  'gdal_rasterize -burn 255 -l AOI AOI.shp AOI.tif'
commandOutput = commands.getoutput(commandString)
print commandOutput
#end of code

I get the error this error:

augmented to the gdal_rasterize command I see this error. When I run it via
a shell script, I don't see the error:
ERROR 4: `AOI.tif' not recognised as a supported file format.


#!/bin/sh
python create_empty_raster.py
gdal_rasterize -burn 255 -l AOI AOI.shp AOI.tif

Runs ok.

So I am confused, why I can't call gdal_rasterize from python ?
Thanks, for any help

Oz Nahum
Universtät Tuebingen
Applied Environmental Sciences
-- 

----
           Imagine there's no countries
           It isn't hard to do
           Nothing to kill or die for
           And no religion too
           Imagine all the people
           Living life in peace
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090330/b14d5eaf/attachment.html


More information about the gdal-dev mailing list