# ArcMap Field Calculator Python

647
6
04-30-2021 06:44 PM
Labels (3)
New Contributor

Hello everyone

I have a question concerning Python in ArcMap (field calculator):

I want to write following code with python, in attributes table; field calculator. But I can't.

Could you help me,

Thanks.

Dim pSpRef1 As ISpatialReference
Dim pSpRFc As SpatialReferenceEnvironment
Set pSpRFc = New SpatialReferenceEnvironment
Dim pGCS As IGeographicCoordinateSystem

Set pGCS =
Set pSpRef1 = pGCS
pSpRef1.SetFalseOriginAndUnits -180, -90, 1000000

Dim pPCS As IProjectedCoordinateSystem
Dim pSpRef2 As ISpatialReference
Set pPCS =
Albers)
pPCS.SetFalseOriginAndUnits 0, 0, 1000
Set pSpRef2 = pPCS
Dim dblArea As double
Dim CenterX As double
Dim CenterY As double
Dim pArea As IArea

Set pArea = [shape]

Dim pGeo As IGeometry
Set pGeo = pArea
Set pGeo.SpatialReference = pSpRef1
pGeo.Project pSpRef2

Set pArea = pGeo
dblArea = pArea.Area

theKm = dblArea / 1000000

6 Replies
MVP Esteemed Contributor

If you want to calculate geometry in a different coordinate system and/or units

... sort of retired...
New Contributor

Thenk you, but I need to know how in python

MVP Esteemed Contributor

Then examine the code associated with the tool's script located in

You will probably be able to simplify it substantially.

... sort of retired...
New Contributor

Thank you again,

I examined it, but not  figure it out. I'm new in Python.

I want to write  with Python Parser of the Field Calculator.

MVP Esteemed Contributor

Seeing there are existing tools to accomplish this task, and yet you want to write it on your own without explaining why, it seems like this may be a question for school/studies.  If you can provide a reason why you have to write it in Python yourself, people may be more willing to help or offer additional suggestions.

New Contributor

This is a situation related to Phd. I thought these steps wouldn't work, sometimes different results can come out, but they did.
thanks again, DanPatterson

thank you JoshuaBixby