<?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: List feature class for Loop and Add Field, Calculate Field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/list-feature-class-for-loop-and-add-field/m-p/108719#M8407</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have a much closer look at the help for SpatialJoin. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will see on the RHS that the input data types &lt;/SPAN&gt;&lt;STRONG style="text-decoration: underline;"&gt;must&lt;/STRONG&gt;&lt;SPAN&gt; be "Feature Layer" so you have to use MakeFeatureLayer_management() first to make layers from the featureclasses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS Avoid using CalculateField in a script, use a cursor. The CalculateField tool just wraps a cursor around the expression, but you lose all control of the calculation. If you use a cursor you can test for unexpected data, such as Null values or zero and take action, print error messages and handle different cases. The expressions are also much easier to write. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Leave CalculateField for Modelbuilder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Dec 2011 07:33:00 GMT</pubDate>
    <dc:creator>KimOllivier</dc:creator>
    <dc:date>2011-12-14T07:33:00Z</dc:date>
    <item>
      <title>List feature class for Loop and Add Field, Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-class-for-loop-and-add-field/m-p/108718#M8406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to automate a process where I have several Feature Classes and I want to perform a Spatial Join to one file.&amp;nbsp; I then want to create a field and then populate it in the original Feature Class with a field from the joined feature class.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
from arcpy import env
import os

# The workspace environment needs to be set before ListFeatureClasses
#&amp;nbsp;&amp;nbsp;&amp;nbsp; to identify which workspace the list will be based on
#&amp;nbsp;&amp;nbsp; 
env.workspace = "e:/Project"
out_workspace = "e:/Project/Results"


# Loop through a list of feature classes in the workspace
#
for fc in arcpy.ListFeatureClasses():
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; output = os.path.join(out_workspace, fc)

 # Spatial Join the FC to the cooresponding pop nbrhd file

&amp;nbsp;&amp;nbsp;&amp;nbsp; target_features = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; join_features = "e:/Project/PopularNeighborhoods"
&amp;nbsp;&amp;nbsp;&amp;nbsp; out_feature_class = output

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SpatialJoin_analysis(target_features, join_features, out_feature_class)

&amp;nbsp;&amp;nbsp;&amp;nbsp; target_explore = fc

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(target_explore, "popular_Hood", "Text", 50, "", "", "", "NULLABLE", "NON_REQUIRED")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know the that calculate portion of the script isn't in there, but I wanted to see if I could get it to create new files with the added field and it isn't working. Any help would be greatly appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Dec 2011 19:30:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-class-for-loop-and-add-field/m-p/108718#M8406</guid>
      <dc:creator>AmyReinke</dc:creator>
      <dc:date>2011-12-13T19:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: List feature class for Loop and Add Field, Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/list-feature-class-for-loop-and-add-field/m-p/108719#M8407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have a much closer look at the help for SpatialJoin. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will see on the RHS that the input data types &lt;/SPAN&gt;&lt;STRONG style="text-decoration: underline;"&gt;must&lt;/STRONG&gt;&lt;SPAN&gt; be "Feature Layer" so you have to use MakeFeatureLayer_management() first to make layers from the featureclasses.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS Avoid using CalculateField in a script, use a cursor. The CalculateField tool just wraps a cursor around the expression, but you lose all control of the calculation. If you use a cursor you can test for unexpected data, such as Null values or zero and take action, print error messages and handle different cases. The expressions are also much easier to write. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Leave CalculateField for Modelbuilder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2011 07:33:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/list-feature-class-for-loop-and-add-field/m-p/108719#M8407</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2011-12-14T07:33:00Z</dc:date>
    </item>
  </channel>
</rss>

