Skip to main content
Post Closed as "Duplicate" by PolyGeo arcpy
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
deleted 2 characters in body
Source Link

All I'm trying to do is use SelectLayerByAttribute to select all lines less than 5.1 meters. However, no matter what query I try I keep getting "error 000358 invalid expression" when I run the script as a tool. I have already tried using various combinations of escape characters and string concatenations like ' "Shape_Length" < '5.1' ' and '"Shape_Length" <' + '5.1'. I've also have tried putting Shape_Length in {}'s. I tried doing the same query in the python window in ArcMap and all I have to do is "Shape_Length < 5.1" and it works just fine. I've never been so stumped. Anyone have anymore ideas on what to try?

import arcpy
import os
from arcpy import env
from arcpy.sa import *
from arcpy import da

arcpy.env.overwriteOutput = True
arcpy.SetLogHistory(False)
arcpy.CheckOutExtension("spatial")

og_polyline = arcpy.GetParameterAsText(0)
polyline =arcpy.CopyFeatures_management(og_polyline,r"in_memory/lines")

layer=arcpy.MakeFeatureLayer_management(polyline,"thelayer.lyr")

calc_fields=["SHAPE@","OBJECTID"]

norepeatlist=[]

query="Shape_Length < + 5.1"

arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", query)

All I'm trying to do is use SelectLayerByAttribute to select all lines less than 5.1 meters. However, no matter what query I try I keep getting "error 000358 invalid expression" when I run the script as a tool. I have already tried using various combinations of escape characters and string concatenations like ' "Shape_Length" < '5.1' ' and '"Shape_Length" <' + '5.1'. I've also have tried putting Shape_Length in {}'s. I tried doing the same query in the python window in ArcMap and all I have to do is "Shape_Length < 5.1" and it works just fine. I've never been so stumped. Anyone have anymore ideas on what to try?

import arcpy
import os
from arcpy import env
from arcpy.sa import *
from arcpy import da

arcpy.env.overwriteOutput = True
arcpy.SetLogHistory(False)
arcpy.CheckOutExtension("spatial")

og_polyline = arcpy.GetParameterAsText(0)
polyline =arcpy.CopyFeatures_management(og_polyline,r"in_memory/lines")

layer=arcpy.MakeFeatureLayer_management(polyline,"thelayer.lyr")

calc_fields=["SHAPE@","OBJECTID"]

norepeatlist=[]

query="Shape_Length < + 5.1"

arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", query)

All I'm trying to do is use SelectLayerByAttribute to select all lines less than 5.1 meters. However, no matter what query I try I keep getting "error 000358 invalid expression" when I run the script as a tool. I have already tried using various combinations of escape characters and string concatenations like ' "Shape_Length" < '5.1' ' and '"Shape_Length" <' + '5.1'. I've also have tried putting Shape_Length in {}'s. I tried doing the same query in the python window in ArcMap and all I have to do is "Shape_Length < 5.1" and it works just fine. I've never been so stumped. Anyone have anymore ideas on what to try?

import arcpy
import os
from arcpy import env
from arcpy.sa import *
from arcpy import da

arcpy.env.overwriteOutput = True
arcpy.SetLogHistory(False)
arcpy.CheckOutExtension("spatial")

og_polyline = arcpy.GetParameterAsText(0)
polyline =arcpy.CopyFeatures_management(og_polyline,r"in_memory/lines")

layer=arcpy.MakeFeatureLayer_management(polyline,"thelayer.lyr")

calc_fields=["SHAPE@","OBJECTID"]

norepeatlist=[]

query="Shape_Length < 5.1"

arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", query)
Source Link
Loading