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.

asked Nov 16, 2021 at 23:40
2
  • 2
    The below answer is a great workaround. ogrmerge.py definitely doesn't support an input from file param, but it would be a good addition, so I suggest you submit an enhancement request. Commented Nov 17, 2021 at 0:15
  • If you have the same question but are using arcpy: gis.stackexchange.com/questions/148822/… Commented Nov 22, 2021 at 17:22

1 Answer 1

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.

answered Nov 17, 2021 at 0:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.