Posts

Showing posts with the label GIS5103

Module 6: Working with Geometries

Image
The purpose of this week's lab was to explore the geometries of a shapefile by writing vertices to a text file. The final script created a new TXT file, used a search cursor to iterate over the rivers shapefile geometries with  for loops, and then writing data to the new TXT file. The final TXT file contains the following data from the rivers.shp : feature OID, vertex ID (created in the script), x & y coordinates, and the name of the feature. Below is a screen shot of part of the data in the new TXT file (the full TXT file is not shown as it is very long and contains 0-25 features with a total of 247 vertices). One of the things that made creating and running this script easy was the use of geometry tokens, specifically OID@ and SHAPE@. Geometry tokens are pieces of code that allow us to interact and access specific information about the geometry of features, which saves time when working with large datasets and/or features with a lot of geometry information. The ...

Module 5: Exploring & Manipulating Data

Image
The purpose of this lab was to explore spatial data with scripting using search cursors, lists and dictionaries. A template script was provided and modified in the Spyder IDE to perform the required functions. The final script creates a new geodatabase called ath22, copies 8 feature classes into the geodatabase, queries the feature class cities for the names and population sizes within the county seat and creates and populates a dictionary called county_seats with names and population size circa 2000 of every 'County Seat' city in New Mexico. Included in the script output are processing messages indicating which process is running, that the process was completed and how long it took to complete the process. The first tasks of the script created a new file geodatabase called ath22 and copy 8 feature classes into the geodatabase. The code for this part of the script was easy to create. To print the messages with spaces so they are easier to read, it is useful to add '\n...

Module 4: Geoprocessing

Image
The purpose of this week's lab was to design a model in ModelBuilder in ArcGIS Pro and use Python 3 to create a script to perform multiple geoprocessing tasks. For the first part of the assignment, I used ArcGIS Pro created a model in ModelBuilder called SoilErase. The model clipped all soils to the extent of the basin, selected all soils classified as "Not prime farmland" and erased the "Not prime farmland" from the basin polygon. Three geoprocessing tools were added to the model: Clip, Select and Erase. When successfully run, the model produced the following shapefile: For the second part of the assignment, I used Spyder IDE to create a script to perform 3 geoprocessing tasks on a hospitals shapefile. Before writing the script, I found it useful to visualize the tools with their inputs and outputs by first creating the model in ModelBuilder. For the script, I included code to import the arcpy modules and set the workspace to the Data folder. The 3 geop...

Module 3: Debugging and Error Handling

Image
The purpose of this lab was to implement debugging procedures, interpret script error messages, fix syntax and other errors, and modify scripts to run with exceptions. There were three scripts with errors that required debugging. The first script was supposed to print out the names of all fields in a shapefile attribute table (parks.shp), but three errors had to be corrected before it would run correctly. All three errors were Syntax error s. Spyder marks some errors in the script code with an orange exclamation point before the line containing the error. In this script the errors were in Lines 12, 14, and 15. One error was a capitalization  error and the other two were misspellings. After correcting these Syntax errors, the script ran successfully as shown below in the IPthyon console output:  The second script was supposed to print out the names of all the layers in an ArcGIS Pro project, but several errors had to be corrected before it would run correctly. Becau...

Module 2: Python Fundamentals

Image
The purpose of this lab was to create a Python script by manipulating string variables using a list, creating loops and conditional statements, and iterating variables within loops to control workflows. The final Python script had to be run using Spyder. The tasks performed by the script include printing my last name, running a dice game (the code was provided and debugged), populating and printing a list with 20 random integers from 0 to 10, and removing an integer (in my case 2) from the list and reprinting it. One run of my final script is above. I found it easiest to test individual lines of code and steps of the assignment in new, separate files in order to get them to run properly. There was a lot of trial and error for me in this assignment and I found creating the while loops the most troublesome. The first two steps of the assignment - printing my last name and debugging code - were the easiest. In order to print my name, I assigned my full name to a string, split the st...

Module 1: Introducing Python

Image
The objective of the first lab for the GIS Programming course was to become familiar with Python interfaces and run a Python script using the Spyder interface. In order to open Spyder, I opened the Python Command Prompt and typed "spyder". It is useful to note that if the command prompt is closed, Spyder will also be closed. In order to run the provided python script, I opened it and clicked the Run button. The process results appeared in the IPython Pane and Variable Explorer Pane. When run, the script created all the folders I will use for this course. The result of this script is above, showing all 8 module folders and the three folders within each. This was a fairly easy, straightforward lab and was a good orientation to the Spyder interface.