Water Snake Programming: A simple technical report

By Casey J. McLaughlin

Sometimes GIS development is about making maps easier for other people.  ArcGIS’s Python Add-ins functionality is a really easy way of automating map tasks and making mapping easier for end-users.  My first add-in was really simple but also reminded me why I’m only a part-time programmer…..

Many years ago I built a map document for helping TMDL permit reviewers see what was going on in the watershed.  Users work in a database and when ready, open a document that displays the watershed.  There are 147 HUCs approximating watersheds in Region 7.  I wrote a VBA script that fires when the document is opened which goes and grabs the HUC_ID from a database generated text file.  The script then sets the definition query and zooms to the HUC.  When the map opens, the user can start working right in the area of interest.  It’s a fairly simple routine that saves users from a few simple steps.

All good things require updates and this summer the application needed a minor update – of course we also added 50+ data layers so maybe it wasn’t minor!  Besides data, the script I wrote 5+ years ago also needed revision, especially because ArcGIS has discontinued support for VBA.

Yes, ArcGIS Desktop 10 does support Microsoft VBA. However ArcGIS 10 is the last version with VBA support, so we encourage you to start the migration process.  Python is an integral part of ArcGIS Desktop for automating tasks and the new add-in capabilities allow developers to easily create and deploy ArcMap customizations

ESRI recommends migrating VBA code to Python.  I think this is fantastic – Python is an open source, easy to learn, widely supported, multi-use, and generally fun language.  When I first started writing Python, I spent an hour writing a program that had taken me a week in VBA (maybe a slight exaggeration but back then I felt programming in VBA was like getting turned into a newt…and yes, I got better).

ArcGIS now supports a really easy interface for creating Python add-ins.  The new method is really easy but I haven’t been programming in ArcGIS for awhile so I watched the 60 minute training video and immediately started programming (yes, I read the docs, honestly).   The program I wrote performs the same function; when opening a TMDL document, find the HUC_ID and zoom to it.

The python script:

 def openDocument(self)
 mxd = arcpy.mapping.MapDocument(“current”)
 mxd_name = os.path.splitext(os.path.basename(mxd.filePath))[0]
 ##Only try this if it is a TMDL document or in the TMDL directory
 if mxd_name.find("TMDL") == 0:
 #Open the IFO file and parse out the HUC ID
 ifo = mxd.filePath.rstrip(mxd.filePath[-3:]).upper() + "ifo"
 #check if it exists and then parse it out
 openFile = open(ifo, 'r')
 huc = openFile.readline().split(",")[2] ## Grabs the 3rd comma delimited element from the 1st line
 df = mxd.activeDataFrame
 lyr = arcpy.mapping.ListLayers(mxd, "8 Digit HUC", df)[0] ## Should look at source?
 lyr.definitionQuery = u"HUC_ID ='" + huc.strip() + "'"
 recordCount = len(arcpy.Describe(lyr).fidset.split(";")) ##Get number of features, if it is 1, zoom, otherwise it should error
 if recordCount == 1:
 df.extent = lyr.getExtent()
 arcpy.RefreshActiveView()
 else:
 pythonaddins.MessageBox(lyr.name + " found " + str(recordCount) + " records for HUC " + str(huc) ,"Error Selecting HUC", 0)
return

I was happy because I tested the script in the Python window in ArcGIS and it worked! I could make the startUp() function fire, but since none of the data was loaded, my function needed to be in openDocument(). Again, smooth sailing until I realized I couldn’t make the openDocument() function fire….or any function that wasn’t the startUp()! I didn’t find anything helpful during an internet search so I took a walk around the lake and a simple thought occurred to me about extensions. They need to be clicked ON to work! This was my gotcha moment – that time when I realized one little detail that I had overlooked.

I’m all done writing my extension and it works well-enough (suggestions are welcome). Now the users can zoom directly to their area of interest. Of course, I think it’d work better as a web map, but I’ll leave that for a future request, perhaps in 5 more years.

TMDL_EXAMPLE_APPLICATION

Casey McLaughlin is a first generation Geospatial Enthusiast who has worked with EPA since 2003 as a contractor and now as the Regional GIS Lead. He currently holds the rank of #1 GISer in EPA Region 7′s Environmental Services Division.

Editor's Note: The views expressed here are intended to explain EPA policy. They do not change anyone's rights or obligations. You may share this post. However, please do not change the title or the content, or remove EPA’s identity as the author. If you do make substantive changes, please do not attribute the edited title or content to EPA or the author.

EPA's official web site is www.epa.gov. Some links on this page may redirect users from the EPA website to specific content on a non-EPA, third-party site. In doing so, EPA is directing you only to the specific content referenced at the time of publication, not to any other content that may appear on the same webpage or elsewhere on the third-party site, or be added at a later date.

EPA is providing this link for informational purposes only. EPA cannot attest to the accuracy of non-EPA information provided by any third-party sites or any other linked site. EPA does not endorse any non-government websites, companies, internet applications or any policies or information expressed therein.

A Road Map for a Road Map: New NAS Study on Spatial Science

By Jeffery Robichaud

The National Academy of Science’s Committee on Spatial Data Enabling USG Strategic Science in the 21st Century (whew a mouthful) just released a report entitled Advancing Strategic Science: A Spatial Data Infrastructure Road Map for the U.S. Geological Survey.  I don’t know any of the professors that were on the committee, so I’m not sure if the use of “Road Map” is tongue in cheek but it certainly sounds like the groan-eliciting plays-on-words that I am known for. 

The United States Geological Survey (USGS) plays an important role in geospatial activities across the country, and at EPA we rely heavily on their work, especially GIS professional fan favorites such as the National Hydrography Dataset, the National Land-Cover Dataset, and the National Elevation Dataset.  We work closely with USGS both at the national level as well as here at the regional level.   Because of this relationship and some of our overlapping goals, I was interested to read the report and understand what we at EPA could take away.  Like all National Academy of Science works, this one will take several reads to fully sink in, but I did glean some overarching themes which resonated with me especially for geospatial activities within the public sector.

The importance of quick and meaningful data sharing and data discovery – In a world as fast as ours, decisions must get made all day, every day based on the information one has in hand.  It shouldn’t be surprising then that getting data into the hands of decision makers (either through sharing or ease of discovery) will lead us to more informed and hopefully better decisions, especially in emergency situations.     

Maintaining data over the long haul – All technology, including GIS, seems to move at such a rapid clip, that we as a society seem to love and covet the next big thing.  However, data doesn’t go bad…unless we let it by not maintaining the systems and the access to historical information.    

The importance of partners – It can’t be stressed enough that going it alone on a project may not yield the best results.  Strong partnerships can bring more resources to bear, tap into numerous specific and unique talents not accessible to a sole entity, and aid in the discovery of new markets for data and information.  

I encourage you to read the report as it is a thoughtful catalogue of the spatial data infrastructure challenges facing USGS as they move forward.   And please feel free to post your thoughts below, especially as the relate to road maps for infrastructure of environmental data.     

About the Author: Jeffery Robichaud is a second generation EPA scientist who has worked for the Agency since 1998. He currently serves as Deputy Director of EPA Region 7′s Environmental Services Division.

Editor's Note: The views expressed here are intended to explain EPA policy. They do not change anyone's rights or obligations. You may share this post. However, please do not change the title or the content, or remove EPA’s identity as the author. If you do make substantive changes, please do not attribute the edited title or content to EPA or the author.

EPA's official web site is www.epa.gov. Some links on this page may redirect users from the EPA website to specific content on a non-EPA, third-party site. In doing so, EPA is directing you only to the specific content referenced at the time of publication, not to any other content that may appear on the same webpage or elsewhere on the third-party site, or be added at a later date.

EPA is providing this link for informational purposes only. EPA cannot attest to the accuracy of non-EPA information provided by any third-party sites or any other linked site. EPA does not endorse any non-government websites, companies, internet applications or any policies or information expressed therein.

Do You Really Know Where You Are?

By Casey J. McLaughlin

Wikipedia: Mercator

Map projections have caused me great pain.  The standard Mercator map I grew up with became standard 500 years – shapes are well represented and any line drawn on the map represents a true compass bearing.  In other words, a Mercator map was incredibly useful for navigating and became the projection of choice for sea travel.  Take a step back and understand that a  projection is “a method by which the curved surface of the earth is portrayed on a flat surface” (ESRI GIS Dictionary).  Wikipedia has a good description of map projections. Seemingly a simple concept, there are several hundred types of projections.  Each has its own uses, but all flat maps contain distortion of some kind.

Greenland and Antarctica appear as huge white areas.  Notice the grid cells at the top and bottom are quite long.  This projection distorts area as you travel away from the equator.  Would you it surprise you that in reality, Africa is 14 times larger than Greenland?!   On the television series, “The West Wing” (Season 2, episode 16) character Josh Lyman asks a group of cartographers:

“Relative size is one thing, but you’re telling me Germany isn’t where we think it is?”

Dr. Fallow responds:   “Nothing is where you think it is.

Maps Without Bordes: Gall-Peters Projection

Casey McLaughlin is a first generation Geospatial Enthusiast who has worked with EPA since 2003 as a contractor and now is the Regional GIS Lead. He currently holds the rank of #1 GISer in the EPA Region 7′s Environmental Services Division.

Editor's Note: The views expressed here are intended to explain EPA policy. They do not change anyone's rights or obligations. You may share this post. However, please do not change the title or the content, or remove EPA’s identity as the author. If you do make substantive changes, please do not attribute the edited title or content to EPA or the author.

EPA's official web site is www.epa.gov. Some links on this page may redirect users from the EPA website to specific content on a non-EPA, third-party site. In doing so, EPA is directing you only to the specific content referenced at the time of publication, not to any other content that may appear on the same webpage or elsewhere on the third-party site, or be added at a later date.

EPA is providing this link for informational purposes only. EPA cannot attest to the accuracy of non-EPA information provided by any third-party sites or any other linked site. EPA does not endorse any non-government websites, companies, internet applications or any policies or information expressed therein.