AnsweredAssumed Answered

ARCGIS 10, VB.NET, calculate centroids

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

Hello,

  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.


  Anyway,

  The source code used in 9,3 was :


  (A)

'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 *************************************************

  Try

pCalculator.Calculate()

  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 http://gis.stackexchange.com/questions/52983/syntax-for-arcgis-icalculator-object/198681#198681 )  :

 
  (B)

  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.set_maximum(iTotalRecords)

myProgressCalc.Show()

myProgressCalc.Text = "Veuillez patienter svp"

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

myProgressCalc.Update()


   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.Store()

pFeature = pFeatureCursor.NextFeature


   myProgressCalc.Go()


    End While

myProgressCalc.Close()

  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 - http://desktop.arcgis.com/fr/arcmap/10.3/manage-data/tables/calculating-area-length-and-other-geometric-properties.htm )


 

Screen capture 1

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

 

or Arc tool => Data Management Tools => Entities => Add geometric attributes (http://pro.arcgis.com/fr/pro-app/tool-reference/data-management/add-geometry-attributes.htm )


  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


  Matthieu

Outcomes