• 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 秒)

  • 相关阅读:
    使用Python操作MySQL数据库
    SQL server数据库语句
    SQL server数据库
    实施工程师
    Vue外卖项目
    每日思考记录(12)
    Vue核心知识点
    jQuery快速入门
    js
    css2
  • 原文地址:https://www.cnblogs.com/gisoracle/p/10854724.html
Copyright © 2020-2023  润新知