Python實現Table To Point代碼

</pre><pre name="code" class="python"><span style="font-family:KaiTi_GB2312;font-size:18px;color:#000099;"><span style="white-space:pre">	</span>ArcGIS中提供了XY To Point的工具,但是在ArcToolBox裏並沒有提供根據Table中的XY座標轉換爲Point的工具,不利於GP工具的調用,共享一下。</span>
</pre><pre name="code" class="python">
<span style="color: rgb(0, 0, 153); font-family: KaiTi_GB2312;font-size:18px;">-------------------------------------</span>
"""
    Create Point Feature Class from Table
"""

################### Imports ########################
import arcpy as ARCPY
import arcpy.management as DM
import arcpy.da as DA
import ErrorUtils as ERROR
import os as OS
import locale as LOCALE
LOCALE.setlocale(LOCALE.LC_ALL, '')

################ Output Field Names #################
fieldList = ["XCoord", "YCoord"]

################### GUI Interface ###################
def TableToPoints():
    """A Table that is include xy coordinates is used to make some points."""

    #get user provided inputs and outputs
    inTable = ARCPY.GetParameterAsText(0)
    outputFC = ARCPY.GetParameterAsText(1)
    
    # define a empty points feature object
    point = ARCPY.Point()
    
    # A list to hold the pointGeometry objects
    pointList = []
    
    # for each coordinate pair,populate the point object and create a new pointgeometry
    with DA.SearchCursor(inTable, fieldList) as cursors:
        for row in cursors:
            point.X = row[0]
            point.Y = row[1]
            pointGeometry = ARCPY.PointGeometry(point)
            pointList.append(pointGeometry)
             
    # create copy of the pointGeometry objects,by using pointgeometrylist as input to the copyfeatures tool
    ARCPY.CopyFeatures_management(pointList, outputFC)

if __name__ == "__main__":
    TableToPoints()
--------------------歡迎來訪,拒絕轉載---------------------

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章