arcgis10.2.2工具箱python2.7的脚本代码:凡是SHAPE_Area < 数值的图斑进行自动删除并导出剩余图斑数据
时间: 2024-01-22 14:19:13 浏览: 23
以下是一个可能的代码示例:
```python
import arcpy
# 设置工作空间
arcpy.env.workspace = "C:/data"
# 设置要素类名称
fc_name = "my_feature_class.shp"
# 设置删除条件
delete_condition = "SHAPE_Area < 100"
# 打开要素类
fc = arcpy.MakeFeatureLayer_management(fc_name)
# 使用删除条件选择要删除的要素
arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", delete_condition)
# 删除选定的要素
arcpy.DeleteFeatures_management(fc)
# 导出剩余要素
output_name = "remaining_features.shp"
remaining_fc = arcpy.FeatureClassToFeatureClass_conversion(fc, arcpy.env.workspace, output_name)
```
这段代码假设你已经设置了工作空间到包含要素类的目录,并且要素类名称为“my_feature_class.shp”。脚本使用“SHAPE_Area < 100”作为删除条件,选择所有面积小于100的要素进行删除。然后,剩余的要素将被导出到新的要素类“remaining_features.shp”中。
相关问题
arcgis10.2.2工具箱python2.7的脚本代码,凡是SHAPE_Area < 数值的图斑进行自动删除并导出剩余图斑数据
以下是一个可能的解决方案:
```python
import arcpy
# 设置工作空间
arcpy.env.workspace = "C:/data"
# 设置输入和输出的图层
input_layer = "my_shapefile.shp"
output_layer = "my_output_shapefile.shp"
# 设置删除条件
delete_expression = "SHAPE_Area < {}".format(num)
# 使用MakeFeatureLayer函数创建图层
arcpy.MakeFeatureLayer_management(input_layer, "temp_layer")
# 使用SelectLayerByAttribute函数根据删除条件选择要删除的要素
arcpy.SelectLayerByAttribute_management("temp_layer", "NEW_SELECTION", delete_expression)
# 使用DeleteFeatures函数删除选择的要素
arcpy.DeleteFeatures_management("temp_layer")
# 使用CopyFeatures函数将剩余的要素导出为新的图层
arcpy.CopyFeatures_management("temp_layer", output_layer)
```
其中,`num` 为一个数值变量,代表删除条件中的数值。你需要根据自己的具体情况替换掉工作空间、输入图层、输出图层和删除条件等参数。
arcgis10.2.2工具箱python2.7的脚本代码出理凡是SHAPE_Area < 数值的图斑进行自动删除并导出剩余图斑数据
以下是一个示例脚本,可以实现你的需求:
```python
import arcpy
# 设置工作空间和要素类路径
arcpy.env.workspace = r"C:\data"
fc = "my_shapefile.shp"
# 创建游标遍历要素
with arcpy.da.UpdateCursor(fc, ["SHAPE_Area"]) as cursor:
for row in cursor:
# 如果SHAPE_Area小于指定值,删除要素
if row[0] < 数值:
cursor.deleteRow()
# 完成游标操作
del cursor
# 导出剩余要素到新的 shapefile 文件
out_fc = r"C:\output\remaining_shapefile.shp"
arcpy.CopyFeatures_management(fc, out_fc)
```
你需要将代码中的 `C:\data` 替换为你自己的工作空间路径,将 `my_shapefile.shp` 替换为你的要素类名称,将 `数值` 替换为你想要删除的 SHAPE_Area 的最小值,将 `C:\output\remaining_shapefile.shp` 替换为你想要导出剩余要素的输出路径。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![tbx](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![tbx](https://img-home.csdnimg.cn/images/20210720083646.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)