私はarcpyを使用しています。自分のワークスペース内のいくつかのジオデータベースにネストされた特定のフィーチャクラス "building"を抽出します。ここでArcGIS Python(Arcpy)で指定された名前のフィーチャクラスを選択する
はコードです:
import arcpy
import os
workspace = "C:/Wiley/P1/gis"
search = "Building"
outdir = "C:/Wiley/P1/gis/HK80.gdb"
fc = []
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Polygon")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
if search == filename:
fc.append(os.path.join(dirpath, filename))
if fc:
output = os.path.join(outdir, os.path.basename(search) + "_merge")
arcpy.Merge_management(fc, output)
このコードは成功しました。
しかし、私は、コードを少し拡大し、これらすべてのフィーチャクラスをループにマージコマンドを実行してください非常に多くの他のフィーチャクラスは、「ビル」から離れてジオデータベースにあります:私はヒットどこ
import arcpy
import os
#--------------------------
#example list workspace
arcpy.env.workspace = "C:/Wiley/P1/gis/HKU_Job69.gdb"
#Generate exmaple list dataset
datasets = arcpy.ListDatasets(feature_type='All')
datasets = [''] + datasets if datasets is not None else []
fc_list = []
#--------------------------
#where all the gdb is nested
workspace = "C:/Wiley/P1/gis"
#define output
outdir = "C:/Wiley/P1/gis/HK80.gdb"
#List of Feature classes
fc = []
#define walk for looping
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="Any")
for ds in datasets:
for fc_example in arcpy.ListFeatureClasses(feature_dataset=ds):
fc_list.append(fc_example)
for f in fc_list: #Loop through the list
for dirpath, dirnames, filenames in walk:
for filename in filenames:
if f == filename:
fc.append(os.path.join(dirpath, filename))
if fc:
output = os.path.join(outdir, os.path.basename(search) + "_merge")
arcpy.Merge_management(fc, output)
です壁。このコードに何か問題はありますか?私はPythonに慣れていないので、あなたは訓練された目のために、ロジックのエラーをすぐに見つけ出すことができます。 f変数はまったくループしていないようです。
https://gis.stackexchange.com/q/254711としてクロス提起します/ 115 – PolyGeo