1

I am new to GIS and Python is not my forte, so I am looking for some help. Ideally, what I am trying to do is create a tool that allows the user to select an address from my Address points layer. I need to select values from multiple fields: STREET_NUMBER, STREET_NAME and STREET_TYPE. What I really need help with is building my expression. Here is what I have so far:

# Import system modules
import arcpy
from arcpy import env
# Set workspace
workspace = r"O:\Users\Student\Scratch\SC_Test.gdb"
# Set variables
stNum = arcpy.GetParameterAsText(0) 
stName = arcpy.GetParameterAsText(1) 
stType = arcpy.GetParameterAsText(2)
# Make layer from feature class
arcpy.MakeFeatureLayer_management("Address", "add_lyr")
arcpy.SelectLayerByAttribute_management("add_lyr", "NEW_SELECTION", "STREET_NUMBER" = stNum)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 3, 2015 at 16:28
1
  • Welcome to GIS stack exchange. There are tons of questions around here like yours, here's one that may help gis.stackexchange.com/questions/144838/… If you're still getting errors, it's best to include them in your question. Commented Jun 3, 2015 at 16:45

1 Answer 1

2

Your where clause needs to be wrapped in quotes. Also, is the 'STREET_NUMBER' field numeric? If so, your expression can be fixed by doing this:

arcpy.SelectLayerByLocation_management("add_lyr", "NEW_SELECTION",'"STREET_NUMBER" = {}'.format( stNum))

If it is a text field, you will need to wrap that in single quotes:

arcpy.SelectLayerByLocation_management("add_lyr", "NEW_SELECTION", ''' "STREET_NUMBER" = '{}' '''.format( stNum))
answered Jun 3, 2015 at 16:47
2
  • I ran the tool in ArcMap using just the STREET_NUMBER parameter (which is numeric) to test and the tool ran fine, however it did not select anything from my Address layer. Maybe I should be more explicit... I want this tool to select an address from my Address layer, that way it can be easily located in ArcMap. I also want the expression to facilitate my STREET_NAME and STREET_TYPE fields, which are both text, to locate a single, specific address. Thank you ! Commented Jun 3, 2015 at 19:54
  • Perhaps instead of just having a text parameter for the stNum variable, you can just change that parameter to a SQL data type and that way you can use the Select By Attribute GUI. You will have to make sure that it is obtained from your Address Feature class though. Commented Jun 3, 2015 at 20:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.