Posts

Showing posts from June, 2023

Programming Week 6: Geometries

Image
In the last lab of the course, we were given a shapefile of rivers on Maui and had to write a .txt file of these rivers' names, information, and the XY coordinates of their vertices. We did this by creating a search cursor that iterated over each point in each array for each row in the rivers.shp file. Each row in the original file contains the information for a different river represented by a polyline feature. The points in each feature's array are the vertices that determine the curve of the line. For each feature, I numbered the vertices with a vertex ID. The resulting .txt file printed the feature ID, vertex ID, X coordinate, Y coordinate, and the river's name, as seen below.  The one part of the script I struggled to write was the for loops for the cursor. Specifically, I wasn't sure how to format and concatenate the fields to be written to the .txt file. I tried using the field names themselves with different containers/field delimiters (for example, str("OI...

Programming Week 5: Exploring and Manipulating Spatial Data

Image
For this week's lab, we wrote a script that created a new geodatabase, copied data from the Data folder into the geodatabase, used the arcpy.SearchCursor() function to search a feature class of cities in New Mexico for county seats, and created a dictionary of county seats in New Mexico and their populations.  Here is the complete output from the final version of my script:             I had several issues with the step in which we had to create a SearchCursor for the citie first error I got was “RuntimeError: ERROR 999999: Something unexpected caused the tool to fail” for the line “with arcpy.SearchCursor(fc, fields, '"FEATURE" = \'County Seat\'') as cursor:”. I then tried several different ways of handling the field names (for example, by deleting this for loop I wrote and calling getValue individually for each field name:)        for field in fields:             print(row.getValue(field)) Eventu...

Programming Week 4: Geoprocessing

Image
For the first part of this week's lab, we created a model in ArcGIS Pro's ModelBuilder to create a new layer from the exiting soils and basin layers. The model clips soils to the extent of basin , selects the clipped soils records that are classified as "Not prime farmland", and erases these selections from the clipped soils layer. ModelBuilder is a very handy tool that makes it easier to visualize a complex, multi-part process (though it is possible to get confused in its labyrinth!), and it reminds me of the flowcharts we did at the beginning of the course. The three-part model resulting in a layer called soils_Clip_Select_Erase In the second part of the lab, we wrote a script in an ArcGIS Pro Notebook that added XY coordinates to a hospitals shapefile, created a 1000 meter buffer around each hospital, and dissolved these buffers into a single feature. The hospitals_dissolve and hospitals layer I first created a new map and added the hospitals shapefile so I co...

Programming Week 3: Debugging and Handling Errors

Image
In this week's lab, we practiced finding and correcting errors in Python scripts and catching exceptions using try-except statements. The first script prints the names of the fields in the attribute table for the parks.shp shapefile, and had a few syntax errors that I corrected. Output from Script 1 The second script prints the spatial reference information and the layers for the project TravisCountyAustinTX.aprx. I got the error AttributeError: ‘module’ object has no attribute ‘mp' , which I googled and learned that I was using Python 2.7.16 instead of Python 3.9.11, because I opened the script in regular IDLE instead of IDLE for ArcGIS Pro. You can see the different Python versions in the screenshots from script 1 (above, before I realized this mistake) and scripts 2 and 3 (below). Output from Script 2 Output from Script 3 Script 3 Part A was supposed to print the name of the parks layer, make the layer visible, and turn on labels for the layer, then save the project. Part B ...