Tessellation python

时间:2017-03-10 16:11:51

标签: arcpy tessellation

我对蟒蛇世界很新,这是我自己编写的第一个剧本,但我正在寻求帮助。

除了需要整理的脚本外,我还遇到了使用arcpy的地理处理工具的问题。我想基于点数据集群创建曲面细分,并最终在曲面细分中创建少于50个点。我已经创建了一个运行的脚本,但是,我正在尝试为生成曲面细分工具自动化Areal Unit,它似乎挂断了。我最终杀了剧本。

更新以添加新代码:

因此,新代码应该创建六边形曲面细分,与pnts文件连接以及连接计数> 50创建六边形镶嵌,每个六边形钻孔至50磅。这是我第一次尝试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)

这是我的错误:Traceback(最近一次调用最后一次):   文件“D:/Ed_Stuff/Testing/Def_Tess_Test.py”,第50行,in     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)   GenerateTessellation中的文件“C:\ Program Files(x86)\ ArcGIS \ Desktop10.4 \ ArcPy \ arcpy \ management.py”,第15539行     提高e ExecuteError:错误000375:无效的范围域。 无法执行(GenerateTessellation)。

1 个答案:

答案 0 :(得分:0)

该错误肯定表明GenerateTesselation是失败的地方。不过,我猜这个原因。可能的解决方案......

  1. Shape_Type更改为&#34; HEXAGON&#34;而不是&#34; Hexagon&#34;
  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)