<?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: Calculate fields using logic with Python - standalone script in ArcGIS Spatial Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050593#M11231</link>
    <description>&lt;P&gt;Thank you for your informative answer. I corrected the script accordingly, but unfortunately, I still have the same error. Do you see maybe some other error in my script that may cause this error? I think that I implemented everything like in the example on esri website, but it does not work.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Apr 2021 12:09:15 GMT</pubDate>
    <dc:creator>KK2</dc:creator>
    <dc:date>2021-04-23T12:09:15Z</dc:date>
    <item>
      <title>Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050016#M11225</link>
      <description>&lt;P&gt;Hallo, I would like to ask how to populate a new attribute field using &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field-examples.htm" target="_self"&gt;logic with python&lt;/A&gt; as standalone script without opening Raster Calculator and pasting the script attached below. How to assign with python the information from which attribute(s) and from which dataset the new attribute will be populated?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Expression:
Reclass(!WELL_YIELD!)

Code Block:
def Reclass(WellYield):
    if (WellYield &amp;gt;= 0 and WellYield &amp;lt;= 10):
        return 1
    elif (WellYield &amp;gt; 10 and WellYield &amp;lt;= 20):
        return 2
    elif (WellYield &amp;gt; 20 and WellYield &amp;lt;= 30):
        return 3
    elif (WellYield &amp;gt; 30):
        return 4&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 12:01:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050016#M11225</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-22T12:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050038#M11226</link>
      <description>&lt;P&gt;Use the spatial analyst's Con function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It this example W is your WellYield raster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;OutRas = Con(W &amp;lt;= 10, 1, Con(W &amp;lt;= 20, 2, Con(W &amp;lt;= 30, 3, 4)))&lt;/LI-CODE&gt;&lt;P&gt;or try&lt;/P&gt;&lt;LI-CODE lang="python"&gt;OutRas = RoundUp(Divide(W, 10.))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 12:45:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050038#M11226</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-22T12:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050044#M11227</link>
      <description>&lt;P&gt;Thank you for the answer, but I am not working on raster but on polygon shapefile and I would like to run it as standalone python script, so I think the Con function will not help me much. I am looking for a script that indicates me the input data and input attributes in the attribute table from which the logic statement is evaluated to populate a new attribute in my polygon shapefile.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 12:50:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050044#M11227</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-22T12:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050048#M11228</link>
      <description>&lt;P&gt;Ahh field calculator&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank"&gt;Calculate Field (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 12:57:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050048#M11228</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-22T12:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050528#M11229</link>
      <description>&lt;P&gt;Thank you for the answer, it is what I was looking for.&lt;/P&gt;&lt;P&gt;However, I received an error while running the script, which was as follow:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Runtime error  Traceback (most recent call last):   File "&amp;lt;string&amp;gt;", line 3, in &amp;lt;module&amp;gt;   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 3183, in CalculateField     raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of VB | PYTHON | PYTHON_9.3. Failed to execute (CalculateField).  &lt;/LI-CODE&gt;&lt;P&gt;Do you know maybe what might be wrong in my code? I think it might be because of the line attached below, because the example code was taking area and I want to reclassify my input data to another classes and I am not sure if my implementation is correct. In the line attached below&amp;nbsp; I wanted to take the attribute value to calculate the new attribute.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Set local variables
inTable = "CLC"
expression = "getClass(float(!SHAPE.CLC1!))"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The entire code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = "E:/CLC_data/CLC.shp"

# Set local variables
inFeatures = "CLC"
fieldName = "NEW_code"
#fieldPrecision = 9
#fieldAlias = "refcode"
fieldLength = 50
 
# Execute AddField for new fields
arcpy.AddField_management(inFeatures, fieldName, "TEXT", field_length=fieldLength)

# Set local variables
inTable = "CLC"
expression = "getClass(float(!SHAPE.CLC1!))"

#Create NEW_code for CLC1
codeblock = """
def getClass(CLC1):  
  if (CLC1 == 1):  
    return 'A_1'  
  elif (CLC1 == 2):  
    return 'A_2'
  elif (CLC1 == 3):  
    return 'A_3'   	
  else:
	return 'error'"""
 	
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3", 
                                codeblock)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 23 Apr 2021 06:21:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050528#M11229</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-23T06:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050572#M11230</link>
      <description>&lt;P&gt;you don't need Shape&lt;/P&gt;&lt;P&gt;float(!SHAPE.CLC1!)&lt;/P&gt;&lt;P&gt;should be&amp;nbsp;&lt;/P&gt;&lt;P&gt;!CLC1!&lt;/P&gt;&lt;P&gt;since that is the field you are using as the source information&lt;/P&gt;</description>
      <pubDate>Fri, 23 Apr 2021 10:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050572#M11230</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-23T10:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050593#M11231</link>
      <description>&lt;P&gt;Thank you for your informative answer. I corrected the script accordingly, but unfortunately, I still have the same error. Do you see maybe some other error in my script that may cause this error? I think that I implemented everything like in the example on esri website, but it does not work.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Apr 2021 12:09:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050593#M11231</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-23T12:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050742#M11233</link>
      <description>&lt;P&gt;arcpy.env.workspace = "E:/CLC_data&lt;/P&gt;&lt;P&gt;the folder would be the workspace&lt;/P&gt;&lt;P&gt;What you have with the shapefile appended to it is the featureclass name&lt;/P&gt;</description>
      <pubDate>Fri, 23 Apr 2021 16:04:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1050742#M11233</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-23T16:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051251#M11248</link>
      <description>&lt;P&gt;Thank you for your reply. I have&amp;nbsp; amended the script according to your suggestion, but unfortunately I still have the same error. It has to be something different, but I don't know what it is.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 10:26:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051251#M11248</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-26T10:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051284#M11249</link>
      <description>&lt;P&gt;Post a clean version of your script so we can see what changes were made.&amp;nbsp; And your error message again too&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 13:11:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051284#M11249</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-26T13:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051618#M11250</link>
      <description>&lt;P&gt;Below I attach the updated script and the error message. I also changed 'float' to 'short' in expression line, because my attribute is saved as short, but it did not change anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = "E:/CLC_data"

# Set local variables
inFeatures = "CLC"
fieldName = "NEW_code"
#fieldPrecision = 9
#fieldAlias = "refcode"
fieldLength = 50
 
# Execute AddField for new fields
arcpy.AddField_management(inFeatures, fieldName, "TEXT", field_length=fieldLength)

# Set local variables
inTable = "CLC"
expression = "getClass(short(!CLC1!))"

#Create NEW_code for CLC1
codeblock = """
def getClass(CLC1):  
  if (CLC1 == 1):  
    return 'A_1'  
  elif (CLC1 == 2):  
    return 'A_2'
  elif (CLC1 == 3):  
    return 'A_3'   	
  else:
	return 'error'"""
 	
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3", 
                                codeblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Runtime error  Traceback (most recent call last):   File "&amp;lt;string&amp;gt;", line 3, in &amp;lt;module&amp;gt;   File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 3183, in CalculateField     raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of VB | PYTHON | PYTHON_9.3. Failed to execute (CalculateField).  
&amp;gt;&amp;gt;&amp;gt; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 05:52:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051618#M11250</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-27T05:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051645#M11251</link>
      <description>&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank"&gt;Calculate Field (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;arcpy.management.CalculateField(in_table, field, expression, {expression_type}, {code_block}, {field_type})&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3",&lt;BR /&gt;codeblock)&lt;/P&gt;&lt;P&gt;"getClass(short(!CLC1!))"&amp;nbsp; # wrong&lt;/P&gt;&lt;P&gt;leave out short&lt;/P&gt;&lt;P&gt;"getClass(!CLC1!)"&lt;/P&gt;&lt;P&gt;AND the error says....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; .... not a member of VB | PYTHON | PYTHON_9.3&lt;/P&gt;&lt;P&gt;and you put .... "PYTHON3",&lt;/P&gt;&lt;P&gt;try&amp;nbsp; "PYTHON" or&amp;nbsp; "PYTHON_9.3"&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 09:46:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051645#M11251</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-27T09:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051651#M11252</link>
      <description>&lt;P&gt;Thank you again for your valuable help. Amending your suggestions helps me to run the script successfully. I used PYTHON3 before, because such example I have found on &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_self"&gt;ESRI&lt;/A&gt; website.&lt;/P&gt;&lt;P&gt;With these changes the script works:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;expression = "getClass(!CLC1!)"
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON", 
                                codeblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 10:07:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051651#M11252</guid>
      <dc:creator>KK2</dc:creator>
      <dc:date>2021-04-27T10:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate fields using logic with Python - standalone script</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051653#M11253</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/309612"&gt;@KK2&lt;/a&gt;&amp;nbsp;Always use the current help files to validate syntax.&amp;nbsp; You would not be the first one that gets led astray by "googling" for help.&lt;/P&gt;&lt;P&gt;I always navigate from here&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/main/welcome-to-the-arcgis-pro-app-help.htm" target="_blank" rel="noopener"&gt;ArcGIS Pro help—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;for general help&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/main/arcgis-pro-tool-reference.htm" target="_blank" rel="noopener"&gt;ArcGIS Pro geoprocessing tool reference—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;for tool information and&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/main/arcgis-pro-arcpy-reference.htm" target="_blank" rel="noopener"&gt;ArcGIS Pro Python reference—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;for python specific information.&lt;/P&gt;&lt;P&gt;Take care&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Apr 2021 10:13:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/calculate-fields-using-logic-with-python/m-p/1051653#M11253</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-27T10:13:38Z</dc:date>
    </item>
  </channel>
</rss>

