Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

This assignment has 2 parts:

1. Writing the script


2. Converting the script to a tool

Getting Started
Open a New Project in ArcMap and import the datasets ‘PopulatedPlaces’ and ‘Airports’. It is
best to put these feature classes inside the Default geodatabase associated with your project.

Part 1: Writing a script (7 points)


You can do this first part either in a Notebook associated with ArcMap, or as a Python Script
associated with ArcMap. A Notebook allows you to write code in small parts and test each part.
On the other hand, it will be easier to convert the script into a tool. If you are using a Notebook,
remember to save the Notebook specifically. Saving the project does not always save the
notebook.
Find how many airports are there within 10 Kms (10000m) of a Populated place in Uruguay.
Even though you use a Notebook to test parts of your code, the final cell of your notebook
should have the answer in a similar format as below (numbers are wrong in this example):
PopulatedPlaces has 27874 features.
Airports has 45784 features.
There are 2 airports within 10000 m of a populated place in Uruguay.

When testing the code remember to ‘clear selection’. Otherwise, the tool will run only on the
selected features.
Hints:
1. You might want to set your ArcPy environment to allow overwrites of files (if you plan
on testing your script a few times).
2. You have been provided the two shapefiles necessary to do this assignment. Make sure
that both files use the same spatial reference. Given that you’ll need to specify the
search radius (buffer) in meters, you’ll want to make sure that both shapefiles are in an
appropriate spatial reference that uses meters.
a. Tip: WKID 3857 WGS_1984_Web_Mercator_Auxiliary_Sphere is a good option.
b. Create a function that does the projection and returns the name of the projected
file. Then call this function for both shapefile user inputs. This is the optimal
solution.
3. Use buffer analysis to buffer the cities by the user-specified radius and create a new
shapefile.
4. Use Select Layer By Location analysis or Select Layer By Attribute analysis to do the
intersect and subsetting by country respectively.
Part 2: Create a Geoprocessing script tool (8 points)
Convert the above code into a Geoprocessing Script tool. This part is meant to be done
primarily through self-exploration and learning. We have provided the resources you will need
in the “practice resources”. However, since this is the last piece of deliverable in the entire
course, we expect you to be able to solve problems independently, specially when it comes to
modifying code to fit a particular program interface. Thus, step-by-step instructions are not
provided.
1. Create a new toolbox in ArcToolbox and call it YourName_ArcPyLab.tbx
2. Copy your Notebook code into a file with a .py extension.
3. The tool should accept as input the following parameters:
a. Workspace: remember to set filter as Workspace > Local database
b. Country Name: String
c. Buffer Distance: Long
4. Change all of the user-input functions to arcpy.GetParameterAsText(<index>)
5. Change all of your print statements to arcpy.AddMessage(<statement>)
6. The output of the tool should be text in the form of messages in same format as above.

Submission
Submit both your Python Notebook and the Toolbox

You might also like