
Вот мой пример кода с использованием Python и gdalwarp. Я беру GCP, чтобы получить экстент, а затем использую его в команде gdalwarp. Я также пробовал rasterio, но мне не повезло. Я продолжаю получать одни и те же странные данные. Любая помощь будет оценена по достоинству.
try:
result = subprocess.run(
["gdalinfo", f"HDF5:{input_file}:{subdataset_path}"],
capture_output=True,
text=True,
check=True,
)
output = result.stdout
except subprocess.CalledProcessError as e:
print("Error running gdalinfo:", e)
print("Output:", e.output)
exit(1)
gcps = []
gcp_pattern = r'\((\d+\.\d+),(\d+\.\d+)\) -> \(([\d\.-]+),([\d\.-]+),\d+\)'
matches = re.findall(gcp_pattern, output)
gcps = []
for match in matches:
pixel, line, lon, lat = map(float, match)
gcps.append({"pixel": pixel, "line": line, "lon": lon, "lat": lat})
xmin = min(item['lon'] for item in gcps)
xmax = max(item['lon'] for item in gcps)
ymin = min(item['lat'] for item in gcps)
ymax = max(item['lat'] for item in gcps)
gdal_warp = f'gdalwarp -t_srs EPSG:4326 -te {xmin} {ymin} {xmax} {ymax} {input_filepath} {output_file}'
Подробнее здесь: https://stackoverflow.com/questions/792 ... on-or-gdal