当前位置:网站首页>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
边栏推荐
- Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
- 机器学习面试准备(一)KNN
- Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
- The human agent of kDa, Jinbei kd6, takes you to explore the metauniverse
- MySQL advanced SQL statement of database (2)
- 六月集训(第30天) —— 拓扑排序
- Why can't you rob scientists of NFT
- Quick completion guide for mechanical arm (V): end effector
- The rising star of Goldshell STC box
- Compare the maximum computing power of the Cenozoic top ant s19xp and the existing s19pro in bitland
猜你喜欢

The digital collection of sunanmin's lotus heart clearing was launched on the Great Wall Digital Art

Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home

“昆明城市咖啡地图”再度开启,咖啡拉近城市距离

"Kunming City coffee map" activity was launched again

Koreano essential creates a professional style
![JS get the substring of the specified character position and the specified character position interval of the specified string [simple and detailed]](/img/01/6829e85bf28431eb06e70b87ceaaff.jpg)
JS get the substring of the specified character position and the specified character position interval of the specified string [simple and detailed]

KOREANO ESSENTIAL打造气质职场范

孙安民作品《莲花净心》数字藏品上线长城数艺

苹果5G芯片被曝研发失败,QQ密码bug引热议,蔚来回应做空传闻,今日更多大新闻在此...
[email protected]体感机械臂"/>技能梳理[email protected]体感机械臂
随机推荐
Eth is not connected to the ore pool
Setting up the d2lbook environment for Li Mu's "hands on learning and deep learning"
机器人系统动力学——惯性参数
Leetcode question brushing (I) -- double pointer (go Implementation)
The AOV function of R language was used for repeated measures ANOVA (one intra group factor and one inter group factor) and interaction Plot function and boxplot to visualize the interaction
How to deploy deflationary combustion destruction contract code in BSC chain_ Deploy dividend and marketing wallet contract code
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
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 】
"Kunming City coffee map" was opened again, and coffee brought the city closer
After recording 7000 IELTS words in 100 sentences, there are only 1043 words (including simple words such as I and you)
Action bright: take good care of children's eyes together -- a summary of the field investigation on the implementation of action bright in Guangxi
Deploy lvs-dr cluster
Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
[C language quick start] let you know C language and get started with zero basics ③
1033 To Fill or Not to Fill
MIT-6874-Deep Learning in the Life Sciences Week6
Leetcode question brushing (IV) -- greedy thought (go Implementation)
6. Redis new data type
MIT-6874-Deep Learning in the Life Sciences Week5
L'activité "Kunming City coffee map" a rouvert