Hexagon Geospatial
MENU

Spatial Modeler Tutorials

Learn more about our products, find answers, get the latest updates, and connect with other Hexagon Geospatial product users, or get support from our professional service team.
Showing results for 
Search instead for 
Do you mean 

Using Merge Features to dissolve boundaries between neighboring polygons

by Technical Evangelist ‎07-30-2018 01:35 PM - edited ‎07-31-2018 06:35 AM (428 Views)

Download model (and sample data)

 

Description:

 

Problem

 

As part of a Spatial Model I had performed image segmentation on a CIR airphoto to produce area geometry features. Those features had then been classified using Machine Learning into discrete classes (e.g. "forest", "wheat", etc) stored in an attribute field called Name (such as by using the techniques shown in this Spatial Recipe). Styling was applied using the unique occurrences of Name attributes to form the data displayed in the left-hand 2D View of the screenshot below.

 

The final problem was how to combine segments which touched, and which shared the same Name attribute value, to form larger, contiguous area geometries (the results being shown in the right-hand 2D View of the screenshot below).

 

Input shapefile of classified segments is shown in the left 2D View, results of running Merge_Features.gmdx on the right
Merge_Features_Results.png

 

Solution

 

This is possible using the Merge Features operator and knowledge of how to apply Functional Attributes

The screenshot below shows the basic Merge Features operator. The features to be merged would be fed into the FeaturesIn port.

 

Merge Features operator
Merge_Features_Operator.PNG

 

To perform the desired merge of area geometries the following parameters were set:

 

The Criteria port was double-clicked and the Merge Touching Geometries and Matching Attributes option selected. 

 

The MatchAttributeNames port was double-clicked and the Name field was selected.

 

 
Match_Attribute_Name.png

 

Leaving the rest of the Operator set to its defaults would result in all area geometries which touch and which share a common value for the Name attribute to be merged into features with a single area geometry each. However the resulting features would only contain the geometry attribute, not any of the other attribute information from the FeaturesIn data stream. Consequently we wouldn't know what class (Name) each merged area geometry represented.

 

This is where the SummaryAttributen ports come in. If at runtime the port has not been explicitly set, then it defaults to internally creating a functional attribute with a field name of "Geometry" and an expression of "MERGE(<geom>)" where <geom> represents the name of the primary geometry field of the input features. Hence FeaturesOut would contain the desired geometry attribute containing merged geometries, but no other attributes. We need to add more than a single functional attribute if we want additional attribute fields populated and passed to the FeaturesOut.

 

To do this, right click on the Merge Attributes operator and select the Add Port option (Merge Features is an expandable operator). This adds an additional port called SummaryAttribute2. More such ports can be added if additional attributes are desired on the FeatureOut by right-clicking and selecting Add Port again.

 

Merge_Features_Operator2.PNG

 

We need two SummaryAttributen ports because, once we define a functional attribute to carry across the Name attribute we need to explicitly tell the Operator to create the merged geometries. 

 

So the SummaryAttribute1 port was double-clicked and in the Functional Attribute dialog we defined an output field name of Geometry and an Expression as MERGE(FeaturesIn.Geometry). This functional attribute thus applies what otherwise would be the default behavior of merging.

 

Generating Geometry attribute using Functional Attributes
FA_Mege_Geometry.png

 

The SummaryAttribute2 port was double-clicked and in the Functional Attribute dialog we defined an output field name of Class and an Expression as FIRST(FeaturesIn.Name). Since we are merging multiple area polygons into single areas based on the common attribute value of the Name field it is acceptable to simply use the Name attribute value of the first area that was merged to assign to the output area Class field. 

 

Generating Class attribute using Functional Attributes
FA_First_Attribute.png

 

Then it's a simple case of feeding FeaturesOut to the subsequent steps of the Model. In this case going straight out to a Preview or a Features Output operator to create a shapefile.

 

Merge_Features.gmdx
Merge_Features_Model.PNG

 

Obviously you would embed this into your larger Spatial Model rather than just running it file to file.  

Courses
Contributors