<?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 Calculate Field - Convert Meters to Feet in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401559#M73466</link>
    <description>&lt;P&gt;I am trying to calculate a field from the SHAPE.LEN field and convert it from meters to feet....&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the calculate field in ArcPro and it worked fine.. I exported the Python and it gave me this&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
arcpy.management.CalculateField("GIS_DATA.SDE_DITCHING", "LENGTH_FT", "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", """import math
def MetersToFeet(length):
    return (3.280839895) * length
""", "TEXT", "NO_ENFORCE_DOMAINS")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ANY THOUGHTS on why this is failing?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I now want to put this in a stand alone .py script that I will run with a bunch of other code... I did this and am getting this error... I tried all&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

layers_to_Update = {
"DitchingLayers": "Database Connections\\DEV@gis_data.sde\\GIS_DATA.SDE_DITCHING"
}

def updateLengthField():
    for layer in layers_to_Update.keys():
        fromSDE = layer
        updateLayer = layers_to_Update[layer]
        fieldUpdate = "LENGTH_FT"
        arcpy.env.workspace = "Database Connections\\DEV@gis_data.sde"

        arcpy.management.CalculateField(updateLayer, fieldUpdate, "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", """import math
        def MetersToFeet(length):
            return (3.280839895) * length
        """, "TEXT", "NO_ENFORCE_DOMAINS")

if __name__ == '__main__':
    updateLengthField()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000989: Python syntax error: File "&amp;lt;string&amp;gt;", line 2&lt;BR /&gt;def MetersToFeet(length):&lt;BR /&gt;^&lt;BR /&gt;IndentationError: unexpected indent&lt;/P&gt;&lt;P&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then tried this and got this error&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

layers_to_Update = {
"DitchingLayers": "Database Connections\\DEV@gis_data.sde\\GIS_DATA.SDE_DITCHING"
}

def updateLengthField():
    for layer in layers_to_Update.keys():
        fromSDE = layer
        updateLayer = layers_to_Update[layer]
        print(updateLayer)
        fieldUpdate = "LENGTH_FT"
        print(fieldUpdate)
        arcpy.env.workspace = "Database Connections\\DEV@gis_data.sde"

        arcpy.management.CalculateField("GIS_DATA.SDE_DITCHING", "LENGTH_FT", "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", """import math def MetersToFeet(length):return (3.280839895) * length""", "TEXT", "NO_ENFORCE_DOMAINS")

if __name__ == '__main__':
    updateLengthField()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000989: Python syntax error: File "&amp;lt;string&amp;gt;", line 1&lt;BR /&gt;import math def MetersToFeet(length):return (3.280839895) * length&lt;BR /&gt;^&lt;BR /&gt;SyntaxError: invalid syntax&lt;/P&gt;&lt;P&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2024 17:05:16 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2024-03-27T17:05:16Z</dc:date>
    <item>
      <title>Calculate Field - Convert Meters to Feet</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401559#M73466</link>
      <description>&lt;P&gt;I am trying to calculate a field from the SHAPE.LEN field and convert it from meters to feet....&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the calculate field in ArcPro and it worked fine.. I exported the Python and it gave me this&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy
arcpy.management.CalculateField("GIS_DATA.SDE_DITCHING", "LENGTH_FT", "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", """import math
def MetersToFeet(length):
    return (3.280839895) * length
""", "TEXT", "NO_ENFORCE_DOMAINS")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ANY THOUGHTS on why this is failing?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I now want to put this in a stand alone .py script that I will run with a bunch of other code... I did this and am getting this error... I tried all&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

layers_to_Update = {
"DitchingLayers": "Database Connections\\DEV@gis_data.sde\\GIS_DATA.SDE_DITCHING"
}

def updateLengthField():
    for layer in layers_to_Update.keys():
        fromSDE = layer
        updateLayer = layers_to_Update[layer]
        fieldUpdate = "LENGTH_FT"
        arcpy.env.workspace = "Database Connections\\DEV@gis_data.sde"

        arcpy.management.CalculateField(updateLayer, fieldUpdate, "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", """import math
        def MetersToFeet(length):
            return (3.280839895) * length
        """, "TEXT", "NO_ENFORCE_DOMAINS")

if __name__ == '__main__':
    updateLengthField()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000989: Python syntax error: File "&amp;lt;string&amp;gt;", line 2&lt;BR /&gt;def MetersToFeet(length):&lt;BR /&gt;^&lt;BR /&gt;IndentationError: unexpected indent&lt;/P&gt;&lt;P&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then tried this and got this error&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

layers_to_Update = {
"DitchingLayers": "Database Connections\\DEV@gis_data.sde\\GIS_DATA.SDE_DITCHING"
}

def updateLengthField():
    for layer in layers_to_Update.keys():
        fromSDE = layer
        updateLayer = layers_to_Update[layer]
        print(updateLayer)
        fieldUpdate = "LENGTH_FT"
        print(fieldUpdate)
        arcpy.env.workspace = "Database Connections\\DEV@gis_data.sde"

        arcpy.management.CalculateField("GIS_DATA.SDE_DITCHING", "LENGTH_FT", "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", """import math def MetersToFeet(length):return (3.280839895) * length""", "TEXT", "NO_ENFORCE_DOMAINS")

if __name__ == '__main__':
    updateLengthField()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000989: Python syntax error: File "&amp;lt;string&amp;gt;", line 1&lt;BR /&gt;import math def MetersToFeet(length):return (3.280839895) * length&lt;BR /&gt;^&lt;BR /&gt;SyntaxError: invalid syntax&lt;/P&gt;&lt;P&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 17:05:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401559#M73466</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-27T17:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field - Convert Meters to Feet</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401565#M73467</link>
      <description>&lt;P&gt;Never mind I got it with this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def MetersToFeet(length):
    return (3.280839895) * length

def updateLengthField():
    for layer in layers_to_Update.keys():
        fromSDE = layer
        updateLayer = layers_to_Update[layer]
        fieldUpdate = "LENGTH_FT"
        arcpy.env.workspace = "Database Connections\\GIS_3_DEV@gis_data.sde"

        arcpy.management.CalculateField("GIS_DATA.SDE_VDOT_MAINT_DITCHING", "LENGTH_FT", "MetersToFeet((float(!SHAPE.LEN!)))", "PYTHON3", "", "TEXT", "NO_ENFORCE_DOMAINS")&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Mar 2024 17:13:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401565#M73467</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-27T17:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field - Convert Meters to Feet</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401571#M73468</link>
      <description>&lt;P&gt;The above now works BUT I want to get this working against a REST service ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;So something like the below but not DELETE rather CACULATE&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    url = urlDeleteFeatures
    whereclause='1=1'
    gis_payload = {
        'token': currenttoken,
        'f': 'json',
        'where': f'''{whereclause}'''
        }
    response = requests.request("POST", url=url, data=gis_payload)
    print("Done Deleting")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how the expression would look&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1711560010853.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99244i69FD120BC433414E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="kapalczynski_0-1711560010853.png" alt="kapalczynski_0-1711560010853.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 17:20:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401571#M73468</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-27T17:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field - Convert Meters to Feet</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401622#M73469</link>
      <description>&lt;P&gt;Got with this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1711565973413.png" style="width: 668px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99251i41957AEBE0224A3A/image-dimensions/668x339?v=v2" width="668" height="339" role="button" title="kapalczynski_0-1711565973413.png" alt="kapalczynski_0-1711565973413.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;BUT not sure how to get that into a python script..&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tried this... no error but nothing happening..&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    url = urlCalculateFeatures
    whereclause='1=1'
    gis_payload = {
        'token': currenttoken,
        'f': 'json',
        'url':'https://xxxx.xxx.xx.gov/env/rest/services/DEV/UpdateLengthField/FeatureServer/0',
        'expression':'[{"field": "LENGTH_FT", "sqlExpression": "Shape__Length*30.280839895"}]',
        'where': f'''{whereclause}'''
        }
    response = requests.request("POST", url=url, data=gis_payload)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401622#M73469</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-27T19:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field - Convert Meters to Feet</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401643#M73470</link>
      <description>&lt;P&gt;got it... hunting and hunting finally looking at the network payload in the browser i saw the parameter was called calcExpression not expression or Update Expresstion in the image above... ... gotta love cryptic naming conventions ESRI puts out... parameter names are different for each method of updating... uggg&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    url = urlCalculateFeatures
    whereclause='1=1'
    gis_payload = {
        'token': currenttoken,
        'f': 'json',
        'calcExpression':'[{"field": "LENGTH_FT", "sqlExpression": "Shape__Length*300.280839895"}]',
        'sqlFormat':'standard',
        'where': f'''{whereclause}'''
        }
    print(gis_payload)
    response = requests.request("POST", url=urlCalculateFeatures, data=gis_payload)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="kapalczynski_0-1711567830858.png" style="width: 769px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/99254i0E48E8FE79073817/image-dimensions/769x277?v=v2" width="769" height="277" role="button" title="kapalczynski_0-1711567830858.png" alt="kapalczynski_0-1711567830858.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 19:30:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-meters-to-feet/m-p/1401643#M73470</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-03-27T19:30:44Z</dc:date>
    </item>
  </channel>
</rss>

