Last active
July 2, 2023 03:57
-
-
Save lpinner/ffefd520fd4c2e9329ac32643c898ccb to your computer and use it in GitHub Desktop.
OS Terrain50 to GeoTIFF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://gis.stackexchange.com/a/462686/2856 | |
# CC-BY-SA 4.0 | |
import os | |
import zipfile | |
from osgeo import gdal | |
gdal.UseExceptions() | |
input = "/path/to/terr50_gagg_gb.zip" | |
output = input.replace(".zip", ".tif") | |
srs = "EPSG:27700" | |
zips = (z for z in zipfile.ZipFile(input).namelist() if z.endswith(".zip")) | |
vrts = [] | |
for zip in zips: | |
basename = os.path.basename(zip)[0:4].upper() | |
asc = "/vsizip/{/vsizip/{%s}/%s}/%s.asc" % (input, zip, basename) | |
vrt = f"/vsimem/{basename}.vrt" | |
gdal.Translate(vrt, asc, outputType=gdal.GDT_Float32) | |
vrts.append(vrt) | |
vrt = f"/vsimem/terr50_gagg_gb.vrt" | |
gdal.BuildVRT(f"/vsimem/terr50_gagg_gb.vrt", vrts) | |
gdal.Translate(output, vrt, outputSRS=srs, creationOptions=["TILED=YES", "COMPRESS=LZW", "PREDICTOR=2"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment