Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

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 need to create a script in Python for use in ArcMap 10.

This script must be able to calculate a field from the shp currently selected in ArcMap.

Any ideas? I'm new to Python.

share|improve this question

After running a tool in ArcMap you can go to the results window (Geoprocessing > Results) and right click on the finished tool. This will give the option to copy the Python code that you can then paste into your Python shell of choice. This is a great way to begin learning. After working with Python for a couple years now I still find myself doing this just to find out how the GP tool wants the parameters.

share|improve this answer

Unless I'm missing something from your question, you're just asking how to calculate [field2] from [field1] in the same shapefile.

If so, you just need to use the "Calculate Field" tool to do this. And if you just want to run this tool on a selected feature(s), all ArcGIS tools will only work on the selection set if one exists.

ArcGIS Help has python code examples that show exactly how to do it in Python.

Look in the "Code Sample" section about halfway down help. Their [generalized] example is:

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.AddField_management("<in_table>", "<field>", "TEXT", "", "", "20")
arcpy.CalculateField_management("<in_table>", "<field_to_calc>",
                                <field_with_values>, "PYTHON")

If that is all you are after, it's pretty simple.

share|improve this answer

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.