Select to view content in your preferred language

How to merge (union) features using Python

8752
8
Jump to solution
05-03-2011 09:19 AM
by Anonymous User
Not applicable
Original User: Julie6

I'm trying to find the equivalent function as ArcObject's TopologicalOperator.Union in Python to merge 2 features into one. How to do this?

Thanks!

Julie
0 Kudos
1 Solution

Accepted Solutions
LoganPugh
Frequent Contributor
You could use either Dissolve_management or UnsplitLine_management to do this if creating intermediate/derived data is acceptable.

You could even use DeleteFeatures_management to delete the original two features and Append_management to append the dissolved feature back into the original feature class, though intermediate data would still be created.

View solution in original post

0 Kudos
8 Replies
LoganPugh
Frequent Contributor
What is the workflow for the operation? Are the features to be merged in the same feature class or different feature classes? Normally with geoprocessing you'd select (or create a feature layer from) the features to be merged and run a Union and then depending on the purpose, a Dissolve. Both of these steps create new feature classes instead of modifying the input feature class(es), which may or may not be desirable.

If you need to work at a finer grained level than that you, and you need to do it in Python, I believe you would have to either use ArcObjects in Python or manipulate the geometry directly at the coordinate level using a lot of math or a 3rd party Python module such as Shapely.
0 Kudos
by Anonymous User
Not applicable
Original User: csny490

Not sure if you simply want to "merge" the geometry (either the Merge or Append tools), or actually overlay geometry via an actual overlay operation (the Union tool, or perhaps Intersect? - depending on what you are trying to do).

For the union though, the syntax in Python would be something like:

arcpy.Union_analysis(input1FC + ";" + input2FC, outputFC, "ONLY_FID", "1 FEET", "GAPS")
0 Kudos
by Anonymous User
Not applicable
Original User: Julie6

I need to merge 2 streams in same feature class, not merging 2 feature classes. The step could be:
1. find the 2 streams that connect to each other (I know how to do this)
2. create a new feature using the geometry of the 2 stream by merging them together
3. delete the 2 streams.

Thanks.
0 Kudos
LoganPugh
Frequent Contributor
You could use either Dissolve_management or UnsplitLine_management to do this if creating intermediate/derived data is acceptable.

You could even use DeleteFeatures_management to delete the original two features and Append_management to append the dissolved feature back into the original feature class, though intermediate data would still be created.
0 Kudos
by Anonymous User
Not applicable
Original User: Julie6

Thanks, that is the tool I need.

But there is one problem, I don't want to Unsplit all the connect stream, only some that fall to a certain category. I thought I would be able to loop through the features and if I find the 2 streams that need to merge, I'll just merge the stream and delete the 2.

But both Dissolve and Unsplit are taking a feature layer, so do I have to export the streams that need to be merged to a separate layer, unsplit then insert them back?

Thanks.
0 Kudos
LoganPugh
Frequent Contributor
If they operate like most geoprocessing tools they should only operate on the selected features, but if not, Make Feature Layer should work. A feature layer is not a permanent copy of the data, just an snapshot or "view" of some subset of the original data. The Unsplit tool will create a new output feature class consisting of the dissolved features, however. You could then delete the features that were selected and append in the dissolved features.
0 Kudos
by Anonymous User
Not applicable
Original User: Julie6

I will give it a try. Thank you very much for the quick response.
0 Kudos
ChrisSnyder
Honored Contributor
You could probably also do this (merge two features into one) using an update cursor.
0 Kudos