0

I have Point Of Interest (POI) data for two different years. I wrote code to get two feature classes where each contains the POIs that differ (spatially) from the other release. I make mostly use of the arcpy.SelectLayerByLocation_management.

# Get intersection from the "new side"
arcpy.SelectLayerByLocation_management(new_layer, "ARE_IDENTICAL_TO", old_layer, "", "NEW_SELECTION")
# This selection contains NEW WITHOUT OLD
arcpy.SelectLayerByLocation_management(new_layer, "", "", "", "SWITCH_SELECTION")
# NEW WITHOUT OLD feature layer output
arcpy.CopyFeatures_management(new_layer, new_diffs)
# Get intersection
# First switch the selection from the previous layer again
arcpy.SelectLayerByLocation_management(new_layer, "", "", "", "SWITCH_SELECTION")
# Then proceed as above
# Get intersection from the "old side"
arcpy.SelectLayerByLocation_management(old_layer, "ARE_IDENTICAL_TO", new_layer, "", "NEW_SELECTION")
# This selection contains OLD WITHOUT NEW
arcpy.SelectLayerByLocation_management(old_layer, "", "", "", "SWITCH_SELECTION")
# OLD WITHOUT NEW feature layer output
arcpy.CopyFeatures_management(old_layer, old_diffs)

It works ok, but I don't got the cases where the POI location may have changed a tiny bit (maybe to a more accurate position) but the POI itself is the same. I would NOT want to have these included in the output, or in other words, I would not classify them as a real difference. So I additionally might want to compare with something like a arcpy.Buffer_analysis and check for additional POI's names if they are equal to the one which differs spatially.

Is there an easy way to integrate this functionality into my code?

The unique IDs for the POIs change from release to release, so they are not 100% identifiable throughout different releases (yes, really, I also couldn't believe it). But it should be enough for me to just check for equal names.

EDIT:
I drew a picture to make it a Little bit more clear what I want to get.
enter image description here

0

2 Answers 2

1

Please try adding the following codes after your original code;

# Analyse near featues using the Near_analysis tool
arcpy.Near_analysis(old_diffs, new_layer, "5 METER") # assuming your tolorance is 5 Meter

# Now Attribute join the new_layer attributes to the old_diffs 
arcpy.JoinField_management(old_diffs, "NEAR_FID", new_layer, "OID", "")

# Now you can delete the duplicated feature using query
uc = arcpy.da.UpdateCursor("old_diff", ["nam", "nam_1"])
for row in sc:
    if str(row[0]) == str(row[1]):
        sc.deleteRow()
del row
del uc

# finally Merge old_diff with new_layer in order to include odd features
arcpy.Merge_management([old_diff, new_layer], "final_data")
1
  • This Near_analysis function is nice, but I don't have an ArcInfo license, how can you rewrite this within ArcView?
    – Flugmango
    Commented Jul 11, 2017 at 7:12
0

It is a bit difficult for me to get a solution without actual data. If I understood your question correctly, following might help;

# Get intersection from the "new side"
arcpy.SelectLayerByLocation_management(new_layer, "ARE_IDENTICAL_TO", old_layer, "", "NEW_SELECTION")
# This selection contains NEW WITHOUT OLD
arcpy.SelectLayerByLocation_management(new_layer, "", "", "", "SWITCH_SELECTION")
# NEW WITHOUT OLD feature layer output
arcpy.CopyFeatures_management(new_layer, new_diffs)
# Get intersection
# First switch the selection from the previous layer again
arcpy.SelectLayerByLocation_management(new_layer, "", "", "", "SWITCH_SELECTION")
# Then proceed as above
# Get intersection from the "old side"
arcpy.SelectLayerByLocation_management(old_layer, "ARE_IDENTICAL_TO", new_layer, "", "NEW_SELECTION")
# This selection contains OLD WITHOUT NEW
arcpy.SelectLayerByLocation_management(old_layer, "", "", "", "SWITCH_SELECTION")
# OLD WITHOUT NEW feature layer output
old_diffs = arcpy.CopyFeatures_management(old_layer, old_diffs)

# Creating a list of the old POI names
old_names = []; 
sc = arcpy.da.SearchCursor(old_layer, "name_field", "*")

# Storing old names in the list "old_names"
for row in sc:
    old_names.append(row[0])
del row
del sc

# Now query names in "old_diffs" dataset
uc = arcpy.da.UpdateCursor(old_diffs, "name_field", "*")
for row in uc:
    if (row[0] in old_names):   # checks if the POI name is in the old_names
        uc.deleteRow()          # delets the feature class if the name matches
del row
del uc

# Save the updated data to new dataset
arcpy.CopyFeatures_management(old_diffs, final_data)
2
  • 1
    This deletes every POI which has the same name, no matter where it is located. I only want to delete POIs with the same name, if they are very close (e.g. 5 meter) to the one with the same name, because it is very likely then that it is a duplicate POI.
    – Flugmango
    Commented Jul 10, 2017 at 12:03
  • I came up with the following workaround. Some field names might need to be changed according to the dataset. Hope that helps,
    – GeoDev
    Commented Jul 10, 2017 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.