<?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 Copy multiple field values to a new field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/copy-multiple-field-values-to-a-new-field/m-p/539398#M42150</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;System ArcGIS 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem: copy values in multiple fields to one added field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a polygon shapefile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Its attribute table has five fields, including C0011, C0012, C0013, C0014, and C0032.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Each field has two rows, S and W.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;S or W represent multiple polygons. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In total there are ten rows in the attribute table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;No rows are overlapped between fields. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I want to add a field called ???sum??? and copy the values from C0011 to C0032 to this field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I generated the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, the line of query seems wrong syntax.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly advise how to describe wild card for field of C0011, C0013, and C0032.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;##Script Name: calculate sum
##Description: calculate sum&amp;nbsp; 
##Created By: Elaine Kuo
##Date: 26/05/2012
 

#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

#Set the workspace.
gp.Workspace= "H:/temp/test"
#gp.Workspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O/P_Turdidae_22"

#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp"
#outWorkspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O"

#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Create a value table that will hold all of the input features to Merge.
vt = gp.createobject("ValueTable") 

# Loop through every item in the list that was just generated
for fc in fcs:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object.
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add a field to this shapefile, of type LONG
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField (fc, "All", "Text", 6,6)&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Populate the input value table with feature classes.
&amp;nbsp;&amp;nbsp;&amp;nbsp; vt.AddRow(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.ListFields(fc, "C*", "String")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.toolbox = "Data Management"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addMessage(type(field))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select records to be deleted (C*, i.e. C7658)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make temporary featureclasses
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Select_analysis(fc,("output.shp"))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # copy values in existing fields to the new field
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "\"%s\" = 'C*'" % field.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("output.shp", "All", query,"PYTHON_9.3")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace.
&amp;nbsp;&amp;nbsp;&amp;nbsp; OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # clear memory of temporary shapefiles
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete("output.shp")


gp.AddMessage(gp.GetMessages())
print gp.GetMessages()

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 26 May 2012 01:49:56 GMT</pubDate>
    <dc:creator>ElaineKuo</dc:creator>
    <dc:date>2012-05-26T01:49:56Z</dc:date>
    <item>
      <title>Copy multiple field values to a new field</title>
      <link>https://community.esri.com/t5/python-questions/copy-multiple-field-values-to-a-new-field/m-p/539398#M42150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;System ArcGIS 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Problem: copy values in multiple fields to one added field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a polygon shapefile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Its attribute table has five fields, including C0011, C0012, C0013, C0014, and C0032.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Each field has two rows, S and W.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;S or W represent multiple polygons. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In total there are ten rows in the attribute table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;No rows are overlapped between fields. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I want to add a field called ???sum??? and copy the values from C0011 to C0032 to this field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I generated the code below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, the line of query seems wrong syntax.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please kindly advise how to describe wild card for field of C0011, C0013, and C0032.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;##Script Name: calculate sum
##Description: calculate sum&amp;nbsp; 
##Created By: Elaine Kuo
##Date: 26/05/2012
 

#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

#Set the workspace.
gp.Workspace= "H:/temp/test"
#gp.Workspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O/P_Turdidae_22"

#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp"
#outWorkspace= "H:/temp_stage_2_3_polygon_limit_1984_no_R_O"

#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Create a value table that will hold all of the input features to Merge.
vt = gp.createobject("ValueTable") 

# Loop through every item in the list that was just generated
for fc in fcs:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Break out the name, no path or extension, using the describe object.
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = gp.describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureName = desc.name

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add a field to this shapefile, of type LONG
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField (fc, "All", "Text", 6,6)&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Populate the input value table with feature classes.
&amp;nbsp;&amp;nbsp;&amp;nbsp; vt.AddRow(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; Get a list of the fields in the featureclass
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = gp.ListFields(fc, "C*", "String")
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Loop through every item in the list that was just generated 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.toolbox = "Data Management"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addMessage(type(field))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Select records to be deleted (C*, i.e. C7658)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Make temporary featureclasses
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Select_analysis(fc,("output.shp"))

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # copy values in existing fields to the new field
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; query = "\"%s\" = 'C*'" % field.Name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("output.shp", "All", query,"PYTHON_9.3")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Validate the new feature class name for the output workspace.
&amp;nbsp;&amp;nbsp;&amp;nbsp; OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # clear memory of temporary shapefiles
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete("output.shp")


gp.AddMessage(gp.GetMessages())
print gp.GetMessages()

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 May 2012 01:49:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-multiple-field-values-to-a-new-field/m-p/539398#M42150</guid>
      <dc:creator>ElaineKuo</dc:creator>
      <dc:date>2012-05-26T01:49:56Z</dc:date>
    </item>
  </channel>
</rss>

