Showing posts with label GIS 4102/5103 GIS Programming. Show all posts
Showing posts with label GIS 4102/5103 GIS Programming. Show all posts

Friday, July 29, 2016

Module 11 - Sharing Tools

Our module this week took sharing scripts to the next level.  We learned to take an existing script, place it in a toolbox.  Once it was in our toolbox, we could now add various parameters using sys.argv[ ] avoiding hard coding paths.  While providing comments in a script is very useful, for someone unfamiliar with python, reading the script would be difficult.  The script tool uses a gui interface; this gui, is not automatically populated with descriptions about the various parameter.  Last week we learned where to place the description of the tool in the tool properties.  This week we learned how to use the Item Description tab in AcrCatalog to edit the syntax section for each of the parameters.  Adding information here provides built in help/guidance for the end user so that they know what type of information is expected for each parameter.  This allows them to execute the tool without a working knowledge of scripting.  Another advantage to using a script tool is that it can be embedded into the toolbox.  This allows for simpler sharing since only the toolbox would need to be shared, not the underlying script related to the tool.  In addition, once the script is embedded a password may be assigned.  The tool functionality is not affected by the password, but the ability to view and export the actual script is prohibited unless you know the password.   This prevents script piracy and ensures your hard work remains your hard work and others cannot take credit or modify its contents. The combined screenshots below illustrate the gui interface for the script tool and the results of utilizing said tool within ArcMap.




As this is our final blog post for the semester, we were asked to summarize the most memorable, interesting or useful things learned about Python with ArcGIS.  Honestly, the most memorable/useful thing from this course has been overcoming my fear of scripting.  After the first couple of assignments, I no longer dreaded the thought of tackling the next one.  This was huge for me and will greatly help not only future GIS work but also work involving other programming languages as I will not have the mental block I once had.  From the course overview perspective, I think the raster module will prove particularly useful and time saving in the future.  Additionally, the ability to setup scripts for repetitive tasks and be able to set them to use workspace parameters rather than hard coded locations is huge.  Combine that with the ability to share these time saving tasks with coworkers and you look like the department rock star.

Monday, July 25, 2016

Module 10 Creating Custom Tools

This week we focused on the use of custom tools to both automate workflow and share time saving processes with others.  Our goal was to create a tool box to house a script which would perform a clip on multiple objects.

Here are the notes from my process summary  about how to create a script tool and a valuable tip I learned, the hard way!
This list assumes you have a functional stand-along script named SAScript.py
1.       In either Arc Catalog or ArcMap, navigate to the location you want to create the script tool.
2.       Right click on the folder intended to house your script tool and select New, Toolbox.  Name your tool box.  In this case SAScript.tbx
3.       Right click SAScript.tbx and choose add script
4.       In the dialog box name your script (in this case SAScript); repeat in the label field and add a description of what your script does in the description field.  Toggle the Store relative path names to on before choosing next.
5.       Browse for your script file, choose open and then choose next.
6.       At this time, you can skip the adding parameters and just choose finish.
7.       Run the tool either in ArcCatalog or ArcMap; it will say there are no parameters but it will run and either work or return errors if your script has an issue.

8.       After checking this, right click on your script and choose properties.  You may know enter your parameters which will be dependent on the type of script you created.

TIP:  Don't overthink or apply "common sense" to the parameter properties.  Your output file location direction parameter should say Input!  If you change it to output as I did, the tool cannot write to an output file.  This will cause great consternation if you don't catch your mistake!



Tool dialog, Tool results and flow chart for creating the script tool:






Tuesday, July 19, 2016

Module 9 Working with Rasters

This module was all about working with rasters and the arcpy.sa module and functions.  We learned to list and describe raters, use them in geoprocessing, incorporate map algebra into the geoprocessing and use classes to define raster tool parameters.  Below you will find the area in which I struggled with the lab, my flowchart and my final raster result showing two classes, 0 and 1.

Which step did you have the most difficulty with? Describe 1) the problem you were having, and 2) the solution or correct steps to fix it. Be detailed with your explanation.
1.       I had the most trouble with the checking out of the spatial analyst extension.  Despite finding my code to appear accurate and the SA extension to be available my if else statement returned “The Spatial Analyst license is not available” from the else statement
2.       I carefully checked my code and the indentions.  All appeared correct.
3.       I confirmed within ArcMap that the extension was in fact toggled on, which it was.
4.       I closed ArcMap and ArcCatalog and checked the task manager to make sure nothing was open which would be using the license.
5.       I closed and reopened pythonwin, ran the script and received the same error.
6.       Online research indicated that this is a glitch and can often be resolved by rebooting.  I performed a reboot, but my script still returned the same message.
7.       Since I work locally, I tried doing the same steps in PythonWin on the Citrix server with the same results.
8.       I tried another reboot and when I still had no success, I rewrote the entire section of the script.  Success!


Saturday, July 9, 2016

Module 8 Geometries

Pseudocode:

#Import all modules, classes, enable overwrite output setting and set workspace, import file input,
START
set file output path
Set Variable for rivers.shp
Set Variable for text fie output rivers_RHamaty.txt
Create Search Cursor (.shp variable, OID@, SHAPE@, NAME)
Print “Search Cursor created and gathering information and creating results in text file”
      Create for loop for row in cursor
      Set vertexid equal to 0
      Create for loop for point in row 1; getPart(0)
            Output to text file (row 0 vertex id  x,y coordinate, row 2) “\n”
Close output file
Print “Text file created Successfully”
Delete Row
Delete Cursor

END



Tuesday, June 28, 2016

Module 7: Working with Spatial Data

This week we explored and manipulated spatial data by checking for, describing and listing data.  We worked with lists, dictionaries, Search Cursors, Update Cursors, Insert Cursors and learned to validate table and field names.  Here is a screen shot of this week’s script results in which we created a new geodatabase and populated it with information from an existing database.  Once created we listed the feature classes within our new database, used a Search Cursor and field delimiter to create a loop which would obtain names and populations for only County Seats.  This information was then used to update our empty dictionary; after updating, it was printed.

1.      I struggled with steps 6-8.  Initially I thought we were supposed to print the Search Cursor results which I was finally able to achieve after trying numerous variations of the exercises in the book and lab exercises.  I was finally able to get past my road block by adding Field Delimiter.  I then printed the resulting row.  As I moved on to the next section I realized we were supposed to develop a blend of steps 5-7 to achieve our results.  What was hanging me up with this portion was my placement of my empty dictionary creation.

2.      Once I placed my empty dictionary creating inside my for loop I was able to create variables for row 0 and row 1, update by dictionary and print the dictionary.



Saturday, June 18, 2016

Module 6: Python Geoprocessing

This week we practiced geoprocessing within the ArcMap Interactive Python Window and in PythonWin.   For short and sweet items which you might not use again, the interactive python win is fine; for more complicated scripts and those I might use in the future, I prefer PythonWin.  Here is my flowchart and the script results:

This lab was pretty straightforward, here are my process steps:
1.      I used yEdGraph Editor by yWorks to create a flow chart before beginning my script
2.      Once I had my flow chart, I reviewed the tool help for each of the functions in ArcDesktop
3.      Because the help menu is so thorough, it was extremely easy to write this script.

For those of you that have not used yEdGraph Editor it you should try it.  It makes flow charting extremely easy and is available as a free download with no adware.  


Monday, June 6, 2016

Participation Assignment #1 - “The Bureau of Land Management Uses Esri Story Maps to Encourage Public Land Exploration”

I found an interesting article through Directions Magazine.  This site provides links to GIS related information from multiple sources.  This particular article was in Esri Technology.  Titled “The Bureau of Land Management Uses Esri Story Maps to Encourage Public Land Exploration”, the article describes the recent evolution of improving information release to the public to encourage travel to our public lands.  Being a huge proponent of travel to State and Federal parks, this article caught my interest.  The Bureau of Land Management (BLM) has had a public awareness campaign called “My Public Lands”.  This campaign is now being enhanced using Esri Story Maps.  Bob Wick, a BLM wilderness specialist and photographer, published a series of travelogues every Tuesday last winter.  Known as the #traveltuesday campaign, this Tumblr blog extends the bureaus GIS into a public outreach tool via social media.  While an exciting step for the BLM, it is also a positive step forward for ESRI as they are beginning to see national organizations using Story Maps in new ways to engage the public.  Wick also produced a Summer Road Trip which was a photo journal through America’s forests, deserts and canyons.  This project was also based on the Esri Story Map Journal Template.  While this photo journal gave potential visitors a preview of what they could expect it did not offer quite as much as the #traveltuesday project which includes a personalized travel record including interactive maps of each of Wick’s destinations.  Wick, a 28-year veteran of the BLM is quite familiar with their GIS maps.  “ By integrating photography, multimedia and maps, the Esri Story Map journals bring America’s beautiful public landscapes to life…Our potential visitors can use the journals as real travel guides or the public can experience their lands virtually from any location.”  (Wick)  I think this travelogue is a fantastic idea.  I love the idea of having photography accompanied with GIS based maps of the site.  This article contained several links which are worth checking out if you have interest in our amazing Public Land System!  The link to the main article is:  http://www.directionsmag.com/pressreleases/the-bureau-of-land-management-uses-esri-story-maps-to-encourage-public-land/469535.  I hope you enjoy reading the article and exploring Wick’s story maps via the article’s links.

Monday, May 30, 2016

Module 3 Python Fundamentals Part 2

This weeks module continued with fundamentals of python adding paths, modules, conditional statements, loop structures, obtaining user input and commenting.  These items were used in conjunction with lists, strings, variables, data types and functions from the previous module.  Our task was to debug an existing script, add comments and then create a list of 20 random integers and once printed, count and remove the "unlucky" number.  This task used conditional statements and loop structures along with variables, lists, strings and casting.


Monday, May 23, 2016

Module 2 Python Fundamentals Part 1 - String me along.....

Process Summary Notes:
Part 1, Step 4: Calculate the length of your last name.
This step involves two separate actions that can be combined into one line of code, or can be done on two lines of code. Give a detailed explanation of how you completed this step.
1.       I assigned my full name as StringName and then used the split function to separate it into a list (variable listName).
2.       I created the variable lastNameLen and gave it a value of len(listName[1]).  This calculated the length of the last name item in my list.

I know it is still quite early in the semester, but I am enjoying python coding and finding it to be more simple than I had expected.  I think this is going to be an incredibly valuable skill for both GIS and critical thinking!

Below are my results and my flow chart.



Saturday, May 14, 2016

Module 1, Introducing Python......one more reason to love constrictors....

Ok, so it's not about constrictors, but they're still cool.  Who couldn't love the Pythonwin icon?  What a great addition to my taskbar and of course toolset!
The screenshot shown represents a series of folders and subfolders created instantaneously by running a Python Script.  This is a great time saver and I wish I had known this information last semester when I painstakingly created my class folders manually! 

Our task this week was quite straightforward.  I downloaded the specified .py file from the R: drive and placed it on my S: drive.  After right-clicking and choosing edit, I reviewed the contents of the script and then closed the window.  I ran the script by double-clicking rather than choosing run from within Pythonwin.  Once I saw the words process complete in the interface window I checked my Windows Explorer and noted that the 12 folders and respective sub-folders had been created.  A great tool I will modify and use in the future.  As an extra back-up and because I cannot access eLearning (during my lunch hour) from my office PC, I use my C drive on my laptop to complete my assignments and then copy those to the S: and H: drives.  I liked the ease of the CreateModuleFolders.py script; consequently, I modified it so that it created the same directory and folder structure on my laptop’s C: drive.  This will make uploading to my S and H drives very easy.  Because I often work locally, I downloaded and installed Pythonwin on my laptop.