AnsweredAssumed Answered

Area of overlap between two polygons

Question asked by JConklin on Jan 26, 2012
Latest reply on Jan 30, 2012 by whe-esristaff
I am trying to calculate the area (square feet) of overlap (intersection) of polygons in two shapefiles.  Layer 1 has only one polygon.  Layer two has many and I know that all of them intersect with the polygon in layer 1.  I am trying to calculate the area of the overlap.  My code loops through every feature in layer 2 and intersects it with the polygon in Layer 1 using iTopologicalOperator6.IntersectEx.  The problem is that the area it calculates is zero for most of the features.  It only gets an area for some.  As I mentioned, in reality, all polygons intersect.  My code is attached.  I verified that the loop is getting all features, so it seems the function using the .intersectex method has a problem. 

Any help is appreciated.  Thanks.
Justin


Protected Overrides Sub OnClick()                  Try              Dim pMap As IMap = My.ArcMap.Document.FocusMap             Dim pFLIndex As IFeatureLayer = pMap.Layer(0)             Dim pFLSections As IFeatureLayer = pMap.Layer(1)              'get selected features from Sections             Dim pFeatSel As IFeatureSelection = pFLSections             Dim pSelFeats As ISelectionSet = pFeatSel.SelectionSet              'MsgBox(pSelFeats.Count)              'Get feature from Index Layer             Dim pIndexFeature As IFeature = Nothing             Dim pCursor As ICursor = pFLIndex.Search(Nothing, False)              pIndexFeature = pCursor.NextRow              'MsgBox(pBufFeature.OID & "  " & pIndexFeature.OID)              'Loop through features in Buffered sections and calculate overlap sq ft             Dim pCur As IFeatureCursor = Nothing              Dim pBufFeature As IFeature = Nothing             pSelFeats.Search(Nothing, False, pCur)              pBufFeature = pCur.NextFeature              Do Until pBufFeature Is Nothing                 Dim dblOverLap As Double = GetArea(pBufFeature, pIndexFeature) 'Calls function                  pBufFeature.Value(10) = dblOverLap                 pBufFeature.Store()                  pBufFeature = pCur.NextFeature             Loop              My.ArcMap.Document.ActiveView.Refresh()           Catch ex As Exception             MsgBox(ex.ToString & vbCr & vbCr & ex.Message)         End Try          My.ArcMap.Application.CurrentTool = Nothing      End Sub           Private Function GetArea(ByVal FeatureA As IFeature, ByVal FeatureB As IFeature) As Double          Dim SourceArea As IArea         Dim TargetArea As IArea         Dim TopoOp As ITopologicalOperator6         Dim IntersectArea As IArea          SourceArea = FeatureA.ShapeCopy 'FeatureA and FeatureB are the polygons to be checked for overlap         TargetArea = FeatureB.ShapeCopy          TopoOp = TargetArea          IntersectArea = TopoOp.IntersectEx(SourceArea, False, ESRI.ArcGIS.Geometry.esriGeometryDimension.esriGeometry2Dimension)         GetArea = IntersectArea.Area '/ SourceArea.Area) * 100 'returns the percentage of first polygon which overlaps second polygon          SourceArea = Nothing         TargetArea = Nothing         TopoOp = Nothing         IntersectArea = Nothing      End Function

Outcomes