3

I want to aggregate some polygons in edit session using ArcObjects and c# language. In other words, my purpose is to use methaheuristic algorithms for polygon aggregation. So, I want to aggregate some polygons, see the numerical results and if it is not good, don't save it, and aggregate some others. And, in order for that, I want to implement it using edit session.For that purpose, I have implemented "Merge" which is in the editor toolbar. The code that I have used for merging two features is as follows:

Private void MergeFeatures (IFeature mainFeature, IFeature subFeature)
{
ITopologicalOperator union=mainFeature.Shape as ITopologicalOperator;
mainFeature.Shape=union.Union (subFeature.Shape);
mainFeature.Store();
}

But my problem is that it does not bring the polygons together. In other words, it just changes the attribute table of the feature class. The screenshot of part of my data is as follows:

enter image description here

5
  • Are the polygons you want to "merge" actually adjacent and share boundaries? Suggest you amend you question with some images to show what you have and want.
    – Hornbydd
    Nov 7, 2017 at 21:26
  • @whyzar, I have edited my post for more explanation.
    – parastoo
    Nov 8, 2017 at 6:36
  • @Hornbydd, actually some of my polygons overlap each other and some of them doesn't share any boundaries. But my goal is to aggregate polygons that has intersect. I have inserted a screenshot of part of my data in my post.
    – parastoo
    Nov 8, 2017 at 6:36
  • OK this is getting better, what do you mean by "...it just changes the attribute table of the feature class". Changes what? Can you show us a before union operation and after? Also in your image you show 3 polygons (1 overlapping another) is these that you are attempting merge into a single polygon?
    – Hornbydd
    Nov 8, 2017 at 12:54
  • @Hornbydd, In my image, there are three polygons that I certainly want to aggregate those two that have intersect each other. However, I am not sure if I should aggregate the third one with these polygons or not. Because the objective function of my methaheuristic algorithm should determine it. I mean that, I want my program sequentially aggregate two polygons, calculate one objective function, if the results became better, accept it, if not, doesn't save it and go to the next two polygons. And about the attribute table, I mean that when using union, just two records changes to one record.
    – parastoo
    Nov 9, 2017 at 12:40

1 Answer 1

1

I have found calling Simplify() can resolve unexpected results from various geometry operations.

private IGeometry unionPolygons(IPolygon4 p1, IPolygon4 p2)
{
//simplify the inputs
(p1 as ITopologicalOperator3).IsKnownSimple_2 = false;
(p1 as ITopologicalOperator3).Simplify();

(p2 as ITopologicalOperator3).IsKnownSimple_2 = false;
(p2 as ITopologicalOperator3).Simplify();

//union
IGeometry result = (p1 as ITopologicalOperator3).Union(p2);

//simplify the output
(result as ITopologicalOperator3).IsKnownSimple_2 = false;
(result as ITopologicalOperator3).Simplify();

return result;
}

Alternatively, you can use IBufferConstruction to union geometries (just pass 0 for the buffer if you only want to union):

    private IGeometry unionAndBuffer(IEnumGeometry inputGeometries, double bufferSize)
            {
                IBufferConstruction bufferConstructor = new BufferConstructionClass();
                IBufferConstructionProperties2 bufferOptions = bufferConstructor as IBufferConstructionProperties2;

                bufferOptions.EndOption = esriBufferConstructionEndEnum.esriBufferFlat;
                bufferOptions.ExplodeBuffers = false;
                bufferOptions.GenerateCurves = false;
                bufferOptions.OutsideOnly = false;
                bufferOptions.SideOption = esriBufferConstructionSideEnum.esriBufferFull;
//this does the union and ensures a single geometry in the result
                bufferOptions.UnionOverlappingBuffers = true; 
                bufferOptions.UseGeodesicBuffering = false;

                IGeometryCollection outputBuffers = new GeometryBagClass() as IGeometryCollection;

                bufferConstructor.ConstructBuffers(inputGeometries, bufferSize, outputBuffers);

                if (outputBuffers.GeometryCount <= 0)
                    return null;

                IGeometry g = outputBuffers.get_Geometry(0);
                return g;
            }

It can take some experimentation to get the result you want.

3
  • Thanks for your help, but this code doesn't implement what I want. I want my program sequentially aggregate two polygons, calculate a measure, if the results became better, accept it, if not, doesn't save it (stop editing) and go to the next two polygons (again start editing).
    – parastoo
    Nov 9, 2017 at 12:47
  • What exactly do you mean by "aggregate"? What "measure" do you want to calculate? How do you determine if a result is "better"?
    – nef001
    Nov 10, 2017 at 13:07
  • by "aggregate" I mean that two features that are within a distance with each other, change into one feature, both in the attribute table and visually in the ArcMap. About the "measure", it is the difference of the area of the features before and after aggregation. If it is below a threshold, it is acceptable. Actually, there is a toolbox in the ArcToolBox of ArcGIS for Cartography purpose that "Aggregate Polygons" is one of its constituents. But the problem is that I want to implement it under edit session to be able to undo it.
    – parastoo
    Nov 11, 2017 at 16:21

Your Answer

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

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