Wednesday, July 15, 2015

Module 8 - Working with Geometries

This week's lab was a fun one. We read up on how to work with geometries, an interesting and informative topic that gave me new insight to feature classes. In the lab exercises we worked with geometries and creating a shapefile from a text file. For the main lab assignment we created a script that would create a new text file and write feature class attributes and vertices to the new file. 

While we are and were encouraged to write psuedocode to help organize our approach, I was still a little shaky on the concept of pseudocode, so I initially just dove right into playing with the code. After reading up a bit more on the simplicity of pseudocode, I created this one based on just reading the lab guidelines for what the script would/should do. There were a few things that changed or developed differently in the code itself, but this was a pretty basic good outline. 


Start
  Import modules
  import environment
  set workspace to …/Module8/Data
  enable overwriteOutput
  search cursor to call OID, Shape, Name from rivers.shp
  open new text file, enable write mode
  for loop for rows:
           Vertex variable = 0
           for loop for arrays using .getPart method:
                    vertex variable + 1
        method.write(OID +  “ “  + Vertex variable +  “ “ + “ “ + X coord + “ “ + Y coord +    
        Name)
        print (OID +  “ “  + Vertex variable +  “ “ + “ “ + X coord + “ “ + Y coord +  Name)
  close text file
  delete row
  delete cursor
End

The creation of the code went well, although I definitely had some challenges. The book and exercises were a very valuable resource this lab! Issues were mostly figuring out the proper syntax for the vertex variable adding 1 for each array, and the proper syntax for the write and print lines. Lots of code and print exploring there! To work through it I shortened the code to just a print statement after each part I was stuck on and worked the code until I got the result I wanted. For example, I got the vertex variable syntax correct, then I got the vertex, X, and Y strings correct, then the name (I went with replacement fields/format method for Name and OID), and finally with a simple addition of parentheses I got the OID to print/write correctly too. A fun evening of problem solving!


Results of script that searches and writes vertices and attributes from a shapefile to a newly created text file. 

No comments:

Post a Comment