How to test feature class for existence of records in a 2nd feature class

418
2
05-13-2014 08:39 PM
SC1
by
New Contributor II
I think this should have been easy, but I have spent all day racking my brains...

I have 2 feature classes (points). One comes in daily let's say. The other is a accumulation of all the dailies that come in.

I want to test if the daily FC has any records that are already present in the cumulative FC, and ignore those when appending or copying into the cumulative FC.

I have tried nesting cursors but that doesn't seem to work.... they both have a unique ID field, but at some stage I will want to add another condition that the ID and operator fields must be unique combined (the same ID can have more than one operator).

I am so lost.... any help appreciated.
Tags (2)
0 Kudos
2 Replies
SC1
by
New Contributor II
does something like this make sense?

for each record in table1
    if table1.record.field1.value somewhere in table2.field1 and table1.record.field2.value = table2.field2 (for that matching record)
        skip doing anything on this row
    else
        append table1.row to table2
0 Kudos
NeilAyres
MVP Alum
Are your test variables unique identifiers?
I would think that the logic should go something like this...
Open search cursors on both Fcs. Perhaps load the relevant data into 2 dictionaries or something.
Run Daily Fc against All Fc and do your test.
If you get a match, construct a list of identifiers in Daily Fc that do match (perhaps using the OID).
Then you need to switch this to the ones that don't match.
A technique I have used in the past (picked up from the very clever people on this forum) is to use sets.
Like :
IDsMissing = list(set(list of all IDs in Daily Fc).difference(set(list of found match IDs)))

This give you a list of the IDs which don't match.
Use this to make a feature layer using a select statement.
Copy this feature layer to a temp Fc.
Append this into All Fc.
Good luck,
Neil
0 Kudos