Wednesday, June 22, 2022

Programming in GIS - Geometries

A Stream of Rivers: IODs, Vertex ID, X and Y, and Names of river feature points in the rivers.shp shapefile

 In lab 5 we used what we had learned in previous weeks with search cursors and for loops, and created a series of nested for loops that allowed us to retrieve multiple levels of data brought up in a search cursor. 

A central aspect of this week's module was that data in features is stored in different tiers; features/rows, arrays, and points/vertices. While you may use a cursor to return details about features in a shapefile, if you want to get at all the way down to the points of a feature, you'll need to use several levels of for loops or special position-specific methods to get there. 

The concepts of this week's module felt fairly straightforward, and the material stacked nicely with what we learned in the past, so aside from some positioning fumbling with the method syntax I didn't have too much trouble getting the main course of the code into the editor. However, the longer the code is the more room there is for errors, and I spent probably the majority of my time on this lab editing small things. Such as trying to decipher the cause of a syntax error that I was sure I had right (turns out there was a misplaced ")" and editing and rerunning blocks of code until I had the spaces in the output in a way that made the most sense. 

The process reminds me very much of learning any spoken or written language: Once you can confidently communicate the idea, you spend a long time toying with word choice and inflection.

The other part of this lab that gave me trouble was getting every variable that needed it turned into a string with str(), so that it would be able to print into the text file. I think I finally have a better handle on that aspect though, and I have become very familiar with the "literal" error from a line of print code. 

Nesting Forbird Season: the "nested" for loops in this code allow the user to access data in different levels of a feature.

Lessons Learned:
  • If you expected multiple point pairs from your cursor and you only have one, it might be that you're only accessing an array or feature, but not the points
  • open text files with infile = open() 
  • allow python to write to text files with "w" in the open() function
  • keep in mind that you need to let things be overwritten if you're going to call the script over and over
  • the "\n" at the end of a writing for loop are crucial for keeping a text file readable
  • when in doubt, print with a str() and extra spaces
  • an insert cursor adds rows to a data file, but you can use infile.write to add cursor returns to text-based files
  • check the little things before you change the big things



No comments:

Post a Comment

GIS Portfolio

 As a final assignment at the end of my time with University of West Florida, I have built a GIS portfolio StoryMap. The final product is em...