Select to view content in your preferred language

Conditionally deleting records

3439
15
Jump to solution
04-02-2019 10:17 AM
PrestonEllison
Occasional Contributor

Im trying to come up with a way to conditionally delete some records in a table. For instance, i have variably shaped polygons that when spatially joined with a point feature class tend to result in excess points on the larger polygons. I would like to set up a definition query to select and eventually delete every other or even every 2 out of 3 rows IF (and only if) there are, say more than 10 occurrences of that record. Im trying to implement this in arcmap via a python/sql query. Im sure there is way to do this in the output file (.csv) but I would like to maintain the integrity of the data in arcmap prior to exporting it.

Any help on how to go about doing this?

0 Kudos
15 Replies
JoshuaBixby
MVP Esteemed Contributor

If you type the following after the code runs, what do you get:

print(oids)

I tested the code on some sample data on my machine before posting it, so I think the logic and code are sound.  Can you post either a subset and/or sanitized set of data here for me to test on?

0 Kudos
PrestonEllison
Occasional Contributor

Absolutely, whats the best route to get you a sample data set?

When i run the print, I get the following....

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Just looking at your screenshot, you left off the last line, the one that actually selects the records:

fl.setSelectionSet("NEW_SELECTION", oids)
PrestonEllison
Occasional Contributor

Yikes, how did i miss that.

It works! This is perfect. Im assuming i could change the frequency of the selection by adjusting line 6 "group size"

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Yes, the group_size variable sets how many photo points you want per Account_Nu, roughly.  If you only have 3 points and the group size is 6, it will just select all 3.  The trick that took a bit of thought was how to get staggered points along the photo traversing path.  Grabbing the first or last x number of photos is easy, but I figured you don't want just 4 photos at the start of the property if there are 50 photos along the perimeter of the property.

0 Kudos
PrestonEllison
Occasional Contributor

Exactly. The idea was to get a representative view of the entire property vs just a cluster of points from roughly the same location.The way this is set up is extremely helpful and i cant thank you enough.

cheers