I'd like to create training data for a machine learning pipeline. To do this I want to take a large raster and split it into multiple equal sized cells.
I have a very basic loop for generating the pixel-wise coordinates, how do I generate a cell from these when splitting up a GeoTIFF?
def splitImageIntoCells(img, filename, squareDim):
numberOfCellsWide = img.shape[1] // squareDim
numberOfCellsHigh = img.shape[0] // squareDim
x, y = 0, 0
for hc in range(numberOfCellsHigh):
y = hc * squareDim
for wc in range(numberOfCellsWide):
x = wc * squareDim
# Need some method from Rasterio here
# to crop at the given x and y...
Best Answer
I devised the following 4 methods:
To use these you would simply read in an image with Rasterio, and call the first method like so: