<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can not create polygon from text file with ID , X, Y, values in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109598#M8462</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I did it like this&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;spatial_ref = # Define Spatial referene here
point = arcpy.Point(X, Y)
point_geometry = arcpy.PointGeometry(point, spatial_ref)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can use &lt;SPAN style="font-family: 'courier new', courier;"&gt;point_geometry&lt;/SPAN&gt; with your insert cursor (which should be opened with the ID field as well as SHAPE@) to create the feature with the ID.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:35:26 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2021-12-11T06:35:26Z</dc:date>
    <item>
      <title>Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109593#M8457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 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,&lt;/P&gt;&lt;P&gt;my text file points.txt and the code is as follows&lt;/P&gt;&lt;P&gt;1 542935 1619969&lt;/P&gt;&lt;P&gt;2 543015 1619964&lt;/P&gt;&lt;P&gt;3 543079 1619924&lt;/P&gt;&lt;P&gt;4 543095 1619896&lt;/P&gt;&lt;P&gt;5 543107 1619816&lt;/P&gt;&lt;P&gt;6 543099 1619768&lt;/P&gt;&lt;P&gt;7 543067 1619669&lt;/P&gt;&lt;P&gt;8 543047 1619629&lt;/P&gt;&lt;P&gt;9 543007 1619593&lt;/P&gt;&lt;P&gt;10 542979 1619577&lt;/P&gt;&lt;P&gt;11 542923 1619569&lt;/P&gt;&lt;P&gt;12 542883 1619577&lt;/P&gt;&lt;P&gt;13 542810 1619625&lt;/P&gt;&lt;P&gt;14 542738 1619649&lt;/P&gt;&lt;P&gt;15 542698 1619701&lt;/P&gt;&lt;P&gt;16 542690 1619733&lt;/P&gt;&lt;P&gt;17 542699 1619773&lt;/P&gt;&lt;P&gt;18 542719 1619821&lt;/P&gt;&lt;P&gt;19 542775 1619893&lt;/P&gt;&lt;P&gt;20 542883 1619953&lt;/P&gt;&lt;P&gt;21 542935 1619969&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy, fileinput, string, os
&amp;gt;&amp;gt;&amp;gt; from arcpy import env
&amp;gt;&amp;gt;&amp;gt; env.workspace = "D:/Data"
&amp;gt;&amp;gt;&amp;gt; inputfile = "D:/Data/points.txt"
&amp;gt;&amp;gt;&amp;gt; fc = "newpoly.shp"
&amp;gt;&amp;gt;&amp;gt; arcpy.CreateFeatureclass_management("D:/Data", fc, "polygon")
&amp;lt;Result 'D:\\Data\\newpoly.shp'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; cursor = arcpy.da.InsertCursor(fc, ["SHAPE@"])
&amp;gt;&amp;gt;&amp;gt; array = arcpy.Array()
&amp;gt;&amp;gt;&amp;gt; point = arcpy.Point()
&amp;gt;&amp;gt;&amp;gt; for line in fileinput.input(inputfile):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point.ID, point.X, point.y = string.split(line, " ")
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; array.add(arcpy.Point(X, Y))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.insertRow([arcpy.Polygon(array)])
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fileinput.close()
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it is unable to create polygon feature, after running the code "newpoly.shp" is empty with values like&lt;/P&gt;&lt;P&gt;FID Shape Id&lt;/P&gt;&lt;P&gt;0&amp;nbsp;&amp;nbsp; Polygon 0&lt;/P&gt;&lt;P&gt;where am i wrong?, why it is not writing geometry, Please help me&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks You&lt;/P&gt;&lt;P&gt;Sadananad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:35:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109593#M8457</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2021-12-11T06:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109594#M8458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you format your code so indentation can be checked.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/55181" target="_blank"&gt;Code Formatting... the basics++&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp; In any event, are you saying that you couldn't see a polygon or that you were expecting to see the point number because you won't see them.&amp;nbsp; Are the points in clockwise order? Is it a simple polygon?&amp;nbsp; And you might want to try CopyFeatures rather than CreateFeatureClass&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Polygon&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Array&lt;/SPAN&gt;&lt;SPAN class="p"&gt;([&lt;/SPAN&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Point&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="o"&gt;*&lt;/SPAN&gt;&lt;SPAN class="n"&gt;coords&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k"&gt;for&lt;/SPAN&gt; &lt;SPAN class="n"&gt;coords&lt;/SPAN&gt; &lt;SPAN class="ow"&gt;in&lt;/SPAN&gt; &lt;SPAN class="n"&gt;feature&lt;/SPAN&gt;&lt;SPAN class="p"&gt;])))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="p"&gt;,,,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/copy-features.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/copy-features.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Copy Features—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/SPAN&gt; vx&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/create-feature-class.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/create-feature-class.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Create Feature Class—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:35:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109594#M8458</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T06:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109595#M8459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like you are closing your input text file after reading the first line.&lt;/P&gt;&lt;P&gt;Put the .close outside of the loop.&lt;/P&gt;&lt;P&gt;I believe that the geometry constructor sorts out the directionality of the coordinate loop first before writing the geometry.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2016 10:49:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109595#M8459</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2016-05-18T10:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109596#M8460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And the del cursor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2016 10:50:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109596#M8460</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2016-05-18T10:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109597#M8461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14635820848771153 jive_text_macro" data-renderedposition="8_8_1203_0" jivemacro_uid="_14635820848771153"&gt;&lt;P&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;First, you should really be working with spatial references.&amp;nbsp; As it stands now, you are creating polygons and feature classes/shape files that have no spatial references.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Beyond what &lt;A href="https://community.esri.com/migrated-users/5327"&gt;Neil Ayres&lt;/A&gt;​ covered, i.e., closing the file after one point is read, I am surprised the code runs completely.&amp;nbsp; Specifically, the following line should generate an error:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14635820898131137 jive_text_macro" data-renderedposition="86_8_1203_16" jivemacro_uid="_14635820898131137"&gt;&lt;P&gt;array.add(arcpy.Point(X, Y))&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;You have not defined X or Y anywhere in the code you have posted, so it should generate a NameError.&amp;nbsp; Since you have already defined a Point and set its ID, X, and Y attributes; all you need to do is pass the point into the array:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14635822009225953 jive_text_macro" data-renderedposition="154_8_1203_16" jivemacro_uid="_14635822009225953"&gt;&lt;P&gt;array.add(point)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your current code will not populate an "ID" field seperate from the FID for two reasons:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Your feature class only has an auto-generated ID field (FID) and a shape field.&lt;/LI&gt;&lt;LI&gt;Even if your feature class had an additional "ID" field, you have defined your insert cursor with only the shape field.&amp;nbsp; The FID field will be created automatically for you, but no other fields will be populated.&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2016 14:42:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109597#M8461</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-05-18T14:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109598#M8462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I did it like this&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;spatial_ref = # Define Spatial referene here
point = arcpy.Point(X, Y)
point_geometry = arcpy.PointGeometry(point, spatial_ref)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can use &lt;SPAN style="font-family: 'courier new', courier;"&gt;point_geometry&lt;/SPAN&gt; with your insert cursor (which should be opened with the ID field as well as SHAPE@) to create the feature with the ID.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:35:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109598#M8462</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-11T06:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109599#M8463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are also some good examples in the help, I'd stay closer to their recipe&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/python/writing-geometries.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/python/writing-geometries.htm"&gt;Writing geometries—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;Also see some of my tribulations here&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/message/163495"&gt;Creating polygons with holes using ArcPy&lt;/A&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 May 2016 04:16:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109599#M8463</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2016-05-19T04:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109600#M8464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You So Much&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 06:38:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109600#M8464</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2016-05-27T06:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109601#M8465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thank You So Much&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 06:39:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109601#M8465</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2016-05-27T06:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109602#M8466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thank You So Much&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 06:39:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109602#M8466</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2016-05-27T06:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109603#M8467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thank You So Much&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 06:39:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109603#M8467</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2016-05-27T06:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109604#M8468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thank You So Much&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 06:39:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109604#M8468</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2016-05-27T06:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can not create polygon from text file with ID , X, Y, values in Python</title>
      <link>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109605#M8469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Thank You So Much&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 06:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/can-not-create-polygon-from-text-file-with-id-x-y/m-p/109605#M8469</guid>
      <dc:creator>SadanandacharB1</dc:creator>
      <dc:date>2016-05-27T06:39:55Z</dc:date>
    </item>
  </channel>
</rss>

