I´m trying to make a tool that would be able to compare 2 layers of any type (polygon, point, polyline) and find differences between them. Lets say i have a layer of roads (Polyline) from 2005 (layer X) and from 2015 (layer Y). This tool would check those layers and mark the roads missing in layer X (field Change = 1), roads missing in layer Y (field Change = -1) and the roads without change (field Change = 0). Note that matching objects between those layers by IDs might be uncorrect, I decided to make their own unique key.
So far I have a field named Geo_IDx and y (for both layers), that holds geometry token "SHAPE@JSON", created by arcpy.UpdateCursor:
cursor2 = arcpy.da.UpdateCursor(Input2, [fieldnames2, "SHAPE@JSON", "Geo_IDx"])
Here comes the first issue: the string saved in "Geo_IDx" field is very long (currently set for 5000 signs, because I don't want to lose part of the geometry information).
- Do you have any advice about how to make some better unique key for the comparison?
Another problem is that this comparison takes very long time for layers with big amount of objects stored in them.
Then I Merge the layers to have all those values in 1 layer, that holds the field "Change". After this I am comparing the "Geo_ID" fields from both layers, provided that if value from layer X matches with any value in layer Y, there was no change in that object. If the value is missing in either of those layers, something has changed, so by cursors I find in which layer the value is missing and update the Change value as mentioned above.
Following script shows the way I´m trying to update the "Change" field. geo1 and geo2 are lists of all values from Geo_IDx => geo1 and Geo_IDy => geo2.
cursor3 = arcpy.da.UpdateCursor(Output,[f_names_merge, "Geo_IDx", "Geo_IDy", "Change"]) for row in cursor3: if row: if row in geo2: row = -1 elif row in geo1: row = 1 else: row = 0 cursor3.updateRow(row)
What I think the script is failing on is comparing the geometry strings, that are saved in Geo_ID fields. I dont have any idea why.
- Do you have any better idea of unique key for every object?
- Is there any easier way to do this? (provided I´m using ArcEditor license).
- Is it possible to compare the values of "SHAPE@JSON"?
I do not have access to FME.