Posts

Showing posts with the label GIS5103

Lab 6 [GIS5103]: Working with Geometries

Image
The screenshot above shows the output from this week's lab where skills emphasizing working with geometry objects were addressed. In the output above these skills were used to read a shapefile and then write specific information on each feature to a text file. The items on each line in the output file included the object ID number, vertex count number, X coordinate, Y coordinate, and feature name. The general pseudocode was as follows: Start     Step 0: (Setup)     Setup input filepath     Setup output filepath     Step 1: (Prepare output file)     Create output filename     Open output file for writing      Step 2: (Write details to output file)     Create search cursor to extract OID@, SHAPE@, NAME for each feature     Iterate through each row/feature in cursor         Set vertexID to 0 ...

Lab 5 [GIS5103]: Exploring and Manipulating Data

Image
The screenshots above represent the output from a multi-part Python script that performs the following steps: Step 1: Create and initialize a new geodatabase Step 2: Create a Search Cursor for cities associated with county seats Step 3: Create and initialize a dictionary for cities associated with county seats The initial pseudocode for these script requirements included: START     Step 1:             Setup filepath naming     Create new geodatabase     Iterate over features in Data:          Copy feature from Data folder into new geodatabase          Print name of copied feature to screen     Step 2:     Setup filepath naming     Setup field list of specific attributes within cities feature (NAME, FEATURE, POP_2000)   ...

Lab 4 [GIS5103]: Geoprocessing

Image
The screenshot above provides the output from a Python script created this week to process a shapefile containing the locations of hospitals around the University of Texas at Austin, as shown here for part of this map: A 1000-meter buffer was created around each hospital location, and then these overlapping buffer regions were dissolved into a separate, single feature, as shown here for the final output around the same area shown above: An overview of the major steps in the overall workflow is provided here: Overview of Major Steps in Overall Workflow: STEP 0 : verify licensing, extensions, and input file hospitals.shp available STEP 1 : hospitals.shp à add XY coordinates à produce hospitalsXY.shp STEP 2 : hospitalsXY.shp à perform buffering à produce hospitalsXY_buffered.shp STEP 3 : hospitalsXY_buffered.shp à perform dissolving à produce hospitalsXY_buffered_dissolved.shp Key ArcPy functions explored this week for error handling ...

Lab 3 [GIS5103]: Debugging and Error Handling

Image
In this week's lab we examined the templates for three separate Python scripts to identify syntax errors and exceptions and how best to locate these using Spyder. The output from the first script that prints out the names of fields from a shapefile is shown here: Identifying the syntax errors within this script emphasized the importance of consistency with variable naming and the correct format for iterating with a for loop. The second script was designed to display a more complete set of items from an ArcGIS project file, including spatial reference information and layer information, as shown here: Systematically identifying the syntax errors in this script emphasized the importance of file path naming and consistency with variable name capitalization, as well as understanding the relevance of correctly formatting and spelling method names. A third and final script provided training in using the try-except statement, as shown in the following flowchart: ...

Lab 2 [GIS5103]: Python Fundamentals

Image
Output from Module 2 Python script This week's lab focused on practicing with data types and fundamental constructs in the Python scripting language, including for and while loops, as well as  if statements. I examined the differences between  functions  and methods , and I additionally learned how to work with lists, strings, and numbers in Python.  The output shown above is for a Python script that performed these tasks: Step 1: Print the last element of a list containing a full name. Step 2: Display the dice rolls of a set of players and their  game status (win, lose, or tie). Step 3: Create a list of 20 random numbers in the range 0 to 10. Step 4: Remove a preset number from a list. A flowchart I sketched as part of Step 4 is shown here: In this case, I have two variables that I initialize prior to entering the while loop. Within the while loop, I continue to remove the preset number from the list based on the number of ...

Lab 1 [GIS5103]: Introducing Python

Image
The screenshot above provides the result of running my first Python script (based on Python version 3.6.8) to automatically generate folders that will be used this semester for organizing the data, scripts, and results in each module of GIS5103 GIS Programming. One of the main take-aways from the lab this week was interpreting " The Zen of Python ", written by Tim Peters, which I summarized as follows: "The Zen of Python" provides 19 guiding principles to consider when writing Python code. A recurring theme across the principles is that LOOKS MATTER – we should strive to write code that is easy to decipher and read. If there is a simple versus clever way to write the code, we should stick with the simple and explicit version, and we should follow this principle with each line of code (i.e., multiple lines of code that are easy to read are better than one complex line). We should also choose variable names that make reading the code easier (e.g., use a variable ...