サブフォルダーを再帰的に繰り返し、すべてのシェープファイルを単一のシェープファイルにマージするための基本的なスクリプトは次のとおりです。
#!/bin/bash
consolidated_file="./consolidated.shp"
for i in $(find . -name '*.shp'); do
    if [ ! -f "$consolidated_file" ]; then
        # first file - create the consolidated output file
        ogr2ogr -f "ESRI Shapefile" $consolidated_file $i
    else
        # update the output file with new file content
        ogr2ogr -f "ESRI Shapefile" -update -append $consolidated_file $i
    fi
doneホバーのウェブ上のすべての例に、私は出力ファイルを更新する場合に、-nlnタグが追加されていることに気づきました。たとえば:
ogr2ogr -f "ESRI Shapefile" -update -append $consolidated_file $i -nln mergedドキュメントによると:
新しいレイヤーに別名を割り当てます
そして、「マージ」と呼ばれる一時的なシェープファイルを作成し、ループの最後で、ファイルは最後にマージしたシェープファイルと同じであることに気付きました。
なぜこれが必要なのか分かりませんか?このタグなしで正常にマージできたからです。