Select to view content in your preferred language

Calculate geometry

921
1
12-15-2010 06:13 AM
USFS_AGOLAdministrator
Deactivated User
Hello all,

I have written code to intersect two polygon layers, and then calculate the acres of the resulting intersected layer.  To verify that my tool is giving accurate info, I've run the same process using ArcToolbox intersect, and then right click the resulting layer's field name, and choosing "Calculate Geometry" to get the acres of the intersected layer.  The results from ArcToolbox and the results from my custom tool do not match.  I'm getting values for the acres of the intersected layer like:

My Custom Tool:                ArcToolBox:
108400.148                       108423.527
17108.401                         17112.09
11624.977                         11627.484
85768.753                         85787.251
...

So the results of my tool are in the same ball park as what I'm getting back from Toolbox, but I'd like to be able to call the same code that toolbox does when it executes "Calculate Geometry".  Does anyone have sample code of how to calculate acres using Calculate Geometry?

Here is the code I am currently using:

'Get the first feature.
            pUpDFCursor = pFeatureclass.Update(Nothing, False)
            pFeature = pUpDFCursor.NextFeature

            'Loop through all features.
            Do Until pFeature Is Nothing

                'Step the progress bar.
                pStatusBar.StepProgressBar()

                pArea = pFeature.Shape
                dblArea = pArea.Area

                'Calculate Acres from Area.
                pFeature.Value(pFeature.Fields.FindField(strField)) = pArea.Area / 4046.85642
               
                'Update all features with newly calculated acres.
                pUpDFCursor.UpdateFeature(pFeature)
                pFeature = pUpDFCursor.NextFeature
            Loop

Can I call calculate geometry directly through arcobject?  I'm using Visual Studio 2008, .Net.
0 Kudos
1 Reply
Venkata_RaoTammineni
Regular Contributor
Hello all,

I have written code to intersect two polygon layers, and then calculate the acres of the resulting intersected layer.  To verify that my tool is giving accurate info, I've run the same process using ArcToolbox intersect, and then right click the resulting layer's field name, and choosing "Calculate Geometry" to get the acres of the intersected layer.  The results from ArcToolbox and the results from my custom tool do not match.  I'm getting values for the acres of the intersected layer like:

My Custom Tool:                ArcToolBox:
108400.148                       108423.527
17108.401                         17112.09
11624.977                         11627.484
85768.753                         85787.251
...

So the results of my tool are in the same ball park as what I'm getting back from Toolbox, but I'd like to be able to call the same code that toolbox does when it executes "Calculate Geometry".  Does anyone have sample code of how to calculate acres using Calculate Geometry?

Here is the code I am currently using:

'Get the first feature.
            pUpDFCursor = pFeatureclass.Update(Nothing, False)
            pFeature = pUpDFCursor.NextFeature

            'Loop through all features.
            Do Until pFeature Is Nothing

                'Step the progress bar.
                pStatusBar.StepProgressBar()

                pArea = pFeature.Shape
                dblArea = pArea.Area

                'Calculate Acres from Area.
                pFeature.Value(pFeature.Fields.FindField(strField)) = pArea.Area / 4046.85642
               
                'Update all features with newly calculated acres.
                pUpDFCursor.UpdateFeature(pFeature)
                pFeature = pUpDFCursor.NextFeature
            Loop

Can I call calculate geometry directly through arcobject?  I'm using Visual Studio 2008, .Net.



Public Sub t_IArea_polygon()
   Dim pID As New UID
   pID = "esriEditor.editor"
   Dim pEditor As IEditor
   Dim pApp As IApplication
   Set pApp = Application
   Set pEditor = pApp.FindExtensionByCLSID(pID)
  
   If pEditor.SelectionCount <>  1 Then
     MsgBox "select one polygon"
     Exit Sub
   End If
  
   Dim pEnumFeat As IEnumFeature
   Dim pFeature As IFeature
   Dim i As Long

   Set pEnumFeat = pEditor.EditSelection

   Dim pArea As IArea
   Dim pCenter As IPoint
   Dim pLabel As IPoint
   Set pCenter = New Point
   Set pLabel = New Point

   Set pFeature = pEnumFeat.Next

   While Not pFeature Is Nothing
     If pFeature.Shape.GeometryType = esriGeometryPolygon Then
       Set pArea = pFeature.Shape
       MsgBox "+++Polygon::IArea properties..." & vbCrLf _
       & "Area = " & pArea.Area & vbCrLf _
       & "Center.X = " & pArea.Centroid.X & vbCrLf _
       & "Center.Y = " & pArea.Centroid.Y & vbCrLf _
       & pArea.LabelPoint.X & vbCrLf _
       & "LabelPoint.Y = " & pArea.LabelPoint.Y

       pArea.QueryCentroid pCenter
       pArea.QueryLabelPoint pLabel
       MsgBox "+++Polygon::IArea Queries..." & vbCrLf _
       & "Center = " & pCenter.X & "," & pCenter.Y & vbCrLf _
       & "Label = " & pLabel.X & "," & pLabel.Y & vbCrLf

     End If
     Set pFeature = pEnumFeat.Next
   Wend

End Sub
0 Kudos