当前位置:网站首页>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
边栏推荐
- 技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled
- Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
- 【Rust日报】2021-01-22 首份Rust月刊杂志邀请大家一起参与
- 打通供应链 深圳礼品展助跨境电商寻破局之道
- Ant s19xp appeared in 140t, why is it called the computing power ceiling by the world
- "Kunming City coffee map" was opened again, and coffee brought the city closer
- 技能梳理[email protected]在oled上控制一条狗的奔跑
- 2022 Season 6 perfect children's model toxon division finals came to a successful conclusion
- Get through the supply chain Shenzhen gift show helps cross-border e-commerce find ways to break the situation
- Why can't you rob scientists of NFT
猜你喜欢
Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
Why can't you rob scientists of NFT
Js獲取指定字符串指定字符比特置&指定字符比特置區間的子串【簡單詳細】
IPhone address book import into Excel
[email protected]体感机械臂"/>
技能梳理[email protected]体感机械臂
Didn't receive robot state (joint angles) with recent timestamp within 1 seconds
Article content cannot be copied
2022第六季完美童模 合肥赛区 初赛圆满落幕
机器人系统动力学——惯性参数
Test memory read rate
随机推荐
"Hackers and painters" -- why not be stupid
Tooltips in the era of touch
"Kunming City coffee map" activity was launched again
光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly
mysql数据库基础:TCL事务控制语言
背课文记单词,读课文记单词,读文章记单词;40篇文章搞定3500词;71篇文章突破中考单词;15篇文章贯通四级词汇;15篇文章贯通六级词汇
Curl --- the request fails when the post request parameter is too long (more than 1024b)
Why can't you rob scientists of NFT
【Rust日报】2021-01-22 首份Rust月刊杂志邀请大家一起参与
Arm新CPU性能提升22%,最高可组合12核,GPU首配硬件光追,网友:跟苹果的差距越来越大了...
郭琳加冕 2022第三季完美大师 全球人气季军
Basic MySQL operation commands of database
SolidWorks质量特性详解(惯性张量、转动惯量、惯性主轴)
[ark UI] implementation of the startup page of harmoniyos ETS
技能梳理[email protected]语音模块+stm32+nfc
train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
MySQL log management, backup and recovery of databases (1)
Automated stock trading ensemble strategy based on Reinforcement Learning