Sunday, 10 September 2017

arcpy - Correct SQL expression for SelectbyAttribute Tool




I'm trying to apply the sql expression described here https://geonet.esri.com/thread/76028, that involves querying out odd values in a field. The specific sql expression is Round(NumberField / 2, 0) <> NumberField / 2.


I've written this in python:


import arcpy

plantFile = r"U:\Users\K\Plants.shp"
field = "UID"

expression = Round("UID" / 2, 0) <> "UID" / 2
arcpy.SelectLayerByAttribute_management(plantFile, "NEW_SELECTION", expression)


and it returns this error: NameError: name 'Round' is not defined


The expression works when applied in ArcGIS, but not in arcpy. Any hints?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...