This project is read-only.

Merge Polygons (Unite, Join etc...)

Feb 21, 2011 at 4:34 AM
Edited Feb 21, 2011 at 4:40 AM

Not sure if this is a bug, I might use it incorrectly. So opened the case in discussion section not in the Issue Tracker.

There are a few classes with the similar implementations. One of the examples: “ClipPolygon” or “MergePolygon”, “BufferPolygon”

MapWinGIS.Utils.ClipPolygon ; MapWinGIS.Utils.MergeShapes ;  MapWinGeoProc.SpatialOperations. ClipShapesWithPolygon ; MapWinGeoProc.SpatialOperations. MergeShapes ; MapWinGIS.Shape.Clip

Etc… Similar procedures are accessible using MapWinGis.Utils class , some of them through  MapWinGeoProc. dll.


I Tried to merge (join) shapes using following code: MapWinGeoProc.SpatialOperations.MergeShapes

But once the function is called I get the error: “COM object that has been separated from its underlying RCW cannot be used”.

Tried to use another procedure found which was “BufferPolygonSF”, but got the following error: “External component has thrown an exception. “

Looks like I placed and registered all required dll, just wondering what might case the problem. What classes are obsolete, what are new, which functionality is working better, in what cases is more efficient to use what procedure?


All I need to do is to join some shapes together within the same shape file. Just merge shapes, or join  them only if they have the same value in the attribute table. Just wondering is there e some efficient way of doing this. or may be somebody come across with this algorithm, so I could implement this?

Thanks for help

Feb 21, 2011 at 6:35 PM


I 'd start from Utils.ClipPolygon (UNION_OPERATION).  Have you tried it? (geos_c.dll is needed)

Also you can post the sample which produce "External component has thrown an exception" error. I'll check whether it is a fault of MapWinGIS.



Feb 22, 2011 at 1:55 AM


You was right I missed geos_c.dll file. Now it is working, and thank you for the advice, not all of existing implementations are working as fast and as good as following code:

MapWinGIS.Utils u = new Utils();
u.ClipPolygon(PolygonOperation.UNION_OPERATION, shp, nextshp);

My input file contains about 10000 squares, and the output shape was correct and also it contained correct holes.

So far I tested two more similar implementations, first one:

MapWinGeoProc.SpatialOperations.MergeShapes(ref shp, ref nextshp, out tmpshp);

This time it took 39mins, the outline shape was correct, but this algorithm skips holes!

Another one was following:

MapWinGIS.Shape nextshp = inputSF.get_Shape(nextShpID);
shp.Clip(nextshp, tkClipOperation.clUnion);

 Not as bad as previous case, the result outline shape was correct and I saw correct holes in polygons, but it took 7.15mins.

So, the very first implementation is the best one.

Just wonderring if there is a quite good code, why there is a need to keep all implementations?

Actually there are few more similar functions like this: Dissolve, MapWinGeoProc.SpatialOperations.BufferPolygonSF.

Would you recommend to try something else?

I couldn’t attached file to this post, so I sent you the shapefile examples with source code by mail.