Where_clause in arcpy.Select_analysis

907
2
05-15-2014 12:33 AM
AnikaMeyer
New Contributor
Hello to everyone:

I have some dificulties to find the correct syntax of the where_clause in a selection process:

Both of this two possibilies give me an error.
wheresatz='"CLAVE"='+nummapa
wheresatz=""" "CLAVE" = """ + nummapa

nummapa is an integer value.

Perhaps you may have a look to my code below.
Thank you in advance.
Anika

_______
import arcpy

from arcpy import env
import os

vRutaResultado = "D:\\geodatos\\temp_capascorte\\"
vRutaResultado2 = "D:\\geodatos\\temp_capascorte\\shp\\"
try:

    env.workspace = "D:\\mapas\\Topografia\\shp"
    rows = arcpy.SearchCursor("malla_25000.shp")

    for row in rows:
        row = rows.next()
        nummapa = int(row.getValue("CLAVE"))
        print nummapa

        #wheresatz='"CLAVE"='+nummapa
        wheresatz=""" "CLAVE" = """ + nummapa
        print wheresatz

        out_feature_class = vRutaResultado2+"m25"+str(nummapa)+".shp"
        ##where_clause = '"CLASS" = \'4\''

        arcpy.Select_analysis("malla_25000.shp", out_feature_class, wheresatz)

        fcList = arcpy.ListFeatureClasses()
        for fc in fcList:
            if fc <> 'malla_25000.shp':
                print "cortanto capa: " + str(fc) + "......"
                nomfin = vRutaResultado+str(nummapa)+str(fc)
                print nomfin
                arcpy.Clip_analysis(fc,out_feature_class, nomfin)


    print "Ejecutado"

except:
    print "se ha detectado un error que impide ejecutar el script"
    print(arcpy.GetMessages(2))
Tags (2)
0 Kudos
2 Replies
AhmedEl-Sisi
Occasional Contributor III
try to convert it to string first
wheresatz=""" "CLAVE" = """ + + str(nummapa)
0 Kudos
AnikaMeyer
New Contributor
Perfect! Thank you very very much. Problem solved!
This is the correct where_clause:
wheresatz=""" "CLAVE" = """ + str(nummapa)
0 Kudos