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

  • 相关阅读:
    Python 常用集合类型的增删改查分合 list tuple dict set
    C# Protobuf如何做到0分配内存的序列化/反序列化(2)
    用java springboot 下载无水印抖音快手视频
    下载腾讯视频为mp4简单方法
    java springboot笔记
    如何下载西瓜视频中的 blob:https 的视频下载
    一行Python代码实现for循环和if else判断
    Redis报错:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to...
    pandas pd.concat() 提示没有 join_axes 参数
    Flask+Celery 执行时报错:def _connparams(self, async=False, _r210_options=( ^ SyntaxError: invalid syntax
  • 原文地址:https://www.cnblogs.com/gisoracle/p/10854724.html
Copyright © 2011-2022 走看看