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

  • 相关阅读:
    django模板使用
    django视图的定义
    字符串逆序
    Django 中Admin站点的配置
    Django模型Model的定义
    Django安装部署
    Linux常用命令
    深拷贝,浅拷贝
    lambda 表达式 (匿名函数)
    生成器与迭代器
  • 原文地址:https://www.cnblogs.com/gisoracle/p/10854724.html
Copyright © 2011-2022 走看看