Select to view content in your preferred language

gp.select_analysis(row,output) iternation,  possible or not?

724
4
11-24-2010 11:31 AM
JianLiu2
Emerging Contributor
how to iterate a function as:

rows=gp.SearchCursor(featureclass)
row=rows.Next()

while row:
gp.select_analysis(row,output)
row=rows.Next()

so that I would be able to select a feature record from row1 to row n in a featurecalss seperately. But clearly, "select_analysis" doesn't accept "row" as a leagal input... SO any alternatives?

I was thinking of SQL in {where clause}, but how to write the SQL codes (it seems SQL dosen't allow an iterating variable either, like {where i=range(1,100), "OBJECTID=i"} ?)

thanks indeed!!
0 Kudos
4 Replies
ChrisSnyder
Honored Contributor
Yes, all you need to use the OBJECTID value (BTW, not always called OBJECTID). For example:

myFC = r"C:\temp\test.shp"
oidFieldName = gp.describe(myFC).oidfieldname
searchRows = gp.searchcursor(myFC)
searchRow = searchRows.next()
while searchRow:
   oidFieldValue = searchRow.getvalue(oidFieldName)
   outputFC = r"C:\temp\output_" + str(oidFieldValue) + ".shp"
   gp.Select(myFC, outputFC, oidFieldName + " = " + str(oidFieldValue)
   searchRow = searchRows.next()
0 Kudos
JianLiu2
Emerging Contributor
thanks! try it right away!!:D
0 Kudos
JianLiu2
Emerging Contributor
it perfectly works, thanks!

I think my problem is the SQL sentence .., such as {OIDFieldName + "= " + str(OIDFieldValue)}.

I didn't know the expression: + " = " + ...

Any suggestions on manuals/references for SQL writing?

best

Jian
0 Kudos
ChrisSnyder
Honored Contributor
0 Kudos