This image defines the excitement I had for this week's assignment.
For this week's assignment, we began exploring geoprocessing, more specifically conducting geoprocessing utilizing ESRI's model builder and writing out Python code. The learning outcomes expected from this assignment were being able to create and modify scripts, creating a script tool using Modelbuilder, using Python 3 to perform multiple geoprocessing tasks, and knowing how to share toolboxes.
Being able to write a script and performing multiple tasks at once is definitely a skill set I want to utilize in my job, that is why I was so excited for this week's assignment because I am now learning ways of making my life easier. The script we had to write this week was definitely a big stepping stone in that direction for me. To successfully write the script the code had to first add XY coordinates to a hospital's shapefile, and then print text saying that the process of adding the coordinates is occurring. After the XY coordinates are added we next need to have the code process a buffer analysis of 1000 meters around each hospital point. But at the same time as the buffer, we need to dissolve the buffer into one polygon which allows for a cleaner display of the 1000-meter buffer around the hospitals. After the buffer analysis with the dissolved buffers is concluded another message should display saying that the process underwent a buffer analysis and the corresponding start and end time messages.
This is what the result of the code should look like:
To get to this result, I needed to set my file workspace so that the code knew where to pull the data from and then I needed to set the name of the file being inputted into all of the tools. I then needed to write out the first tool which was the XY coordinates one, it should look something like this: arcpy.AddXY_management(in_features). The in_features is the hospital shapefile, and the only reason why this code was able to be run was because of arcpy being in the front. Arcpy must be included in all cases where geoprocessing tools are utilized. When I wrote my initial code I made it so that the original shapefile wasn't getting the xy coordinates added to it, instead, it was being copied and the copy of the dataset was getting the xy coordinates. That obviously wasn't what the code was meant to do, so I removed that from it. The messages you see below the shapefile image were necessary to include as they showed the process for each tool beginning and ending. Originally, there was no space in between the two different tools being used, to add the space I printed a new line by typing print('\n').
To conduct the buffer analysis and the dissolve tool the code needed to look like this: arcpy.Buffer_analysis('hospitals.shp', 'S:/GISProgramming/Module4/Results/hospitals_buffer.shp', '1000 METERS', '','', 'ALL'). The first comma section is the input feature, the second section is where the resulting buffer will be outputted and the name of the buffer shapefile, and the third section is the buffer distance parameters. Now if I wanted to do just a simple buffer analysis I would be done, but I also needed to dissolve the buffer into one polygon. The assignment did not specify any parameters for the dissolved buffer, the only thing that needed to be specified was that all of the buffers created needed to be dissolved. If you look at the code above after the '1000 METERS' section, that is where the dissolve begins. All you would need to type with the default parameters is: , '', '', 'ALL') and that will get you the dissolved outcome you are looking for.
This week's assignment gave me so many ideas to begin automating and building models for my job, this is the main reason I took this class. With these new skills, I know I will be able to further my career.
Thanks for reading!