1

How might I feed the list filenames to use as input from a text file?

Obvious things like the below do not work; there's no indication from the doc page that it's supposed to. Still this has to be a relatively common scenario. So how do people solve it?

The list of files I have is about 900 items, much too long to simply paste as a joined string of text to the command line, and they're not in a single folder so wildcards are out.

ogrmerge -o output.gpkg -i input-files.txt
ogrmerge -o output.gpkg < input-files.txt`

If it's relevant I'm using the ogr available via Qgis on Windows.

2
2

Example solution using Windows CMD syntax.

Initialize the target using a single source layer as a template:

ogrmerge -o img-source-footprints.shp ^
  -single ^
  -src_layer_field_name Source ^
  -src_layer_field_content {AUTO_NAME} ^
  \\server\imagery\Satellites\S_AitchHill.gdb ^
  -nln S_Satellites_AitchHill_50cm_16Sep2011_f

Now use a shell scripting FOR loop to read each line and append to what was created above :

for %%a "delims=" in (input-files.txt) do (ogrmerge ^
  -o img-source-footprints.shp ^
  -update -single ^
  -src_layer_field_name Source ^
  -src_layer_field_content {AUTO_NAME} ^
  %%a)

Delims= is to specify using only end of line character to separate records (the default is tabs and spaces)
-src... is beyond the scope of the question but nice. It records the filename that the data came from.

The input text file used in this example:

\\server\imagery\Satellites\S_AitchHill.gdb -nln S_Satellites_AitchHill_50cm_16Sep2011_f
\\server\imagery\Satellites\S_AitchHill.gdb -nln S_Satellites_AitchHill_50cm_12Jul2014_f
\\server\imagery\Satellites\S_AlaskaHwy.gdb -nln S_Satellites_AlaskaHwy_ShakwakCorridor_50cm_15Sep2010_f
\\server\imagery\Satellites\S_AlaskaHwy.gdb -nln S_Satellites_AlaskaHwy_ShakwakCorridor_50cm_04Sep2010_f

The source layers are Esri Feature Classes in a file geodatabase. The -nln parameter is needed to tell Ogr to look for that item inside the .gdb, that it can't be resolved from the file system. If your data are shapefiles you can skip that part.

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.