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.CreateFolder_management(os.path.dirname(output_path), os.path.basename(output_path)) gdb_path = os.path.join(output_path, "output.gdb") if not arcpy.Exists(gdb_path): arcpy.CreateFileGDB_management(output_path, "output.gdb", "CURRENT") expression = arcpy.AddFieldDelimiters(feature_class, "SHAPE_Area") + " < " + query if arcpy.Exists(feature_class): with arcpy.da.UpdateCursor(feature_class, "*", where_clause=expression) as cursor: for row in cursor: cursor.deleteRow() arcpy.FeatureClassToFeatureClass_conversion(feature_class, gdb_path, "output_feature_class") del cursor arcpy.FeatureClassToFeatureClass_conversion(feature_class, gdb_path, "output_feature_class", where_clause=expression) print("操作完成") else: print("要素类不存在")运行错误:Traceback (most recent call last): File "D:\多对一空间连接\批量删除小面积.py", line 26, in <module> File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\conversion.py", line 1675, in FeatureClassToFeatureClass raise e ExecuteError: ERROR 999999: 执行函数时出错。 执行(FeatureClassToFeatureClass)失败。 执行(删除小面)失败。请改正代码
时间: 2024-01-22 13:18:55 浏览: 158
使用arcpy获取简单的矢量数据信息.zip_arcPy 查询_arcpy 数据读入_arcpy 读取数据_arcpy矢量拼接
根据错误信息,是在 `FeatureClassToFeatureClass_conversion` 函数的调用中发生了错误。具体错误信息需要查看 ArcGIS 的日志,不过在这里可以给出一些可能导致错误的原因和解决方法:
1. `feature_class` 参数和 `output_path` 参数中的路径名应该使用反斜杠 `\` 而不是斜杠 `/`。
2. 如果 `feature_class` 参数或 `output_path` 参数中的路径名包含空格,则需要使用引号将路径名括起来,例如 `"C:\data\input feature class.shp"`。
3. `FeatureClassToFeatureClass_conversion` 函数中的第三个参数应该是输出的要素类的名称,而不是输出路径。因此,应该将第三个参数改为 `"output_feature_class"`。
4. 如果删除要素类中的行之后,要素类为空,则在调用 `FeatureClassToFeatureClass_conversion` 函数时会出错。在删除行之前,可以先检查要素类是否为空,如果为空,则不需要调用 `FeatureClassToFeatureClass_conversion` 函数。
下面是修改后的代码:
```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.CreateFolder_management(os.path.dirname(output_path), os.path.basename(output_path))
gdb_path = os.path.join(output_path, "output.gdb")
if not arcpy.Exists(gdb_path):
arcpy.CreateFileGDB_management(output_path, "output.gdb", "CURRENT")
expression = arcpy.AddFieldDelimiters(feature_class, "SHAPE_Area") + " < " + query
if arcpy.Exists(feature_class):
count = arcpy.GetCount_management(feature_class)
if int(count.getOutput(0)) == 0:
print("要素类为空,不需要进行操作")
else:
with arcpy.da.UpdateCursor(feature_class, "*", where_clause=expression) as cursor:
for row in cursor:
cursor.deleteRow()
arcpy.FeatureClassToFeatureClass_conversion(feature_class, gdb_path, "output_feature_class", where_clause=expression)
print("操作完成")
else:
print("要素类不存在")
```
阅读全文