我正在尝试从一组点创建多边形。我已经将XY点数据加载到ArcMap中,格式如下:六角形X Y 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()发布于 2019-11-05 05:18:05
我不能修改脚本,但我找到了一种方法来达到我想要的最终结果。我将XY数据点放入ArcMap中,然后使用points to Line脚本生成直线。然后,我使用QGIS将线条更改为多边形,以带回Arcmap。
https://stackoverflow.com/questions/58700111
复制相似问题