首页 > 解决方案 > ArcMap - “NoneType”对象没有属性“GetPart”

问题描述

我正在尝试从一组点创建多边形。I have loaded the XY point data into ArcMap without issue in a format similar to below: Hexagon XY EJCCFCBIHF -84.8775 32.1875 EJCCFCBIHF -84.9 32.1486 EJCCFCBIHF -84.945 32.1486 EJCCFCBIHF -84.9675 32.1875 EJCCFCBIHF -84.945 32.2265 EJCCFCBIHF -84.9 32.2265 EJCCFCCGFE -84.8775 32.2655 EJCCFCCGFE - 84.9 32.2265 EJCCFCCGFE -84.945 32.2265 EJCCFCCGFE -84.9675 32.2655 EJCCFCCGFE -84.945 32.3044 EJCCFCCGFE -84.9 32.3044 EJCCFCECBD -84.8775 32.4214 EJCCFCECBD -84.9 32.3824 EJCCFCECBD -84.945 32.3824 EJCCFCECBD -84.9675 32.4214 EJCCFCECBD -84.945 32.4603 EJCCFCECBD -84.9 32.4603

然后我尝试使用类似于下面有人编写的脚本,但我收到错误“NoneType”对象没有属性“GetPart”。有什么想法会是什么问题?任何帮助都会很棒。

脚本:

import arcgisscripting
import os

def point2polygon():
    gp = arcgisscripting.create(9.3)
    gp.OverWriteOutput = 1

    # Input point FC
    inPts = gp.GetParameterAsText(0)
    # Output polygon FC
    outPoly = gp.GetParameterAsText(1)
    # PolyID Field
    IDField = gp.GetParameterAsText(2)
    # Sort Field
    sortField = gp.GetParameterAsText(3)
    if sortField == "#":
        sortField = ""

    if sortField == "":
        cursorSort = IDField
    else:
        cursorSort = IDField + ";" + sortField

    createPolysFromPoints(gp, inPts, outPoly, IDField, cursorSort) 

def createPolysFromPoints(gp, inPts, outPoly, IDField, cursorSort):
    try:
        # Assign empty values to cursor and row objects
        iCur, sRow, sCur, feat = None, None, None, None

        shapeName = gp.Describe(inPts).ShapeFieldName

        # Create the output feature class
        #
        outPath, outFC = os.path.split(outPoly)
        gp.CreateFeatureClass(outPath, outFC, "Polygon", inPts, "", "", inPts)

        # Open an insert cursor for the new feature class
        #
        iCur = gp.InsertCursor(outPoly)
        sCur = gp.SearchCursor(inPts, "", None, cursorSort, cursorSort)

        sRow = sCur.Next()

        # Create an array and point object needed to create features
        #
        lineArray = gp.CreateObject("Array")
        pt = gp.CreateObject("Point")

        # Initialize a variable for keeping track of a feature's ID.
        #
        ID = -1
        while sRow:
            pt = sRow.GetValue(shapeName).GetPart(0)            
            currentValue = sRow.GetValue(IDField)

            if ID == -1:
                ID = currentValue

            if ID <> currentValue:
                if lineArray.count > 2:  # need a minimum of 3 points to form a valid polygon
                    # To close polygon, add the starting point to the end
                    #
                    lineArray.Add(lineArray.GetObject(0))

                    feat = iCur.NewRow()
                    if ID: #in case the value is None/Null
                        feat.SetValue(IDField, ID)
                    feat.SetValue(shapeName, lineArray)
                    iCur.InsertRow(feat)
                else:
                    gp.AddWarning("Not enough points to create a polygon for %s: %s" % (IDField, str(ID)))
                lineArray.RemoveAll()

            lineArray.Add(pt)
            ID = currentValue
            sRow = sCur.Next()

        # Add the last feature
        #
        if lineArray.count > 1:
            feat = iCur.NewRow()
            if ID: #in case the value is None/Null
                feat.SetValue(IDField, currentValue)
            feat.SetValue(shapeName, lineArray)
            iCur.InsertRow(feat)
        else:
            gp.AddWarning("Not enough points to create a line for %s: %s" % (IDField, str(ID)))
        lineArray.RemoveAll()

    except Exception, err:
        print err.message
        gp.AddError(err.message)

    finally:
        if iCur:
            del iCur
        if sRow:
            del sRow
        if sCur:
            del sCur
        if feat:
            del feat

if __name__ == '__main__':
    point2polygon()

标签: arcmap

解决方案


我无法更正脚本,但我找到了一种解决方法来获得我想要的最终结果。我将 XY 数据点放入 ArcMap,然后使用 Points to Line 脚本生成线条。然后我使用 QGIS 将线条更改为多边形以带回 Arcmap。


推荐阅读