def convertEastingNorthing(self, eastingnorthing):
     from mapnik import Projection, Coord
     
     britishProjection = Projection('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs')
     c = Coord(float(eastingnorthing[0]), float(eastingnorthing[1]))
     c = britishProjection.inverse(c)
     return [c.y,c.x]
示例#2
0
    def convertEastingNorthing(self, eastingnorthing):
        from mapnik import Projection, Coord

        britishProjection = Projection(
            '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs'
        )
        c = Coord(float(eastingnorthing[0]), float(eastingnorthing[1]))
        c = britishProjection.inverse(c)
        return [c.y, c.x]
示例#3
0
#!/usr/bin/env python

from mapnik import Coord, Envelope, Projection, forward_, inverse_
import sys

if (len(sys.argv) < 2):
    print sys.argv[0] + " <epsg:code> <Coord or Envelope>"
    sys.exit(1)
else:
    epsg = sys.argv[1]
    p = Projection('+init=%s' % epsg)
    coord = map(float,sys.argv[2].split(','))
    if len(coord) == 2:
        long_lat = Coord(*coord)
        print 'Forwarded:',
        print p.forward(long_lat)
        print
        print 'Inversed:',
        print p.inverse(long_lat)      
    elif len(coord) == 4:
        extent = Envelope(*coord)
        print 'Forwarded:',
        print forward_(extent,p)
        print
        print 'Inversed:',
        print inverse_(extent,p)
示例#4
0
import MySQLdb

""" 
To install mapnik via aptitude use something like apt-get install 
python-mapnik. Might need to apt-cache search on some distros.

Alternatively http://mapnik.org/
"""
from mapnik import Projection, Coord
from decimal import Decimal

DB_HOST = "localhost"
DB_USER = "******"
DB_PASSWORD = "******"
DB_DATABASE = "database"

britishProj = Projection('+init=epsg:27700') # British National Grid

con = MySQLdb.Connect(host = DB_HOST, user = DB_USER, passwd = DB_PASSWORD, db = DB_DATABASE)

cursor = con.cursor()
cursor.execute("SELECT postcode, eastings, northings FROM %s", (DB_DATABASE))
results = cursor.fetchall()

for result in results:
	 val = Coord(float(result[1]), float(result[2]))
	 val = britishProj.inverse(c)
	 #cursor.execute("UPDATE uk_postcode_dev SET latitude='%f', longitude='%f' WHERE postcode='%s'" % (val.y, val.x, result[0]))
	 print result[0]
	 print val.y, val.x
To install mapnik via aptitude use something like apt-get install 
python-mapnik. Might need to apt-cache search on some distros.

Alternatively http://mapnik.org/
"""
from mapnik import Projection, Coord
from decimal import Decimal

DB_HOST = "localhost"
DB_USER = "******"
DB_PASSWORD = "******"
DB_DATABASE = "database"

britishProj = Projection('+init=epsg:27700')  # British National Grid

con = MySQLdb.Connect(host=DB_HOST,
                      user=DB_USER,
                      passwd=DB_PASSWORD,
                      db=DB_DATABASE)

cursor = con.cursor()
cursor.execute("SELECT postcode, eastings, northings FROM %s", (DB_DATABASE))
results = cursor.fetchall()

for result in results:
    val = Coord(float(result[1]), float(result[2]))
    val = britishProj.inverse(c)
    #cursor.execute("UPDATE uk_postcode_dev SET latitude='%f', longitude='%f' WHERE postcode='%s'" % (val.y, val.x, result[0]))
    print result[0]
    print val.y, val.x
示例#6
0
#!/usr/bin/env python

from mapnik import Coord, Envelope, Projection, forward_, inverse_
import sys

if (len(sys.argv) < 2):
    print sys.argv[0] + " <epsg:code> <Coord or Envelope>"
    sys.exit(1)
else:
    epsg = sys.argv[1]
    p = Projection('+init=%s' % epsg)
    coord = map(float, sys.argv[2].split(','))
    if len(coord) == 2:
        long_lat = Coord(*coord)
        print 'Forwarded:',
        print p.forward(long_lat)
        print
        print 'Inversed:',
        print p.inverse(long_lat)
    elif len(coord) == 4:
        extent = Envelope(*coord)
        print 'Forwarded:',
        print forward_(extent, p)
        print
        print 'Inversed:',
        print inverse_(extent, p)