<?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 Initialize fields with values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552381#M43103</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've got a CSV file with a series of points in each row, point 1, point 2, and point 3. &amp;nbsp;The row also has a series of attributes that I want to be in the attribute table of the resulting feature class (most notably 'id' and 'token'). &amp;nbsp;I can make the polygons ok, but I'm struggling to figure out how to actually get the values into the fields. &amp;nbsp;They're all coming up with default values. &amp;nbsp;I've tried to iterrate back over the resulting shape file to no avail. &amp;nbsp;I'm not sure what tree to even begin barking up at this point. &amp;nbsp;Can anyone point me towards what tree to start barking up?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;print "Starting!"&lt;/P&gt;&lt;P&gt;fc = 'c:/temp/test.dbf'&lt;BR /&gt;#fields = ['Home_y', 'Home_x', 'Work_y', 'Work_x', 'School_y', 'School_x']&lt;BR /&gt;fields = ['Home_x', 'Home_y', 'Work_x', 'Work_y', 'School_x', 'School_y', 'id', 'token']&lt;/P&gt;&lt;P&gt;feature_info = []&lt;BR /&gt;features = []&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;feature = []&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;feature = [[row[0],row[1]],[row[2],row[3]],[row[4],row[5]]] &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;poly = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]),arcpy.SpatialReference(4326)) &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddField_management(poly,"id","TEXT")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddField_management(poly,"token","TEXT")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#arcpy.CalculateField_management(poly, "id", "Hello_World")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;features.append(poly)&lt;/P&gt;&lt;P&gt;print "Writing shape file..."&lt;BR /&gt;arcpy.CopyFeatures_management(features, "c:/temp/polygons.shp")&lt;BR /&gt;print "Done writing shape file..."&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Sep 2016 20:23:46 GMT</pubDate>
    <dc:creator>FrankLaFone</dc:creator>
    <dc:date>2016-09-29T20:23:46Z</dc:date>
    <item>
      <title>Initialize fields with values</title>
      <link>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552381#M43103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've got a CSV file with a series of points in each row, point 1, point 2, and point 3. &amp;nbsp;The row also has a series of attributes that I want to be in the attribute table of the resulting feature class (most notably 'id' and 'token'). &amp;nbsp;I can make the polygons ok, but I'm struggling to figure out how to actually get the values into the fields. &amp;nbsp;They're all coming up with default values. &amp;nbsp;I've tried to iterrate back over the resulting shape file to no avail. &amp;nbsp;I'm not sure what tree to even begin barking up at this point. &amp;nbsp;Can anyone point me towards what tree to start barking up?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;print "Starting!"&lt;/P&gt;&lt;P&gt;fc = 'c:/temp/test.dbf'&lt;BR /&gt;#fields = ['Home_y', 'Home_x', 'Work_y', 'Work_x', 'School_y', 'School_x']&lt;BR /&gt;fields = ['Home_x', 'Home_y', 'Work_x', 'Work_y', 'School_x', 'School_y', 'id', 'token']&lt;/P&gt;&lt;P&gt;feature_info = []&lt;BR /&gt;features = []&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc, fields) as cursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for row in cursor:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;feature = []&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;feature = [[row[0],row[1]],[row[2],row[3]],[row[4],row[5]]] &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;poly = arcpy.Polygon(arcpy.Array([arcpy.Point(*coords) for coords in feature]),arcpy.SpatialReference(4326)) &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddField_management(poly,"id","TEXT")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddField_management(poly,"token","TEXT")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;#arcpy.CalculateField_management(poly, "id", "Hello_World")&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;features.append(poly)&lt;/P&gt;&lt;P&gt;print "Writing shape file..."&lt;BR /&gt;arcpy.CopyFeatures_management(features, "c:/temp/polygons.shp")&lt;BR /&gt;print "Done writing shape file..."&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:23:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552381#M43103</guid>
      <dc:creator>FrankLaFone</dc:creator>
      <dc:date>2016-09-29T20:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Initialize fields with values</title>
      <link>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552382#M43104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what you are looking for... when a field is created, within a FC or shapefile or whatever... a default value is indeed used for the records. &amp;nbsp;You have no control over this. &amp;nbsp;This does not differ from when you do it manually. &amp;nbsp;If you want to ascribe values to the field(s) just created, then you have to calculate a value for it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:36:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552382#M43104</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-09-29T20:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Initialize fields with values</title>
      <link>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552383#M43105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, but when I calculate a value (which should be just copying a value from the CSV into that field), it says the field doesn't exist. &amp;nbsp;Yet when I open the shape file, the field is there.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Sep 2016 20:38:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552383#M43105</guid>
      <dc:creator>FrankLaFone</dc:creator>
      <dc:date>2016-09-29T20:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Initialize fields with values</title>
      <link>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552384#M43106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You either use an updatecursor to establish values after the field is created or use&amp;nbsp;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/calculate-field.htm"&gt;Calculate Field—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp;to establish the values outside an updatecursor, or you create the file from the csv directly. &amp;nbsp;The field may not 'exist' because the file/field creation has not been completed at the time you are trying to establish a value for it. &amp;nbsp;It is time sequencing... nothing exists until arcmap says it does&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Sep 2016 21:00:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/initialize-fields-with-values/m-p/552384#M43106</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-09-29T21:00:46Z</dc:date>
    </item>
  </channel>
</rss>

