1

I would like to create a custom merge tool that merges 2 polygons within 1 feature class together. I want to have a tool that merges 2 polygons and adds up a specific attribute. Is there any way to use the existing Merge tool in the editor toolbar and add custom code to it or have another way of merging 2 polygons together in the arcpy environment. enter image description here

Working with ArcGIS 10.2.1 and Python 2.7

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 20, 2016 at 21:55
6
  • You should be able to create a Python Addin to merge your polygons. Will you delete the input Polygons after the merge? Commented Apr 20, 2016 at 22:04
  • Can you please explain how? What tool (arcpy or other) would I use? Commented Apr 20, 2016 at 22:06
  • Here is a tutorial, to create an Addin. desktop.arcgis.com/en/arcmap/10.3/guide-books/python-addins/…. Esri has good documentation. Commented Apr 20, 2016 at 22:09
  • Thanks, I have created several addin's in the past, and am familiar with the process. I just don't know how to, within arcpy, merge 2 features in 1 feature class together. The Merge tool in ArcToolbox is designed for 2 feature classes, not 2 features. Thanks Commented Apr 20, 2016 at 22:18
  • You could run any geoprocessing tool such as Dissolve or Merge to an in-memory FC, then append the original FC. There are different options with Merge, Dissolve to Sum a field. Commented Apr 20, 2016 at 22:31

1 Answer 1

1

You can do this by working with the arcpy.Geometry objects. It is very easy to merge polygons once they are selected. As @klewis suggested, you could use an Add-In to select some geometries (draw a box to get an extent object, turn extent object into polygon, then select layer by location intersection of box).

Then to merge all the parts into one, just do something like this:

>>> mxd = arcpy.mapping.MapDocument('current')
>>> sr = arcpy.SpatialRefrence(mxd.activeDataFrame.spatialReference)
>>> array = arcpy.Array()
>>> with arcpy.da.SearchCursor("canb_bound", ['SHAPE@']) as rows:
... for r in rows:
... for part in r[0]:
... # add each part of each selected polygon to array
... array.append(part)
... 
>>> poly = arcpy.Polygon(array, sr) # this is what you want, do whatever with it
>>> arcpy.management.CopyFeatures(poly, r'in_memory\multipart_poly_merge') 
answered Apr 20, 2016 at 22:32
3
  • You might want to add the other field you want stats for, then append those values to a list to perform whatever statistics on those values. Commented Apr 20, 2016 at 22:38
  • Yep, that wouldn't be hard to work in, the above is just demonstrating a simple geometry merge. If the user is just adding some values, at each iteration in the top loop (not the parts), they could append the values to a list and run a sum(). Commented Apr 20, 2016 at 22:42
  • Thanks for your code, good idea of perhaps how to start. I only mentioned the Editor>Merge tool, because this would allow the user to select which polygons attributes we would want to maintain. I am not sure if there is a way to harness this code/tool, and use parts of it within the custom merge tool? Commented Apr 20, 2016 at 22:44

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.