Tuesday, 21 July 2015

arcpy - Why does this SQL syntax produce empty feature class with ArcGIS Select_analysis?


I'm working on a script that involves an arcpy.select_analysis function. The problem I have is that when I run the script it produces an empty file. I've verified that the whole thing works when in the Select GUI, and produces the correct output, and then have even exported the SQL expression and copy/pasted it into the arcgis python window, but no dice.


Here is the script and warning in ArcGIS python window



Here is the table view showing that zip 10004 does exist in this field.]


I've zoomed the extent both way out and way in to see if that makes a difference, but it doesn't. Any advice would be much appreciated!



Answer



Instead of:


"'ZIP' = '10004'"

try this:


'"ZIP" = ' + "'10004'"

The reason that your original expression gives an empty output is because the string 'ZIP' is not the same as (equal to) the string '10004'.



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...