# Python in ArcGIS Pro 1

Institute for Environmental and Spatial Analysis...University of North Georgia

## 1   Calculate Field

Probably, one of the most useful Python features in ArcGIS Pro for regular users.

Still, you need to know a little bit of Python.

When do you want to use it?

• A field can have multiple different values depending on other fields.
• Manual way? Select a subset of features, assign a field value to them, and repeat for other subsets.
• Why Python? More efficient because you can achieve what you want in one run with no manual selections.

### 1.1   Let’s try Calculate Field

2. Can you find the Calculate Field tool?
3. There are seven categories of the wind speed for the state of Georgia in the GRIDCODE field.
4. We want to convert these codes to the ranges of miles per hour (WindMph).
• Check Georgia 50m WPC Map.pdf for the ranges.
def getWindMph(gridcode):
if gridcode == 1:
return '0.0-12.5'
elif gridcode == 2:
return '12.5-14.3'
elif gridcode == 3:
return '14.3-15.7'
elif gridcode == 4:
return '15.7-16.8'
elif gridcode == 5:
return '16.8-17.9'
elif gridcode == 6:
return '17.9-19.7'
else:
return '>19.7'

## 2   Homework: Classification of Georgia counties using Calculate Field

2. Classify Georgia counties into low, medium, and high population densities.
1. Add a new field PopDens and populate it with the population density in $\text{people}/\text{km}^2$ using the totpop10 and Sq_Miles fields.
2. Add a new field PopDensCat and populate it with either Low, Medium, or High using the mean $\pm$ standard deviation of the population density for the range of the medium category.
3. Compress your final Shapefile and PythonCode.txt with your assignment expression and Python code block into FirstLastname.zip.
# Assignment expression: Textbox just above the Code Block in Calculate Field
your assignment here calling the function below
# Code Block: Code Block in Calculate Field
# you have to show me your mean and standard deviation of the population density in code
4. Upload FirstLastname.zip to D2L ⇒ Assignments ⇒ Homework 1.

### 2.1   Homework solution

def getPopDensCat(popdens):
mean = 72.5267584956
sd = 143.460174992
if popdens < mean - sd:
return 'Low'
elif popdens < mean + sd:
return 'Medium'
else:
return 'High'