Я пытаюсь создать полигоны из набора точек. Я загрузил данные точек XY во ArcMap без проблем в формате, аналогичном ниже: шестиугольник XY EJCCFCBIHF -84,8775 32,1875 32,1486 EJCCFCBIHF -84,9 EJCCFCBIHF -84,945 32,1486 32,1875 -84,9675 EJCCFCBIHF EJCCFCBIHF -84,945 32,2265 32,2265 EJCCFCBIHF -84,9 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()