掌握林业信息技术 共创中国蓝 加入收藏  设为首页 
您现在的位置: 主页 > 技术园地 > 林业勘测 >
分类归档
林业技术新闻
林业基础知识
植物价值
技术园地
行业标准
政策法律法规
林业软件
林业勘测内容

一种四至坐标的计算方法(Python ARCGIS实现)


发布日期:2016-07-09 01:07      阅读次数:       文章摘自:未知

import arcpy
infc =arcpy.GetParameterAsText(0)
 
try: 
 
    # 新建东西南北四至坐标字段,这里X是横坐标,Y是纵坐标
    arcpy.management.AddField(infc,"East_X","DOUBLE",18,10,"","东X")
    arcpy.management.AddField(infc,"East_Y","DOUBLE",18,10,"","东Y")
    arcpy.management.AddField(infc,"West_X","DOUBLE",18,10,"","西X")
    arcpy.management.AddField(infc,"West_Y","DOUBLE",18,10,"","西Y")
    arcpy.management.AddField(infc,"South_X","DOUBLE",18,10,"","南X")
    arcpy.management.AddField(infc,"South_Y","DOUBLE",18,10,"","南Y")
    arcpy.management.AddField(infc,"North_X","DOUBLE",18,10,"","北X")
    arcpy.management.AddField(infc,"North_Y","DOUBLE",18,10,"","北Y")
 
    desc = arcpy.Describe(infc)
    shapefieldname = desc.ShapeFieldName
    rows = arcpy.UpdateCursor(infc)
 
    # 遍历几何对象
    for row in rows:    
 
        # 创建几何对象 
        feat = row.getValue(shapefieldname)
 
        row.East_X=feat.extent.XMin
        row.West_X=feat.extent.XMax
        row.South_Y=feat.extent.YMin
        row.North_Y=feat.extent.YMax
               
        # 标记部件个数
        partcount = feat.partCount
        print partcount
 
        # 遍历每个部件
        for part in feat:
            pntcount = 0
 
            # 遍历所有点,查找xy极值对应坐标值
            for pnt in part:
 
                if pnt:
 
                   print("{0}, {1}".format(pnt.X, pnt.Y))
 
                   if pnt.X==row.East_X:
                      row.East_Y=pnt.Y
 
                   if pnt.X==row.West_X:
                      row.West_Y=pnt.Y
 
                   if pnt.Y==row.South_Y:
                      row.South_X=pnt.X
 
                   if pnt.Y==row.North_Y:
                      row.North_X=pnt.X
           
                   pntcount += 1
  
                # 孤岛多边形
                else: 
                     print "孤岛多边形:"
 
            print pntcount
            
        rows.updateRow(row)
 
    del row,rows 
 
except arcpy.ExecuteError:
       print "工具运行失败,请检查输入要素是否为多边形,字段是否已存在"
       print arcpy.GetMessages()

尚未注册畅言帐号,请到后台注册