本文主要是介绍arcgis 快速删点方法,删除线上两点距离过小的点,距离小于某值得点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
想要工具箱直接私信我哦!!!
在处理矢量数据时,线上有时会有很多密集的点,一个个手动删除太麻烦了
下面我来展示一个快速删点方法
1,原始没删点之前
2运行工具脚本
3运行脚本后结果
import arcpy
import os
import sys
import math
import numpy
import arcpy.mapping as mapping
reload(sys)
sys.setdefaultencoding('utf-8')
arcpy.env.overwriteOutput = True
inFeatures= arcpy.GetParameterAsText(0)
dis= arcpy.GetParameterAsText(1)
outpath= arcpy.GetParameterAsText(2)#workspace=arcpy.mapping.MapDocument("current")def getdis(x1,y1,x2,y2):#两点间距离return math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))def getpointlist(pList):#2点列表pList重新排列xyList#
# arcpy.AddMessage("-----pList:"+str(pList))num=len(pList)
# arcpy.AddMessage("点的个数num:"+str(num))dis_list1=[]for i in range(num-1):x1=float(pList[i].split(";")[0])y1=float(pList[i].split(";")[1])x2=float(pList[i+1].split(";")[0])y2=float(pList[i+1].split(";")[1])d=getdis(x1,y1,x2,y2)#计算相邻两点的距离dis_list1.append(d)
# arcpy.AddMessage("循环两点的距离:"+str(d))
# arcpy.AddMessage("循环dis_list1距离列表:"+str(dis_list1))d_mix1=min(dis_list1)
# arcpy.AddMessage("d_mix列表:"+str(d_mix1))if d_mix1<float(dis):count=len(dis_list1)for i in range(0,count):if dis_list1[i]<float(dis):del pList[i+1]xyList=pList
# arcpy.AddMessage("pList列表3:"+str(xyList))breakdis_list2=[]n=len(xyList)for i in range(n-1):x1=float(xyList[i].split(";")[0])y1=float(xyList[i].split(";")[1])x2=float(xyList[i+1].split(";")[0])y2=float(xyList[i+1].split(";")[1])d=getdis(x1,y1,x2,y2)#计算相邻两点的距离dis_list2.append(d)
# arcpy.AddMessage("循环dis_list2距离列表:"+str(dis_list2))d_mix2=min(dis_list2)if d_mix2<float(dis):getpointlist(xyList)if d_mix2>=float(dis):
# xyList=pList
# arcpy.AddMessage("xyList列表2:"+str(xyList))return xyList
# arcpy.AddMessage("xyList列表1:"+str(xyList))return xyListsr=arcpy.Describe(inFeatures).spatialReference
#1得到点列表pList
desc=arcpy.Describe(inFeatures)
ptype=desc.shapeType
arcpy.AddMessage("ptype:"+str(ptype))
pList=[]
with arcpy.da.UpdateCursor(inFeatures,("OID@","SHAPE@"))as cursor:for row in cursor:FID=row[0]feat=row[1]
# arcpy.AddMessage("FID=%i"%FID)
# pList.append("FID=%i"%FID)pList1=[]partnum=0for part in feat:i=0for pnt in feat.getPart(partnum):if pnt:x=pnt.Xy=pnt.YpList1.append(str(x)+";"+str(y))else:
# pList.append("Interior Ring:")arcpy.AddMessage("Interior Ring:")i=i+1partnum+=1
# arcpy.AddMessage("pList1:"+str(pList1))#2点列表pList重新排列xyListpList.append(getpointlist(pList1))#arcpy.AddMessage("pList:"+str(pList))
if ptype=="Polygon":xylist=[]num=len(pList)for i in range(0,num):n=len(pList[i])List1=[]for j in range(0,n):x=float(pList[i][j].split(";")[0])y=float(pList[i][j].split(";")[1])pnt=arcpy.Point(x,y)List1.append(pnt)xylist.append(List1)features = []for feature in xylist:List2=[]for coords in feature:List2.append(coords)array = arcpy.Array(List2)array.append(array[0])features.append(arcpy.Polygon(array))arcpy.CopyFeatures_management(features, os.path.join(outpath,"点处理后面.shp"))arcpy.env.workplace =outpathmxd=arcpy.mapping.MapDocument("current")df = arcpy.mapping.ListDataFrames(mxd)[0]insertLayer = arcpy.mapping.Layer(os.path.join(outpath,"点处理后面.shp"))arcpy.mapping.AddLayer(df, insertLayer, "TOP")arcpy.AddMessage("!!!OK!!!")if ptype=="Polyline":xylist=[]num=len(pList)for i in range(0,num):n=len(pList[i])List1=[]for j in range(0,n):x=float(pList[i][j].split(";")[0])y=float(pList[i][j].split(";")[1])pnt=arcpy.Point(x,y)List1.append(pnt)xylist.append(List1)features = []for feature in xylist:List2=[]for coords in feature:List2.append(coords)array = arcpy.Array(List2)arcpy.Polyline(array)features.append(arcpy.Polyline(array))arcpy.CopyFeatures_management(features, os.path.join(outpath,"点处理后线.shp"))arcpy.env.workplace =outpathmxd=arcpy.mapping.MapDocument("current")df = arcpy.mapping.ListDataFrames(mxd)[0]insertLayer = arcpy.mapping.Layer(os.path.join(outpath,"点处理后线.shp"))arcpy.mapping.AddLayer(df, insertLayer, "TOP")arcpy.AddMessage("!!!OK!!!")
这篇关于arcgis 快速删点方法,删除线上两点距离过小的点,距离小于某值得点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!