2017-03-10 7 views
-1

私はPythonの世界ではかなり新しいです。これは私が書いた最初のスクリプトですが、助けを求めています。Tessellation Python

整理する必要のあるスクリプトの他に、私はarcpyを使ってジオプロセシングツールに問題があります。私は、ポイントデータのクラスタに基づいて、最終的にテッセレーション内にテッセレーションを作成したいと思います.50ポイント未満です。私は実行するスクリプトを作成しましたが、テッセレーション生成ツールのAreal Unitを自動化しようとしていますが、ハングアップしているようです。私はスクリプトを殺し終わる。新しいコードを追加する更新

ので、新しいコードは、六角テッセレーションを作成することになっPNTSファイルに参加し、参加回数> 50のためにされては六角あたり50 PNTSへのドリルダウン六角テッセレーションを作成します。これは私の最初のパイソン関数の試みであり、最初は足でジャンプしています。最初の大きなエラーは無効なドメインの範囲ですが、私はそれが何を意味し、何を求めているのかに関して問題を抱えています。

私は信じているコードの最終行を知っています。

import arcpy as ap 
import os 

ap.env.overwriteOutput = True 
ap.env.workspace = "D:\\Ed_Stuff\Testing\All_Test_Workspace.gdb" 
out_gdb = "D:\\Ed_Stuff\Testing\All_Test_Out.gdb" 
pnts = "D:\Ed_Stuff\Hexagon.gdb\hexagon_subset" 
out_fc = "D:\\Ed_Stuff\Testing\All_Test_Workspace\Total_Tess.shp" 

def create_hex(pnts, out_fc, level=0, area=2560608986): 
    #pull extent from initial point feature 
    desc = ap.Describe(pnts) 
    Ext = desc.extent 
    SR = desc.SpatialReference 
    #generate hexagon for initial extent 
    out_fc = os.path.join(out_gdb,'hex_level_{0}'.format(level)) 
    ap.GenerateTessellation_management(out_fc, Ext, "Hexagon", area, SR) 
    print "Worked Check 1" 
    #spatially join with point layer 
    ap.MakeFeatureLayer_management(pnts, 'pnts_lyr') 
    fc_join = os.path.join(out_gdb, 'join_level_{0}'.format(level)) 
    ap.SpatialJoin_analysis(out_fc, 'pnts_lyr', fc_join, "JOIN_ONE_TO_ONE", "KEEP_ALL", "INTERSECT") 
    print "Worked Check 2" 
    ##ap.MakeFeatureLayer_management(fc_join, "fc_join_lyr", "'Join_Count'<50") 
    ##ap.SelectLayerByAttribute_management (in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause}) 
    #make layer of all hexes with 'Join_Count' < 50 and append to output tess file 
    ap.MakeFeatureLayer_management(fc_join, "fc_join_lyr", "'Join_Count'<50") 
    ap.Append_management(fc_join_lyr, out_fc) 
    print "Apended Again"+fc_join 
    field = arcpy.ListFields(fc_join, "Join_Count") 
    for field in fc_join: 
     if 'Join_Count' > 50 and level < 32: 
      ap.Dissolve_management(fc_join, dis_hex, ['OID'], '', "MULTI_PART", '') 
      hex_multi = os.path.join(out_gdb, 'multihex_level_{0}'.format(level)) 
      ap.MultipartToSinglepart_management (dis_hex, hex_multi) 
      print "Working... Maybe" 
      with arcpy.da.SearchCursor(hex_multi, field('OID')) as cursor: 
       for field in cursor: 
        hex = "in_memory/hex_{0}_{1}".format(level, 'OID') 
        desc = ap.Describt(hex) 
        Ext = desc.extent 
        create_hex(hex, out_fc, level+1, area*(1/3)) 
        print "Boots and Pants" 
        ap.Delete_management(hex) 

     elif level >= 32: 
      ap.Append_management(fc_join_lyr, out_fc) 
      print "Done at 32!" 

create_hex(pnts, out_fc) 

これは私のエラーです:トレースバック(最新の呼び出しは、最後の): ファイル "D:/Ed_Stuff/Testing/Def_Tess_Test.py"、行50、 create_hex(PNTS、out_fc)で ファイル「D :/Ed_Stuff/Testing/Def_Tess_Test.py "、17行目、create_hex ap.GenerateTessellation_management(out_fc、Ext、" Hexagon "、area、SR) ファイル" C:\ Program Files(x86)\ ArcGIS \ Desktop10.4 \ ArcPy \ arcpy \ management.py "、行15539、GenerateTessellation raise e ExecuteError:エラー000375:無効な範囲ドメインです。 (GenerateTessellation)の実行に失敗しました。

+0

どのくらい時間が動作しますか? ArcMapの内部から実行した場合、同じ操作がどれくらい時間がかかりますか? – Erica

+0

こんにちはエリカ、それは私が最終的にそれを殺す前に12時間以上走った。私はそれがかなり大きいデータセットであるので、それはずっと長くしました。 –

+0

ここで私のコードを更新する方法を理解しようとしています。スクリプトを関数形式で書くように言われました。新しいコードと新しいエラーが発生しました。 –

答えて

0

このエラーは、確かにGenerateTesselationが失敗していることを示しています。私はその理由で推測しています。考えられる解決策...

  1. 変更Shape_Type代わりに「ヘキサゴン」の「HEXAGON」へ
  2. より可能性が高い、面積単位(パラメータSizeは)それを指定された単位を持つ必要があります。現在、areaは整数として定義されており、代わりに文字列で指定する必要があります(単位は、"5000 SquareMiles")。

    GenerateTesselation help pageからのコード例が役に立つことがあります。あなたはそれを殺すために必要がある前に

    # Find the width, height and linear unit used by the input feature class' extent 
    # Divide the width and height value by three 
    # Multiply the divided values together and specify an area unit from the linear unit 
    # Should result in a 4x4 grid covering the extent. (Not 3x3 since the squares hang over the extent.) 
    w = extent.width 
    h = extent.height 
    u = extent.spatialReference.linearUnitName 
    area = "{size} Square{unit}s".format(size=w/3 * h/3, unit=u)