Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a feature class whose attribute table looks like this:

Latitude | Longitude | Area

For the area column, all rows are null. I would like to put in a specific value for all rows using Python.

I know how to do this on the front-end in the ArcMaps application ( right click > Open Attribute Table > right click on column > field calculator > input value).

How can I accomplish this programmatically using Python?

share|improve this question
    
Do you want to calculate the area for each feature? –  Alex Tereshenkov Jun 11 at 18:49

2 Answers 2

up vote 3 down vote accepted

The simplest way, until you are more familiar with the syntax, would be to use the field calculator as you normally do and then go to Geoprocessing -> Results. From there, you can expand Current Session and, right-clicking on the most recent tool that was run, select Copy as Python Snippet.

You'll likely have to change the names of a few inputs, but that should get you started.

share|improve this answer
    
+1 for Copy As Python Snippet –  PolyGeo Jun 12 at 8:31

You can calculate the values for a column with Python by using either a GP tool Calculate Field or arcpy UpdateCursor (this one is faster when working with large datasets).

For calculating the geometrical properties of features, you can either use GP tool Add Geometry Attributes or using tokens (such as SHAPE@AREA) of update cursor.

share|improve this answer
1  
+1 for cursors, specifically the data access module. I don't really use Calculate Field anymore. –  Paul Jun 11 at 18:55
1  
@Paul, I still do :) sometimes it is just plain easier syntax wise. Of course only for minor datasets. –  Alex Tereshenkov Jun 11 at 18:58
    
Anything past one or two lines, yes. :) –  Paul Jun 11 at 18:59

Your Answer

 
discard

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.