ConstructUnion method some time returning an empty geometry

549
3
06-07-2010 11:07 AM
ShenglinXu
New Contributor
I found ConstructUnion method some time returning an empty geometry even all the geometries added are not empty.
Could you help to find out why? Is it a known issue?


// Sample code
IGeometry pGeomBag = null;
IGeometryCollection geometryCollection = null;

pGeomBag = new GeometryBagClass();
                                    
pGeomBag.SpatialReference = objFeature.ShapeCopy.SpatialReference;
geometryCollection = (IGeometryCollection)pGeomBag;

//buffer each selected roads and add to geometryCollection

geometryCollection.AddGeometry(objBufferResult, ref missing, ref missing);

//Do construct union

IPolygon polygon = new PolygonClass();
ITopologicalOperator2 objTopo = polygon as ITopologicalOperator2;
if (objTopo != null)
{
objTopo.ConstructUnion((IEnumGeometry)pGeomBag);
        objTopo.IsKnownSimple_2 = false;
        objTopo.Simplify();

IGeometry objExclusion = new PolygonClass();               
         objExclusion = (IGeometry)objTopo;
}
0 Kudos
3 Replies
PascalVezina
Occasional Contributor II
Good day,

I am having the same issue with ConstructUnion. In my code, I try 10 times, if one of them works then I'm OK, if not I use the long "union" method instead.

Regards,

P.Vezina
0 Kudos
PascalVezina
Occasional Contributor II
After consulting with ESRI support, it was found that limiting to 100 geometries for the ConstructUnion works.  So, process by batch of 100 geometries and you'll be fine.

Regards,

P.Vezina
0 Kudos
AndreaFlesca
New Contributor
Same problem: ConstructUnion doesn't work.
I'm developing with ArcGIs Engine SDK 10.1  for C++/Qt and I'm on Linux.
Here is my code:



    IGeometryBagPtr cGeometryBag(CLSID_GeometryBag);
    IGeometryCollectionPtr cGeometryCollection = cGeometryBag; // QI
    IGeometryPtr * cGeomVector = new IGeometryPtr[len];
    for (i = 0; i < len; i++)
    {
        IPointCollectionPtr cPointCollection(CLSID_Polygon);
        // I fill the cPointCollection object with my polygones (triangles)
        IPolygonPtr cPolygon = cPointCollection; // QI
        cGeomVector = cPolygon;
    }
    hr = cGeometryCollection -> AddGeometries((long)len, (IGeometry**)cGeomVector);
    if (FAILED(hr))
    {
        cout << "Impossible to add geometries" << std::endl;
        return;
    }
    long cGeomCount;
    hr = cGeometryCollection -> get_GeometryCount(&cGeomCount);
    if (FAILED(hr))
    {
        cout << "Impossible to calculate the number of geometries (1)" << std::endl;
        return;
    }
    cout << "Number of geometries (1): " << cGeomCount << std::endl;
    // in this dump I see that the number of geometries (in the GeometryCollection) is OK

    IEnumGeometryPtr cEnumGeometry = cGeometryBag; // QI
    hr = cEnumGeometry -> get_Count(&cGeomCount);
    if (FAILED(hr))
    {
        cout << "Impossible to calculate the number of geometries (2)" << std::endl;
        return;
    }
    cout << "Number of geometries (2): " << cGeomCount << std::endl;
    // in this dump I see that the number of geometries (in the EnumGeometry) is OK

    IPolygonPtr cResultPolygon(CLSID_Polygon);
    ITopologicalOperator2Ptr cTopoOp = cResultPolygon;
    hr = cTopoOp -> ConstructUnion(cEnumGeometry);
    if (FAILED(hr))
    {
        cout << "Impossible to do ConstructUnion" << std::endl;
        return;
    }
    IPointCollectionPtr cFinalPointCollection = cResultPolygon; // QI

    hr = cFinalPointCollection -> get_PointCount(&cGeomCount);
    if (FAILED(hr))
    {
        cout << "Impossible to calculate the number of points (3)" << std::endl;
        return;
    }
    cout << "Number of points (3): " << cGeomCount << std::endl;
    // In this dump the number (of points of the new geometry) is not OK, is always zero!

    


Where do I go wrong?
Are there examples in C++ to refer to?
The result remains the same (negative) if I change the line:
IPointCollectionPtr cFinalPointCollection = cResultPolygon; // QI

with:
IPointCollectionPtr cFinalPointCollection = cTopoOp; // QI


Any help would be appreciated.
Cheers from Italy.
0 Kudos