[GIS] ‘gdal_merge’ is not recognized as an internal or external command, operable program or batch file in OSGeo4w Shell

gdalgdal-mergeosgeo4w

I am trying to batch mosaic a set of rasters using gdal in OSGeo4w shell command line. When I try to use gdal_merge I am getting error as below.

    run o-help for a list of available commands
    C:\>gdal_merge
    'gdal_merge' is not recognized as an internal or external command,
    operable program or batch file. 

I tried to see the available libraries in OSGeo. I found gdal_merge is not installed while running
o-help

C:\>o-help
                   -={ OSGeo4W Shell Commands }=-
  avcexport                               avcimport
  cct                                     cs2cs
  curl                                    derb
  dllupdate                               fax2ps
  fax2tiff                                fftw-wisdom
  gdaladdo                                gdalbuildvrt
  gdaldem                                 gdalenhance
  gdalinfo                                gdallocationinfo
  gdalmanage                              gdalserver
  gdalsrsinfo                             gdaltindex
  gdaltransform                           gdalwarp
  gdal_contour                            gdal_grid
  gdal_rasterize                          gdal_translate
  genbrk                                  genccode
  gencfu                                  gencmn
  gencnval                                gendict
  gennorm2                                genrb
  gensprep                                geod
  geotifcp                                gie
  gif2h5                                  gnmanalyse
  gnmmanage                               gpsbabel`

But I am seeing gdal_merge in other system.
Also, I am able to find the gdal_merge.py in the below directory.

C:\OSGeo4W64\apps\Python37\Scripts

Why is it not showing in my system, and how do I fix this issue?

Best Answer

Even gdal_merge.py is a Python script, with OSGeo4W installation command "gdal_merge" is supposed to work as well because there exists a "gdal_merge.bat" launch script that Windows fires with "gdal_merge" command.

C:\OSGeo4W64\bin>dir gdal_merge*
 Volume in drive C is Windows
 Volume Serial Number is BBBB-BBBB

 Directory of C:\OSGeo4W64\bin

12.02.2020  13.54                99 gdal_merge.bat
03.02.2020  23.59            19 848 gdal_merge.py

enter image description here

What the batch file does is to set the environment right and then ask Python to run the gdal_merge.py script

@echo off 
call "%OSGEO4W_ROOT%\bin\o4w_env.bat" 
python "%OSGEO4W_ROOT%\bin\gdal_merge.py" %* 

If gdal_merge.py and gdal_merge.bat are missing from the OSGeo4W\bin directory then something has gone wrong with the installation.