I am using ArcGIS Pro, and I have 2 feature layers of polygon type that have a couple similar fields. One layer has the right shape geometry, but the other layer has the right information. How do I replace the geometry of all the fields that have the right information with that of the right geometry. The Replace Geometry and Transfer attributes functions work for one shape at a time. I have thousands to work with, so help me out please.
Solved! Go to Solution.
There's a method to do this with python and UpdateCursor, since you can read/write the special SHAPE@ geometry 'field' like you would for other attribute fields.
You will need a unique ID or other value to positively match features from one feature class to the other to transfer the SHAPE. Do you have a such an attribute in each feature class?
The python workflow would be something like this:
import arcpy
# Define the paths to your feature classes
source_fc = "path_to_source_feature_class"
target_fc = "path_to_target_feature_class"
# Define the fields
unique_id_field = "your_unique_id_field" # This is the common unique ID field
geometry_field = "SHAPE@" # For accessing geometries
# Create a dictionary from the source feature class
geometry_dict = {}
# Use a SearchCursor to populate the dictionary with geometries from the source_fc
with arcpy.da.SearchCursor(source_fc, [unique_id_field, geometry_field]) as search_cursor:
for row in search_cursor:
unique_id = row[0]
geometry = row[1]
geometry_dict[unique_id] = geometry
# Use an UpdateCursor to update the geometries in the target_fc
with arcpy.da.UpdateCursor(target_fc, [unique_id_field, geometry_field]) as update_cursor:
for row in update_cursor:
unique_id = row[0]
if unique_id in geometry_dict:
# Update the geometry in the target_fc if the unique ID matches
row[1] = geometry_dict[unique_id]
update_cursor.updateRow(row)
There's a method to do this with python and UpdateCursor, since you can read/write the special SHAPE@ geometry 'field' like you would for other attribute fields.
You will need a unique ID or other value to positively match features from one feature class to the other to transfer the SHAPE. Do you have a such an attribute in each feature class?
The python workflow would be something like this:
import arcpy
# Define the paths to your feature classes
source_fc = "path_to_source_feature_class"
target_fc = "path_to_target_feature_class"
# Define the fields
unique_id_field = "your_unique_id_field" # This is the common unique ID field
geometry_field = "SHAPE@" # For accessing geometries
# Create a dictionary from the source feature class
geometry_dict = {}
# Use a SearchCursor to populate the dictionary with geometries from the source_fc
with arcpy.da.SearchCursor(source_fc, [unique_id_field, geometry_field]) as search_cursor:
for row in search_cursor:
unique_id = row[0]
geometry = row[1]
geometry_dict[unique_id] = geometry
# Use an UpdateCursor to update the geometries in the target_fc
with arcpy.da.UpdateCursor(target_fc, [unique_id_field, geometry_field]) as update_cursor:
for row in update_cursor:
unique_id = row[0]
if unique_id in geometry_dict:
# Update the geometry in the target_fc if the unique ID matches
row[1] = geometry_dict[unique_id]
update_cursor.updateRow(row)
This worked, thank you!
Do you have a unique key between the two layers? Perhaps you could do a join by attribute between the two layers and transfer your attributes that way? Once you've done the join, you'd just use the calculate field tool to transfer the attributes. I don't think you'll be able to transfer the geometry that way though, so you'd need to transfer the attributes over to the layer that has the correct geometry.