import subprocess

# Listado de provincias y coordenadas BBOX (minX, minY, maxX, maxY)
provincias = [
    ("LE", 165583.129, 4655806.488, 359308.075, 4788784.113),
    ("ZA", 166293.171, 4554377.594, 314056.639, 4684823.089),
    ("SA", 169552.259, 4461045.538, 324235.561, 4577275.269),
    ("PA", 332186.405, 4623962.870, 426172.410, 4768571.337),
    ("VA", 301212.762, 4550866.655, 418262.506, 4686558.174),
    ("AV", 267323.246, 4439241.892, 401971.713, 4558944.559),
    ("SG", 355283.212, 4499034.248, 482647.809, 4604268.097),
    ("BU", 390164.779, 4589063.267, 539565.204, 4790489.131),
    ("SO", 454133.116, 4545251.750, 601862.518, 4666205.433),
]

vrt_input = "mosaico_u30.vrt"

for nombre, min_x, min_y, max_x, max_y in provincias:
    tif_output = f"{nombre}.tif"
    cmd = [
        "gdal_translate",
        "-of", "GTiff",
        "-projwin", str(min_x), str(max_y), str(max_x), str(min_y),
        "-a_nodata", "255 255 255",
        "-co", "COMPRESS=JPEG",
        "-co", "PHOTOMETRIC=YCBCR",
        "-co", "TILED=YES",
        "-co", "BIGTIFF=YES",
        vrt_input,
        tif_output
    ]
    print(f"Generando {tif_output}...")
    subprocess.run(cmd, check=True)

print("¡Proceso completado con éxito en formato BigTIFF!")