Python in ArcGIS Pro
Institute for Environmental and Spatial Analysis...University of North Georgia
Contents
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
- Download georgia-wind-50m.zip from GIS data and add the Shapefile to a new map.
- Can you find the Calculate Field tool?
- There are seven categories of the wind speed for the state of Georgia in the
GRIDCODEfield. - 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'
1.2 Homework 1: Classification of Georgia counties using Calculate Field
- Download Counties_Georgia.zip from GIS data and add the Shapefile to a new map.
- Classify Georgia counties into low, medium, and high population densities.
- Add a new field
PopDensand populate it with the population density in $\text{people}/\text{km}^2$ using thetotpop10andSq_Milesfields. - Add a new field
PopDensCatand populate it with eitherLow,Medium, orHighusing the mean $\pm$ standard deviation of the population density for the range of the medium category.
- Add a new field
- 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 your function here # you have to show me your mean and standard deviation of the population density in code - Upload FirstLastname.zip to D2L ⇒ Assignments ⇒ Homework 1.
