I am trying to compare the fields of 2 feature layers to each other. The fields, though, have different names. I think this image shows this a little better:
I am lost as to how this can be accomplished. I am trying to compare modified's FIELD2 to baseline's FIELD1, etc.
While I am sure that I will need arcpy.FieldMappings, I wrote these few lines:
baseline_copy_path = os.path.join(self.tempPath ,"baseline_copy.shp")
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(self.revisedFile)
fieldmappings.addTable(baseline_copy_path)
At this point, I am unsure how to proceed.
I am looking for help in finding example code doing this or somebody who might outline how to proceed. At the end of the comparison, I am looking to produce a DEFeatureClass
for each of these: new features in the modified file, deletions, overlapping features, changed attributes in modified fiel and finally, removed features. The changes I am looking for are in the geometries.
1 Answer 1
You should start with a simple Union. Just be aware of two details described on that page: 1) how ESRI renames fields when unioned feature classes share field names; 2) the FID_ fields that ESRI creates during a union and how to use them. With that knowledge, it's really simple to query out the various things you're looking for.
From your example above, here are some example queries:
To query spatial areas that were covered by baseline but not by modified:
FID_modified = -1
To query spatial areas that were added in modified but were not covered by baseline:
FID_baseline = -1
- To query areas where the value of FIELD1 (now renamed to FIELD2) has changed:
FIELD1 <> FIELD2
Note that examples one and two won't necessarily identify "deleted" or "added" features. For that, it's best to use Editor Tracking. Otherwise, you can't really determine whether something is the same feature or another feature with the same attributes in the same location. If that's okay with you, then something like:
FID_baseline <> -1
AND FID_modified <> -1
AND (FIELD1 <> FIELD2_1
OR FIELD2 <> FIELD3_1
OR FIELD3 <> FIELD1_1
OR FIELD4 <> FIELD6)
That would query features that have at least one altered value at that location.
Note that the benefit of Union over something like Spatial Join is that Union can pull out the portions of features that have changes--in the case that geometries have been changed.
EDIT: If you're using points/lines, please don't. Points, lines, and polygons don't exist in our 3-dimensional (spatially speaking) universe, and using points and lines results in misrepresentations of data that will come back to bite you. Polygons are also a tragic compromise, but the limitations of the available tools constrain much GIS work to 2-dimensions. However, if you are using points/lines, then you could use some convoluted chain of Intersect, Erase, and Append to yield a result that is comparable to Union.
-
What is going to happen if inputs are not polygons? Moreover it is not going to work for polygons either. -1 BTW for solution that has nothing to do with the question.FelixIP– FelixIP2016年10月11日 20:31:22 +00:00Commented Oct 11, 2016 at 20:31
-
@FelixIP, what do you mean has nothing to do with the question? The data model image includes no UID in either dataset. Read the last sentence in the OP's edit: he's looking for changes by geometry. I take this to mean that if an area was covered by a FIELD1 value of 4 and that area is now covered by a FIELD2_1 value of 4, then it has not changed. My answer would identify that. His sentence could be interpreted as he's looking for changes to the geometry of a given feature, but considering he apparently has no UID, that's impossible and I, therefore, assumed not what he's asking.Tom– Tom2016年10月11日 20:47:23 +00:00Commented Oct 11, 2016 at 20:47
-
You rephrase your answer, I remove my down vote. Union tool will no accept other geometries, but polygonsFelixIP– FelixIP2016年10月11日 22:55:46 +00:00Commented Oct 11, 2016 at 22:55
DEFeatureClass
for each of these: new features in the modified file, deletions, overlapping features, changed attributes in modified field and finally, removed features. The changes I am looking for are in the geometries."