<?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: ERROR 000358: Invalid expression Failed to execute (MakeFeatureLayer) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279346#M67433</link>
    <description>&lt;P&gt;The expression looks ok.&amp;nbsp; The only thing I can think of is your field type, if Speed is a string rather than float/number then the expression would fail in this manner.&lt;/P&gt;&lt;P&gt;if it is a string and you don't need to do any &amp;gt; &amp;lt; comparison:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;where_clause = "Speed = '30' AND Shape_Length &amp;lt; 400"&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 17 Apr 2023 17:45:42 GMT</pubDate>
    <dc:creator>DavidPike</dc:creator>
    <dc:date>2023-04-17T17:45:42Z</dc:date>
    <item>
      <title>ERROR 000358: Invalid expression Failed to execute (MakeFeatureLayer)</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279187#M67428</link>
      <description>&lt;P&gt;My python script should identify sections of roads based on two criteria: wheather they're adjacent to roads with a lower speed limit, and weather they're shorter than 400m. I get an error related to the MakeFeatureLayer tool. Any help is appreciated.&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

# Set up workspace and input feature class
arcpy.env.workspace = r"C:\Users\Local.gdb"
input_fc = "Full_Roads_CC"

# Set up a search cursor to iterate over the features in the feature class
fields = ["Limit_TRO","Shape_Length", "SHAPE@"]
cursor = arcpy.da.SearchCursor(input_fc, fields)

# Initialize some variables to track the state of the search

prev_speed = None
prev_line = None
selected_lines = []

# Loop thourgh the features in the fc
for row in cursor:
    speed = row[0]
    length = row[1]
    line = row[2]
    
     # Check if the current line is between two sections of lines where speed = 20
    if prev_speed == 20 and speed == 30 and length &amp;lt; 400:
        selected_lines.append(line)
        
     # Update the previous speed and line
    prev_speed = speed
    prev_line = line
    
# Select the roads that meet the criteria
output_layer = "selected_roads"
where_clause = "Speed = 30 AND Shape_Length &amp;lt; 400"
arcpy.management.MakeFeatureLayer(input_fc, output_layer,where_clause)

# Add the selected roads to the output layer
arcpy.management.CopyFeatures(selected_lines, output_layer)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error is:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;ExecuteError                              Traceback (most recent call last)
In  [7]:
Line 28:    arcpy.management.MakeFeatureLayer(input_fc, output_layer,where_clause)

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in MakeFeatureLayer:
Line 9395:  raise e

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in MakeFeatureLayer:
Line 9392:  retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(*gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), True)))

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in &amp;lt;lambda&amp;gt;:
Line 512:   return lambda *args: val(*gp_fixargs(args, True))

ExecuteError: ERROR 000358: Invalid expression
Failed to execute (MakeFeatureLayer).&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 10:27:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279187#M67428</guid>
      <dc:creator>Nina_Ca</dc:creator>
      <dc:date>2023-04-17T10:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000358: Invalid expression Failed to execute (MakeFeatureLayer)</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279341#M67432</link>
      <description>&lt;P&gt;I get that error if&amp;nbsp;r"C:\Users\Local.gdb\Full_Roads_CC" doesn't have a field named "Speed".&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:34:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279341#M67432</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-04-17T17:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000358: Invalid expression Failed to execute (MakeFeatureLayer)</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279346#M67433</link>
      <description>&lt;P&gt;The expression looks ok.&amp;nbsp; The only thing I can think of is your field type, if Speed is a string rather than float/number then the expression would fail in this manner.&lt;/P&gt;&lt;P&gt;if it is a string and you don't need to do any &amp;gt; &amp;lt; comparison:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;where_clause = "Speed = '30' AND Shape_Length &amp;lt; 400"&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Apr 2023 17:45:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-failed-to-execute/m-p/1279346#M67433</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-04-17T17:45:42Z</dc:date>
    </item>
  </channel>
</rss>

