<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Converting OS Eastings/Northings to Grid References in Python</title>
	<atom:link href="http://oliverobrien.co.uk/2010/02/en-to-gridref-in-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://oliverobrien.co.uk/2010/02/en-to-gridref-in-python/</link>
	<description>I see data, I make maps</description>
	<lastBuildDate>Sat, 04 Feb 2012 04:18:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Mike Evans</title>
		<link>http://oliverobrien.co.uk/2010/02/en-to-gridref-in-python/#comment-35</link>
		<dc:creator>Mike Evans</dc:creator>
		<pubDate>Tue, 18 Jan 2011 20:03:41 +0000</pubDate>
		<guid isPermaLink="false">http://oliverobrien.co.uk/?p=317#comment-35</guid>
		<description>This may be too late for Tony but here&#039;s a python script to convert the other way.
&lt;code&gt;
#!/bin/env python
&#039;&#039;&#039;
Convert OS refs with letters to cartesian coords in meters.
&#039;&#039;&#039;
import math

def os_cart(inref):
        &#039;&#039;&#039; Return a tuple of two 7 digit OS numeric grid refs from an XXNNNN type reference.
        Also returns the accuracy of the original OS ref since this is lost when
        the data are padded to two 6 digit grid refs.
        Example: os_cart(&quot;SN109112&quot;) returns (210900, 211200, 100)
        &#039;&#039;&#039;
        #print inref
        &#039;&#039;&#039;get numeric values of letter references, mapping A-&gt;0, B-&gt;1, C-&gt;2, etc:&#039;&#039;&#039;
        inref = inref.replace(&quot; &quot;,&quot;&quot;) #Strip all spaces out
        # Deal with the letters
        l1 = ord(inref[0].upper())-ord(&quot;A&quot;)
        l2 = ord(inref[1].upper())-ord(&quot;A&quot;)
        # shuffle down letters after &#039;I&#039; since &#039;I&#039; is not used in grid:
        if l1 &gt; 7: l1 -= 1
        if l2 &gt; 7: l2 -= 1

        e = str(((l1-2)%5)*5 + (l2%5)) #easting
        n = str(int((19-math.floor(l1/5)*5) - math.floor(l2/5))) #northing

        # Now the numbers
        gridref = inref[2:]
        e += gridref[:int(len(gridref)/2)]
        n += gridref[int(len(gridref)/2):]
        # Pad short refs with correct number of zeros for postGIS
        # This does imply a greater accuracy then the original data suggest
        # however and should be used with caution, see next line.
        a =  1 * int(math.pow(10,6-len(n))) # Calculate the accuracy of original coordinates in metres.
        n = int(math.pow(10,6-len(n))) * int(n)
        e = int(math.pow(10,6-len(e))) * int(e)
        return int(e), int(n), int(a)

if __name__ == &quot;__main__&quot;:
        &#039;&#039;&#039; Run some test code id called directly from command line&#039;&#039;&#039;
        OSREF = &quot;SN109112&quot;
        point = os_cart(OSREF)
        print OSREF, point
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>This may be too late for Tony but here&#8217;s a python script to convert the other way.<br />
<code><br />
#!/bin/env python<br />
'''<br />
Convert OS refs with letters to cartesian coords in meters.<br />
'''<br />
import math</p>
<p>def os_cart(inref):<br />
        ''' Return a tuple of two 7 digit OS numeric grid refs from an XXNNNN type reference.<br />
        Also returns the accuracy of the original OS ref since this is lost when<br />
        the data are padded to two 6 digit grid refs.<br />
        Example: os_cart("SN109112") returns (210900, 211200, 100)<br />
        '''<br />
        #print inref<br />
        '''get numeric values of letter references, mapping A-&gt;0, B-&gt;1, C-&gt;2, etc:'''<br />
        inref = inref.replace(" ","") #Strip all spaces out<br />
        # Deal with the letters<br />
        l1 = ord(inref[0].upper())-ord("A")<br />
        l2 = ord(inref[1].upper())-ord("A")<br />
        # shuffle down letters after 'I' since 'I' is not used in grid:<br />
        if l1 &gt; 7: l1 -= 1<br />
        if l2 &gt; 7: l2 -= 1</p>
<p>        e = str(((l1-2)%5)*5 + (l2%5)) #easting<br />
        n = str(int((19-math.floor(l1/5)*5) - math.floor(l2/5))) #northing</p>
<p>        # Now the numbers<br />
        gridref = inref[2:]<br />
        e += gridref[:int(len(gridref)/2)]<br />
        n += gridref[int(len(gridref)/2):]<br />
        # Pad short refs with correct number of zeros for postGIS<br />
        # This does imply a greater accuracy then the original data suggest<br />
        # however and should be used with caution, see next line.<br />
        a =  1 * int(math.pow(10,6-len(n))) # Calculate the accuracy of original coordinates in metres.<br />
        n = int(math.pow(10,6-len(n))) * int(n)<br />
        e = int(math.pow(10,6-len(e))) * int(e)<br />
        return int(e), int(n), int(a)</p>
<p>if __name__ == "__main__":<br />
        ''' Run some test code id called directly from command line'''<br />
        OSREF = "SN109112"<br />
        point = os_cart(OSREF)<br />
        print OSREF, point<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver</title>
		<link>http://oliverobrien.co.uk/2010/02/en-to-gridref-in-python/#comment-34</link>
		<dc:creator>Oliver</dc:creator>
		<pubDate>Tue, 07 Sep 2010 12:52:47 +0000</pubDate>
		<guid isPermaLink="false">http://oliverobrien.co.uk/?p=317#comment-34</guid>
		<description>Not on me, I&#039;m afraid. However adapting parts of phpcoord/JScoord for python may be fruitful - see http://www.jstott.me.uk/phpcoord/</description>
		<content:encoded><![CDATA[<p>Not on me, I&#8217;m afraid. However adapting parts of phpcoord/JScoord for python may be fruitful &#8211; see <a href="http://www.jstott.me.uk/phpcoord/" rel="nofollow">http://www.jstott.me.uk/phpcoord/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tony</title>
		<link>http://oliverobrien.co.uk/2010/02/en-to-gridref-in-python/#comment-33</link>
		<dc:creator>tony</dc:creator>
		<pubDate>Tue, 07 Sep 2010 11:02:51 +0000</pubDate>
		<guid isPermaLink="false">http://oliverobrien.co.uk/?p=317#comment-33</guid>
		<description>Do you have or know of a python script to do conversion the other way, OS Grid -&gt; eastings/northings

Tried to reverse engineer the linked javascript but failing miserably :-(</description>
		<content:encoded><![CDATA[<p>Do you have or know of a python script to do conversion the other way, OS Grid -&gt; eastings/northings</p>
<p>Tried to reverse engineer the linked javascript but failing miserably <img src='http://oliverobrien.co.uk/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

