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?

  • 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

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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