代码拉取完成,页面将自动刷新
# -*- 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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。