lemanlake

Doing multiple queries with a loop

Discussion created by lemanlake on Jan 18, 2012
Latest reply on Jan 19, 2012 by dkwiens
Hello everyone !

I work on ArcGIS 9.3 and I'd want to execute many queries in a row with Python.

Actually I have a layer, called "lines" that contains all the bus lines of a city. And my question is : how to save each line in a different layer ?
I thought the best thing to do would be :
- a query by attributes : field used : "blines". Characterizes the number of the lines (1, 2, 3 and so on)
- and then to save each query in a distinct layer

A good solution would be a loop in order to make the computation faster but I don't really know how to do.

I tried to make that script but I guess I'm very far from the right result :


import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")

# Variables in local
lines_shp = "d:\\Travaux\\NantesMetropole\\lines.shp"

test = ["blines"]
while 1:
    for i in test:
        try:
            gp.Select_analysis(lines_shp, i_shp, i)
            print "Query successful"
        except:
            print "Error"
    break


Have you got any ideas ?

Thank you !
Julien

Outcomes