Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a tile index representing the tile scheme used to tile Lidar data. I want to tile imagery rasters using the same tiling scheme. I have not found anyway using open source tools to tile a raster based on a shapefile template. All the tools I have found require you to know the tile size and origins.

Are there any tools (especially GDAL) that will do this out of the box?

share|improve this question
You would have to add the looping part but see the cutline and cwhere arguments to gdalwarp, I think together you could crop out tiles based on each tile in the vector source. – mdsumner Dec 12 '12 at 22:02
up vote 2 down vote accepted

I don't think there is a direct way to do it, but the following bash script should work for you. It's a two step procedure :

  1. You'll need to create temporary shapefiles for each feature so that you can extract the feature Extent
  2. You will then pass the extent to gdal_translate.
for id in $(ogrinfo -ro -al input.shp | grep uniqueID | grep -o '[0-9]*'); 
   ogr2ogr tmp_ouput$id.shp input.shp -where "uniqueID = $id"; 
   extent=$( ogrinfo -al -so input$id | grep Extent | sed 's/Extent: (//g' | sed 's/)//g' | sed 's/(//g' | sed 's/-/,/g' | awk -F, '{print $1 $2 $3 $4}' ); 
   gdal_translate -projwin $extent -of GTiff input_raster.tif subset_raster.tif"; 

You'll need to replace 'uniqueID' with a unique Feature or Object ID in your shapefile.
Kudos to this post as it was very useful.

share|improve this answer
Thanks @dmci - That looks pretty similar to what I was thinking of scripting myself with Python if there isn't and existing tool. I haven't had much experience with open source tools, but have done plenty of Python scripting in ArcGIS and non GIS projects. Could you give any details as to what that same workflow might look like using Python or at least in a Windows environment? – Brian Dec 13 '12 at 21:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.