zoukankan      html  css  js  c++  java
  • ArcGIS Python 获得坐标

    import arcpy
    
    infc = arcpy.GetParameterAsText(0)
    
    # Identify the geometry field
    #
    desc = arcpy.Describe(infc)
    shapefieldname = desc.ShapeFieldName
    
    # Create search cursor
    #
    rows = arcpy.SearchCursor(infc)
    
    # Enter for loop for each feature/row
    #
    for row in rows:
        # Create the geometry object
        #
        feat = row.getValue(shapefieldname)
    
        # Print the current multipoint's ID
        #
        print "Feature %i:" % row.getValue(desc.OIDFieldName)
        partnum = 0
    
        # Step through each part of the feature
        #
        for part in feat:
            # Print the part number
            #
            print "Part %i:" % partnum
    
            # Step through each vertex in the feature
            #
            for pnt in feat.getPart(partnum):
                if pnt:
                    # Print x,y coordinates of current point
                    #
                    print pnt.X, pnt.Y
                else:
                    # If pnt is None, this represents an interior ring
                    #
                    print "Interior Ring:"
            partnum += 1     

     改进代码

    # -*- coding: cp936 -*-
    import arcpy
    
    infc = arcpy.GetParameterAsText(0)
    
    # Identify the geometry field
    #
    desc = arcpy.Describe(infc)
    shapefieldname = desc.ShapeFieldName
    
    # Create search cursor
    #
    rows = arcpy.SearchCursor(infc)
    
    # Enter for loop for each feature/row
    #
    for row in rows:
        # Create the geometry object
        #
        feat = row.getValue(shapefieldname)
    
        # Print the current multipoint's ID
        #
        arcpy.AddMessage("Feature %i:" % row.getValue(desc.OIDFieldName))
        print "Feature %i:" % row.getValue(desc.OIDFieldName)
        partnum = 0
    
        # Step through each part of the feature
        #
        for part in feat:
            # Print the part number
            #
            print "Part %i:" % partnum
            arcpy.AddMessage("Part %i:" % partnum)
            # Step through each vertex in the feature
            #
            i=0
            for pnt in feat.getPart(partnum):
                if pnt:
                    # Print x,y coordinates of current point
                    #
                    print pnt.X, pnt.Y
                    arcpy.AddMessage("i="+str(i)+",X="+str(pnt.X)+", Y="+str(pnt.Y))
                else:
                    # If pnt is None, this represents an interior ring
                    #
                    print "Interior Ring:"
                    arcpy.AddMessage("Interior Ring:")
                i=i+1
            partnum += 1

    输出坐标如下

    消息
    执行: 获得坐标 fw_1
    开始时间: Mon May 13 08:31:04 2019
    正在运行脚本 获得坐标...
    Feature 660:
    Part 0:
    i=0,X=57219.7552977, Y=86478.4272009
    i=1,X=57797.135264, Y=86224.559745
    i=2,X=57266.9342054, Y=86029.10427
    i=3,X=57219.7552977, Y=86478.4272009
    Interior Ring:
    i=5,X=57345.5657184, Y=86314.4243312
    i=6,X=57408.4709287, Y=86170.6409933
    i=7,X=57514.0618175, Y=86278.4784967
    i=8,X=57345.5657184, Y=86314.4243312
    Completed script 获得坐标...
    成功 在 Mon May 13 08:31:04 2019 (经历的时间: 0.00 秒)

  • 相关阅读:
    andrew ng 学习
    360一些笔试题
    安装visual studio2010提示“Windows Installer 服务不可用”的解决办法
    算法学习从赌钱游戏看PageRank算法
    jQuery Masonry 一个 jQuery动态网格布局的插件
    国内HTML5前端开发框架汇总
    Windows Performance Monitor 学习笔记
    ThinkPad预装win8系统机型安装win7系统的操作指导
    jQuery的Ajax的自动完成功能控件
    JavaScript的Forms验证Parsley.js
  • 原文地址:https://www.cnblogs.com/gisoracle/p/10854724.html
Copyright © 2011-2022 走看看