2017-03-10 4 views
-1

저는 파이썬 세계에 처음으로 익숙합니다. 이것은 제가 작성한 첫 번째 스크립트이지만 도움이 될만한 자료입니다.Tessellation python

정돈해야 할 스크립트 외에도 arcpy를 사용하여 지오 프로세싱 도구에 문제가 있습니다. 포인트 데이터의 클러스터를 기반으로 테셀레이션을 만들고 싶습니다. 결국 테셀레이션 내에서 50 점 미만을 갖게됩니다. 나는 실행 스크립트를 만들었지 만, 테셀레이션 생성 도구에 대한 Areal Unit을 자동화하려고 시도하고 있으며 끊기고있는 것 같습니다. 나는 대본을 죽이는 결과를 낳는다. 그래서 새로운 코드가 육각 테셀레이션을 만들 예정이다

pnts 파일을 가입 수를 조인> 50 육각 당 아래로 50 pnts을 드릴 육각 테셀레이션을 만들 :

새로운 코드를 추가하도록 업데이트되었습니다. 이것은 python 함수에 대한 나의 첫 번째 시도이며 먼저 피트로 점프합니다. 첫 번째 주요 오류는 유효하지 않은 도메인 범위이지만 정확히 무엇을 의미하는지에 대해 문제가 있습니다.

내가 믿는 코드의 마지막 줄을 알고 있습니다.

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)