import arcpy # 输入参数 fc = arcpy.GetParameterAsText(0) # 要素类 field = arcpy.GetParameterAsText(1) # 查询字段 value = arcpy.GetParameterAsText(2) # 查询条件值 # 构建查询语句 query = "{} = '{}'".format(arcpy.AddFieldDelimiters(fc, field), value) # 删除符合条件的要素 with arcpy.da.UpdateCursor(fc, ["OID@", field], where_clause=query) as cursor: for row in cursor: cursor.deleteRow() arcpy.AddMessage("Deleted OID {} with {} = {}".format(row[0], field, value))运行错误IndentationError: unexpected indent (批量删除小面积.py, line 10) 执行(删除小面)失败。请改正代码
时间: 2023-12-13 21:02:41 浏览: 91
使用arcpy获取简单的矢量数据信息.zip_arcPy 查询_arcpy 数据读入_arcpy 读取数据_arcpy矢量拼接
你的代码缩进不正确,导致出现了 IndentationError 错误。可以尝试将代码修改为如下所示:
```
import arcpy
# 输入参数
fc = arcpy.GetParameterAsText(0) # 要素类
field = arcpy.GetParameterAsText(1) # 查询字段
value = arcpy.GetParameterAsText(2) # 查询条件值
# 构建查询语句
query = "{} = '{}'".format(arcpy.AddFieldDelimiters(fc, field), value)
# 删除符合条件的要素
with arcpy.da.UpdateCursor(fc, ["OID@", field], where_clause=query) as cursor:
for row in cursor:
cursor.deleteRow()
arcpy.AddMessage("Deleted OID {} with {} = {}".format(row[0], field, value))
```
修改后,可以尝试重新运行代码。
阅读全文