I have a raster that needs to be split into tiles (each tile a new raster). I have a Shapefile with multiple polygons (these polygons are how I want the raster split).
How do I do this using GDAL?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI have a raster that needs to be split into tiles (each tile a new raster). I have a Shapefile with multiple polygons (these polygons are how I want the raster split).
How do I do this using GDAL?
You can split the image to small tiles by the size of the (tile_size) using a code like this one:
file_path,file_name = {{put-yor-path-and-name-here}}
gdal_img = gdal.Open(img)
RasterXSize = gdal_img.RasterXSize
RasterYSize = gdal_img.RasterYSize
transform = gdal_img.GetGeoTransform()
minX = transform[0]
maxY = transform[3]
img_pixelWidth = transform[1]
img_out = str(path) + "\\" + str(out_img_name) + r".TIF"
gdalnumeric.SaveArray(gdalnumeric.LoadFile(img,startX,
startY,tile_sizeX,tile_sizeY),
img_out,"GTiff")
You can use the Select by Attributes tool to select all of the raster features inside the shapefiles. Then right click on the raster in the Table of Contents and go to Data > Export to CAD.