Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a code snippet that I can't figure out:

'Define a calculator for NewArea field
    pCalculator = New Calculator
    With pCalculator
        .Cursor = pCursor
        .PreExpression = "Dim dbarea as double" & vbCrLf _
                       & "Dim pArea as IArea" & vbCrLf _
                       & "Set pArea = [Shape]" & vbCrLf _
                       & "dbArea = pArea.area"
        .Expression = "dbArea"
        .Field = "NewArea"
    End With

    'Calculate the field values of NewArea field

What is pCalculator calculating here? What is [Shape] in this context? I'm migrating this old VBA code to Python, and I'm stuck at this segment.

A more general question, what is the significance of the square brackets in the pre-expression? Are they placeholders for the expression?

share|improve this question
up vote 3 down vote accepted

All this is doing is calculating the area of each feature. You can easily do the same thing with the Python version of the parser with !shape.area!. See the documentation.

Using ArcObjects, I would suggest using an update cursor as in this sample (relevant code posted below): Calculate area geoprocessing function tool

' Create an Update Cursor
indexA = inputFeatureClass.FindField(sField)
Dim updateCursor As IFeatureCursor = inputFeatureClass.Update(Nothing, False)
Dim updateFeature As IFeature = updateCursor.NextFeature()
Dim geometry As IGeometry
Dim area As IArea
Dim dArea As Double

Do While Not updateFeature Is Nothing
    geometry = updateFeature.Shape
    area = CType(geometry, IArea)
    dArea = area.Area
    updateFeature.Value(indexA) = dArea
    updateFeature = updateCursor.NextFeature()

' Release the update cursor to remove the lock on the input data.
share|improve this answer
Awesome, thank you. – Kyle M Feb 27 '13 at 3:20
Months later I'm back at this exact snippet. This code throws a "General error executing calculator." Do you know why? I'm writing a VB add-in, and this code came from VBA. Is there some syntax issue that VB doesn't like here? – Kyle M Jul 24 '13 at 3:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.