2

From windows command shell how might I merge a single layer from multiple file-gdb's into another file-gdb using ogr2ogr? All input gdb's have identically named feature classes and attribute structures.

pseudo example:

ogr2ogr {input layername} D:\output.gdb x:\incoming\*.gdb

it's the layername part I'm having trouble with.

matt wilkie
  • 28,176
  • 35
  • 147
  • 280

1 Answers1

6

In windows command line you could:

FOR /D /R %g IN (*.gdb) DO ogr2ogr -update -append -f FileGBD D:\output.gdb x:\incoming\%g input_layername

Just place the input_layername after the input dataset.

/D tells FOR to search for directories and /R asks it to do it recursively.

In a .bat file, replace the '%' with '%%', so %g > %%g

Extended batch file example using a) gdb's wrapped in zipfiles as data source, b) projecting to a new coordinate system, and c) selecting multiple input feature classes:

set ogropt=-f FileGBD --config FGDB_BULK_LOAD YES -t_srs EPSG:3579
set layers=Layer_1 Layer_2 Layer_3

for /r %%g in (x:\incoming\*gdb.zip) do (
    ogr2ogr %ogropt% -update -append output.gdb %%g %layers%
    )
matt wilkie
  • 28,176
  • 35
  • 147
  • 280
SaultDon
  • 10,389
  • 1
  • 43
  • 78
  • This works. Where I went astray was thinking multiple input files were allowed, similar to gdal_merge. Also, much to my delight, input gdb-in-zipfiles work, although with hundreds of apparently harmless Recode UTF-8 errors. – matt wilkie Mar 27 '15 at 17:25