I am trying to clip a raster image into a small image using coordinates in a CSV file. In the CSV file, I have minx,maxx,miny,maxy as the coordinates which makes the bounding box and clips the images.
I have a total of 100,000 coordinates and it will create 50,000 images. I am trying to number the images in ascending numbers. Example 0,1,2,3.... till 50,000. The problem is that when clipping it's escaping some images and only clipping 26,000 images. I just cannot find the bug in my code.
I thought it was the coordinate but when checking the coordinates it seems fine, the bug somehow is in my code.
import pandas as pd
from osgeo import gdal
df = pd.read_csv("G:\\satellite\\align\\satellite.txt")
fs = gdal.Open('G:\\satellite\\align\\satellite.tif')
i, j = 0, 0
while True:
minx = df.iloc[i][0]
miny = df.iloc[i][1]
maxx = df.iloc[i+1][0]
maxy = df.iloc[i+1][1]
out_tif = r"G:\\satellite\\training_images\\satellite_rename\\{0}.tif".format(j)
ds = gdal.Translate(out_tif, fs, projWin = [minx, miny, maxx, maxy])
j = j+1
i += 2
if i > 100000: # The iteration depends on how many co-ordinates you have
break