Python arcpy检查矢量自相交
arcpy检查面矢量自相交或异相交的问题。
相交的基本思路如下:
检查相交的Python脚本如下,需在ArcGIS 10以上版本中运行 ,最后生成__WT.shp的矢量,即为问题矢量:
import arcpy
#打开覆盖写入
arcpy.env.overwriteOutput=True
A="E:\\zxj\\hh.shp"
fold="E:\\zxj\\"
index=A.rfind("\\")
B=fold+A[index:-4]+"B.shp"
C=fold+A[index:-4]+"C.shp"
D=fold+A[index:-4]+"D.shp"
E=fold+A[index:-4]+"E.shp"
G=fold+A[index:-4]+"G.shp"
#问题区域
prob=fold+A[index:-4]+"__WT.shp"
#关闭结果加入图层
arcpy.env.addOutputsToMap=False
arcpy.FeatureToLine_management(A,B)
arcpy.FeatureToPolygon_management(B,C)
arcpy.Intersect_analysis([C,A],G)
arcpy.FeatureToPoint_management(G, D)
arcpy.FeatureToPoint_management(A, E)
#打开结果加入图层
arcpy.env.addOutputsToMap=True
arcpy.Erase_analysis(E,D,prob)
检查相交、重复、重叠
效果如下。重复只会标记一次,相交会标记两次,重叠标记一次。重叠指一个要素在另一个要素内部
import arcpy
import os
#检查相交或重复的问题A = r"D:\data\test.shp"
fold = r'D:\data\bb'#打开覆盖写入
arcpy.env.overwriteOutput=True
index=A.rfind("\\")
B=fold+A[index:-4]+"B.shp"
C=fold+A[index:-4]+"C.shp"
D=fold+A[index:-4]+"D.shp"
E=fold+A[index:-4]+"E.shp"
G=fold+A[index:-4]+"G.shp"
if not os.path.exists(fold):os.makedirs(fold)
#问题区域 相交的问题
prob=fold+A[index:-4]+"H.shp"
prob2=fold+A[index:-4]+"__WT.shp"
#关闭结果加入图层
arcpy.env.addOutputsToMap=False
arcpy.FeatureToLine_management(A,B)
arcpy.FeatureToPolygon_management(B,C)
arcpy.Intersect_analysis([C,A],G)
arcpy.FeatureToPoint_management(G, D)
arcpy.FeatureToPoint_management(A, E)
arcpy.Erase_analysis(E,D,prob)
#添加字段 问题类型
arcpy.AddField_management(prob, "problem", "TEXT","","", 12)
with arcpy.da.UpdateCursor(prob, "problem") as cursor:for row in cursor:row[0] = "相交"cursor.updateRow(row)
del cursor
#检查重复的问题,根据坐标是否一致判断#E = r'D:\data\fumz\test\testE.shp'
sets = set()
sets2 = set()
arcpy.AddField_management(E, "problem", "TEXT","","", 12)
fields = ['SHAPE@WKT','problem','SHAPE@X','SHAPE@Y']with arcpy.da.UpdateCursor(E, fields) as cursor:for row in cursor:id = row[0]id2 = '%s,%s'%(row[2],row[3])if id in sets:row[1] = '重复'cursor.updateRow(row)elif id2 in sets2:row[1] = '疑似相交'cursor.updateRow(row) else:cursor.deleteRow()#cursor.updateRow(row)sets.add(id)sets2.add(id2)
del cursor
#打开结果加入图层
arcpy.env.addOutputsToMap=True#合并图层
arcpy.Merge_management([E, prob], prob2)
#arcpy.env.addOutputsToMap=Falsedelete = False
#删
if delete:arcpy.Delete_management(B)arcpy.Delete_management(C)arcpy.Delete_management(D)arcpy.Delete_management(E)arcpy.Delete_management(G)arcpy.Delete_management(prob)
批处理版
# -*- coding: utf-8 -*-
import arcpy
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
#检查相交或重复的问题shpFolder = r"D:\data\a" #shp文件夹
fold = r'D:\data\a\bc' #输出文件夹
#---------------------分割线-------------------------------
files = [shpFolder+"\\"+i for i in os.listdir(shpFolder) if i.endswith('.shp')]
for A in files:#打开覆盖写入A = A.decode('gbk')arcpy.env.overwriteOutput=Trueindex=A.rfind("\\")B=fold+A[index:-4]+"B.shp"C=fold+A[index:-4]+"C.shp"D=fold+A[index:-4]+"D.shp"E=fold+A[index:-4]+"E.shp"G=fold+A[index:-4]+"G.shp"if not os.path.exists(fold):os.makedirs(fold)#问题区域 相交的问题prob=fold+A[index:-4]+"H.shp"prob2=fold+A[index:-4]+"__WT.shp"#关闭结果加入图层arcpy.env.addOutputsToMap=Falsearcpy.FeatureToLine_management(A,B)arcpy.FeatureToPolygon_management(B,C) arcpy.Intersect_analysis([C,A],G)arcpy.FeatureToPoint_management(G, D)arcpy.FeatureToPoint_management(A, E)arcpy.Erase_analysis(E,D,prob)#添加字段 问题类型arcpy.AddField_management(prob, "problem", "TEXT","","", 12)with arcpy.da.UpdateCursor(prob, "problem") as cursor:for row in cursor:row[0] = "相交"cursor.updateRow(row)del cursor#检查重复的问题,根据坐标是否一致判断#E = r'D:\data\fumz\test\testE.shp'sets = set()sets2 = set()arcpy.AddField_management(E, "problem", "TEXT","","", 12)fields = ['SHAPE@WKT','problem','SHAPE@X','SHAPE@Y']with arcpy.da.UpdateCursor(E, fields) as cursor:for row in cursor:id = row[0]id2 = '%s,%s'%(row[2],row[3])if id in sets:row[1] = '重复'cursor.updateRow(row)elif id2 in sets2:row[1] = '疑似相交'cursor.updateRow(row) else:cursor.deleteRow()#cursor.updateRow(row)sets.add(id)sets2.add(id2)del cursor#打开结果加入图层arcpy.env.addOutputsToMap=True#合并图层arcpy.Merge_management([E, prob], prob2)#arcpy.env.addOutputsToMap=Falsedelete = True#删if delete:arcpy.Delete_management(B)arcpy.Delete_management(C)arcpy.Delete_management(D)arcpy.Delete_management(E)arcpy.Delete_management(G)arcpy.Delete_management(prob)
Python arcpy检查矢量自相交相关推荐
- arcgis 经纬度转大地坐标_土地报备坐标txt(坐标交换数据)转shp遇到的坑及其Python(ArcPy/ArcGIS)实现...
目录 土地报备坐标txt文件(坐标交换数据)转shp遇到的坑以及该功能的Python(ArcPy/ArcGIS)实现 一. 使用 Python(ArcPy) 绘制shp 什么是ArcPy 如何构造sh ...
- python参数检查类型_Python类型检查
python参数检查类型 1.什么是类型检查? (1. What is Type Checking?) Type Checking is the programming language featur ...
- Python(arcpy) 批量计算流域面积
需要注意: 1.只有面元素才可以计算面积,所以如果手上数据是边界线的文件,则需要将之转为面文件,参见Python(arcpy) 批量将线元素转化为面元素 2.地理坐标系无法计算面积,需要在投影坐标系下 ...
- 20来行的Python拼写检查器
近来Google的人工智能围棋机器人AlphaGo击败了欧洲围棋冠军樊麾二段(原中国国少队队员),引起了围棋界的轩然大波.AlphaGo采用的是机器学习加上蒙特卡洛算法的方式.蒙特卡洛算法早有研读,而 ...
- Python语法检查——pyflakes
Python 语法检查 -- pyflakes 安装 python -m install pyflakes 使用 python -m pyflakes xxx.py
- Python 代码检查之Pylint
Pylint是什么 pylint是一个python代码检查工具 Pylint能干什么 这里列出了很多,单是我想前三种应该是最有用的 检查python代码符不符合PEP8规范 检查代码中的错误 提供重构 ...
- 土地报备坐标txt文件转shp遇到的坑以及该功能的 Python(Arcpy) 实现
文章目录 土地报备坐标txt文件转shp遇到的坑以及该功能的 Python(Arcpy) 实现 一. 使用 Python(ArcPy) 绘制shp 什么是ArcPy 如何构造shp(面) 主要涉及方法 ...
- 在ArcGIS上使用python(arcpy包)的入门教程
1.why arcpy? 如果简单将arcgis理解成绘图与分析两大功能的话(由于本人对arcgis使用十分局限,该分类仅为个人使用范畴内的一个总结),arcpy包在arcgis的分析功能上有很大的帮 ...
- python拼写检查_拼写检查 -
Python文本处理教程™
检查拼写是任何文本处理或分析的基本要求. python中的pyspellchecker包提供了这个功能,可以找到可能错误拼写的单词,并建议可能的更正. 首先,我们需要在python环境中使用以下命令安 ...
最新文章
- 行如风 Angular 初识3
- 如何用 Python 和机器学习帮你决策?
- KVM复制虚拟机,KVM克隆虚拟机
- 使用.net开发手机管理软件(一至三)
- gpg: no valid OpenPGP data found. 解决办法
- aes256 php,如何在PHP中进行AES256解密?
- 如何让大数据分析更有效
- 查询数量查看表的所有相关列信息
- 用vmware workstation做双机集群的详细过程(三)
- Junit 4 的 @Before 和 @BeforeClass 对比 Junit 5 @BeforeEach 和 @BeforeAll
- 微信小程序生成二维码最新版
- 通过GPS测试跑步速度可行性验证
- 如何自学C语言(一个菜鸟的学习路)
- 谷歌浏览器86版_Google 谷歌浏览器 Chrome v87.0.4280.66 Win Mac Linux 安卓等稳定版
- 部件级、处理机级和处理机间流水线
- c语言visit函数作用,Visit
- 网易企业邮箱优势功能
- 北京公积金打印贷款证明(缴存明细+异地贷款职工缴存使用证明)
- (总)百度AI 平台API调用
- 基于SSM开发大学食堂采购管理系统
热门文章
- #1716 : 继承顺位(dfs)
- 特征因子是什么意思_尺度因子是什么意思
- 时间序列—显著相关性和滞后性分析_python
- 【统计学】一篇文章读懂stata相关性系数矩阵输出 加星号 (*)显著水平 学术论文
- 办公软件-Excel:Excel百科
- 湖北省两化融合贯标专项解读,2022年申报奖励补贴以及申报条件汇总
- 2018互联网女皇报告:数据采集/共享/优化,以狂暴的步伐激增
- 基于log4net的日志组件扩展封装,实现自动记录交互日志 XYH.Log4Net.Extend(微服务监控)...
- tcpdump使用命令
- CMMI, 6 Sigma