[[ArcGIS]]
*ArcPy(ArcGIS10)に関する覚書 [#x4f227e3]
**ワイルドカードを用いて複数ファイルを指定する [#n467ab7f]
マージなどの複数のデータを入力する処理を行う際に
ワイルドカードを用いてファイルを指定する手順~

>&color(red){'''# globモジュールをインポートする'''};
>import glob~
>&color(red){'''# 出力ファイルのパスと名前を指定'''};
>outputdata = "C:\\temp\\ps_merge_all.shp"~
>&color(red){'''# ワイルドカードを使用して入力データリストを指定'''};
>files = glob.glob('C:\\temp\\*.shp')~
>&color(red){'''# Process: マージ (Merge)'''};
>arcpy.Merge_management(files, outputdata)~

**河口から流路延長1kmごとにポイントを発生させる処理 [#lb649f13]
あまり美しくないですが・・
あとお金がないと(=arcinfoがないと)できません
あと大学じゃないと(=arcinfoがないと)できません

&color(red){'''# Set the necessary product code'''};~
&color(red){'''# import arcinfo'''};~

&color(red){'''# Import arcpy module'''};~
import arcpy~

&color(red){'''# 必要なエクステンションの指定'''};~
arcpy.CheckOutExtension("Network")~

&color(red){'''# 河口のポイントデータ(test_shisetsu)とネットワークデータセット(test02_ND)を指定する'''};~
&color(red){'''# Local variables:'''};~
test_shisetsu = "C:\\temp\\test.mdb\\test_shisetsu"~
test02_ND = "C\\temp\\test.mdb\\test02\\test02_ND"~

&color(red){'''# ワークスペースの指定'''};~
tempWorkspace = "C:\\temp\\temp"~
outputWorkspace = "C:\\temp\\fin"~

&color(red){'''#変数xを1000から100000まで1000間隔で繰り返し処理する'''};~
try:
>for x in range(1000, 101000, 1000):
>>&color(red){'''#変数の宣言'''};
>>&color(red){'''#ネットワーク解析レイヤの名前'''};
>>fc = "reach" + str(x)[:-3]
>>&color(red){'''#河口からの距離の変数'''};
>>mkyori = str(x)
>>&color(red){'''#ネットワーク解析レイヤからラインデータを抽出'''};
>>line_l = "reach" + str(x)[:-3] + "\\ライン"
>>&color(red){'''#ポイントデータのファイル名'''};
>>output1 = tempWorkspace + "\\p_" + str(x)[:-3] + ".shp"
>>&color(red){'''#ポイントデータをレイヤに変換する際の名前'''};
>>layer1 = str(x)[:-3] + "L"
>>&color(red){'''#ポイントデータからデータを抽出する際の条件式'''};
>>formula1 = "\"ToCumul_k\" =" + str(x)
>>&color(red){'''#最終的なポイントデータのファイル名'''};
>>output2 = outputWorkspace + "\\ps_" + str(x)[:-3] + ".shp"
>>&color(red){'''# Process: 到達圏レイヤの作成 (Make Service Area Layer)'''};
>>arcpy.MakeServiceAreaLayer_na(test02_ND, fc, "k", "TRAVEL_FROM", mkyori, "NO_POLYS", "NO_MERGE", "RINGS", "TRUE_LINES", "OVERLAP", "NO_SPLIT", "", "k", "ALLOW_UTURNS", "", "TRIM_POLYS", "100 Meters", "NO_LINES_SOURCE_FIELDS")
>>&color(red){'''# Process: ロケーションの追加 (Add Locations)'''};
>>arcpy.AddLocations_na(fc, "施設", test_shisetsu, "Name # #;CurbApproach # 0;Attr_k # 0;Breaks_k # #", "5000 Meters", "", "a SHAPE;test02_ND_Junctions NONE", "MATCH_TO_CLOSEST", "APPEND", "NO_SNAP", "5 Meters", "INCLUDE", "a #;test02_ND_Junctions #")
>>&color(red){'''# Process: 解析の実行 (Solve)'''};
>>arcpy.Solve_na(fc, "SKIP", "TERMINATE")
>>&color(red){'''# Process: フィーチャの頂点 → ポイント (Feature Vertices To Points)'''};
>>&color(red){'''# Process: フィーチャの頂点 → ポイント (Feature Vertices To Points)←抽出した河川区間の最上流部と最下流部にのみポイントを発生させる処理'''};
>>arcpy.FeatureVerticesToPoints_management(line_l, output1, "DANGLE")
>>&color(red){'''# Process: フィーチャ レイヤの作成 (Make Feature Layer)'''};
>>&color(red){'''# Process: フィーチャ レイヤの作成 (Make Feature Layer)←ぴったり1km間隔で発生したポイントのみをレイヤとして抽出する処理'''};
>>arcpy.MakeFeatureLayer_management(output1, layer1, formula1, "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;FacilityID FacilityID VISIBLE NONE;FromCumul_ FromCumul_ VISIBLE NONE;ToCumul_k ToCumul_k VISIBLE NONE;ORIG_FID ORIG_FID VISIBLE NONE;DANGLE_LEN DANGLE_LEN VISIBLE NONE")
>>&color(red){'''# Process: フィーチャのコピー (Copy Features)'''};
>>&color(red){'''# Process: フィーチャのコピー (Copy Features)←抽出したレイヤをフィーチャクラスに変換する処理'''};
>>arcpy.CopyFeatures_management(layer1, output2, "", "0", "0", "0")
>>print mkyori

except:
>print "error"



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS