Skip to main content

Posts

Showing posts with the label GIS Programming

Working with Rasters

 In this last lab assignment for GIS Programming, I learned how to work with rasters using the arcpy.sa (Spatial Analysis) module. Our goal was to create a single raster image that met the following goals through the original dataset:  Forest landcover (classifications 41, 42, and 43)  Slope between 5° and 20° • Aspect between 150° and 270° To achieve these goals, I created five temporary rasters files and then combined them into one raster layer. I came across a couple of issues while creating my script for this assignment.  The first issue I came across was I had 1,2,3 as the second number component in the RemapValue statement. I had missed the part in the script template that stated to assign all the new values to 1. My second major issue was also caused by skipping a line. I did not add the line to create the elevation raster. This gave me some very interesting issues. While the script ran through all the way, whenever I tried to map my final raster file I got ...

Working with Geometries

 This week I learned about working with geometries in Arcpy; how to read, write, and work with multipart features. We began by setting our workspace and utilizing a cursor in order to create a new txt file, and write data into it from the rivers.shp. Below is a short summary of the steps I took:  Import arcpy from arcpy import env set workspace set overwrite set outpath define variable for river.shp create txt (rivers_ESG.txt) create search cursor set variables for OID, NAME, and vID to be able to call upon them set first for loop in cursor vID + = 1 set second loop in row[1] set third for point in part print OID, vID, coordinates x,y, NAME output.write (same as above) to add to text file I encountered one main issue, and that was how to print everything.  Looking back at the past lessons, I saw that I had to call upon the .format( ). However,  this function did not work for printing the names. After connecting with my peers, they suggested using simply row[2]. ...

Exploring and Manipulating Data

 This week was the most challenging lab yet. I created a script from scratch to create a new file geodatabase, copy feature classes into it that met a SQL criteria, create a dictionary, and lastly list the keys and values of the said features classes into the dictionary.  Below is a flow map of my script. Two struggles I had: 1          My first struggle was to print the list of copied files and print times. I couldn’t figure out what was wrong in my statement, as it ran but did not print. One of my peers mentioned that it’s because when using row.GetValue(), it can register the item as an integer and not print. I then cast a string str(row.GetValue()) and resolved my issue. 2          My second biggest issue was determining how to place the statement to add the key and values to the dictionary. <dictionary variable>[<key>]=<value> I added the statement inside my for loop, after...

Geoprocessing

 This week we learned geoprocessing in ArcGIS Pro via the Modelbuilder and Python.  First, I built a model in the ModelBuilder. My goal:   Clips all soils to the extent of the basin   Selects all soils that are classified as "Not prime farmland" under the [FARMLNDCL] attribute  Erases the "Not prime farmland" soil selection from the basin polygon  First, I utilized the Clip tool to remove the Soil areas (input feature) from the Basin area (clip feature). [I think of the layers of the cookie dough sheet (clip feature) vs the cookie cutter (input feature).] Second, I used the clipped data from step one to Select only the areas classified as ‘Not prime farmland,” utilizing the query Where FARMLNDCL is equal too ‘Not prime farmland.’ Here the attribute ‘Not prime farmland’ comes from the clipped clipped soil layer. Lastly, I used the erased the selected data (Erase feature) from step 2 from the original soil shapefile (input feature). The second p...

Debugging with Python on Spyder

 This week's lab focused on debugging and catching errors in python code. I personally used the program Spyder to do this.  We worked on three different pre-written scripts that had various different errors and/or exceptions. To find the errors in the code, I used the four steps we learned about in the lecture and our textbook (Python Scripting for ArcGIS Pro).  1) Syntax This type of error can be easily spotted when looking at your code (missing a letter, parenthesis, or something that should be upper or lowercase). You can also run the code and Spyder will tell you exactly what type of error, the line, and with a carrot, the location of the error.  I used this method to debug the first script of the assignment.  Script 1: List the field names of Shapefile in ArcGIS 2) Debugging and Stepping through the Code In this lab, I also learned how to use the debugging tool. The debugger tool can be run to go the entire code, stopping after the error, or you can op...

Python Foundamentals

 In our first week of GIS Programming, I learned the foundations of Python. Wow, was this incredibly hard! I found it extremely challenging to wrap my head around the subtle nuances of syntax and all the different functions and methods available to use. I love puzzles and critical thinking, and that is a huge part of python; coming up with efficient and creative solutions. As I become knowledgeable and better at using python, I am excited to see all the ways I will be able to use it.  Our Lab this week consisted first of learning how to create a string and then indexing or slicing them. This was the easiest of the tasks, as we learned also to use a while loop in combination with functions(i.e.: range, len, append, random) and methods (i.e.: object.method(argument)). Utilizing the while loop, I debugged a prewritten code that generated random wins and losses for players in a dice game. I also created/utilized a while loop to generate 20 random numbers between 0 and 10. Then I c...