我对 python 世界相当陌生,这是我自己编写的第一个脚本,但我正在寻求一些帮助。
除了需要整理的脚本外,我还遇到了使用 arcpy 的地理处理工具的问题。我想基于点数据集群创建镶嵌,最终在镶嵌中,点数少于 50。我创建了一个可以运行的脚本,但是,我正在尝试为生成镶嵌工具自动化区域单元,但它似乎挂断了。我最终杀死了脚本。
更新以添加新代码:
因此,新代码应该创建一个六边形镶嵌,使用 pnts 文件连接,如果连接计数 > 50,则创建六边形镶嵌,每个六边形钻取到 50 个 pnt。这是我第一次尝试使用 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 行,在 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 中引发 e ExecuteError: ERROR 000375: Invalid range domain。执行失败 (GenerateTessellation)。