Problem with select analysis + copy rows in loop

6648
31
Jump to solution
04-03-2015 07:49 AM
KONPETROV
Occasional Contributor III

Hi, i am trying to implement various combinations of tools trying to export some rows  from a pnt shapefile based on a query (or while or for loop).I have a column (Condition) with values TRUE and FALSE and i want to export every row for the statement,  Condition = "TRUE". However i only want those rows who respond to TRUE and if a FALSE follows i don't want to export nothing else, although after FALSE maybe there are more TRUE.

an example:

FID  Condition    H    Wo                                                  FID  Condition                                        H         Wo
0      TRUE         65    20                                                     0      TRUE                                              65        20
1      TRUE         54    25                                                     1      TRUE                                              54        25
2      TRUE         54     0      I want only these values  --->   2      TRUE   with the rest of the fields    54         0
3      FALSE       65    25                                                                             
4      TRUE         98     0
5      TRUE         23     5

These are the samples of code i tried, to export the rows based my statement :

import arcpy, os

fc = "c:/Task/data/In.shp"

outworkspace = "c:/Task/data/In.shp"

fields = ["FID", "Condition", "H", "Wo"]

with arcpy.da.UpdateCursor(fc, fields) as cursor:

     for row in cursor:

         while [row] = 'TRUE':

         arcpy.CopyRows_management("In", "c:/Task/data/Out.shp")

and also with select analysis:

import arcpy, os

from arcpy import env

env.workspace = "c:/Task/data/In.shp"

fc = "c:/Task/data/In.shp"

fields = ["FID", "Condition", "H", "Wo"]

with arcpy.da.UpdateCursor(fc, fields) as cursor:

     for row in cursor:

         while [row] = 'TRUE':

         arcpy.Select_analysis("In", "Out_s", '[Condition] = "TRUE"'))

But for some reason i always get an error.

0 Kudos
31 Replies
SepheFox
Frequent Contributor

Also a good point, Blake. Perhaps the ultimate solution is to post the "correct" answer as an edit at the bottom of your original question, mark as correct the person who gave the closest answer, and give a helpful to everyone who contributed. Poor Kon! He will feel like he can't do anything right!

JoshuaBixby
MVP Esteemed Contributor

I think we will have to agree to disagree on this one.  Unless an OP got little to no feedback and researched the answer himself/herself, taking functional code snippets from responses and repackaging them into a "final" answer seems like an easy way to abuse the point system.  Part of the learning process is reading the whole discussion and understanding what comment was the crux of the solution.  I really wish GeoNet's points and discussions were structured more like StackExchange/Overflow, but we have to make due with what we have before us.

0 Kudos