[gdal-dev] gdal_rasterize does not burn the polygon]

Frank Warmerdam warmerdam at pobox.com
Sun Apr 20 10:10:05 EDT 2008


Xiaodong Zhang wrote:
> Hi there,
> 
> I tried to use "gdal_rasterize -burn 0 -l test test/test.shp 
> 2003_Yield_03.tif" to highlight the area covered by the polygon, but it 
> does not seem to work. The figure below shows the polygon is inside the 
> extension of the image. The problem is that the area inside the polygon 
> was not highlighted (or burned). Could anybody please tell me where I 
> did wrong. The test data is attached.
> 
> The image and the shape file are not in the same projection, but I'm not 
> sure if this could be the cause. As both of them showed nicely in ENVI. 
> I used ogr2ogr to convert a few points into a polygon using WKT format. 
> Do I need to some fancier thing to make polygons?

Xiaodong,

The problem is indeed the incompatible coordinate systems.  I copied
the gdalinfo report of the .tif projection to a file called target.prj
(these contents):

PROJCS[" Projection Name = Lambert Azimuthal Equal-ar",
     GEOGCS["WGS 84",
         DATUM["WGS_1984",
             SPHEROID["WGS 84",6378137,298.2572235630016,
                 AUTHORITY["EPSG","7030"]],
             AUTHORITY["EPSG","6326"]],
         PRIMEM["Greenwich",0],
         UNIT["degree",0.0174532925199433],
         AUTHORITY["EPSG","4326"]],
     PROJECTION["Lambert_Azimuthal_Equal_Area"],
     PARAMETER["latitude_of_center",45],
     PARAMETER["longitude_of_center",-100],
     PARAMETER["false_easting",0],
     PARAMETER["false_northing",0],
     UNIT["metre",1,
         AUTHORITY["EPSG","9001"]]]

Then reprojected the vectors like this:

  ogr2ogr out.shp test -t_srs ./target.prj

Then did the rasterize:

  gdal_rasterize -burn 0 -l out out.shp 2003_Yield_03.tif

And the expected effect was achieved.

The lesson is that gdal_rasterize will not reproject your vector
input for you.  You need to do this yourself.  If you wish you could
file a ticket requesting that gdal_rasterize be improved, or at least
issue a warning in a case like this.

In the meantime, reproject your inputs manually.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list