5 Star 15 Fork 8

Luoge/Landslide_Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
select_null_fc.py 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
Luoge 提交于 2024-04-22 02:32 . 修复 S2-选择NULL点 中的bug
# -*- coding: utf-8 -*-
import arcpy
def construct_clause(fc_name, fieldname, with_or=False):
if with_or:
#clause = f" OR {fc_name}.{fieldname} IS NULL"
clause = " OR {0}.{1} IS NULL".format(fc_name,fieldname)
else:
#clause = f"{fc_name}.{fieldname} IS NULL"
clause = "{0}.{1} IS NULL".format(fc_name,fieldname)
return clause
def select_null_fc(input_fc, fc_name):
fields = arcpy.ListFields(input_fc)
fieldnames = [f.name for f in fields]
if 'OBJECTID' in fieldnames:
fieldnames.remove('OBJECTID')
if 'Shape' in fieldnames:
fieldnames.remove('Shape')
if 'pointid' in fieldnames:
fieldnames.remove('pointid')
if 'grid_code' in fieldnames:
fieldnames.remove('grid_code')
sum_clause = ""
for f_name in fieldnames:
if sum_clause=="":
sum_clause = construct_clause(fc_name, f_name)
else:
sum_clause = sum_clause + construct_clause(fc_name, f_name, with_or=True)
return sum_clause
if __name__=='__main__':
# ArcGIS工具箱模式
input_fc = arcpy.GetParameterAsText(0)
arcpy.AddMessage(input_fc)
# 代码模式
# arcpy.env.workspace = "F:/GIS_RS_Data/博士论文数据.gdb"
# input_fc = "栅格单元2013(小)_fc"
sum_clause = select_null_fc(input_fc, fc_name=input_fc)
print(sum_clause)
arcpy.management.SelectLayerByAttribute(input_fc, "NEW_SELECTION", sum_clause, None)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xushiluo/Landslide_Analysis.git
git@gitee.com:xushiluo/Landslide_Analysis.git
xushiluo
Landslide_Analysis
Landslide_Analysis
master

搜索帮助