<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>super-cooper &#187; gis</title>
	<atom:link href="http://www.super-cooper.com/archive/tag/gis/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.super-cooper.com</link>
	<description>Python, GIS, and a sprinkling of mindless drivel from Chad Cooper</description>
	<lastBuildDate>Wed, 08 Dec 2010 02:12:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Python and GIS &#8211; Beyond ModelBuilder and PythonWin</title>
		<link>http://www.super-cooper.com/archive/2008/11/15/python-and-gis-beyond-modelbuilder-and-pythonwin/</link>
		<comments>http://www.super-cooper.com/archive/2008/11/15/python-and-gis-beyond-modelbuilder-and-pythonwin/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 16:14:03 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=62</guid>
		<description><![CDATA[This is a presentation I gave last February at the ESRI Petroleum User Group conference in Houston, TX. I just discovered SlideShare the other day. Python And GIS &#8211; Beyond Modelbuilder And Pythonwin View SlideShare presentation or Upload your own. (tags: esri pug)]]></description>
			<content:encoded><![CDATA[<p>This is a presentation I gave last February at the ESRI Petroleum User Group conference in Houston, TX. I just discovered <a href="http://www.slideshare.net">SlideShare</a> the other day.</p>
<div style="width:425px;text-align:left" id="__ss_716653"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/supercooper/python-and-gis-beyond-modelbuilder-and-pythonwin-presentation?type=powerpoint" title="Python And GIS - Beyond Modelbuilder And Pythonwin">Python And GIS &#8211; Beyond Modelbuilder And Pythonwin</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=pythonandgisbeyondmodelbuilderandpythonwin-1225719286857699-8&#038;rel=0&#038;stripped_title=python-and-gis-beyond-modelbuilder-and-pythonwin-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=pythonandgisbeyondmodelbuilderandpythonwin-1225719286857699-8&#038;rel=0&#038;stripped_title=python-and-gis-beyond-modelbuilder-and-pythonwin-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/supercooper/python-and-gis-beyond-modelbuilder-and-pythonwin-presentation?type=powerpoint" title="View Python And GIS - Beyond Modelbuilder And Pythonwin on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/esri">esri</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/pug">pug</a>)</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/11/15/python-and-gis-beyond-modelbuilder-and-pythonwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m published in ArcUser!</title>
		<link>http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/</link>
		<comments>http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 14:46:16 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[publications]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/</guid>
		<description><![CDATA[My (hopefully first of many) article on GIS and Python has been published in the Spring 2008 edition of ESRI&#8217;s ArcUser magazine. You can get the pdf here , and the code listings here .]]></description>
			<content:encoded><![CDATA[<p>My (hopefully first of many) article on GIS and Python has been published in the Spring 2008 edition of ESRI&#8217;s <a href="http://www.esri.com/news/arcuser/index.html">ArcUser</a> magazine. You can get the pdf <a href="http://www.esri.com/news/arcuser/0708/files/tappingpython.pdf">here</a> , and the code listings <a href="http://www.esri.com/news/arcuser/0708/files/tappingpython.txt">here</a> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mapping point locations with Python and Microsoft Live Search Maps</title>
		<link>http://www.super-cooper.com/archive/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/</link>
		<comments>http://www.super-cooper.com/archive/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 03:04:43 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[publications]]></category>
		<category><![CDATA[pymag]]></category>

		<guid isPermaLink="false">http://super-cooper.com/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/</guid>
		<description><![CDATA[This article was first published in the February 2008 issue of Python Magazine . It is being reproduced here with the permission of Marco Tabini and Associates . Requirements Python 2.4+ pyExcelerator module (http://sourceforge.net/projects/pyexcelerator/ ) Anthony Tuininga&#8217;s ceODBC module (http://sourceforge.net/html/ceODBC.html ) John Machin&#8217;s xlrd module (http://www.lexicon.net/sjmachin/xlrd.htm ) Michael Foord&#8217;s cgiutils module (http://www.voidspace.org.uk/python/cgiutils.html ) Lets face [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>This article was first published in the <a href="http://pymag.phparch.com/c/issue/view/68">February 2008</a> issue of <a href="http://pymag.phparch.com/">Python Magazine</a> . It is being reproduced here with the permission of <a href="http://tabini.ca/">Marco Tabini and Associates</a> .</strong> </em></p>
<p><strong>Requirements</strong></p>
<p>Python 2.4+<br />
pyExcelerator module (<a href="http://sourceforge.net/projects/pyexcelerator/">http://sourceforge.net/projects/pyexcelerator/</a> )<br />
Anthony Tuininga&#8217;s ceODBC module (<a href="http://sourceforge.net/html/ceODBC.html">http://sourceforge.net/html/ceODBC.html</a> )<br />
John Machin&#8217;s xlrd module (<a href="http://www.lexicon.net/sjmachin/xlrd.htm">http://www.lexicon.net/sjmachin/xlrd.htm</a> )<br />
Michael Foord&#8217;s cgiutils module (<a href="http://www.voidspace.org.uk/python/cgiutils.html">http://www.voidspace.org.uk/python/cgiutils.html</a> )</p>
<p><strong>Lets face it, using Python, we can pull data from virtually anywhere in the corporate enterprise &#8211; databases, text files, or other documents. But how can we easily visualize data that has <em>place</em> associated with it? Well, we turn to Python and the API of a popular web-mapping application, that&#8217;s how.</strong></p>
<p><span id="more-50"></span></p>
<p>I was recently tasked with finding a way to routinely (read daily) present a dataset of point locations on a onscreen map to our team of 40 or so people. <a href="http://www.super-cooper.com/images/pymag/figure1.jpg" rel="lightbox[50]"><img class="left" src="http://farm4.static.flickr.com/3035/2417154257_f1ff68e5c4_m.jpg" alt="figure1" width="240" height="195" /> </a> I needed a way to easily disseminate some sort of map product that would display the data, something that required no special software setup on PCs &#8211; and most importantly &#8211; something that would be easy and intuitive for our team members to use. I thought about providing a PDF map product &#8211; I would have to harvest the data, process it, plot it on a map using mapping software, and email the final product to my team members as an attachment. Doesn&#8217;t sound like much fun, does it? Oh, and did I mention that those would all be <em>manual</em> processes to be completed once per day? While pondering this not-so-desirable methodology, I ran across a clever method used by our Information Technology team that passed locational data in a URL to Microsoft Live Maps. Their process takes point locations (in the form of latitude and longitude) from SQL Server, and using VB.Net and the Microsoft Live Search Maps URL API, builds a URL that plots well locations on a Live Search Maps web map. This was it, I would harvest the data, process it, build my URL using the Live Search Maps URL API, and send out the URL to my team nightly in a email. And I would do all of this using Python.</p>
<p><strong>Example dataset</strong></p>
<p>The dataset I needed to map is a gas well drilling schedule stored in a Microsoft Office Excel 2003 workbook. Rows in the workbook represent natural gas wells on the schedule and each has attributes associated with it such as well name, latitude, longitude, and the date drilling commenced; or spud date, as it is called in the oil and gas industry. The schedule gets updated at least daily, and in this line of business, plans can change every hour &#8211; literally. However, it was decided that a process that mapped the locations of the wells on a daily basis would suffice. Also note that, as will be demonstrated later, you don&#8217;t necessarily need point locations with latitude and longitude to  benefit from this process; address locations can be used also.</p>
<p><strong>Choosing a web mapping application<em></em> </strong></p>
<p>When first exploring the option of using a existing web mapping service to plot my well locations, I looked into most of the popular services out there: Google Maps (http://maps.google.com/, my personal favorite for the up-to-date aerial photography and ability to save your own maps, among other things), Yahoo! Maps (http://maps.yahoo.com/), and Microsoft Live Search Maps (http://maps.live.com/ &#8211; Figure 1). As stated earlier, our IT team had chosen Live Search Maps for an earlier application, and I soon learned the reason in doing so is that at the time, Live Search Maps was the only service out there which provided the ability to pass in multiple point locations to plot via latitude and longitude through the URL string. This was very important to the process, as I want to simply pass in all of my well locations through the URL, and then provide this URL to my team members.</p>
<p><strong>Features of Microsoft Live Search Maps</strong></p>
<p>Aside from the already-discussed feature  of passing in multiple locations through the URL string, another great feature of Live Search Maps is the Scratch Pad &#8211; think of it as a &quot;table of contents&quot; for your map (Figure 2). <a href="http://www.super-cooper.com/images/pymag/figure2.png" rel="lightbox[50]"><img class="left" src="http://farm3.static.flickr.com/2260/2417972484_a718030ff0_m.jpg" alt="figure2" width="164" height="240" /> </a> The URL API (which will be discussed shortly) provides us the ability to create a scratch pad which lists each item and a description in a list on the right side of our map. Users can then see a scrollable list of all items that are currently plotted on the map. Also included in the Scratch Pad is the ability to zoom to street, city, or regional levels, send a location in an email, or obtain driving directions to or from a location. No other mapping service was able to provide these capabilities. So using Live Search Maps, my team members would be provided with a somewhat &quot;traditional&quot; web mapping interface that would be easy and intuitive to use, and with the Scratch Pad, they would be given a list of the mapped locations as well as the point locations plotted on the map.</p>
<p><strong>Microsoft Live Search Maps URL API</strong></p>
<p>The Live Search Maps Online Help (<a href="http://help.live.com/Help. aspx?market=en-US&amp;project=WL_Local&amp;querytype=topic&amp;query=WL_ LOCAL_PROC_BuildURL.htm">http://help.live.com/Help. aspx?market=en-US&amp;project=WL_Local&amp;querytype=topic&amp;query=WL_ LOCAL_PROC_BuildURL.htm</a> ) provides us with full documentation to the Live Search Maps URL API. I won&#8217;t go over everything, but I will cover what parts this process uses to build a URL &#8211; you can read the rest at your leisure. The API is fairly simple and straightforward. The first step is to build your standard Live Search Maps URL base &#8211; it&#8217;s always the same:</p>
<p><code>http://maps.live.com/default.aspx?</code></p>
<p>Next, you start to add your parameters. For us, that means set the map style. There are four options to choose from: aerial photo (a), road map (r), hybrid &#8211; aerial photo with labels and some roads (h), and oblique &#8211; commonly referred to as &quot;bird&#8217;s eye view&quot; (o). For this application I decided to use the road map view, since it would provide towns, cities, and major roads &#8211; all labeled &#8211; for users to orient themselves by:</p>
<p><code>http://maps.live.com/default.aspx?style=r</code></p>
<p>Next, we start to define and add our custom annotations to pass in and add to the Scratch Pad. For annotations, the form is:</p>
<p><code>sp=an.latitude_longitude_title_description</code></p>
<p>Latitude and longitude are obviously the locational information for the well, and you are given the option of adding a title and description (they end up on different lines in the scratch pad). So our URL now becomes something like so for the USA 1-18 well set to spud on 11/12/2007 and drilled by rig Smith #2 (note the encoding values used for the dash in the well name and the pound symbol in the rig name &#8211; don&#8217;t forget to encode all of your special characters in your URL string):</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith%202">http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith%202</a> </code></p>
<p>Basically, thats it! Copy and paste the URL above into your web browser and you will get a Live Search Maps map with the USA 1-18 well on the map and in the Scratch Pad. To add additional point locations to the URL, simply add a tilde and the next custom annotation(s):</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith%202~an.35.0878763351_-93.5096775211_Jones%2013-13_11/01/2007%20-%20Smith%2035">http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith<br />
%202~an.35.0878763351_-93.5096775211_Jones%2013-13_11/01/2007%20-%20Smith%2035</a> </code></p>
<p><strong>Harvesting and processing the Excel data</strong></p>
<p>Before we can build our map, we have to get the data out of our Excel workbook. As Figure 3 shows, the worksheet layout is fairly simple. The columns represent, from left to right, well name, spud date (date the well started drilling), total depth, or TD date (the date the well finished drilling and reached total depth), latitude, longitude, and drilling rig number. To harvest our data from the workbook, we will enlist the help of the <strong>PyExcelerator</strong> module (<a href="http://sourceforge.net/projects/pyexcelerator">http://sourceforge.net/projects/pyexcelerator</a> ) and a function that comes with the docs &#8211; which worked right out of the box! Essentially we read the Excel workbook and return a list of lists, where each nested list represents a row in our worksheet. The entire function for parsing the Excel workbook can be found in Listing 1.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">import</span> pyExcelerator, <span style="color: #990000;">os</span>, <span style="color: #990000;">time</span>, <span style="color: #990000;">string</span>, <span style="color: #990000;">calendar</span>, <span style="color: #990000;">datetime</span></code></li>
<li value="2" class="tab0 even"><code><span style="color: #0008E6;font-weight:bold;">import</span> <span style="color: #990000;">smtplib</span>, cgiutils, xldate, DateTime, EmailRecips</code></li>
<li value="3" class="odd">&nbsp;</li>
<li value="4" class="tab0 even"><code><span style="color: #990000;font-weight:bold;">def</span> ExcelToList<span style="color: black;">&#40;</span>fname, worksheet=<span style="color: #FF0000; font-weight: bold;">0</span>, encoding=<span style="color: #2DB300;">'cp1251'</span><span style="color: black;">&#41;</span>:</code></li>
<li value="5" class="tab1 odd"><code>data = pyExcelerator.<span style="color: black;">parse_xls</span><span style="color: black;">&#40;</span>fname,encoding<span style="color: black;">&#41;</span></code></li>
<li value="6" class="tab1 even"><code>sheet_name=data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding<span style="color: black;">&#41;</span></code></li>
<li value="7" class="tab1 odd"><code>values = data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="8" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="9" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">print</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span>:<span style="color: #FF0000; font-weight: bold;">-1</span><span style="color: black;">&#93;</span></code></li>
<li value="10" class="tab1 even"><code>vdict = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="11" class="tab1 odd"><code>row_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="12" class="tab1 even"><code>col_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="13" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row_idx, col_idx <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>values.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="14" class="tab2 even"><code>row_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>row_idx,row_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="15" class="tab2 odd"><code>col_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>col_idx,col_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="16" class="tab2 even"><code>v = values<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx, col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>v, <span style="color: #008000;">unicode</span><span style="color: black;">&#41;</span>:</code></li>
<li value="18" class="tab3 even"><code>v = v.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding, <span style="color: #2DB300;">'backslashreplace'</span><span style="color: black;">&#41;</span></code></li>
<li value="19" class="tab2 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx,col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = v</code></li>
<li value="20" class="tab1 even"><code>vlist = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="21" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>row_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="22" class="tab2 even"><code>vlist.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="23" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> col <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>col_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="24" class="tab3 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span> <span style="color: #0008E6;font-weight:bold;">not</span> <span style="color: #0008E6;font-weight:bold;">in</span> vdict:</code></li>
<li value="25" class="tab4 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>=<span style="color: #008000;">None</span></code></li>
<li value="26" class="tab3 even"><code>vlist<span style="color: black;">&#91;</span>row<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="27" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> vlist</code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing1.txt">listing1.txt</a></li>
</ol>
<p><a href="http://www.super-cooper.com/images/pymag/figure3.png" rel="lightbox[50]"><img class="left" src="http://farm4.static.flickr.com/3174/2417972468_ec4c259180_m.jpg" alt="figure3" width="240" height="112" /> </a></p>
<p>The first step in <strong>ExcelToList</strong> utilizes the parse_xls method of pyExcelerator, which returns a list of two-tuples; one tuple for each worksheet in the workbook where each tuple consists of the worksheet name and worksheet data. The worksheet data is a dictionary mapping each non-blank cell to its cell value:</p>
<p><code>import pyExcelerator, os, time, string, calendar, datetime,<br />
import smtplib, cgiutils, xldate, DateTime<br />
data = pyExcelerator.parse_xls(filename, encoding)</code></p>
<p>Which returns:</p>
<p><code>[('Sheet1', {(0, 1): 39412.0,<br />
(1, 2): 39437.0,<br />
(2, 4): -93.600387566799995,<br />
(0, 0): 'Smith #2-3',<br />
(2, 0): 'Coop #4-17',<br />
(2, 2): 39452.0,<br />
(1, 4): -94.856870378300002,<br />
(1, 1): 39421.0,<br />
(1, 5): 'Rig 4',<br />
(1, 3): 34.831162240499999,<br />
(0, 5): 'Rig 67',<br />
(2, 1): 39431.0,<br />
(2, 5): 'Rig 23',<br />
(0, 4): -97.340309266600002,<br />
(1, 0): 'Jones #1-19',<br />
(2, 3): 35.232594439099998,<br />
(0, 3): 35.276017337600003,<br />
(0, 2): 39430.0}),<br />
('Sheet2', {}),<br />
('Sheet3', {})]</code></p>
<p>Note that we returned a three-item list, but the dictionaries for Sheets 2 and 3 are empty, as there is no data in those worksheets. From this we get the dictionary for the worksheet we want out of the list data (where <code>worksheet=0</code> ):</p>
<p><code>values = data[worksheet][1]</code></p>
<p>Which returns:</p>
<p><code>{(0, 1): 39412.0,<br />
(1, 2): 39437.0,<br />
(2, 4): -93.600387566799995,<br />
(0, 0): 'Smith #2-3',<br />
(2, 0): 'Coop #4-17',<br />
(2, 2): 39452.0,<br />
(1, 4): -94.856870378300002,<br />
(1, 1): 39421.0,<br />
(1, 5): 'Rig 4',<br />
(1, 3): 34.831162240499999,<br />
(0, 5): 'Rig 67',<br />
(2, 1): 39431.0,<br />
(2, 5): 'Rig 23',<br />
(0, 4): -97.340309266600002,<br />
(1, 0): 'Jones #1-19',<br />
(2, 3): 35.232594439099998,<br />
(0, 3): 35.276017337600003,<br />
(0, 2): 39430.0}</code></p>
<p>Sorted, it&#8217;s much easier to see what&#8217;s going on:</p>
<p><code>for each in sorted(data[0][1].items()):<br />
print str(each)[1:-1]</code></p>
<p><code>(0, 0), 'Smith #2-3'<br />
(0, 1), 39412.0<br />
(0, 2), 39430.0<br />
(0, 3), 35.276017337600003<br />
(0, 4), -97.340309266600002<br />
(0, 5), 'Rig 67'<br />
(1, 0), 'Jones #1-19'<br />
(1, 1), 39421.0<br />
(1, 2), 39437.0<br />
(1, 3), 34.831162240499999<br />
(1, 4), -94.856870378300002<br />
(1, 5), 'Rig 4'<br />
(2, 0), 'Coop #4-17'<br />
(2, 1), 39431.0<br />
(2, 2), 39452.0<br />
(2, 3), 35.232594439099998<br />
(2, 4), -93.600387566799995<br />
(2, 5), 'Rig 23'</code></p>
<p>Here again, keys represent the cell mappings (Excel cell <code>A1 = (0,0)</code> ) and values represent the data within the cell. Next, we iterate through our <strong>values</strong> object, putting our key/value cell reference/cell value pairs into the <strong>vdict</strong> object and getting the maximum number of rows and colums (lines 10-19, Listing 1):</p>
<p>Here, our max is 2 rows and 5 columns, since it is zero- based. Finally, we iterate through our <strong>vdict</strong> object, converting it to a two-dimensional list with each list item representing a row in our Excel worksheet. Blank cells are represented by <code>None</code> :</p>
<p><code>vlist = []<br />
for row in range(row_idx_max+1):<br />
vlist.append([])<br />
for col in range(col_idx_max+1):<br />
if (row,col) not in vdict:<br />
vdict[(row,col)]=None<br />
vlist[row].append(vdict[(row,col)])</code></p>
<p>Our end product returned from <strong>ExcelToList</strong> looks like so:</p>
<p><code>[['Smith #2-3', 39412.0, 39430.0, 35.276017337600003, -97.340309266600002, 'Rig 67'],<br />
['Jones #1-19', 39421.0, 39437.0, 34.831162240499999, -94.856870378300002, 'Rig 4'],<br />
['Coop #4-17', 39431.0, 39452.0, 35.232594439099998, -93.600387566799995, 'Rig 23']]</code></p>
<p>Now we have a nice list that we can simply iterate through and process later.</p>
<p><strong>But Wait a Minute! My Data is in <em>&lt;insert your database engine here&gt;</em> ! How do I get it out to use for something like this?</strong></p>
<p>Never fear, if your data is in a RDBMS, you&#8217;re actually better off. If you don&#8217;t already have it, head on over to SourceForge and pick up Anthony Tuininga&#8217;s great ODBC module <strong>ceODBC</strong> (<a href="http://ceodbc.sourceforge.net/html/ceODBC.html">http://ceodbc.sourceforge.net/html/ceODBC.html</a> ) that will allow you to connect to your database. I tested it on SqlServer and DB2 with great success. Listing 2 demostrates how to use ceODBC with SqlServer.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #0008E6;font-weight:bold;">import</span> ceODBC</code></li>
<li value="2" class="tab0 even"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=ceODBC.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'DSN=Wells'</span><span style="color: black;">&#41;</span></code></li>
<li value="3" class="tab0 odd"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> c=db.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="4" class="tab0 even"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> c.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'select wellname, latitudedecimal,</span></code></li>
<li value="5" class="tab0 odd"><code>... <span style="color: black;">longitudedecimal</span> <span style="color: #0008E6;font-weight:bold;">from</span> dbo.<span style="color: black;">wells</span> where wellid <span style="color: #0008E6;font-weight:bold;">in</span></code></li>
<li value="6" class="tab0 even"><code>... <span style="color: black;"><span style="color: black;">&#40;</span></span><span style="color: #FF0000; font-weight: bold;">11587</span>,<span style="color: #FF0000; font-weight: bold;">11194</span>,<span style="color: #FF0000; font-weight: bold;">11157</span><span style="color: black;">&#41;</span><span style="color: #2DB300;">')</span></code></li>
<li value="7" class="tab0 odd"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> c.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="8" class="tab0 even"><code>... &nbsp; &nbsp; <span style="color: #0008E6;font-weight:bold;">print</span> each</code></li>
<li value="9" class="tab0 odd"><code>...</code></li>
<li value="10" class="tab0 even"><code><span style="color: black;">&#40;</span><span style="color: #2DB300;">'GILL #1-18'</span>, <span style="color: #FF0000; font-weight: bold;">33.095599</span>, <span style="color: #FF0000; font-weight: bold;">-92.38563</span><span style="color: black;">&#41;</span></code></li>
<li value="11" class="tab0 odd"><code><span style="color: black;">&#40;</span><span style="color: #2DB300;">'HOW #2-7'</span>, <span style="color: #FF0000; font-weight: bold;">35.10155</span>, <span style="color: #FF0000; font-weight: bold;">-91.48824</span><span style="color: black;">&#41;</span></code></li>
<li value="12" class="tab0 even"><code><span style="color: black;">&#40;</span><span style="color: #2DB300;">'JKK #11-13'</span>, <span style="color: #FF0000; font-weight: bold;">34.09130</span>, <span style="color: #FF0000; font-weight: bold;">-93.45256</span><span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing2.txt">listing2.txt</a></li>
</ol>
<p>This method employs a User DSN I created in the Windows ODBC Administator which uses my Windows credentials to log on to SqlServer. Of course, there are a plethora of database connectivity modules out there, so use whichever you want.</p>
<p><strong>Building the Live Search Maps URL</strong></p>
<p>Now that we have all of our data from the Excel workbook (or RDBMS), we can use it to build Scratch Pad annotations and eventually our URL. Based on the URL API, this looks easy enough, but let&#8217;s perform a few other litle tricks that will make things display much nicer in the Scratch Pad. First, we need to set our URL base:</p>
<p><code>urlBase = 'http://maps.live.com/default.aspx?style=r'</code></p>
<p>Now we need to iterate through our well data list from our Excel workbook, place the list items into namespaces and perform some processing on some of them, then build a annotation string from each one. There are two functions we should discuss first. You may have noticed earlier that after we slurp our data out of our Excel workbook, we are left with date values that look like <strong>39430.0</strong> and <strong>39452.0</strong> . Huh? Many of you will recognize these as Excel dates. Excel stores dates as floating point numbers; the number of days (or fraction thereof) since 12/31/1899, to be exact. For example, 9/20/2006 is actually 38980 to Excel; Excel just formats it to look like a date for simplicity of viewing. To deal with Excel dates and turn them into something I could actually use, I turned to the <strong>xlrd</strong> module (<a href="http://www.lexicon.net/sjmachin/xlrd.htm">http://www.lexicon.net/sjmachin/xlrd.htm</a> ) and its function xldate_as_tuple. Also, to get the well status, we assume that anytime today&#8217;s date falls within the window greater than or equal to spud date (beginning of drilling) and less than or equal to td date (end of drilling), that well is currently drilling. We&#8217;d like to know this and denote it in the Scratch Pad, so we determine each wells status. And if indeed the well is drilling, we note it in our annotation (Listing 3).</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> GetWellStatus<span style="color: black;">&#40;</span>inSpudDt, inPrjTdDt<span style="color: black;">&#41;</span>:</code></li>
<li value="2" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span> <span style="color: #0008E6;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span>:</code></li>
<li value="3" class="tab2 odd"><code>today1 = <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="4" class="tab2 even"><code>today = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="5" class="tab5 odd"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="6" class="tab5 even"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="7" class="tab2 odd"><code>spudDt = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,</code></li>
<li value="8" class="tab6 even"><code>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="9" class="tab2 odd"><code>prjTdDt = <span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,</code></li>
<li value="10" class="tab8 even"><code>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="11" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> today <span style="color: #66cc66;">&gt;</span> prjTdDt:</code></li>
<li value="12" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilled'</span></code></li>
<li value="13" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&gt;</span>= spudDt <span style="color: #0008E6;font-weight:bold;">and</span> today <span style="color: #66cc66;">&lt;</span>= prjTdDt:</code></li>
<li value="14" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilling'</span></code></li>
<li value="15" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&lt;</span> spudDt:</code></li>
<li value="16" class="tab3 even"><code>status = <span style="color: #2DB300;">'Proposed'</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="18" class="tab3 even"><code>status = <span style="color: #2DB300;">'Unknown'</span></code></li>
<li value="19" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="20" class="tab2 even"><code>status = <span style="color: #2DB300;">'Undeterminable'</span></code></li>
<li value="21" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> status</code></li>
<li value="22" class="even">&nbsp;</li>
<li value="23" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> KillObject<span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="24" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="25" class="tab2 odd"><code><span style="color: #990000;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span></code></li>
<li value="26" class="even">&nbsp;</li>
<li value="27" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> WriteOutput<span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, text<span style="color: black;">&#41;</span>:</code></li>
<li value="28" class="tab1 even"><code>writer = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, <span style="color: #2DB300;">'a'</span><span style="color: black;">&#41;</span></code></li>
<li value="29" class="tab1 odd"><code>writer.<span style="color: black;">write</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span></code></li>
<li value="30" class="even">&nbsp;</li>
<li value="31" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, ds<span style="color: black;">&#41;</span>:</code></li>
<li value="32" class="tab1 even"><code>urlBase = <span style="color: #2DB300;">'http://maps.live.com/default.aspx?style=r'</span></code></li>
<li value="33" class="tab1 odd"><code>wholeList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="34" class="tab1 even"><code><span style="color: #008000;">dict</span> = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="35" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> well <span style="color: #0008E6;font-weight:bold;">in</span> wells:</code></li>
<li value="36" class="tab2 even"><code>eachList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="37" class="tab2 odd"><code>name = <span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'#'</span>,<span style="color: #2DB300;">'%23'</span><span style="color: black;">&#41;</span></code></li>
<li value="38" class="tab2 even"><code>spudDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="39" class="tab2 odd"><code>spudDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="40" class="tab2 even"><code>tdDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="41" class="tab2 odd"><code>tdDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="42" class="tab2 even"><code>lat = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">3</span><span style="color: black;">&#93;</span></code></li>
<li value="43" class="tab2 odd"><code><span style="color: #008000;">long</span> = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">4</span><span style="color: black;">&#93;</span></code></li>
<li value="44" class="tab2 even"><code>rig = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">5</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span></code></li>
<li value="45" class="tab2 odd"><code>status = GetWellStatus<span style="color: black;">&#40;</span>spudDateTuple, tdDateTuple<span style="color: black;">&#41;</span></code></li>
<li value="46" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> status == <span style="color: #2DB300;">'Drilling'</span>:</code></li>
<li value="47" class="tab3 odd"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="48" class="tab3 even"><code><span style="color: #2DB300;">'%20-%20'</span> + rig + <span style="color: #2DB300;">'%20-%20'</span> + status.<span style="color: black;">upper</span><span style="color: black;">&#41;</span></code></li>
<li value="49" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="50" class="tab3 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="51" class="tab3 odd"><code><span style="color: #2DB300;">'%20-%20'</span> + rig<span style="color: black;">&#41;</span></code></li>
<li value="52" class="tab2 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>spudDate<span style="color: black;">&#41;</span></code></li>
<li value="53" class="tab2 odd"><code>wholeList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>eachList<span style="color: black;">&#41;</span></code></li>
<li value="54" class="tab1 even"><code>wholeList.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #0008E6;font-weight:bold;">lambda</span> x,y:<span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,y<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="55" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> whole <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="56" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">print</span> whole</code></li>
<li value="57" class="tab1 odd"><code>urlList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="58" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="59" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">del</span> each<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="60" class="tab2 even"><code>wellString = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span>:<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: #FF0000; font-weight: bold;">-3</span><span style="color: black;">&#93;</span></code></li>
<li value="61" class="tab2 odd"><code>urlList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>wellString<span style="color: black;">&#41;</span></code></li>
<li value="62" class="tab1 even"><code>urlStringWells = <span style="color: #990000;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>urlList,<span style="color: #2DB300;">'~'</span><span style="color: black;">&#41;</span></code></li>
<li value="63" class="tab1 odd"><code>masterUrl = urlBase + <span style="color: #2DB300;">'&amp;sp='</span> + urlStringWells + <span style="color: #2DB300;">'~an.36.1164211465469_-94.143074863021_SEECO%</span></code></li>
<li value="64" class="tab1 even"><code>20Fayetteville<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.513123_<span style="color: #FF0000; font-weight: bold;">-93</span>.834189_SWN<span style="color: #66cc66;">%</span>20Ozark<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.0685432008022_</code></li>
<li value="65" class="tab1 odd"><code><span style="color: #FF0000; font-weight: bold;">-92</span>.4189197874021_SWN<span style="color: #66cc66;">%</span>20Conway<span style="color: #66cc66;">%</span>20Office~an.<span style="color: #2DB300;">'</span></code></li>
<li value="66" class="tab1 even"><code>f = <span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span></code></li>
<li value="67" class="tab1 odd"><code>t = <span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span></code></li>
<li value="68" class="tab1 even"><code>dsUpdated = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y, %I:%M %p'</span>, <span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">getmtime</span><span style="color: black;">&#40;</span>ds<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="69" class="tab1 odd"><code>KillObject<span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span></code></li>
<li value="70" class="tab1 even"><code>KillObject<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span></code></li>
<li value="71" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;style type=&quot;text/css&quot;&gt;body,table {font-family:Verdana;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="72" class="tab4 even"><code>font-size:10pt<span style="color: #66cc66;">;</span>empty-cells: show<span style="color: black;">&#125;</span>\n<span style="color: #66cc66;">&lt;</span>/style<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/head<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>\n<span style="color: #2DB300;">')</span></code></li>
<li value="73" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;table style=&quot;width: 700px&quot;&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;h3&gt;AAT Drill Schedule Mapper for '</span>\</code></li>
<li value="74" class="tab4 even"><code>+ <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'&lt;/h3&gt;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="75" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;Drill schedule last updated: '</span> + dsUpdated + <span style="color: #2DB300;">'&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span>\</code></li>
<li value="76" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="77" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;a href=&quot;'</span> + masterUrl + <span style="color: #2DB300;">'&quot;&gt;Click here for a map of the latest<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="78" class="tab4 even"><code>AAT drill schedule<span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="79" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="80" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;*** THIS MESSAGE AUTO-GENERATED ***&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="81" class="tab4 odd"><code><span style="color: #66cc66;">***</span> PLEASE DO NOT REPLY TO THIS EMAIL <span style="color: #66cc66;">***&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="82" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/html&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="83" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'AAT Drill Schedule Mapper for '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>\</code></li>
<li value="84" class="tab4 even"><code>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="85" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Drill schedule last updated: '</span> + dsUpdated<span style="color: black;">&#41;</span></code></li>
<li value="86" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Copy and paste this address into your web broswer:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span> + masterUrl<span style="color: black;">&#41;</span></code></li>
<li value="87" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>** This message auto-generated - please do not respond to this email ***'</span><span style="color: black;">&#41;</span></code></li>
<li value="88" class="even">&nbsp;</li>
<li value="89" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> SendEmail<span style="color: black;">&#40;</span>message, recipients<span style="color: black;">&#41;</span>:</code></li>
<li value="90" class="tab1 even"><code>sender = <span style="color: #2DB300;">'AAT_Drill_Schedule_Mapper'</span></code></li>
<li value="91" class="tab1 odd"><code>server = <span style="color: #990000;">smtplib</span>.<span style="color: black;">SMTP</span><span style="color: black;">&#40;</span>ip_address<span style="color: black;">&#41;</span></code></li>
<li value="92" class="tab1 even"><code>server.<span style="color: black;">sendmail</span><span style="color: black;">&#40;</span>sender, recipients, message<span style="color: black;">&#41;</span></code></li>
<li value="93" class="tab1 odd"><code>server.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="94" class="even">&nbsp;</li>
<li value="95" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> __name__ == <span style="color: #2DB300;">'__main__'</span>:</code></li>
<li value="96" class="even">&nbsp;</li>
<li value="97" class="tab1 odd"><code>wells = ExcelToList<span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="98" class="tab1 even"><code>BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, <span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="99" class="tab1 odd"><code><span style="color: #FF6600;"># Build our email, using both HTML and plain-text inputs</span></code></li>
<li value="100" class="tab1 even"><code>fhtml = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="101" class="tab1 odd"><code>ftxt = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="102" class="tab1 even"><code>html = fhtml.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="103" class="tab1 odd"><code>text = ftxt.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="104" class="tab1 even"><code>subject = <span style="color: #2DB300;">'AAT Drill Schedule Mapper - '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>DateTime.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + DateTime.\</code></li>
<li value="105" class="tab4 odd"><code>RelativeDateTime<span style="color: black;">&#40;</span>days=<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="106" class="tab1 even"><code><span style="color: #FF6600;"># Create the message with both HTML and text formats</span></code></li>
<li value="107" class="tab1 odd"><code>message = cgiutils.<span style="color: black;">createhtmlmail</span><span style="color: black;">&#40;</span>subject, html, text<span style="color: black;">&#41;</span></code></li>
<li value="108" class="tab1 even"><code><span style="color: #FF6600;"># Send the email out</span></code></li>
<li value="109" class="tab1 odd"><code>recips = <span style="color: black;">&#91;</span><span style="color: #2DB300;">'chad_cooper@swn.com'</span><span style="color: black;">&#93;</span> &nbsp;<span style="color: #FF6600;"># for testing</span></code></li>
<li value="110" class="tab1 even"><code><span style="color: #FF6600;">#recips = Dictionaries.aatEmails</span></code></li>
<li value="111" class="tab1 odd"><code>SendEmail<span style="color: black;">&#40;</span>message,recips<span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing3.txt">listing3.txt</a></li>
</ol>
<p>In order to have the wells listed in the Scratch Pad in descending order by spud date (we want the ones drilling the soonest at the top of the list), we will create a list, <strong>eachList</strong> , and add the annotation string and the spud date to this list as items. As we iterate through the wells list, <strong>eachList</strong> gets appended to another list, <strong>wholeList</strong> , which ends up looking like so:</p>
<p><code>['an.35.2760173376_-97.3403092666_Smith%20%232-3_2007/11/21%20-%20Rig%2067%20-%20DRILLING', '2007/11/21'],<br />
['an.34.8311622405_-94.8568703783_Jones #1-19_12/05/2007%20-%20Rig 4', '12/05/2007'],<br />
['an.35.2325944391_-93.6003875668_Coop #4-17_12/15/2007%20-%20Rig 23', '12/15/2007']]</code></p>
<p>Next, we delete the date items from the list, since we no longer need them after the sort. We then build a string from our list elements and add that to our URL base. Finally, we add some of the Southwestern Energy office locations to the end of the URL, so users can get driving directions from any of our offices directly to a well location:</p>
<p><code>urlList = []<br />
for each in wholeList:<br />
del each[1]<br />
wellString = str(each)[3:len(each)-3]<br />
urlList.append(wellString)<br />
urlStringWells = string.join(urlList,'~')<br />
masterUrl=urlBase+'&amp;sp='+urlStringWells+'~an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office<br />
~an.35.513123_-93.834189_SWN%20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.'</code></p>
<p>And our final URL is:</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_Smith%20%232-3_11/21/2007 %20-%20Rig%2067%20-%20DRILLING~an.34.8311622405_-94.8568703783_Jones%20%231-19_12/05/2007%20- %20Rig%204~an.35.2325944391_-93.6003875668_Coop%20%234-17_12/15/2007%20-%20Rig%2023~ an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office~an.35.513123_-93.834189_SWN% 20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.">http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_Smith%20%232-3_11/21/2007<br />
%20-%20Rig%2067%20-%20DRILLING~an.34.8311622405_-94.8568703783_Jones%20%231-19_12/05/2007%20-<br />
%20Rig%204~an.35.2325944391_-93.6003875668_Coop%20%234-17_12/15/2007%20-%20Rig%2023~<br />
an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office~an.35.513123_-93.834189_SWN%<br />
20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.</a> </code></p>
<p>Our next step is to compose our email to send out to the team. In doing this we will write two versions, one for HTML-enabled clients that is styled and contains a clickable link to our map; and one version for text-only enabled email clients. This version is unstyled and provides the entire map URL that can be copy-pasted into a web browser. For our HTML email, we will create a simple HTML file, and write out code to it (Listing 3). Listing 4 shows the HTML output of Listing 3.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code>&lt;html&gt;</code></li>
<li value="2" class="tab0 even"><code>&lt;head&gt;</code></li>
<li value="3" class="tab0 odd"><code>&lt;style type=&quot;text/css&quot;&gt;body,table {font-family:Verdana;font-size:10pt;empty-cells: show}</code></li>
<li value="4" class="tab0 even"><code>&lt;/style&gt;</code></li>
<li value="5" class="tab0 odd"><code>&lt;/head&gt;</code></li>
<li value="6" class="tab0 even"><code>&lt;body&gt;</code></li>
<li value="7" class="tab0 odd"><code>&lt;table style=&quot;width: 700px&quot;&gt;</code></li>
<li value="8" class="tab0 even"><code>&lt;tr&gt;</code></li>
<li value="9" class="tab0 odd"><code>&lt;td&gt;&lt;h3&gt;AAT Drill Schedule Mapper for Friday, 11/23/2007&lt;/h3&gt;&lt;/td&gt;</code></li>
<li value="10" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="11" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="12" class="tab0 even"><code>&lt;td&gt;Drill schedule last updated: Friday, 11/23/2007, 10:08 PM&lt;/td&gt;</code></li>
<li value="13" class="tab0 odd"><code>&lt;/tr&gt;</code></li>
<li value="14" class="tab0 even"><code>&lt;tr&gt;</code></li>
<li value="15" class="tab0 odd"><code>&lt;td&gt;&amp;nbsp;&lt;/td&gt;</code></li>
<li value="16" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="17" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="18" class="tab0 even"><code>&lt;td&gt;&lt;a href=&quot;http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_</code></li>
<li value="19" class="tab0 odd"><code>Smith%20%232-3_2007/11/21%20-%20Rig%2067%20-%20DRILLING~an.35.2325944391_-93.6003875668_</code></li>
<li value="20" class="tab0 even"><code>Coop%20%234-17_2007/12/15%20-%20Rig%2023~an.34.8311622405_-94.8568703783_Jones%20%231-19_</code></li>
<li value="21" class="tab0 odd"><code>2007/12/5%20-%20Rig%204~an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office</code></li>
<li value="22" class="tab0 even"><code>~an.35.513123_-93.834189_SWN%20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20</code></li>
<li value="23" class="tab0 odd"><code>Conway%20Office~an.&quot;&gt;Click here for a map of the latest AAT drill schedule&lt;/a&gt;&lt;/td&gt;</code></li>
<li value="24" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="25" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="26" class="tab0 even"><code>&lt;td&gt;&amp;nbsp;&lt;/td&gt;</code></li>
<li value="27" class="tab0 odd"><code>&lt;/tr&gt;</code></li>
<li value="28" class="tab0 even"><code>&lt;tr&gt;</code></li>
<li value="29" class="tab0 odd"><code>&lt;td&gt;*** THIS MESSAGE AUTO-GENERATED ***&lt;/td&gt;</code></li>
<li value="30" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="31" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="32" class="tab0 even"><code>&lt;td&gt;*** PLEASE DO NOT REPLY TO THIS EMAIL ***&lt;/td&gt;</code></li>
<li value="33" class="tab0 odd"><code>&lt;/tr&gt;</code></li>
<li value="34" class="tab0 even"><code>&lt;/table&gt;</code></li>
<li value="35" class="tab0 odd"><code>&lt;/body&gt;</code></li>
<li value="36" class="tab0 even"><code>&lt;/html&gt;</code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing4.txt">listing4.txt</a></li>
</ol>
<p>Our text version is much simpler:</p>
<p><code>WriteOutput(t,'AAT Drill Schedule Mapper for ' + str(time.strftime('%A, %m/%d/%Y',time.localtime())))<br />
WriteOutput(t,'\n\nDrill schedule last updated: ' + dsUpdated)<br />
WriteOutput(t,'\n\nCopy and paste this address into your web broswer:\n\n' + masterUrl)<br />
WriteOutput(t,'\n\n** This message auto-generated - please do not respond to this email ***') </code></p>
<p>Which provides us with text output of:</p>
<p><code>AAT Drill Schedule Mapper for Friday, 11/23/2007</code></p>
<p><code>Drill schedule last updated: Friday, 11/23/2007, 10:08 PM</code></p>
<p><code>Copy and paste this address into your web broswer:</code></p>
<p><code>http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_Smith%20%232-3_2007/11/21%20-<br />
%20Rig%2067%20-%20DRILLING~an.35.2325944391_-93.6003875668_Coop%20%234-17_2007/12/15%20-%20Rig%<br />
2023~an.34.8311622405_-94.8568703783_Jones%20%231-19_2007/12/5%20-%20Rig%204~an.36.1164211465469_<br />
-94.143074863021_SEECO%20Fayetteville%20Office~an.35.513123_-93.834189_SWN%20Ozark%20Office~an.<br />
35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.</code></p>
<p><code>*** This message auto-generated - please do not respond to this email ***</code></p>
<p><strong>Disseminating the map to our team members</strong></p>
<p>Our final step in this process is to send out to the team the email containing the URL to the day&#8217;s drill schedule. To do this I enlisted the help of Michael Foord&#8217;s <strong>cgiutils</strong> module (<a href="http://www.voidspace.org.uk/python/cgiutils.html">http://www.voidspace.org.uk/python/cgiutils.html</a> ) and the <strong>createhtmlmail</strong> function (Listing 3). createhtmlmail takes our html and text files we just created and uses them as inputs to create a mime-message that will render as html or text, depending on the receiving email client. If no html is supplied, then the <strong>htmllib</strong> module is used to guess a text rendering. createhtmlmail returns us a message object which is passed into the <strong>SendEmail</strong> function; which also takes a list of email addresses of our team members as input. To send our email, we simply create a connection to our Outlook Exchange Server and pass in the sender, our list of recipients, and our html/text message to the smtplib.sendmail object. Finally, we terminate the SMTP session and close out the connection.</p>
<p><code>def SendEmail(message, recipients):<br />
sender = 'AAT_Drill_Schedule_Mapper'<br />
server = smtplib.SMTP(ip_address)<br />
server.sendmail(sender, recipients, message)<br />
server.quit()</code></p>
<p>And that&#8217;s it! I run this script as a Scheduled Task on Windows XP every night at 9PM, and a few minutes later, the email goes out to each of our team members (Figure 4). Listing 5 shows the process in its entirety.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">import</span> pyExcelerator, <span style="color: #990000;">os</span>, <span style="color: #990000;">time</span>, <span style="color: #990000;">string</span>, <span style="color: #990000;">calendar</span>, <span style="color: #990000;">datetime</span></code></li>
<li value="2" class="tab0 even"><code><span style="color: #0008E6;font-weight:bold;">import</span> <span style="color: #990000;">smtplib</span>, cgiutils, xldate, DateTime, EmailRecips</code></li>
<li value="3" class="odd">&nbsp;</li>
<li value="4" class="tab0 even"><code><span style="color: #990000;font-weight:bold;">def</span> ExcelToList<span style="color: black;">&#40;</span>fname, worksheet=<span style="color: #FF0000; font-weight: bold;">0</span>, encoding=<span style="color: #2DB300;">'cp1251'</span><span style="color: black;">&#41;</span>:</code></li>
<li value="5" class="tab1 odd"><code>data = pyExcelerator.<span style="color: black;">parse_xls</span><span style="color: black;">&#40;</span>fname,encoding<span style="color: black;">&#41;</span></code></li>
<li value="6" class="tab1 even"><code>sheet_name=data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding<span style="color: black;">&#41;</span></code></li>
<li value="7" class="tab1 odd"><code>values = data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="8" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="9" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">print</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span>:<span style="color: #FF0000; font-weight: bold;">-1</span><span style="color: black;">&#93;</span></code></li>
<li value="10" class="tab1 even"><code>vdict = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="11" class="tab1 odd"><code>row_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="12" class="tab1 even"><code>col_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="13" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row_idx, col_idx <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>values.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="14" class="tab2 even"><code>row_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>row_idx,row_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="15" class="tab2 odd"><code>col_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>col_idx,col_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="16" class="tab2 even"><code>v = values<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx, col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>v, <span style="color: #008000;">unicode</span><span style="color: black;">&#41;</span>:</code></li>
<li value="18" class="tab3 even"><code>v = v.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding, <span style="color: #2DB300;">'backslashreplace'</span><span style="color: black;">&#41;</span></code></li>
<li value="19" class="tab2 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx,col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = v</code></li>
<li value="20" class="tab1 even"><code>vlist = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="21" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>row_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="22" class="tab2 even"><code>vlist.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="23" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> col <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>col_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="24" class="tab3 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span> <span style="color: #0008E6;font-weight:bold;">not</span> <span style="color: #0008E6;font-weight:bold;">in</span> vdict:</code></li>
<li value="25" class="tab4 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>=<span style="color: #008000;">None</span></code></li>
<li value="26" class="tab3 even"><code>vlist<span style="color: black;">&#91;</span>row<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="27" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> vlist</code></li>
<li value="28" class="even">&nbsp;</li>
<li value="29" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> GetWellStatus<span style="color: black;">&#40;</span>inSpudDt, inPrjTdDt<span style="color: black;">&#41;</span>:</code></li>
<li value="30" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span> <span style="color: #0008E6;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span>:</code></li>
<li value="31" class="tab2 odd"><code>today1 = <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="32" class="tab2 even"><code>today = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="33" class="tab5 odd"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="34" class="tab5 even"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="35" class="tab2 odd"><code>spudDt = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,</code></li>
<li value="36" class="tab6 even"><code>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="37" class="tab2 odd"><code>prjTdDt = <span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,</code></li>
<li value="38" class="tab8 even"><code>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="39" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> today <span style="color: #66cc66;">&gt;</span> prjTdDt:</code></li>
<li value="40" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilled'</span></code></li>
<li value="41" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&gt;</span>= spudDt <span style="color: #0008E6;font-weight:bold;">and</span> today <span style="color: #66cc66;">&lt;</span>= prjTdDt:</code></li>
<li value="42" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilling'</span></code></li>
<li value="43" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&lt;</span> spudDt:</code></li>
<li value="44" class="tab3 even"><code>status = <span style="color: #2DB300;">'Proposed'</span></code></li>
<li value="45" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="46" class="tab3 even"><code>status = <span style="color: #2DB300;">'Unknown'</span></code></li>
<li value="47" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="48" class="tab2 even"><code>status = <span style="color: #2DB300;">'Undeterminable'</span></code></li>
<li value="49" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> status</code></li>
<li value="50" class="even">&nbsp;</li>
<li value="51" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> KillObject<span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="52" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="53" class="tab2 odd"><code><span style="color: #990000;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span></code></li>
<li value="54" class="even">&nbsp;</li>
<li value="55" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> WriteOutput<span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, text<span style="color: black;">&#41;</span>:</code></li>
<li value="56" class="tab1 even"><code>writer = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, <span style="color: #2DB300;">'a'</span><span style="color: black;">&#41;</span></code></li>
<li value="57" class="tab1 odd"><code>writer.<span style="color: black;">write</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span></code></li>
<li value="58" class="even">&nbsp;</li>
<li value="59" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, ds<span style="color: black;">&#41;</span>:</code></li>
<li value="60" class="tab1 even"><code>urlBase = <span style="color: #2DB300;">'http://maps.live.com/default.aspx?style=r'</span></code></li>
<li value="61" class="tab1 odd"><code>wholeList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="62" class="tab1 even"><code><span style="color: #008000;">dict</span> = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="63" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> well <span style="color: #0008E6;font-weight:bold;">in</span> wells:</code></li>
<li value="64" class="tab2 even"><code>eachList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="65" class="tab2 odd"><code>name = <span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'#'</span>,<span style="color: #2DB300;">'%23'</span><span style="color: black;">&#41;</span></code></li>
<li value="66" class="tab2 even"><code>spudDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="67" class="tab2 odd"><code>spudDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="68" class="tab2 even"><code>tdDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="69" class="tab2 odd"><code>tdDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="70" class="tab2 even"><code>lat = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">3</span><span style="color: black;">&#93;</span></code></li>
<li value="71" class="tab2 odd"><code><span style="color: #008000;">long</span> = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">4</span><span style="color: black;">&#93;</span></code></li>
<li value="72" class="tab2 even"><code>rig = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">5</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span></code></li>
<li value="73" class="tab2 odd"><code>status = GetWellStatus<span style="color: black;">&#40;</span>spudDateTuple, tdDateTuple<span style="color: black;">&#41;</span></code></li>
<li value="74" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> status == <span style="color: #2DB300;">'Drilling'</span>:</code></li>
<li value="75" class="tab3 odd"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="76" class="tab3 even"><code><span style="color: #2DB300;">'%20-%20'</span> + rig + <span style="color: #2DB300;">'%20-%20'</span> + status.<span style="color: black;">upper</span><span style="color: black;">&#41;</span></code></li>
<li value="77" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="78" class="tab3 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="79" class="tab3 odd"><code><span style="color: #2DB300;">'%20-%20'</span> + rig<span style="color: black;">&#41;</span></code></li>
<li value="80" class="tab2 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>spudDate<span style="color: black;">&#41;</span></code></li>
<li value="81" class="tab2 odd"><code>wholeList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>eachList<span style="color: black;">&#41;</span></code></li>
<li value="82" class="tab1 even"><code>wholeList.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #0008E6;font-weight:bold;">lambda</span> x,y:<span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,y<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="83" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> whole <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="84" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">print</span> whole</code></li>
<li value="85" class="tab1 odd"><code>urlList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="86" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="87" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">del</span> each<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="88" class="tab2 even"><code>wellString = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span>:<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: #FF0000; font-weight: bold;">-3</span><span style="color: black;">&#93;</span></code></li>
<li value="89" class="tab2 odd"><code>urlList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>wellString<span style="color: black;">&#41;</span></code></li>
<li value="90" class="tab1 even"><code>urlStringWells = <span style="color: #990000;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>urlList,<span style="color: #2DB300;">'~'</span><span style="color: black;">&#41;</span></code></li>
<li value="91" class="tab1 odd"><code>masterUrl = urlBase + <span style="color: #2DB300;">'&amp;sp='</span> + urlStringWells + <span style="color: #2DB300;">'~an.36.1164211465469_-94.143074863021_SEECO%</span></code></li>
<li value="92" class="tab1 even"><code>20Fayetteville<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.513123_<span style="color: #FF0000; font-weight: bold;">-93</span>.834189_SWN<span style="color: #66cc66;">%</span>20Ozark<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.0685432008022_</code></li>
<li value="93" class="tab1 odd"><code><span style="color: #FF0000; font-weight: bold;">-92</span>.4189197874021_SWN<span style="color: #66cc66;">%</span>20Conway<span style="color: #66cc66;">%</span>20Office~an.<span style="color: #2DB300;">'</span></code></li>
<li value="94" class="tab1 even"><code>f = <span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span></code></li>
<li value="95" class="tab1 odd"><code>t = <span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span></code></li>
<li value="96" class="tab1 even"><code>dsUpdated = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y, %I:%M %p'</span>, <span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">getmtime</span><span style="color: black;">&#40;</span>ds<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="97" class="tab1 odd"><code>KillObject<span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span></code></li>
<li value="98" class="tab1 even"><code>KillObject<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span></code></li>
<li value="99" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;style type=&quot;text/css&quot;&gt;body,table {font-family:Verdana;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="100" class="tab4 even"><code>font-size:10pt<span style="color: #66cc66;">;</span>empty-cells: show<span style="color: black;">&#125;</span>\n<span style="color: #66cc66;">&lt;</span>/style<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/head<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>\n<span style="color: #2DB300;">')</span></code></li>
<li value="101" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;table style=&quot;width: 700px&quot;&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;h3&gt;AAT Drill Schedule Mapper for '</span>\</code></li>
<li value="102" class="tab4 even"><code>+ <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'&lt;/h3&gt;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="103" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;Drill schedule last updated: '</span> + dsUpdated + <span style="color: #2DB300;">'&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span>\</code></li>
<li value="104" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="105" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;a href=&quot;'</span> + masterUrl + <span style="color: #2DB300;">'&quot;&gt;Click here for a map of the latest<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="106" class="tab4 even"><code>AAT drill schedule<span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="107" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="108" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;*** THIS MESSAGE AUTO-GENERATED ***&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="109" class="tab4 odd"><code><span style="color: #66cc66;">***</span> PLEASE DO NOT REPLY TO THIS EMAIL <span style="color: #66cc66;">***&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="110" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/html&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="111" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'AAT Drill Schedule Mapper for '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>\</code></li>
<li value="112" class="tab4 even"><code>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="113" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Drill schedule last updated: '</span> + dsUpdated<span style="color: black;">&#41;</span></code></li>
<li value="114" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Copy and paste this address into your web broswer:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span> + masterUrl<span style="color: black;">&#41;</span></code></li>
<li value="115" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>** This message auto-generated - please do not respond to this email ***'</span><span style="color: black;">&#41;</span></code></li>
<li value="116" class="even">&nbsp;</li>
<li value="117" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> SendEmail<span style="color: black;">&#40;</span>message, recipients<span style="color: black;">&#41;</span>:</code></li>
<li value="118" class="tab1 even"><code>sender = <span style="color: #2DB300;">'AAT_Drill_Schedule_Mapper'</span></code></li>
<li value="119" class="tab1 odd"><code>server = <span style="color: #990000;">smtplib</span>.<span style="color: black;">SMTP</span><span style="color: black;">&#40;</span>ip_address<span style="color: black;">&#41;</span></code></li>
<li value="120" class="tab1 even"><code>server.<span style="color: black;">sendmail</span><span style="color: black;">&#40;</span>sender, recipients, message<span style="color: black;">&#41;</span></code></li>
<li value="121" class="tab1 odd"><code>server.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="122" class="even">&nbsp;</li>
<li value="123" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> __name__ == <span style="color: #2DB300;">'__main__'</span>:</code></li>
<li value="124" class="even">&nbsp;</li>
<li value="125" class="tab1 odd"><code>wells = ExcelToList<span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="126" class="tab1 even"><code>BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, <span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="127" class="tab1 odd"><code><span style="color: #FF6600;"># Build our email, using both HTML and plain-text inputs</span></code></li>
<li value="128" class="tab1 even"><code>fhtml = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="129" class="tab1 odd"><code>ftxt = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="130" class="tab1 even"><code>html = fhtml.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="131" class="tab1 odd"><code>text = ftxt.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="132" class="tab1 even"><code>subject = <span style="color: #2DB300;">'AAT Drill Schedule Mapper - '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>DateTime.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + DateTime.\</code></li>
<li value="133" class="tab4 odd"><code>RelativeDateTime<span style="color: black;">&#40;</span>days=<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="134" class="tab1 even"><code><span style="color: #FF6600;"># Create the message with both HTML and text formats</span></code></li>
<li value="135" class="tab1 odd"><code>message = cgiutils.<span style="color: black;">createhtmlmail</span><span style="color: black;">&#40;</span>subject, html, text<span style="color: black;">&#41;</span></code></li>
<li value="136" class="tab1 even"><code><span style="color: #FF6600;"># Send the email out</span></code></li>
<li value="137" class="tab1 odd"><code>recips = <span style="color: black;">&#91;</span><span style="color: #2DB300;">'chad_cooper@swn.com'</span><span style="color: black;">&#93;</span> &nbsp;<span style="color: #FF6600;"># for testing</span></code></li>
<li value="138" class="tab1 even"><code><span style="color: #FF6600;">#recips = Dictionaries.aatEmails</span></code></li>
<li value="139" class="tab1 odd"><code>SendEmail<span style="color: black;">&#40;</span>message,recips<span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing5.txt">listing5.txt</a></li>
</ol>
<p><a href="http://www.super-cooper.com/images/pymag/figure4.png" rel="lightbox[50]"><img class="left" src="http://farm3.static.flickr.com/2292/2417972450_476f5337d8_m.jpg" alt="figure4" width="240" height="163" /> </a></p>
<p><strong>Limitations and other Live Search Maps applications</strong></p>
<p>Internet Explorer imposes a strict limitation of 2,048 characters in the path portion of a URL. I have yet to run into this problem, as most of my URLs generated from this process are on the order of 400-600 characters long. All other modern web browsers (Firefox, Opera, or Safari) will give you no problems in this department.</p>
<p>The Live Search  Maps URL API also provides several other ways to plot locations on its maps. Let&#8217;s say for my application I need to supply a map of driving directions to each well location from our office in Fayetteville, Arkansas. No problem, the URL API provides us with the tools to do so. All we have to do is build a route string with the beginning waypoint (&quot;A&quot;) as the office in Fayetteville, and the end waypoint(s) (&quot;B&quot;) as the well locations:</p>
<p><code>http://maps.live.com/default.aspx?style=r&amp;rtp=adr.&quot;A&quot;~pos.&quot;B&quot;</code></p>
<p>Here, rtp defines the route, adr defines the start waypoint as an address, and pos defines the end waypoint as a specific point on the map. Our office location (&quot;A&quot;) remains static, but the dynamic end waypoints (&quot;B&quot;) can easily be added to the URL through a slight change in our BuildLiveMapsUrl function that adds them in the form of &quot;pos.latitude_longitude_name&quot; to the URL to create a end product such as:</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;rtp=adr.1083%20East%20Sain%20Street%20Fayetteville,%20AR%2072703~pos.35.2760173376_-97.3403092666_Smith%20%232-3">http://maps.live.com/default.aspx?style=r&amp;rtp=adr.1083%20East%20Sain%20Street%20Fayetteville,%20AR%2072703~<br />
pos.35.2760173376_-97.3403092666_Smith%20%232-3</a> </code></p>
<p>We could easily loop through the original dataset and create a series of URLs similar to above and include them as clickable links in our email.</p>
<p><strong>Conclusion</strong></p>
<p>The Microsoft Live Search Maps URL API is a fairly simple, straightforward, and end-user friendly way to display point locations on a map. When combined with a minimal amount of Python code to simply create a URL to use in a existing cross-browser application, Live Search Maps becomes an indispensible tool that allows us to disseminate, view, understand, and interpret data that was once simply sitting around. I hope this article demonstrates how Python can be used to take once lifeless enterprise data and turn it into a dynamic, meaningful, and sexy end product.</p>
<p><strong>About the author</strong></p>
<p>Chad Cooper has been in the Geographic Information Systems field for 5 years, the last 3 of which have been with <a href="http://www.swn.com">Southwestern Energy Company</a> . Chad has been hacking up Python code for the past 2 years. He lives in Arkansas with his wife and two incredibly energetic young sons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some new maps: 8-Digit HUC Watersheds of Arkansas, Night Lights of Arkansas, and other assorted watershed maps</title>
		<link>http://www.super-cooper.com/archive/2005/03/12/new-gallery-watershed-maps-night-lights/</link>
		<comments>http://www.super-cooper.com/archive/2005/03/12/new-gallery-watershed-maps-night-lights/#comments</comments>
		<pubDate>Sat, 12 Mar 2005 16:35:34 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[maps]]></category>

		<guid isPermaLink="false">http://super-cooper.com/?p=88</guid>
		<description><![CDATA[I finally found the time to finish some maps I had been working on for quite some time. Watersheds of Arkansas is one I had started back in 2003, and just never got a chance to finish. I&#8217;m very pleased with how it turned out though. The detail in the elevation is amazing. Took me [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/supercooper/52040013/in/set-1123023/" title="State of Arkansas 8-Digit Hydrologic Unit Code (HUC-8) Subbasin Boundaries by supercooper, on Flickr"><img src="http://farm1.static.flickr.com/26/52040013_b24ba6fc11_m.jpg" width="240" height="166" alt="State of Arkansas 8-Digit Hydrologic Unit Code (HUC-8) Subbasin Boundaries" class="left"/></a><br />
I finally found the time to finish some maps I had been working on for quite some time. <a href="http://www.flickr.com/photos/supercooper/52040013/" title="State of Arkansas 8-Digit Hydrologic Unit Code (HUC-8) Subbasin Boundaries by supercooper, on Flickr">Watersheds of Arkansas</a> is one I had started back in 2003, and just never got a chance to finish. I&#8217;m very pleased with how it turned out though. The detail  in the elevation is amazing. Took me a while to get the colors/contrast/transparency just right on that. <a href="http://www.flickr.com/photos/supercooper/52041622/in/set-1123023/" title="Night Lights of Arkansas map">Night Lights of Arkansas</a> is one I threw together pretty quickly using an already existing template. I ran across the <a href="http://www.nationalatlas.gov/mld/nitelti.html" title="Night Lights National Atlas USGS site">data</a> one day on the web and thought it would make a nice map. Here&#8217;s the <a href="http://www.nationalatlas.gov/metadata/nitelti020l.html" title="Night Lights metadata from USGS">Night Lights metadata</a> if anyone is really interested.</p>
<p>Both of these maps (as with pretty much all of my maps) were made using <a href="http://www.esri.com/software/arcgis/">ArcGIS 8.3</a> from <a href="http://www.esri.com/">ESRI</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2005/03/12/new-gallery-watershed-maps-night-lights/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing lots of rasters</title>
		<link>http://www.super-cooper.com/archive/2004/07/04/processing-lots-of-rasters/</link>
		<comments>http://www.super-cooper.com/archive/2004/07/04/processing-lots-of-rasters/#comments</comments>
		<pubDate>Sun, 04 Jul 2004 20:26:09 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[gis]]></category>

		<guid isPermaLink="false">http://super-cooper.com/?p=28</guid>
		<description><![CDATA[I had a post a few days ago about data, and how it made my happy, and how that was kinda pathetic. And that got me to thinking &#8211; What&#8217;s the largest raster I&#8217;ve processed?&#8230;..Hhhmmmm. Well, here it is: I needed to make shaded relief maps for our site at work, like the one seen [...]]]></description>
			<content:encoded><![CDATA[<p><a title="ned-numbered by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/2420276268/"><img class="left alignleft" style="border: 1px solid grey; margin: 5px;" src="http://farm3.static.flickr.com/2145/2420276268_78231dc1eb_s.jpg" alt="ned-numbered" width="75" height="75" /></a><br />
I had a post a few days ago about data, and how it made my happy, and how that was kinda pathetic. And that got me to thinking &#8211; <em>What&#8217;s the largest raster I&#8217;ve processed?&#8230;..Hhhmmmm</em>. Well, here it is:</p>
<p>I needed to make shaded relief maps for our site at work, like the one seen <a href="http://www.baeg.engr.uark.edu/wml/sites.asp?HUC8=11010010">here</a>. In order to do this, I needed a <a href="http://edc.usgs.gov/products/elevation/dem.html">DEM</a> that covered a very large area. <span id="more-11"></span>Namely, all of Arkansas, most of northern Louisiana, eastern Oklahoma, western Mississippi, southern Missouri, along with chunks of Kansas, Texas, Tennessee, Kentucky, and Illinois.<br />
<a title="ned-states by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/2420276542/"><img class="right alignleft" style="border: 1px solid grey; margin: 5px;" src="http://farm4.static.flickr.com/3033/2420276542_f01bfc697a_s.jpg" alt="ned-states" width="75" height="75" /></a><br />
Oh yeah, and to calculate the hillshade, the DEM has to be seamless. I knew this would take a while. First, I downloaded all of the DEM data from the <a href="http://seamless.usgs.gov/">USGS Raster Extractor</a>. Hell, it&#8217;s free, so get all that you want. I ended up with 56 tiles of unprojected DEMs (the image above).  Each zipped chunk was about 100MB, and all of the data unzipped came to about 4.87GB. I tried to mosaic these, but found out there was a problem; that being that <a href="http://www.esri.com/software/arcgis/arcinfo/index.html">ArcInfo</a> can only address a file 2.147GB in size. So even if I did mosaic these now, I wouldn&#8217;t be able to open it. <em>Hhhhmmmmm</em>. So I realized I had to convert the rasters from floating point decimal (i.e., elevation values of say, 21.2223 meters) to integer (remove the decimal places); this makes the rasters much, much smaller in file size. And since I wasn&#8217;t going to use this big DEM for anything but to make maps, I don&#8217;t need the decimal places.<br />
<a title="ned-five-tiles by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/2420276762/"><img class="left alignleft" style="border: 1px solid grey; margin: 5px;" src="http://farm3.static.flickr.com/2339/2420276762_db5f59fcb2_s.jpg" alt="ned-five-tiles" width="75" height="75" /></a><br />
Next I mosaiced them into five chunks to make the final mosaic a little easier on my machine, plus, the maximum number of grids you can mosaic at once in <a href="http://www.esri.com/software/arcview/index.html">ArcView</a> is 50. These processes really didn&#8217;t take that long on my ole&#8217; trusty steed though; she&#8217;s a Dell Precision Workstation with dual 2.4Ghz Xeons and 2GB of RAM.  Finally, I mosaiced the five larger mosaics into one, and then projected it into NAD83, UTM Zone 15 North, which is what I pretty much work with all of my data in this area in.</p>
<p><a title="ned-projected by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/2420276914/"><img class="right alignleft" style="border: 1px solid grey; margin: 5px;" src="http://farm3.static.flickr.com/2302/2420276914_d764619e6d_s.jpg" alt="ned-projected" width="75" height="75" /></a><br />
Now the projecting took a while, several hours if I remember correctly. That&#8217;s still not bad though. A few years ago, if I would have attempted this on a machine with 1Ghz P3 and 1GB of RAM, it would have taken all night to process, that is if it didn&#8217;t crash after a few hours. The filesize of the final integer, mosaiced, projected, full-size DEM (seen at right) is about 750MB, which is much smaller than the 4.87GB I started off with.</p>
<p>So what&#8217;s the point of all of this? Nothing really, other than it&#8217;s fun to push your equipment (and your knowledge of it, or how to work around its&#8217; limitaions)  to the limits sometimes, just to see what it (and you) can accomplish.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2004/07/04/processing-lots-of-rasters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DRGs for Oklahoma</title>
		<link>http://www.super-cooper.com/archive/2004/06/29/drgs-for-oklahoma/</link>
		<comments>http://www.super-cooper.com/archive/2004/06/29/drgs-for-oklahoma/#comments</comments>
		<pubDate>Tue, 29 Jun 2004 05:02:49 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[gis]]></category>

		<guid isPermaLink="false">http://super-cooper.com/?p=26</guid>
		<description><![CDATA[It&#8217;s kinda sad when you get excited over data. But this isn&#8217;t just data, it&#8217;s data that will make my life a little bit easier. My boss bought me the 7.5-minute DRGs (Digital Raster Graphics) for the entire State of Oklahoma on CD from Charttiff. I already have the Arkansas set, and having them has [...]]]></description>
			<content:encoded><![CDATA[<p><a title="drg by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/2422508860/"><img class="left alignleft" style="border: 1px solid grey; margin: 5px 10px;" src="http://farm3.static.flickr.com/2104/2422508860_1d36d984ba_t.jpg" alt="drg" width="100" height="100" /></a>It&#8217;s kinda sad when you get excited over <em>data</em>.  But this isn&#8217;t just data, it&#8217;s data that will make my life a little bit easier. My boss bought me the 7.5-minute <a href="http://topomaps.usgs.gov/drg/">DRGs</a> (Digital Raster Graphics) for the entire State of Oklahoma on CD from <a href="http://www.charttiff.com/">Charttiff</a>. I already have the Arkansas set, and having them has been a real timesaver. When you rip them off of the CD and onto your hard drive, you select the projection you want and the format (JPEG, TIF). It&#8217;s pretty slick. And most importantly, this means that I don&#8217;t have to hunt around for them on the web, find them in four different formats and in three different projections, and then convert them and reproject them. Yeah, this will make my life <em>alot</em> easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2004/06/29/drgs-for-oklahoma/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Damn you ArcMap!</title>
		<link>http://www.super-cooper.com/archive/2004/03/25/damn-you-arcmap/</link>
		<comments>http://www.super-cooper.com/archive/2004/03/25/damn-you-arcmap/#comments</comments>
		<pubDate>Fri, 26 Mar 2004 04:36:18 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[gis]]></category>

		<guid isPermaLink="false">http://super-cooper.com/?p=14</guid>
		<description><![CDATA[So ArcMap just crashed on me for like the 4,000th time while I was editing this VERY small, VERY simple vector dataset&#8230;..same as always for the last three builds of Arc8x&#8230;.try to save edits, and it crashes! All I can do now is laugh, that&#8217;s all it&#8217;s worth&#8230;.at least they apologize&#8230;here&#8217;s the error message they [...]]]></description>
			<content:encoded><![CDATA[<p><a title="At least they are sorry by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/39698293/"><img class="left" src="http://farm1.static.flickr.com/25/39698293_e778ac08ff_m.jpg" alt="At least they are sorry" width="240" height="110" /></a></p>
<p>So <a href="http://www.esri.com/software/arcgis/arcinfo/index.html">ArcMap</a> just crashed on me for like the 4,000th time while I was editing this VERY small, VERY simple vector dataset&#8230;..same as always for the last three builds of Arc8x&#8230;.try to save edits, and it crashes!  All I can do now is laugh, that&#8217;s all it&#8217;s worth&#8230;.at least they apologize&#8230;here&#8217;s the error message they provide&#8230;</p>
<p><a title="Chad has encountered an error by supercooper, on Flickr" href="http://www.flickr.com/photos/supercooper/51772342/"><img class="right" src="http://farm1.static.flickr.com/25/51772342_ce7d9382b2_m.jpg" alt="Chad has encountered an error" width="240" height="111" /></a></p>
<p>&#8230;and here&#8217;s my version of their error message/apology. I think it sums up how I feel when a crash happens. I made this in Illustrator one day during a time when I was using ArcMap alot for vector editing, and it crashing on me was a daily occurrence. Man I love Illustrator.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2004/03/25/damn-you-arcmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

