Skip to content

Instantly share code, notes, and snippets.

@dpfrakes
Last active March 14, 2024 18:22
Show Gist options
  • Save dpfrakes/0cf1d014b244aff9849049a2b0952a6f to your computer and use it in GitHub Desktop.
Save dpfrakes/0cf1d014b244aff9849049a2b0952a6f to your computer and use it in GitHub Desktop.
Convert DTED to GeoTIFF for Mapbox tileset

Unzip DTED archive. This should contain one inner directory for every longitudinal band (e.g. w077).

Run the following script to convert to 8-bit GeoTIFF. Mapbox tilesets only support 8-bit.

# Convert all dt0 to GeoTIFF
for file in ../dtedlevel0/**/*.dt0; do
    output_file="./$(basename "$file" .dt0).tif"
    gdal_translate -of GTiff -ot Byte "$file" "$output_file"
done

Run the following script to combine all new *.tif files inside each longitudinal directory into a single *.tif.

# Combine all GeoTIFF files per degree band into one GeoTIFF
# Set the base directory
base_dir="../dtedlevel0"
output_dir="$base_dir/all/"
mkdir -p $output_dir

# Loop through all subdirectories
for dir in "$base_dir"/*/; do
    # Extract subdirectory name without path
    subdir_name=$(basename "$dir")
    
    # Find all GeoTIFF files in the subdirectory
    tif_files=$(find "$dir" -maxdepth 1 -type f -name "*.tif")

    # Check if there are GeoTIFF files in the subdirectory
    if [ -n "$tif_files" ]; then
        # Combine GeoTIFF files into a single output file
        output_file="$output_dir/${subdir_name}.tif"
        echo $output_file
        gdal_merge.py -o "$output_file" $tif_files
    fi
done

Upload one of these generated files (located in /dtedlevel0/all/) to Mapbox Studio as a Tileset.

image

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment