I have two vector layer files, 'hausnummer_cropped5' and 'gebaudepoints_cropped5 - Kopie2'. Both have a point geometry and I am trying to shift the locations of the gebaudepoints_cropped5 points onto the corresponding hausnummer_cropped5 points (there is a one-to-one correlation between them) if certain conditions are met (their original locations are slightly different). There are 68 gebaudepoints and 62 hausnummers.
The code I have written is this:
import arcpy gebaudepoints_no = 68 hausnummer_no = 62 count = 0 with arcpy.da.UpdateCursor('hausnummer_cropped5', ['HAUSNR','STRASSE','SHAPE@XY']) as cursor1: for row1 in cursor1: with arcpy.da.UpdateCursor('gebaudepoints_cropped5 - Kopie2', ['ZA3', 'ZA2','GN5','SHAPE@XY']) as cursor2: for row2 in cursor2: if (row2 == row1) and (row2 == row1): # and (row2 > 0): X = row1 Y = row1 count += 1 cursor2.updateRow([row2, row2, row2, [(X),(Y)]]) #cursor2.deleteRow() print count, gebaudepoints_no - count
There are 2 things I don't understand:
After the code has been run, the value of 'count' is 92 and not 68. That means the loop has run 92 times even though it should have run only 68 times.
Most of the gebaudepoints actually get placed on top of the hausnummer points, but around 5 to 6 don't, even though they meet the required conditions. However, if I use the cursor2.deleteRow() statement (which is written as a comment above), all the gebaudepoints get removed so that indicates that the code is actually going through those points as well, but it's just not shifting them.
I didn't have these two problems when I was using a different set of gebaudepoints and hausnummers so I'm wondering why this is occurring in this case.
I am using ArcGis 10.2.2