6

I'm trying to include an integer variable in the SQL where-clause of a tool like this (ArcGIS 10 Python script):

newR = ExtractByAttributes(inR, '"IntField">=2508')

where inR is an integer raster, IntField is an integer field in its attribute table.

The above works, but how can I substitute an integer variable instead of 2508?

I've tried all kinds of different quotes and concatenation, but have not been able to.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 3, 2011 at 22:20

2 Answers 2

8

How about:

val = 2508
newR = ExtractByAttributes(inR, '"IntField">=%d' % val)

Read up on string formatting with python.

answered Mar 3, 2011 at 22:38
0
4

I have found ArcGIS to be very finnicky when it comes to multiple parameters. For example, use of double quotes tends to signify the end of a parameter. One method I use is string concatenation after changing the variable to a string.

intstr = str(intvar) #Converts integer variable to a string
newR = ExtractByAttributes(inR, "IntField>= "+intstr)

answered Mar 3, 2011 at 23:20
0

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.