ConstructUnion runs out of memory

473
2
06-12-2013 06:46 AM
JosephArmbruster
New Contributor III
I create a geometry bag and added 40k or so polygon features into it using the geometry collection interface.  All-together, adding geometries brings my memory stamp up to roughly 520MB or so.  After this, I create an empty polygon and use the topological operator to ConstructUnion against this geometry bag.  This operation spins for 20 seconds or so, then the memory stamp increases without bound, crashing my process.

I originally modified my code to use ConstructUnion instead of multiple Unions, since I saw a noticable performance increase.  Unfortunately, it looks like construct union has some type of sporaddic memory leak.

Questions and comments welcome!
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Joseph,

I've never had any problems with the ConstructUnion method. So after reading your thread I knocked together the following VBA code to test it. I was able to run it without error on 40K and 60K polygons.

This suggests to me that it may be an issue with your input data? Have you run it through the check geometry tool first to see if there are any offending polygons?

Public Sub Test()
    ' Get layer
   Dim pMXDocument As IMxDocument
    Set pMXDocument = ThisDocument
    Dim pMap As IMap
    Set pMap = pMXDocument.FocusMap
    Dim pLayer As ILayer
    Set pLayer = pMap.Layer(0)
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pLayer
    
    ' Get the 40,000 selected polygons
   Dim pFeatureSelection As IFeatureSelection
    Set pFeatureSelection = pFeatureLayer
    Dim pSelectionSet As ISelectionSet
    Set pSelectionSet = pFeatureSelection.SelectionSet
    Debug.Print pSelectionSet.Count
    
    ' Create cursor over selection
   Dim pCursor As ICursor
    pSelectionSet.Search Nothing, False, pCursor
    Dim pRow As IRow
    Set pRow = pCursor.NextRow
    Dim pPolygon As IPolygon
    Dim pGeometryBag As IGeometryBag
    Set pGeometryBag = New GeometryBag
    Dim pSpatialReference As ISpatialReference
    Dim pGeoDataset As IGeoDataset
    Set pGeoDataset = pFeatureLayer.FeatureClass
    Set pSpatialReference = pGeoDataset.SpatialReference
    Set pGeometryBag.SpatialReference = pSpatialReference
    Dim pGeometryCollection As IGeometryCollection
    Set pGeometryCollection = pGeometryBag
    
    ' Add polygons to bag
   Debug.Print "Adding to geometry bag"
    Do While Not pRow Is Nothing
        Set pPolygon = pRow.Value(pRow.Fields.FindField("Shape"))
        pGeometryCollection.AddGeometry pPolygon
        Set pRow = pCursor.NextRow
    Loop
    Debug.Print "done looping"
    
   ' Do the union
   Dim pTopoOp As ITopologicalOperator
    Set pTopoOp = New Polygon
    Dim pEnumGeometry As IEnumGeometry
    Set pEnumGeometry = pGeometryBag
    Debug.Print CStr(pEnumGeometry.Count) & " in bag"
    pEnumGeometry.Reset
    pTopoOp.ConstructUnion pEnumGeometry
    Debug.Print "Got here with out error!"
End Sub


I'm using ArcGIS 10.1, Windows 7, 4GB Ram.

Duncan
0 Kudos
JosephArmbruster
New Contributor III
No issues reported by Check Geometry.

Note: I am running on Arc10.1 sp1, windows 7.
0 Kudos