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've seen some questions on this, but there seem to be many different answers... and none have seemed to work. 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, any ideas appreciated.


share|improve this question

2 Answers 2

up vote 6 down vote accepted

How about:

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

Read up on string formatting with python.

share|improve this answer
That didn't quite work, but it put me on the right track, the problem was to also get the field in double quotes. newR = ExtractByAttributes(inR, "\"IntField\">=%d" % val) Thanks! –  CCID Mar 3 '11 at 23:26
My bad, had an extra double-quote in there. Just edited it and it should be correct now. –  Derek Swingley Mar 3 '11 at 23:28
OK, that works now too, and simpler. –  CCID Mar 4 '11 at 0:14

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)

share|improve this answer
OK, this also does the job, thanks for the reply. –  CCID Mar 4 '11 at 0:15

Your Answer


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.