Hi all,I created the following ArcPy-Python script:# ===== newWritingGeometries3Polygons in PythonWin 2.6.5 ========
# Create a new polygon feature class using a text file of coordinates.
# Each coordinate entry is semicolon delimited in the format of ID;X;Y
# Import ArcPy and other required modules
#
import arcpy
from arcpy import env
import fileinput
import string
import os
env.overwriteOutput = True
# Get the coordinate ASCII file
#
#infile = arcpy.GetParameterAsText(0)
infile = r"C:\TEMP\WritingGeometries\WritingGeometries_3features.txt"
# Get the output feature class
# fcname = arcpy.GetParameterAsText(1)
fcname = r"C:\TEMP\BS_Test.gdb\Polygons_fc"
# Get the template feature class
#
# template = arcpy.GetParameterAsText(2)
template = r"C:\TEMP\BS_Test.gdb\bsInFeatureClass"
try:
# Create the output feature class
#
arcpy.CreateFeatureclass_management(os.path.dirname(fcname),
os.path.basename(fcname),
"Polygon", template)
# Open an insert cursor for the new feature class
#
cur = arcpy.InsertCursor(fcname)
# Create an array and point object needed to create features
#
polygonArray = arcpy.Array()
pnt = arcpy.Point()
# Initialize a variable for keeping track of a feature's ID.
#
ID = -1
for line in fileinput.input(infile): # Open the input file
# set the point's ID, X and Y properties
#
pnt.ID, pnt.X, pnt.Y = string.split(line,";")
print pnt.ID, pnt.X, pnt.Y
if ID == -1:
ID = pnt.ID
# Add the point to the feature's array of points
# If the ID has changed, create a new feature
#
if ID != pnt.ID:
# Create a new row or feature, in the feature class
#
feat = cur.newRow()
# Set the geometry of the new feature to the array of points
#
feat.shape = polygonArray
# Insert the feature
#
cur.insertRow(feat)
polygonArray.removeAll()
polygonArray.add(pnt)
ID = pnt.ID
# Add the last feature
#
feat = cur.newRow()
feat.shape = polygonArray
cur.insertRow(feat)
lineArray.removeAll()
fileinput.close()
del cur
arcpy.SetParameterAsText (0, fcname) # newly added 18Sept2012, per Barbara S.
except Exception as e:
print e.message
I executed the script and I just got 2 polygons - see the attached file for details. Please kindly help and tell me why the 3rd polygon failed to show up ( I believe the following code staments do not work:# Add the last feature
#
feat = cur.newRow()
feat.shape = polygonArray
cur.insertRow(feat)
)Thanks,Scott Chang