|
|
import glob
|
|
|
import os
|
|
|
from PIL import Image
|
|
|
import subprocess
|
|
|
import pdb
|
|
|
from osgeo import gdal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Image.MAX_IMAGE_PIXELS = 10000000000
|
|
|
|
|
|
path_images = "C:/data/mine-sectors/mapbox_mines_0.8m_RGB/"
|
|
|
path_images = "../../ssd/mine-sector-detection/images/"
|
|
|
path_json = "./"
|
|
|
os.makedirs("./out", exist_ok=True)
|
|
|
|
|
|
|
|
|
for file in sorted(glob.glob(path_images + "*.jp2")):
|
|
|
|
|
|
|
|
|
ds = gdal.Open(file, gdal.GA_ReadOnly)
|
|
|
geoTransform = ds.GetGeoTransform()
|
|
|
minx = geoTransform[0]
|
|
|
maxy = geoTransform[3]
|
|
|
maxx = minx + geoTransform[1] * ds.RasterXSize
|
|
|
miny = maxy + geoTransform[5] * ds.RasterYSize
|
|
|
data = None
|
|
|
rb = (ds.GetRasterBand(1)).ReadAsArray()
|
|
|
pixelsize = str(rb.shape[1]) + " " + str(rb.shape[0])
|
|
|
|
|
|
print(file)
|
|
|
print([minx, miny, maxx, maxy])
|
|
|
print(pixelsize)
|
|
|
|
|
|
|
|
|
|
|
|
string = "gdal_rasterize -l LSM_Chile_sectors_class_epsg3857 -a class -ts " + pixelsize + \
|
|
|
" -te " + str(minx) + " " + str(miny) + " " + str(maxx) + " " + str(maxy) + " " \
|
|
|
"-ot Byte -of GTiff '" + path_json + "LSM_Chile_sectors_class_epsg3857.geojson' " \
|
|
|
"./out/mask_" + os.path.basename(file)[:-4] + ".tif"
|
|
|
|
|
|
print(string)
|
|
|
|
|
|
|
|
|
os.system(string)
|
|
|
|
|
|
|
|
|
|