ArcMap Field Calculator Python

726
6
04-30-2021 06:44 PM
pınarspor
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 =
pSpRFc.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)
Set pSpRef1 = pGCS
pSpRef1.SetFalseOriginAndUnits -180, -90, 1000000

Dim pPCS As IProjectedCoordinateSystem
Dim pSpRef2 As ISpatialReference
Set pPCS =
pSpRFc.CreateProjectedCoordinateSystem(esriSRProjCS_NAD1983USA_
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

0 Kudos
6 Replies
DanPatterson
MVP Esteemed Contributor

Use Add Geometry Attributes—Help | Documentation (arcgis.com)

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


... sort of retired...
pınarspor
New Contributor

Thenk you, but I need to know how in python

0 Kudos
DanPatterson
MVP Esteemed Contributor

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

C:\... your install folder ... \Resources\ArcToolBox\Scripts\AddGeometryAttributes.py

You will probably be able to simplify it substantially.


... sort of retired...
0 Kudos
pınarspor
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.

 

0 Kudos
JoshuaBixby
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.

0 Kudos
pınarspor
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

0 Kudos