<?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>George MacKerron: code blog &#187; GIS</title>
	<atom:link href="http://blog.mackerron.com/category/gis/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mackerron.com</link>
	<description>GIS, software development, and other snippets</description>
	<lastBuildDate>Mon, 09 Aug 2010 08:29:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using OS Code-Point Polygons in PostGIS</title>
		<link>http://blog.mackerron.com/2009/11/code-point-polygons-postgis/</link>
		<comments>http://blog.mackerron.com/2009/11/code-point-polygons-postgis/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 12:13:43 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[PostGIS]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.mackerron.com/?p=193</guid>
		<description><![CDATA[Ordnance Survey&#8217;s Code-Point with Polygons &#8220;provides a precise geographical location for each postcode unit in Great Britain&#8221;. It&#8217;s available in various formats, including ESRI .shp files. Many UK academics can access the data via institutional subscription to EDINA Digimap. I&#8217;m using it in my research into subjective wellbeing and environmental quality. This post shows how [...]]]></description>
			<content:encoded><![CDATA[<p>Ordnance Survey&#8217;s <a href="http://www.ordnancesurvey.co.uk/oswebsite/products/codepointpolygons/">Code-Point with Polygons</a> &#8220;provides a precise geographical location for each postcode unit in Great Britain&#8221;. It&#8217;s available in various formats, including <span class="caps">ESRI</span> .shp files. </p>

<p>Many UK academics can access the data via institutional subscription to <a href="http://edina.ac.uk/digimap/"><span class="caps">EDINA</span> Digimap</a>. I&#8217;m using it in <a href="http://personal.lse.ac.uk/MACKERRO/">my research into subjective wellbeing and environmental quality</a>.</p>

<p>This post shows how to:</p>


<ol>
<li><strong>import the data files</strong> into a <a href="http://postgis.refractions.net/">PostGIS</a> database; and</li>
<li><strong>de-normalise the data into a single table</strong>, where there&#8217;s a one-to-one mapping of postcodes to rows, and each row contains either all geographical locations covered by a postcode (as a single geometry column, of type multipolygon) or the reason why no such location is available</li>
</ol>



<p><span id="more-193"></span></p>

<h3>Why de-normalise?</h3>

<p>Step 2 above is required for my purposes because Code-Point data is supplied in a number of separate files per postcode area: </p>


<ul>
<li>a .shp file (and associated .shx and .dbf) mapping postcodes and &#8216;vertical streets&#8217; to the locations they cover;</li>
<li>an accompanying text file mapping postcodes to &#8216;vertical streets&#8217;; and</li>
<li>another text file listing postcodes with no associated locations, either because they represent PO boxes or because the data just isn&#8217;t available.</li>
</ul>



<p>Vertical streets generally represent high-rise buildings, where one location in 2D space may be associated with multiple postcodes. Vertical streets are also a serious pain: not only may one vertical street be associated with many postcodes, but one postcode may be associated with many vertical streets <em>and</em> with non-vertical-street locations too. </p>

<h2>Import the data files</h2>

<p>Download and unzip the Code-Point with Polygons data, in <span class="caps">ESRI</span> .shp format, for the regions you want (where indicative query timings are provided later, these are for whole-UK data &#8212; 120 postcode areas &#8212; on a 2Ghz Intel iMac).</p>

<p>Dump everything in the same directory. For each postcode area XX you should have the following five files:</p>


<ul>
<li><span class="caps">XX.</span>shp, <span class="caps">XX.</span>shx and <span class="caps">XX.</span>dbf</li>
<li>XX_vstreet_lookup.txt</li>
<li>XX_discard.txt</li>
</ul>



<p>If you don&#8217;t already have one you want to use for this purpose, create a PostGIS-enabled PostgreSQL database (in this post, the database is named <code>geo</code>). If you&#8217;re not running PostgreSQL 8.4 or later you may need to fiddle with some fsm_ settings in the Postgres .conf file in order to cope with a data set this large.</p>

<p>Execute the following <span class="caps">SQL </span>to create the tables for discards and vertical streets (e.g. from within pgAdmin):</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_vertical_streets <span style="color: #66cc66;">&#40;</span>
  postcode <span style="color: #1a008a; font-weight: bold;">character</span> <span style="color: #1a008a; font-weight: bold;">varying</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  vstreet <span style="color: #1a008a; font-weight: bold;">character</span> <span style="color: #1a008a; font-weight: bold;">varying</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_discards <span style="color: #66cc66;">&#40;</span>
  postcode <span style="color: #1a008a; font-weight: bold;">character</span> <span style="color: #1a008a; font-weight: bold;">varying</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
  reason <span style="color: #1a008a; font-weight: bold;">character</span> <span style="color: #1a008a; font-weight: bold;">varying</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<p>Next we need to create the table for the .shp-file polygons. We <strong>switch to Ruby</strong> for this &#8212; you can just enter the commands in an <span class="caps">IRB </span>terminal session:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">path = <span style="color:#996600;">'/path/to/CodePoint polygons'</span>
<span style="color:#996600;">`/usr/local/pgsql/bin/shp2pgsql &quot;#{path}/ab.shp&quot; cpp_polygons -p -D -s 27700 | /usr/local/pgsql/bin/psql -d geo -U postgres`</span></pre></div></div>




<p>The -p flag to <code>shp2pgsql</code> just creates a table structure, and the -s 27700 gives it the <span class="caps">EPSG </span>code to tell it we&#8217;re using the <span class="caps">OSGB36 </span>datum. You can use any of the .shp files you&#8217;ve downloaded &#8212; it need not be the AB area one.</p>

<p><strong>Now to do the import</strong> into the three tables. Still in Ruby, execute the following loop:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;#{path}/*.shp&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> f
  <span style="color:#996600;">`/usr/local/pgsql/bin/shp2pgsql &quot;#{f}&quot; cpp_polygons -a -D -s 27700 | /usr/local/pgsql/bin/psql -d geo -U postgres`</span>
  <span style="color:#996600;">`echo &quot;copy cpp_vertical_streets from '#{f.sub(/<span style="color:#000099;">\.</span>shp$/, '_vstreet_lookup.txt')}' csv;&quot; | /usr/local/pgsql/bin/psql geo postgres`</span>
  <span style="color:#996600;">`echo &quot;copy cpp_discards from '#{f.sub(/<span style="color:#000099;">\.</span>shp$/, '_discard.txt')}' csv;&quot; | /usr/local/pgsql/bin/psql geo postgres`</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>Back in <span class="caps">SQL, </span>add some boolean flags we&#8217;ll use later on, then create an index on the postcode column, which will save a <strong>lot</strong> of time later:</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">alter</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">add</span> <span style="color: #1a008a; font-weight: bold;">column</span> <span style="color: #1a008a; font-weight: bold;">discard</span> <span style="color: #1a008a; font-weight: bold;">boolean</span>;
<span style="color: #1a008a; font-weight: bold;">alter</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">add</span> <span style="color: #1a008a; font-weight: bold;">column</span> vstreet <span style="color: #1a008a; font-weight: bold;">boolean</span>;
<span style="color: #1a008a; font-weight: bold;">alter</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">add</span> <span style="color: #1a008a; font-weight: bold;">column</span> vstreet_and_std <span style="color: #1a008a; font-weight: bold;">boolean</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">index</span> pc_index <span style="color: #1a008a; font-weight: bold;">on</span> cpp_polygons <span style="color: #66cc66;">&#40;</span>postcode<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">vacuum</span> <span style="color: #1a008a; font-weight: bold;">analyze</span> cpp_polygons;</pre></div></div>




<p>If you like, you can confirm here that there&#8217;s only one row per postcode &#8212; this query <strong>should return nothing</strong>:</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> 
<span style="color: #1a008a; font-weight: bold;">from</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">a</span> 
<span style="color: #1a008a; font-weight: bold;">inner</span> <span style="color: #1a008a; font-weight: bold;">join</span> cpp_polygons b 
<span style="color: #1a008a; font-weight: bold;">on</span> <span style="color: #1a008a; font-weight: bold;">a</span><span style="color: #66cc66;">.</span>postcode <span style="color: #66cc66;">=</span> b<span style="color: #66cc66;">.</span>postcode 
<span style="color: #1a008a; font-weight: bold;">where</span> <span style="color: #1a008a; font-weight: bold;">a</span><span style="color: #66cc66;">.</span>gid <span style="color: #66cc66;">&lt;&gt;</span> b<span style="color: #66cc66;">.</span>gid;</pre></div></div>




<p>So, we now have all the OS data held in three separate tables. In the rest of the post, we&#8217;ll be merging the data in the discards and vertical streets tables into the main table, cpp_polygons.</p>

<h2>Discards</h2>

<p>We&#8217;re going to create a new table, with the same structure as cpp_polygons, to hold the discarded postcode data. These postcodes will have a <span class="caps">NULL </span>geometry column, and a <span class="caps">TRUE </span>discard column (one of the booleans we added earlier). Later, we&#8217;ll insert the contents of this table into cpp_polygons.</p>

<p>Run the following <span class="caps">SQL</span>:</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">sequence</span> cpp_discard_seq <span style="color: #1a008a; font-weight: bold;">start</span> <span style="color: #1a008a; font-weight: bold;">with</span> <span style="color: #cc66cc;">2000000</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_discard_polys <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #1a008a; font-weight: bold;">select</span> 
  <span style="color: #1a008a;">nextval</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc0000;">'cpp_discard_seq'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> gid<span style="color: #66cc66;">,</span> 
  postcode<span style="color: #66cc66;">,</span>
  <span style="color: #1a008a; font-weight: bold;">cast</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">null</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">character</span> <span style="color: #1a008a; font-weight: bold;">varying</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> upp<span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">substring</span><span style="color: #66cc66;">&#40;</span>postcode <span style="color: #1a008a; font-weight: bold;">from</span> <span style="color: #cc0000;">'^[A-Z][A-Z]?'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> pc_area<span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">cast</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">null</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">geometry</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> the_geom<span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">true</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">discard</span><span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">false</span> <span style="color: #1a008a; font-weight: bold;">as</span> vstreet<span style="color: #66cc66;">,</span>
  <span style="color: #1a008a; font-weight: bold;">false</span> <span style="color: #1a008a; font-weight: bold;">as</span> vstreet_and_std
<span style="color: #1a008a; font-weight: bold;">from</span> cpp_discards
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<h2>Vertical streets</h2>

<p>Similarly, we&#8217;re now going to create a new table with the same structure as cpp_polygons to map vertical street postcodes to the right polygons. This requires a left join of the vertical streets data with some of the geometry data in cpp_polygons.</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">set</span> enable_seqscan <span style="color: #66cc66;">=</span> <span style="color: #1a008a; font-weight: bold;">false</span>; 
<span style="color: #808080; font-style: italic;">-- (otherwise pg sometimes fails to use the index)</span>
&nbsp;
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">sequence</span> cpp_vstreet_seq <span style="color: #1a008a; font-weight: bold;">start</span> <span style="color: #1a008a; font-weight: bold;">with</span> <span style="color: #cc66cc;">3000000</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_vstreet_polys <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #1a008a; font-weight: bold;">select</span> 
    <span style="color: #1a008a;">nextval</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc0000;">'cpp_vstreet_seq'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> gid<span style="color: #66cc66;">,</span> 
    <span style="color: #1a008a; font-weight: bold;">max</span><span style="color: #66cc66;">&#40;</span>v<span style="color: #66cc66;">.</span>postcode<span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> postcode<span style="color: #66cc66;">,</span> 
    <span style="color: #1a008a; font-weight: bold;">cast</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">null</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">varchar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> upp<span style="color: #66cc66;">,</span> 
    <span style="color: #1a008a; font-weight: bold;">max</span><span style="color: #66cc66;">&#40;</span>pc_area<span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> pc_area<span style="color: #66cc66;">,</span> 
    <span style="color: #1a008a;">st_union</span><span style="color: #66cc66;">&#40;</span>the_geom<span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> the_geom<span style="color: #66cc66;">,</span> 
    <span style="color: #1a008a; font-weight: bold;">false</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">discard</span><span style="color: #66cc66;">,</span>
    <span style="color: #1a008a; font-weight: bold;">true</span> <span style="color: #1a008a; font-weight: bold;">as</span> vstreet<span style="color: #66cc66;">,</span>
    <span style="color: #1a008a; font-weight: bold;">false</span> <span style="color: #1a008a; font-weight: bold;">as</span> vstreet_and_std
  <span style="color: #1a008a; font-weight: bold;">from</span> cpp_vertical_streets v 
  <span style="color: #1a008a; font-weight: bold;">left</span> <span style="color: #1a008a; font-weight: bold;">join</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">p</span> 
  <span style="color: #1a008a; font-weight: bold;">on</span> v<span style="color: #66cc66;">.</span>vstreet <span style="color: #66cc66;">=</span> <span style="color: #1a008a; font-weight: bold;">p</span><span style="color: #66cc66;">.</span>postcode
  <span style="color: #1a008a; font-weight: bold;">group</span> <span style="color: #1a008a; font-weight: bold;">by</span> v<span style="color: #66cc66;">.</span>postcode
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<p>Our last new table is for postcodes that are associated with both standard polygons <strong>and</strong> vertical street polygons.</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">sequence</span> cpp_vstreet_and_std_seq <span style="color: #1a008a; font-weight: bold;">start</span> <span style="color: #1a008a; font-weight: bold;">with</span> <span style="color: #cc66cc;">4000000</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_vstreet_and_std_polys <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #1a008a; font-weight: bold;">select</span> 
  <span style="color: #1a008a;">nextval</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc0000;">'cpp_vstreet_and_std_seq'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> gid<span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">p</span><span style="color: #66cc66;">.</span>postcode <span style="color: #1a008a; font-weight: bold;">as</span> postcode<span style="color: #66cc66;">,</span>
  <span style="color: #1a008a; font-weight: bold;">cast</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">null</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">varchar</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> upp<span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">p</span><span style="color: #66cc66;">.</span>pc_area <span style="color: #1a008a; font-weight: bold;">as</span> pc_area<span style="color: #66cc66;">,</span>
  <span style="color: #1a008a;">st_multi</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a;">st_union</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">p</span><span style="color: #66cc66;">.</span>the_geom<span style="color: #66cc66;">,</span> v<span style="color: #66cc66;">.</span>the_geom<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> the_geom<span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">false</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">discard</span><span style="color: #66cc66;">,</span> 
  <span style="color: #1a008a; font-weight: bold;">false</span> <span style="color: #1a008a; font-weight: bold;">as</span> vstreet<span style="color: #66cc66;">,</span>
  <span style="color: #1a008a; font-weight: bold;">true</span> <span style="color: #1a008a; font-weight: bold;">as</span> vstreet_and_std
<span style="color: #1a008a; font-weight: bold;">from</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">p</span>
<span style="color: #1a008a; font-weight: bold;">inner</span> <span style="color: #1a008a; font-weight: bold;">join</span> cpp_vstreet_polys v
<span style="color: #1a008a; font-weight: bold;">on</span> <span style="color: #1a008a; font-weight: bold;">p</span><span style="color: #66cc66;">.</span>postcode <span style="color: #66cc66;">=</span> v<span style="color: #66cc66;">.</span>postcode
<span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<h2>Cleaning and merging</h2>

<p>Now we need to remove the vertical streets and polygons we just merged into a new table from their respective source tables.</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">delete</span> <span style="color: #1a008a; font-weight: bold;">from</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">where</span> postcode <span style="color: #1a008a; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">select</span> postcode <span style="color: #1a008a; font-weight: bold;">from</span> cpp_vstreet_and_std_polys<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">-- the above could take around 25 mins</span>
<span style="color: #1a008a; font-weight: bold;">delete</span> <span style="color: #1a008a; font-weight: bold;">from</span> cpp_vstreet_polys <span style="color: #1a008a; font-weight: bold;">where</span> postcode <span style="color: #1a008a; font-weight: bold;">in</span> <span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">select</span> postcode <span style="color: #1a008a; font-weight: bold;">from</span> cpp_vstreet_and_std_polys<span style="color: #66cc66;">&#41;</span>;</pre></div></div>




<p>And, finally, to merge our three new tables into the main table.</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">insert</span> <span style="color: #1a008a; font-weight: bold;">into</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> <span style="color: #1a008a; font-weight: bold;">from</span> cpp_discard_polys;
<span style="color: #1a008a; font-weight: bold;">insert</span> <span style="color: #1a008a; font-weight: bold;">into</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> <span style="color: #1a008a; font-weight: bold;">from</span> cpp_vstreet_polys;
<span style="color: #1a008a; font-weight: bold;">insert</span> <span style="color: #1a008a; font-weight: bold;">into</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">select</span> <span style="color: #66cc66;">*</span> <span style="color: #1a008a; font-weight: bold;">from</span> cpp_vstreet_and_std_polys;</pre></div></div>




<p>In order to join my own data with this data, I find it easiest to format the postcodes on which the join is made with no spaces. So I add and index the following extra column.</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">alter</span> <span style="color: #1a008a; font-weight: bold;">table</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">add</span> <span style="color: #1a008a; font-weight: bold;">column</span> postcode_no_sp <span style="color: #1a008a; font-weight: bold;">character</span> <span style="color: #1a008a; font-weight: bold;">varying</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #1a008a; font-weight: bold;">update</span> cpp_polygons <span style="color: #1a008a; font-weight: bold;">set</span> postcode_no_sp <span style="color: #66cc66;">=</span> <span style="color: #1a008a; font-weight: bold;">replace</span><span style="color: #66cc66;">&#40;</span>postcode<span style="color: #66cc66;">,</span> <span style="color: #cc0000;">' '</span><span style="color: #66cc66;">,</span> <span style="color: #cc0000;">''</span><span style="color: #66cc66;">&#41;</span>; 
<span style="color: #808080; font-style: italic;">-- the above could take 10 - 15 mins</span>
<span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">index</span> pcns_index <span style="color: #1a008a; font-weight: bold;">on</span> cpp_polygons <span style="color: #66cc66;">&#40;</span>postcode_no_sp<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">vacuum</span> <span style="color: #1a008a; font-weight: bold;">analyze</span> cpp_polygons;</pre></div></div>




<p>You might also want to remove the original vertical street rows, where the postcode column begins with a &#8216;V&#8217;, from the cpp_polygons table &#8212; I didn&#8217;t have any need for this.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.mackerron.com/2009/11/code-point-polygons-postgis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importing the National Statistics Postcode Directory into PostGIS</title>
		<link>http://blog.mackerron.com/2009/05/nspd-into-postgis/</link>
		<comments>http://blog.mackerron.com/2009/05/nspd-into-postgis/#comments</comments>
		<pubDate>Tue, 05 May 2009 10:19:45 +0000</pubDate>
		<dc:creator>George</dc:creator>
				<category><![CDATA[GIS]]></category>
		<category><![CDATA[PostGIS]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://gmackerron.wordpress.com/?p=6</guid>
		<description><![CDATA[This isn&#8217;t a very difficult task, but creating the table is somewhat laborious, so perhaps you&#8217;ll find the following SQL helpful. Step 1 The first step is to create an appropriate table, and pull everything in as character data. create table nspd_2008_11 &#40; postcode_7 char&#40;7&#41;, postcode_8 char&#40;8&#41;, postcode_egif char&#40;8&#41;, intro_date_string char&#40;6&#41;, termination_date_string char&#40;6&#41;, county char&#40;2&#41;, [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t a very difficult task, but creating the table is somewhat laborious, so perhaps you&#8217;ll find the following <span class="caps">SQL </span>helpful.</p>

<p><span id="more-6"></span></p>

<h3>Step 1</h3>

<p>The first step is to create an appropriate table, and pull everything in as character data.</p>


<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> nspd_2008_11 <span style="color: #66cc66;">&#40;</span>
 postcode_7 <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 postcode_8 <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 postcode_egif <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 intro_date_string <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 termination_date_string <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 county <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 la <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ward <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 large_user <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 grid_easting <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 grid_northing <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">7</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 grid_ref_quality <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 health_authority <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 pan_sha <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 country <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 non_geo <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 in_paf <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 go_region <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ssr <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 parl_const <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 eer <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 tecr <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ttwa <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 pct <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 nuts <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ed_1991_ogss <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ed_1991 <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ed_quality <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 address_count <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 delivery_point_count <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 multiple_occupancy_count <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 small_business_count <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 previous_sha <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 lea <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ha <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ward_1991 <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ward_1991_ogss <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 ward_1998 <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 stat_ward_2005 <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 oa <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 oa_indicator <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 cas_ward <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 national_park <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 lsoa <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 scottish_dzone <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 msoa <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 urban_rural_ew <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 urban_rural_scot <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 urban_rural_ni <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 scottish_izone <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 soa_ni <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 oa_class <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
 old_pct <span style="color: #1a008a; font-weight: bold;">char</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">copy</span> nspd_2008_11 <span style="color: #1a008a; font-weight: bold;">from</span> <span style="color: #cc0000;">'/path/to/nspd/file.csv'</span> <span style="color: #1a008a; font-weight: bold;">csv</span>;</pre></div></div>




<h3>Step 2</h3>

<p>Since we&#8217;re going to the trouble of bringing it into PostGIS, likelihood is we&#8217;re going to want to use the spatial data. So let&#8217;s create a new table to hold the point geometries.</p>

<p><strong>Notes:</strong></p>


<ul>
<li>If necessary, we can join this table with our original table, on a postcode column, in future queries. We&#8217;ll index the relevant postcode columns in each table (as primary keys) to speed this up.</li>
<li>We include <span class="caps">OIDS, </span>even though they are deprecated, as an easy way to permit access to the data for visualisation using qGIS.</li>
<li>We exclude postcodes with the quality code &#8217;9&#8242;, because this code means there is no grid reference available.</li>
<li>We set the <span class="caps">SRID </span>of the point data to 27700, which is the appropriate value for the <span class="caps">OSGB36 </span>projection here.</li>
</ul>




<div class="wp_syntax"><div class="code"><pre class="postgresql" style="font-family:monospace;"><span style="color: #1a008a; font-weight: bold;">create</span> <span style="color: #1a008a; font-weight: bold;">table</span> nspd_2008_11_geometry <span style="color: #1a008a; font-weight: bold;">with</span> <span style="color: #66cc66;">&#40;</span><span style="color: #1a008a; font-weight: bold;">oids</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #66cc66;">&#40;</span>
  <span style="color: #1a008a; font-weight: bold;">select</span> postcode_7<span style="color: #66cc66;">,</span>
         grid_ref_quality<span style="color: #66cc66;">,</span>
         <span style="color: #1a008a;">st_setsrid</span><span style="color: #66cc66;">&#40;</span><span style="color: #1a008a;">st_makepoint</span><span style="color: #66cc66;">&#40;</span>
           <span style="color: #1a008a; font-weight: bold;">cast</span> <span style="color: #66cc66;">&#40;</span>grid_easting <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">integer</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
           <span style="color: #1a008a; font-weight: bold;">cast</span> <span style="color: #66cc66;">&#40;</span>grid_northing <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">integer</span><span style="color: #66cc66;">&#41;</span>
         <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">27700</span><span style="color: #66cc66;">&#41;</span> <span style="color: #1a008a; font-weight: bold;">as</span> <span style="color: #1a008a; font-weight: bold;">point</span>
  <span style="color: #1a008a; font-weight: bold;">from</span> nspd_2008_11
  <span style="color: #1a008a; font-weight: bold;">where</span> grid_ref_quality !<span style="color: #66cc66;">=</span> <span style="color: #cc0000;">'9'</span>
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">alter</span> <span style="color: #1a008a; font-weight: bold;">table</span> nspd_2008_11
<span style="color: #1a008a; font-weight: bold;">add</span> <span style="color: #1a008a; font-weight: bold;">constraint</span> postcode_7_key <span style="color: #1a008a; font-weight: bold;">primary</span> <span style="color: #1a008a; font-weight: bold;">key</span> <span style="color: #66cc66;">&#40;</span>postcode_7<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">alter</span> <span style="color: #1a008a; font-weight: bold;">table</span> nspd_2008_11_geometry
<span style="color: #1a008a; font-weight: bold;">add</span> <span style="color: #1a008a; font-weight: bold;">constraint</span> postcode_7_geometry_key <span style="color: #1a008a; font-weight: bold;">primary</span> <span style="color: #1a008a; font-weight: bold;">key</span> <span style="color: #66cc66;">&#40;</span>postcode_7<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #1a008a; font-weight: bold;">vacuum</span> <span style="color: #1a008a; font-weight: bold;">analyze</span>;</pre></div></div>




<p>Now we can connect to the geometry table from qGIS to see the rough shape of Britain in postcode points. In a future post, I may look at creating polygons to represent postcode sectors using the data we&#8217;ve just imported.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.mackerron.com/2009/05/nspd-into-postgis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
