This last week of GIS programming brought working with geometries. We began by creating a search cursor and for loops to iterate over the geometry of shapefiles. Then we used loops to iterate over features/row, an array, and then points to copy them to a text file for said shapefile.
After iterating over rows using the get part method, for
loops, and searching for cursors to retrieve geometry points for the river’s
shapefile, we copied it to a text file. In the screenshot of the text file below,
you can see each of the geometry object ID’s, the Vertex ID’s, XY coordinates,
and stream names that resulted from this process.
Figure 1Text Script for River_ZM38
The previous steps we have been exposed
to, importing modules, setting up an environment, and a workspace, have all become
second nature. The creation of for loops has become easier to grasp. However,
this week, we were introduced to the concept of “nested loops,” which is a loop
within a loop and allows you to access information within features. For
example, to access the specific points in our river’s shapefile, we had to access
each individual row in that feature using a for loop, and iterate again over each
point in the row to get each X, Y coordinate. This concept was easy to
understand; however, the use of the get Part() method initially retrieved
an error stating that “part” was not defined. However, after attending office
hours, I realized that it was not working because I had the vertex_ID in the
wrong location, and I had an extra for loop that was not supposed to be there.
The final hurdle was copying the entire text file. At first, only one line of text was copied into the text file. After
seeking guidance, I learned that this was due to improperly indexing the items
and adding them together as strings.
The flowchart denoting the process
of this script is shown below.
![]() |
Figure 2 Flowchart for Mod6Script_Pousa |
Overall, although coding can be challenging,
this class has demonstrated that code will save us time and energy in any of
our future GIS endeavors.