1

I have a folder full of tiles, and I'd like to convert them into a single GeoTIFF file.

The folder structure looks like this:

10 //the zoom
    554 //y
        860.jpg //x
        861.jpg
        862.jpg

Not quite sure what that structure is called Mapbox Tiles? XYZ? Slippy tiles?

Either way, I tried the following:

gdal_translate.exe -if MBTiles -of GTiff "C:\maps\tiles" "C:\maps\output.tiff"

But it returns:

ERROR 4: "C:\maps\tiles": Permission denied

Does GDAL support conversion of folders full of tiles?

9
  • 1
    does your user have permission to that directory?
    – Ian Turton
    Nov 13, 2021 at 11:21
  • 2
    I was under the impression that the MBTiles format was sqlite DB based not file based (see GDAL MBTiles driver doc and the MBTiles specification)
    – user2856
    Nov 13, 2021 at 11:38
  • 1
    If your folder is full of georeferenced Tiff files, you could create a virtual raster (VRT) first and translate it to a single GeoTIFF file afterwards. See gis.stackexchange.com/questions/230553/… for more info.
    – christoph
    Nov 13, 2021 at 13:14
  • If your tiles are not georeferenced, you need to create World files for each of them at first step.
    – christoph
    Nov 13, 2021 at 13:21
  • 3
    The GDAL driver that supports using a x/y/z folder as source is WMS driver with the TMS minidriver gdal.org/drivers/raster/wms.html#tms.
    – user30184
    Nov 13, 2021 at 13:44

2 Answers 2

1

You can do this, by saving it in a text file and changing the extension to .bat:

set pathin=F:\mydirectoryname\In
set pathout=F:\mydirectoryname\Out
set filename=merged_file

gdalbuildvrt -allow_projection_difference index.vrt %pathin%\*.tif 
gdal_translate index.vrt %pathout%\%filename%.tif -tr 0.3 0.3 -co COMPRESS=LZW -co BIGTIFF=YES -a_nodata 0

Then simply run the bat file. This has the cool bonus of resampling if needed. I do this through the OSGeo4W shell that comes with QGIS - there you already have the GDAL library.

0
  1. Download GDAL. Windows binaries can be found here.

  2. Create a file called tiles.xml, which describes your folder structure. For example:

    <GDAL_WMS>
        <Service name="TMS">
            <ServerUrl>file://C:/map data/Sydney/${z}/${y}/${x}.jpg</ServerUrl>
            <!--<ServerUrl>http://localhost:5000/map%20data/Sydney/${z}/${y}/${x}.jpg</ServerUrl>-->
    
            <Layer>basic</Layer>
            <Format>jpg</Format>
        </Service>
    
        <DataWindow>
            <TileLevel>12</TileLevel>
            <TileY>-360</TileY>
            <YOrigin>top</YOrigin>
        </DataWindow>
    
        <BlockSizeX>256</BlockSizeX>
        <BlockSizeY>256</BlockSizeY>
        <BandsCount>3</BandsCount>
        <ZeroBlockHttpCodes>404</ZeroBlockHttpCodes>
        <MaxConnections>1</MaxConnections>
    </GDAL_WMS>
    
  3. Open a console window and set up an environment variable:

    set PROJ_LIB="C:\Portable\gdal\release-1928-x64-gdal-3-3-3-mapserver-7-6-4\bin\proj7\share"
    
  4. Run the following commands:

    cd "C:\Portable\gdal\release-1928-x64-gdal-3-3-3-mapserver-7-6-4\bin\gdal\apps\"
    
    gdal_translate.exe -of GTiff "C:\map data\Sydney\tiles.xml" "C:\map data\sydney.tiff" -projwin 151.033285 -33.743981 151.300567 -33.957583
    

Information about gdal_translate.exe can be found here.

Information about the WMS/TMS xml file can be found here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.