Can not create polygon from text file with ID , X, Y, values in Python

8089
12
05-18-2016 12:19 AM
SadanandacharB1
New Contributor III


Hi Everyone,

  I am new to Python, I am creating one empty feature class using python code and trying to create polygon using text file which is having ID, X, Y values as below,

my text file points.txt and the code is as follows

1 542935 1619969

2 543015 1619964

3 543079 1619924

4 543095 1619896

5 543107 1619816

6 543099 1619768

7 543067 1619669

8 543047 1619629

9 543007 1619593

10 542979 1619577

11 542923 1619569

12 542883 1619577

13 542810 1619625

14 542738 1619649

15 542698 1619701

16 542690 1619733

17 542699 1619773

18 542719 1619821

19 542775 1619893

20 542883 1619953

21 542935 1619969

>>> import arcpy, fileinput, string, os
>>> from arcpy import env
>>> env.workspace = "D:/Data"
>>> inputfile = "D:/Data/points.txt"
>>> fc = "newpoly.shp"
>>> arcpy.CreateFeatureclass_management("D:/Data", fc, "polygon")
<Result 'D:\\Data\\newpoly.shp'>
>>> cursor = arcpy.da.InsertCursor(fc, ["SHAPE@"])
>>> array = arcpy.Array()
>>> point = arcpy.Point()
>>> for line in fileinput.input(inputfile):
...     point.ID, point.X, point.y = string.split(line, " ")
...     array.add(arcpy.Point(X, Y))
...     cursor.insertRow([arcpy.Polygon(array)])
...     fileinput.close()
...     del cursor

But it is unable to create polygon feature, after running the code "newpoly.shp" is empty with values like

FID Shape Id

0   Polygon 0

where am i wrong?, why it is not writing geometry, Please help me

Thanks You

Sadananad

0 Kudos
12 Replies
SadanandacharB1
New Contributor III

Thank You So Much

0 Kudos
SadanandacharB1
New Contributor III

Thank You So Much

0 Kudos
SadanandacharB1
New Contributor III

Thank You So Much

0 Kudos