OSGeo4Wシェルソリューション
属性テーブルのプロパティ(スキーマ)を抽出する最も簡単な方法は、OSGeo4Wシェルを開いて(Windows OSを使用しているため)、ディレクトリをデータフォルダーに変更し、次のように入力するだけです。
ogrinfo -so inputLayerName.shp inputLayerName
プロジェクション、スキーマ、機能数、範囲などの概要情報が表示されます。その後、多数のシェープファイルがあるためFOR、次のようなサイクルを実行できます。
FOR %f IN (*.shp) DO ogrinfo -so %f %~nf >> properties.txt
これにより、ディレクトリ内のすべてのシェープファイルのプロパティを含む1つのtxtファイルが返されます(出力リダイレクト>>は、各出力をproperties.txtファイルに追加するため)。
または、シェープファイルごとに1つのプロパティファイルに関心がある場合:
FOR %f IN (*.shp) DO ogrinfo -so %f %~nf > %~nf_properties.txt
標準化についてはいくつかの手法があります。RESIZEフィールドのサイズを最適なサイズに変更するには、マージ後にレイヤー作成オプションを使用することをお勧めします(たとえば、長すぎるテキストフィールドは短くなります)。例えば:
ogr2ogr -lco RESIZE=yes merge_resized.shp merge.shp
スクリプトソリューションの処理
QGISで処理ツールボックスを開き、新しいスクリプトを作成して(Scripts-> Tools->をクリックしてCreate new script)、次のように入力します。
##ogrinfo (summary only)=name
##input=vector
##output=output file
import os, subprocess
head, tail = os.path.split(input)
inputname = os.path.splitext(tail)[0]
cmd = 'ogrinfo -so ' + input + ' ' + inputname + ' > ' + output
subprocess.check_call(cmd, shell=True)
好きなように保存してくださいogrinfo_so.py。次に、新しいスクリプトogrinfo (summary only)が処理ツールボックス-> Scripts-> User scriptグループに表示されます。そのまま、またはバッチモードで実行できます。
前に説明したように、フィールド長をサイズ変更するために同じ操作が可能です。
##Resize fields=name
##input=vector
##output=output vector
import subprocess
cmd = 'ogr2ogr -lco RESIZE=YES ' + output + ' ' + input
subprocess.check_call(cmd, shell=True)
呼び出された新しいスクリプトResize fieldsは、Processingツールボックス-> Scripts-> User scriptsグループで使用できます。楽しめ!