1

I selected data by using select layer by attribute, then I need to only select these selection and zoom in to the selection. my code is this, it can zoom in base on the scale I set, but I see other adjacent polygon that has other Code_No, why?

Layer = arcpy.mapping.ListLayers(mxd, "lyr", df) 
arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", "Code_NO = '%s'"%mycodeNo) 
df.extent = lyrLayer1.getSelectedExtent()
df.scale *= 2
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 3, 2014 at 21:23

1 Answer 1

2

If your layer is called "lyr" and you have already created your map document (mxd) and data frame (df) objects, then the following should have a better chance of working. I am not sure about your SQL expression so have hardcoded a value. For your initial testing use something you know exists and then work on the SQL expression after that.

lyrLayer1 = arcpy.mapping.ListLayers(mxd, "lyr", df)[0] 
lyrLayer1.definitionQuery = ''' "Code_NO" = 'TEST_VALUE' '''
df.extent = lyrLayer1.getSelectedExtent()
answered Feb 3, 2014 at 21:42

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.