UserDocs/GdalMerge: gdal_wildmerge.bat

File gdal_wildmerge.bat, 1.4 kB (added by maphew, 7 months ago)

windows batch file to merge using wildcards

Line 
1 @echo off
2 :: initial version, 2005-Nov-17, matt wilkie
3 :: this script is public domain
4 if [%1]==[] (
5         echo.
6         echo -={ gdal_wildmerge }=- Allow gdal_merge to accept wildcards for input files
7         echo .
8         echo .  gdal_wildmerge.bat [input-file-wildcard] [output-file] {options}
9         echo .
10         echo .  gdal_wildmerge d:\src\*.tif mosaick.tif -init -9999
11         echo.
12         goto :EOF
13         )
14         :: %1 is the input wildcard mask
15         :: This is inverted from normal gdal_merge usage in order to allow other
16         :: options be passed to gdal_merge
17
18
19 :: delayed expansion requires windows NT or later command shell
20 :: (it won't work on windows 9x)
21         verify other 2>nul
22         setlocal ENABLEDELAYEDEXPANSION
23         if errorlevel 1 goto :wrong_version
24
25 :: gdal_merge won't overwrite an existing file 
26         if exist %2 goto :file_exists
27
28 :: Build the input file list
29         set infiles=
30         for %%a in (%1) do set infiles=!infiles! "%%a"
31
32 :: Here is were the actual work happens
33         set gdalcmd=gdal_merge %infiles% -o "%2"
34    echo %gdalcmd%
35    :: IMPORTANT, if gdal_merge is not call'ed control doesn't return
36         :: to the batch file
37         call %gdalcmd%
38         goto :EOF
39
40 :file_exists
41         echo *** the output file "%2" already exists.
42         goto :EOF
43
44 :wrong_version
45         echo.
46         echo    Sorry, this batchfile requires DELAYED EXPANSION which is
47         echo    not available in this shell. See
48         echo  http://www.google.com/search?q=enabledelayedexpansion
49         goto :EOF
50