当前位置:网站首页>ArcGIS Pro scripting tool (5) - delete duplicates after sorting
ArcGIS Pro scripting tool (5) - delete duplicates after sorting
2022-06-30 10:31:00 【Learning point GIS】
Requirements describe
Each city has multiple high-speed entrances and exits , The distance between each expressway entrance and the municipal government of the city has been included in the attribute table , How to keep each city closest to the municipal government , That is to say NEAR_DIST What about the highway entrance with the lowest value ?

Solutions
ArcGIS Bring it with you Delete the same item Tools , But only stay OID The top one , And this one is often not what we want to keep . In order to meet the needs , Through the first SearchCursor Build a with duplicate elements sql expression , Reuse Updatecursor Sort each set of duplicates according to requirements , Keep the top item , All items after deletion . Use scripts to build geo processing tools , Parameter setting and interface are as follows .

Python Script
# coding=utf-8
import arcpy
from collections import Counter
fc = arcpy.GetParameterAsText(0)
fieldVaule = arcpy.GetParameterAsText(1)
field_names = fieldVaule.split(";")
field_count = len(field_names)
field_types = []
i = 0
while i < field_count:
field_type = arcpy.ListFields(fc, field_names[i])[0].type
field_types.append(field_type)
i = i+1
def quotes(type):
if type == "String":
return "'"
else:
return ""
value = []
with arcpy.da.SearchCursor(fc, field_names=field_names) as cursor:
for row in cursor:
i = 0
clause = ""
while i < field_count:
quote = quotes(field_types[i])
clause = clause+field_names[i]+" = " + \
quote+str(row[i])+quote+" And "
i = i+1
clause = clause[:-5]
value.append(clause)
del row
del cursor
counts = Counter(value)
dupValue = [id for id in value if counts[id] > 1]
uniValue = list(set(dupValue))
order = arcpy.GetParameter(2)
orderColumn = order.columnCount
orderRow = order.rowCount
switch = {" Keep the minimum ": "ASC",
" Keep the maximum ": "DESC", }
i = 0
orderclause = ""
while i < orderRow:
orderfid = order.getValue(i, 0)
ordertype = order.getValue(i, 1)
orderclause = orderclause+orderfid+" "+switch.get(ordertype)+";"
i = i+1
for uni in uniValue:
with arcpy.da.UpdateCursor(fc, field_names=field_names, where_clause=uni, sql_clause=(None, 'ORDER BY ' + orderclause)) as cursor:
next(cursor)
while True:
try:
next(cursor)
cursor.deleteRow()
except StopIteration:
break
arcpy.AddMessage(" deleted "+uni+" Same as ")
del cursor
Tool demonstration

Tool description
- Apply to ArcGIS Pro and Python 3, If you want to ArcMap and Python 2 Use in , Need to deal with Chinese character encoding
- And ArcGIS Self contained Delete the same item Same tool , This tool does not generate new datasets , Instead, delete the same items directly from the original data set , Please note before use The backup data
- Tools Field and Sort field You can set multiple values and types as needed
- Sorting method Medium Keep the minimum The corresponding order is ascending , Keep the maximum The corresponding order is descending , The tool keeps the first item after the same item in each group
边栏推荐
- AttributeError: ‘Version‘ object has no attribute ‘major‘
- GD32 RT-Thread flash驱动函数
- KOREANO ESSENTIAL打造气质职场范
- The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art
- CSDN博客运营团队2022年H1总结
- Enter the world of helium (hNT) hotspot servers to bring you different benefits
- Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development
- JS obtient la chaîne spécifiée spécifiant la position du caractère & sous - chaîne spécifiant la plage de position du caractère 【 détails simples 】
- 技能梳理[email protected]+adxl345+电机震动+串口输出
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验1 跑马灯(RGB)实验(学习笔记)
猜你喜欢

How to deploy deflationary combustion destruction contract code in BSC chain_ Deploy dividend and marketing wallet contract code

"Kunming City coffee map" activity was launched again

马斯克推特粉丝过亿了,但他在线失联已一周

Robot system dynamics - inertia parameters

NLopt--非线性优化--原理介绍及使用方法

《锦绣中华》中老年公益文旅游-走进佛山敬老院

今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计

苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...

mysql数据库基础:存储过程和函数

South China Industrial Group launched digital economy and successfully held the city chain technology conference
随机推荐
技能梳理[email protected]+adxl345+电机震动+串口输出
机器学习面试准备(一)KNN
[C language quick start] let you know C language and get started with zero basics ③
Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
Jump table introduction
train_de.py: error: argument --save_steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
Notes on numerical calculation - iterative solution of linear equations
mysql数据库基础:视图、变量
IPhone address book import into Excel
Nlopt -- Nonlinear Optimization -- principle introduction and application method
背课文记单词,读课文记单词,读文章记单词;40篇文章搞定3500词;71篇文章突破中考单词;15篇文章贯通四级词汇;15篇文章贯通六级词汇
RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
【Rust日报】2021-01-23 几个新库发布
Who should the newly admitted miners bow to in front of the chip machine and the graphics card machine
Basic MySQL operation commands of database
华南产业集团发力数字经济,城链科技发布会成功召开
MySQL index, transaction and storage engine of database (3)
GD32 RT-Thread OTA/Bootloader驱动函数
ArcGIS Pro + PS 矢量化用地规划图
最新SCI影响因子公布:国产期刊最高破46分!网友:算是把IF玩明白了