[Gdal-dev] how gdal_rasterize works

Markus Neteler neteler at itc.it
Sat Jun 24 03:37:41 EDT 2006


On Sun, Jun 18, 2006 at 01:20:09PM -0400, Frank Warmerdam wrote:
> Markus Neteler wrote:
> >Hi,
> >
> >a stupid command line question: If a SHAPE is my starting point, how
> >to generate the needed raster map for "burn in" (if I don't
> >want to launch my GRASS machine for this)?
> >
> >Certainly easy, but I don't recall...
> 
> Markus,
> 
> Well, to be honest I don't know an easy way.  I would be tempted to
> gdal_translate an input file with the right number of bands, and
> use the various options to set the desired region, size in pixels and
> lines and coordinate system.
> 
> eg.
> 
>   gdal_translate in.tif wrk.tif -ot Byte -outsize 1000 1000 \
>             -a_ullr -117 33 -116 34 -a_srs WGS84
>

Frank,

I found a trick (for the record) to easily generate an "empty"
seed input file using the netpbm tools:


# Fetch extent from SHAPE file:
# ogrinfo -so mycircle.shp mycircle | grep Extent
# Extent: (669750.000000, 5107500.000000) - (671750.000000, 5109500.000000)
#               W               S                 E             N
W=669750
S=5107500
E=671750
N=5109500


# create 1 pixel seed file:
ppmmake white 1 1 | ppm2tiff tmp.tif

# enlarge to desired size and apply projection info:
gdal_translate tmp.tif mycircle.tif -ot Byte -outsize $XSIZE $YSIZE \
	-a_ullr $W $N $E $S -a_srs `cat mycircle.prj | tr -s ' ' '_'`

# "burn" SHAPE into raster map:
gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 \
	-l mycircle mycircle.shp mycircle.tif

Works!

BTW: Any ideas for a fancy shell based parsing of the SHAPE map
extent? In GRASS we have a flag for "shell style" output which
is pretty useful...

Best regards

 Markus




More information about the Gdal-dev mailing list