<?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>youdidwhatwithtsql.com &#187; London Datastore</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/london-datastore/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Get TFL Tube data with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689</link>
		<comments>http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689#comments</comments>
		<pubDate>Sat, 27 Feb 2010 19:18:24 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Data]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[data.gov.uk]]></category>
		<category><![CDATA[London Datastore]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689</guid>
		<description><![CDATA[The London Datastore has loads of datasets available that we can use for free. One of the datasets available is a list of TFL Station Locations. The station location feed is a geo-coded KML feed of most of London Underground, DLR and London Overground stations. Here&#8217;s Powershell script that will extract this data from a [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689">Get TFL Tube data with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://data.london.gov.uk/" target="_blank">London Datastore</a> has loads of datasets available that we can use for free. One of the datasets available is a list of <a href="http://data.london.gov.uk/datastore/package/tfl-station-locations" target="_blank">TFL Station Locations</a>. The station location feed is a geo-coded KML feed of most of London Underground, DLR and London Overground stations. Here&#8217;s <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> script that will extract this data from a url and write it to a pipe-delimited file ready for import into the database of your choice. </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p689code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6892"><td class="code" id="p689code2"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$xml</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> XML
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;http://www.tfl.gov.uk/tfl/syndication/feeds/stations.kml&quot;</span>
<span style="color: #800080;">$csvFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$env:UserProfile\Desktop\tfl_tubes.csv&quot;</span>;
&nbsp;
<span style="color: #008000;"># Empty file if it already exists</span>
<span style="color: #008080; font-weight: bold;">Set-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$csvFile</span> <span style="color: #800080;">$null</span>;
<span style="color: #008000;"># Add headers to file</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$csvFile</span> <span style="color: #800000;">&quot;Station|Address|Coordinates&quot;</span>;
&nbsp;
<span style="color: #008000;"># Load the xml</span>
<span style="color: #800080;">$xml</span>.Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$url</span><span style="color: #000000;">&#41;</span>;
<span style="color: #800080;">$stations</span> <span style="color: pink;">=</span> <span style="color: #800080;">$xml</span>.kml.Document.Placemark;
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$station</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$stations</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$name</span> <span style="color: pink;">=</span> <span style="color: #800080;">$station</span>.name;
	<span style="color: #800080;">$description</span> <span style="color: pink;">=</span> <span style="color: #800080;">$station</span>.description;
	<span style="color: #800080;">$coordinates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$station</span>.Point.coordinates
	<span style="color: #008000;"># This data needs cleaning a bit</span>
	<span style="color: #800080;">$name</span> <span style="color: pink;">=</span> <span style="color: #800080;">$name</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$description</span> <span style="color: pink;">=</span> <span style="color: #800080;">$description</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #800080;">$coordinates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$coordinates</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #008000;"># Ad line to the csv file</span>
	<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$csvFile</span> <span style="color: #800000;">&quot;$name|$description|$coordinates&quot;</span>;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>After running the script check your desktop for a file called <strong>tfl_tubes.csv</strong> which should look something like below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/tfl_tubes.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="TFL Station Locations csv data file" border="0" alt="tfl tubes thumb Get TFL Tube data with Powershell" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2010/02/tfl_tubes_thumb.png" width="244" height="183" /></a></p>
<p><map name='google_ad_map_689_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/689?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_689_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=689&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fget-tfl-tube-data-with-powershell%2F689' title="Get TFL Tube data with Powershell" alt=" Get TFL Tube data with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689">Get TFL Tube data with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/get-tfl-tube-data-with-powershell/689/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

