I have two layer (A, B). I need copy polygon from layer A and replace polygon in layer B, but only geometry. I want to preserve original attribute table from layer A.

  • I am confused. Are you wanting to copy geometry or attributes from A to B? What will be the difference between A and B? – Barbarossa Nov 25 '13 at 16:57
  • I am trying to copy a geometry from one table and paste it to another but it says insufficient permission. I only want to do it for only one mining application. I don't want to digitise the entire area because it will take – mbuyi Dec 8 '17 at 8:26

I would consider using the arcpy.da.UpdateCursor and SHAPE@ token for representing the geometry object. First, you have iterate through the rows to find if the value in some unique ID field matches, and if yes > replace the source geometry with the target one.

  • Alex I am trying to perform the operation your describe using arcpy.da.UpdateCursor and SHAPE@, but with being new to python I can't get it to work. Could you show me an example code for this with "SITE_ID" as the matching field? – Homrich24 Dec 15 '16 at 1:46
  • @Homrich24, sure! Please post a new question and me or some other person will provide an answer. – Alex Tereshenkov Dec 15 '16 at 7:20

If you are only dealing with a few polygons, I would use the Replace Geometry tool on the Advanced Editing toolbar. See http://resources.arcgis.com/en/help/main/10.1/index.html#//01m80000001s000000

Alternately for a few polygons you could copy and paste the polygon(s) into layer B and then use the attribute transfer tool on the Spatial Adjustment toolbar to copy the attributes into the copied polygon; then delete the poly to be replaced.

But if you want to do this for all or many polygons and you have ArcInfo/Advanced, you could convert the affected layer B polygons to points inside the shape (and then later delete these polygons), convert the matching layer A polygons to lines, and then build polygons using the points as attributes. Check to make sure no point on the edge of one shape in B is not in the matching A. Add these new polygons to layer B. Use copies in case of mistake. My guess is Alex's answer is the most elegant, however.

  • You can speed up the manual process outlined here by using the Replace Geometry tool to draw a very simple rectangle around the new geometry without tracing every single one of its vertices. Then select the new geometry, hit the editor menu, go down to clip, then choose to preserve the area that intersects. Then you get all of the new geometry and preserve the attributes. – ndthl May 11 '15 at 9:07
  • This answer/tool worked great for me: I had a copy of the original polygon layer, which I made close to 300 polygon modifications (changing both attributes and polygon boundaries as well). Then I had to update my original layer (containing like 36.000 polygons), with the changes made in the copied layer. I used Replace Geometry and it did the job in a great/seamless manner. Good advice. Thanks! – Delonix R. Jun 14 '17 at 16:03

As already mentioned you can use the da.UpdateCursor to update geometries. The geometries from A is stored in a Dictionary using the da.SearchCursor. The Dictionary is then used in the UpdateCursor to replace geometries where IDs match:

import arcpy

#Change to match your data:
arcpy.env.workspace = r'C:\database.gdb'
A = 'featureclass1'
idfieldA = 'ID123'
B = 'featureclass2'
idfieldB = 'ID456'

#Build a dictionary with IDs as keys and geometries as value
geometries = {key:value for (key,value) in arcpy.da.SearchCursor(A, [idfieldA, 'SHAPE@'])}

#Empty list to store ids in B not found in A
notfound = []

#Update B with geometries from A where ID:s match
with arcpy.da.UpdateCursor(B, [idfieldB, 'SHAPE@']) as cursor:
    for row in cursor:
            row[1] = geometries[row[0]]

print 'Found no id match and could not update geometry for IDs: ', notfound

As stated there is the Replace Geometry Tool. You can also use copy/paste and another doc about copy/paste between databases. If you are comfortable with programing, the arcpy.da.search and update cursor can also do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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