# 在使用过程中如有疑问请发邮件至ryx_32@126.com,声明:该软件仅限中测新图内部使用,请勿用于商业用途,否则后果自负!!!
# ---------------------------------------------------------------------------
class Feature_No():
pass
import sys, string, os,math, arcgisscripting
gp = arcgisscripting.create(9.3)
gp.SetProduct("ArcInfo")
input_poly = gp.GetParameterAsText(0)
angle_min = long(gp.GetParameterAsText(1))
try:
gp.Addmessage("***********************************************")
gp.AddMessage("本工具由中测新图(北京)遥感技术有限责任公司 任延旭编制")
gp.AddMessage("使用前请做好数据备份,工具产生的不良后果请自行承担!")
gp.Addmessage("***********************************************")
result = gp.GetCount_management(input_poly )
count_n = int(result.GetOutput(0))
if count_n <= 0:
raise Feature_No
str_Err = ""
if len(gp.ListFields(input_poly,"Angle_chk")) <=0:
gp.AddField_management(input_poly, "Angle_chk", "TEXT", "", "", 255)
str_Err = ""
cur = gp.UpdateCursor(input_poly,"","","","")
row = cur.next()
gp.SetProgressor("step", "正在检查图形锐角...", 0,count_n, 1)
angle_rj = 0
angle_cf = 0
num = 0
while row:
num += 1
gp.SetProgressorLabel("共有" +str(count_n)+"个图形,正在检查第" + str(num) + "个图形的夹角,还剩余"+str(count_n-num+1)+"个请稍候...")
shapeName = gp.Describe(input_poly).shapeFieldName
geom = row.getValue(shapeName)
part_count = geom.partCount
count = 0
while count < part_count:
p = geom.getPart(count)
p_b = p.next()
p_S = p_b
p1 = p_b
p2 = p.next()
p3 = p.next()
p_2 = p2
while p3:
x1 = round(p1.X,3)
y1 = round(p1.Y,3)
x2 = round(p2.X,3)
y2 = round(p2.Y,3)
x3 = round(p3.X,3)
y3 = round(p3.Y,3)
if (math.fabs(x1-x2)<0.5 and math.fabs(x2-x3)<0.5) or (math.fabs(y1-y2)<0.5 and math.fabs(y2-y3)<0.5):
jiao = -1
else:
l1 = math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))
l2 = math.sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))
l3 = math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
if l1==0 or l2==0 or l3==0:
angle_cf += 1
else:
cj = (l1*l1+l3*l3-l2*l2)/(2*l1*l3)
jiao = math.cos(angle_min*3.1415926/180)
if cj >= jiao:
angle_rj += 1
p1 = p2
p2 = p3
p3 = p.next()
if not p3:
p3 = p_2
x1 = round(p1.X,3)
y1 = round(p1.Y,3)
x2 = round(p2.X,3)
y2 = round(p2.Y,3)
x3 = round(p3.X,3)
y3 = round(p3.Y,3)
if (x1==x2 and x2==x3) or (y1==y2 and y2==y3):
jiao = -1
else:
l1 = math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))
l2 = math.sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))
l3 = math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
if l1==0 or l2==0 or l3==0:
angle_cf += 1
else:
cj = (l1*l1+l3*l3-l2*l2)/(2*l1*l3)
jiao = math.cos(angle_min*3.1415926/180)
if cj >= jiao:
angle_rj += 1
p_b = p.next()
p_S = p_b
p1 = p_b
p2 = p.next()
p3 = p.next()
p_2 = p2
count = count+1
if angle_cf >0 :
str_Err = "存在"+str(angle_cf)+"个重复点 "
if angle_rj >0 :
str_Err = "存在"+str(angle_rj)+"个尖角"
str_Err = str_Err.strip()
if len(str_Err)!=0:
row.setValue("Angle_chk",str_Err)
cur.updateRow(row)
str_Err = ""
row = cur.next()
gp.SetProgressorPosition()
angle_cf = 0
angle_rj = 0
del row
del cur
gp.Addmessage("恭喜你,锐角检查完成!!!o(∩_∩)o")
gp.Addmessage("如有疑问可发送EMAIL至ryx32@126.com")
gp.Addmessage("谢谢使用锐角检查工具")
gp.Addmessage("*****************************")
except Feature_No:
gp.AddError("输入数据不包含任何数据,请重新选择!!!")
except Exception, e:
gp.AddWarning(e.message)