import arcpy import sys # 获取要素类路径和查询条件 feature_class = arcpy.GetParameterAsText(0) query = arcpy.GetParameterAsText(1) if not arcpy.Exists(output_path): arcpy.CreateFileGDB_management(os.path.dirname(output_path), os.path.basename(output_path)) # 构建查询语句 expression = arcpy.AddFieldDelimiters(feature_class, "SHAPE_Area") + " < " + query # 使用 arcpy.da.UpdateCursor 删除要素 with arcpy.da.UpdateCursor(feature_class, "*", where_clause=expression) as cursor: for row in cursor: cursor.deleteRow() # 输出要素类到指定路径 output_path = arcpy.GetParameterAsText(2) arcpy.FeatureClassToFeatureClass_conversion(feature_class, output_path, "output_feature_class") # 完成操作并清理内存 del cursor运行错误:执行: 删除小面 Export_Output 497477.651983 D:\实验2\ffff.shp 开始时间: Wed May 24 19:48:23 2023 正在运行脚本 删除小面... Failed script 删除小面... Traceback (most recent call last): File "D:\多对一空间连接\批量删除小面积.py", line 8, in <module> NameError: name 'output_path' is not defined 执行(删除小面)失败。 失败 在 Wed May 24 19:48:23 2023 (经历的时间: 0.02 秒)请改正代码
时间: 2024-01-29 20:04:03 浏览: 89
import arcpy
import os
import sys
# 获取要素类路径和查询条件
feature_class = arcpy.GetParameterAsText(0)
query = arcpy.GetParameterAsText(1)
# 获取输出要素类路径
output_path = arcpy.GetParameterAsText(2)
if not arcpy.Exists(output_path):
arcpy.CreateFileGDB_management(os.path.dirname(output_path), os.path.basename(output_path))
# 构建查询语句
expression = arcpy.AddFieldDelimiters(feature_class, "SHAPE_Area") + " < " + query
# 使用 arcpy.da.UpdateCursor 删除要素
with arcpy.da.UpdateCursor(feature_class, "*", where_clause=expression) as cursor:
for row in cursor:
cursor.deleteRow()
# 输出要素类到指定路径
arcpy.FeatureClassToFeatureClass_conversion(feature_class, output_path, "output_feature_class")
# 完成操作并清理内存
del cursor
print("操作完成")
阅读全文