import arcpy 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 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("操作完成")运行错误:执行: 删除小面 Export_Output 497477.651983 D:\实验2\新建文件地理数据库.gdb\qqqqqq 开始时间: Wed May 24 19:51:32 2023 正在运行脚本 删除小面... Failed script 删除小面... IndentationError: expected an indented block (批量删除小面积.py, line 11) 执行(删除小面)失败。 失败 在 Wed May 24 19:51:32 2023 (经历的时间: 0.02 秒)请改正代码
时间: 2024-01-29 07:04:19 浏览: 323
Douglas-Peucker.rar_Arcpy_Douglas-Peucker_arcmap _python_道格拉斯-普客
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
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("操作完成")
在Python中,缩进非常重要。您的代码第11行的缩进不正确。请注意在 if 语句下面增加了4个空格。此外,在第7行和第10行之间也需要增加一个空格。我已经帮您更正了代码。
阅读全文