Search code examples
bashshapefilerastergdal

What should the layername be in gdal_rasterize for loop?


I'm new to Linux and am currently trying to run this code in BASH on a set of shapefiles:

for file in /mnt/hgfs/Shared/*.shp ; do
gdal_rasterize -l ??? -burn 1 -tr 0.5 0.5 -te -180 -90 180 90 $file rast2
gdal_merge.py -o rast1 rast2 rast1
done

rast1 is an empty raster used to bind the following rasters to. I can't figure out what the syntax after -l should be in this code...I think the rest runs fine. I've tried using $file but the terminal gives me the following error:

Unable to find layer /mnt/hgfs/Shared/SHAPE1.shp, skipping. 

Any help would be much appreciated.


Solution

  • Note: I've never used GDAL, and am in no way familiar with it.

    Since the bottom of http://www.gdal.org/gdal_rasterize.html indicates that a layer name of "mask" can be used with "mask.shp", I suggest stripping the extension from $file and using that as the layer name:

    gdal_rasterize -l $(basename $file .shp) -burn 1 -tr 0.5 0.5 -t -180 -90 180 90 $file rast2