Thursday, June 20, 2024

Geometries in Python

In this week's assignment, we had to write a script that created a text file, used a Search Cursor to find information from a shape file, and then add this information to the file in a csv format.

This lab feels like it took me forever! I got the process done step by step, and often felt like trying to move forward to the next step undid the previous one. The loops within the Search Cursor threw me for a loop - pun intended. I was ready for the basic set up for the Search Cursor, as we’ve spent a good bit of time working on these during the last assignment. I doubled checked the attribute table for the data to make sure I had the correct phrasing of the name header. I borrowed quite a few of the codes from the exercise, changing them to make sense for the assignment. But it took some finagling to get the information to print out as instructed. I finally solved all of my issues by putting all of the information in one print command. It took a bit of tweaking. I read a lot about the .format as well, trying to figure it out. 

The next step was to populate the text document. I added a “f.write” command at the bottom of the script and it returned one line. Oh right – the cursor has run and it needs to be reset! After unsuccessfully trying to reset cursors last week, I figured the easiest thing was to write the text document while I printed everything in IDLE. So I moved this code on up into the Cursor and was able to get the following result.
Here's a sample of the final text document.

This is the code I created to write the document.



 


No comments:

Post a Comment

GIS Portfolio

To show off all I have learned during my GIS Graduate Certificate program, I created an online portfolio. Click here to check it out.  The ...