Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am attempting to make a simple select and zoom python script for my address points. Currently the script will complete successfully but will not select or zoom to the entered point. I am using two parameters that have been set in the Script Tool. Address_Number (Long) and Address_Name (String) which both have identical spellings/data types in Properties>>Parameters

Here's the code:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
addLayer = arcpy.mapping.Layer("G:\Layers\GIS_SDE.AddressPoints.lyr")
arcpy.mapping.AddLayer(df, addLayer, "TOP")
Address_Number = arcpy.GetParameterAsText(0)
Address_Name = arcpy.GetParameterAsText(1
arcpy.SelectLayerByAttribute_management("GIS_SDE.AddressPoints", "NEW_SELECTION", "A_NBR = %Address_Number% AND ADDR = %Address_Name%")
df.zoomToSelectedFeatures()

Any help is appreciated.

Thanks, Jordan

share|improve this question

1 Answer 1

The problem is the Where Clause that you are supplying to SelectLayerByAttributes.

I would recommend that you try the technique used by @blah238 in this answer to another question.

You could do something like this to utilize the referenced function with multiple conditions/fields, joining them with the AND operator:

arcpy.SelectLayerByAttribute_management("GIS_SDE.AddressPoints",
"NEW_SELECTION",
" AND ".join(
    [buildWhereClause("GIS_SDE.AddressPoints", "A_NBR", Address_Number),
     buildWhereClause("GIS_SDE.AddressPoints", "ADDR", Address_Name)]))
share|improve this answer
    
Thanks @blah238 - your enhanced version of my answer will certainly be easier to follow. –  PolyGeo Mar 3 '13 at 11:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.