arcmap - 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()
解决方案
我无法更正脚本,但我找到了一种解决方法来获得我想要的最终结果。我将 XY 数据点放入 ArcMap,然后使用 Points to Line 脚本生成线条。然后我使用 QGIS 将线条更改为多边形以带回 Arcmap。
推荐阅读
- java - 创建具有相同宽度的项目的工具栏
- javascript - 数学脚本无法正常工作我希望它如何工作
- sonarqube - 声纳错误
- php - 工作票预订系统无法验证数据
- c++ - 避免库中的循环重载和专业化依赖(AKA 手动 C++ 导出方法)
- django - Heroku dynos:从技术上讲,我可以在 Django 设置中使用更少的 dynos 吗?
- python - python的哪个web框架有点击按钮弹出子页面的功能?
- angular - 如何使用 Angular 6 刷新依赖的 ng-tabs
- javascript - 单行函数体周围更漂亮的箭头括号
- excel - Excel 计算唯一值整列,例如 A:A