AnsweredAssumed Answered

ARCGIS 10, VB.NET, calculate centroids

Question asked by acoucite on Jun 17, 2016
Latest reply on Jun 23, 2016 by acoucite


  I have migrated an toolbar initially developped for ArcGis 9,3. This tool is used by non-programmer or cartographers.

  One procedure is called to generate centroids of attributes table and after to launch an calculation.


  The source code used in 9,3 was :


'instantiating new calculator and cursor

  pCalculator = New Calculator

  pCursor = CType(pFeatureClass.Update(Nothing, True), ICursor)

    'Centroid Y

  With pCalculator

  .Cursor = pCursor

.PreExpression = "Dim pGeomShp as IGeometry" & vbNewLine & "Set pGeomShp = [shape]" & vbNewLine & "Dim pArea as IArea" & vbNewLine & "Set pArea = pGeomShp" & vbNewLine

.Expression = "pArea.Centroid.Y"

  .Field = "centroidY"

  End With

    'try & catch *************************************************



  Catch ex As System.Exception

MessageBox.Show("Error: " + ex.Message)

  End Try

  This was working until moving to ArcGis 10 (an upper). A crash was observed while launching pCalculator.Calculate().

  I’ve migrated this code that way (like proposed here )  :


  Dim nCentroidXFieldIndex As Integer = pFeatureClass.FindField("centroidX")

  Dim nCentroidYFieldIndex As Integer = pFeatureClass.FindField("centroidY")

  Dim nBldg_sizeFieldIndex As Integer = pFeatureClass.FindField("Bldg_size")

      If TypeOf pFeatureClass Is IFeatureClass Then

  If TypeOf pFeatureCursor Is IFeatureCursor Then


  Dim pArea As IArea

  Dim pFeature As IFeature = pFeatureCursor.NextFeature()

  Dim myProgressCalc As New FileProgressForm



myProgressCalc.Text = "Veuillez patienter svp"

myProgressCalc.lblProgress.Text = "Calcul des données géographiques"


   pArea = CType(pFeature.Shape, IArea)

   While pFeature IsNot Nothing

pFeature.Value(nCentroidXFieldIndex) = pArea.Centroid.X

pFeature.Value(nCentroidYFieldIndex) = pArea.Centroid.Y

pFeature.Value(nBldg_sizeFieldIndex) = pArea.Area


pFeature = pFeatureCursor.NextFeature


    End While


  End If

  End If

  It’s working but it’s working extremely slowly ! The first code (A) was executed in less than 3 minutes. The new one (B) in 25 minutes !

  In fact, I just want to programmaticaly call a the new calculate geometry tool (when displaying attributes table - )


Screen capture 1

Too bad, can't upload PNG and JPEG files...


or Arc tool => Data Management Tools => Entities => Add geometric attributes ( )

  Screen capture 2



or any other methods !


Both tools are working great in ArcGis Desktop but I can’t find my way to make them work in VB.NET.


Please, any suggestions ? (It’s just driving me crazy).


Thanks by advance for your answer, and sorry for screen capture in french and for poor english speaking