Blog Home  Home RSS 2.0 Atom 1.0 CDF  
Hairy Spider Blog - gmap
A web of intrigue
 
 Wednesday, January 25, 2006
Last night I was restless, I had one of the nights where ideas pop into my head.

Anyway I was thinking what was happening on the other side of the world right now. Well then I wondered what was actually on the other side of the world. So then I thought how do I define that. Well, as far as I'm concerned there are three extra locations that could be described as the other side of the world:

The exact opposite this would be reached by digging a whole through the centre of the earth, and where you break the surface is the other side of the world. Aswell as this there are also the mirror locations as reflected by the equator and the imaginary meridian 180° away.

So I wrote this Gmap implementation to see what's opposite any location on the globe. As it is given that the world is pretty much covered by water there's very little to see.

1/25/2006 11:02:55 AM (GMT Standard Time, UTC+00:00)  #      gmap  | 
So how the hell do you convert from one coordinate system to another. Well the proper way would be to study and learn all about 3D trig.

The easy way is to read this paper: National GPS Network information: Annexe C. Converting between grid Eastings and Northings and ellipsoidal latitude and longitude

I've done this and it made my eyes bleed. I've taken the information in it and produced the following C# code:

using System;


namespace tt
{
/// /// /// public class LatLonConversions
{
const double a = 6377563.396;
const double b = 6356256.91;
const double e2 = (a -b)/a;
const double n0 = -100000;
const double e0 = 400000;
const double f0 = 0.999601272;
const double phi0 = 0.855211333;
const double lambda0 = -0.034906585;
const double n = (a-b)/(a+b);


private LatLonConversions()
{ }

public static LatLon ConvertOSToLatLon(double E, double N)
{
double phi = 0;
phi = (N-n0)/(a*f0) + phi0;
double M = b * f0 * ( (1 + n + 5/4*n*n + 5/4*n*n*n)*(phi - phi0) - (3*n + 3*n*n + 21/8*n*n*n) * Math.Sin(phi-phi0) * Math.Cos(phi+phi0) +
(15/8*n*n + 15/8*n*n*n) * Math.Sin(2*(phi-phi0))*Math.Cos(2*(phi+phi0))-35/24*n*n*n*Math.Sin(3*(phi-phi0))*Math.Cos(3*(phi+phi0)));

while (N-n0-M>=0.01)
{
phi = (N-n0-M)/(a*f0)+phi;
M = b * f0 * ( (1 + n + 5/4*n*n + 5/4*n*n*n)*(phi - phi0) - (3*n + 3*n*n + 21/8*n*n*n) * Math.Sin(phi-phi0) * Math.Cos(phi+phi0) +
(15/8*n*n + 15/8*n*n*n) * Math.Sin(2*(phi-phi0))*Math.Cos(2*(phi+phi0))-35/24*n*n*n*Math.Sin(3*(phi-phi0))*Math.Cos(3*(phi+phi0)));
}

double v = a*f0*Math.Pow(1-e2*Math.Sin(phi)*Math.Sin(phi),-0.5);

double p = a*f0*Math.Pow(1-e2*Math.Sin(phi)*Math.Sin(phi),-1.5)*(1-e2);
double n2 = v/p-1;

double vii = Math.Tan(phi)/(2*p*v);
double viii = Math.Tan(phi)/(24*p*v*v*v)*(5+3*Math.Tan(phi)*Math.Tan(phi) + n2 - 9*Math.Tan(phi)*Math.Tan(phi)*n2);
double ix = Math.Tan(phi)/(720*p*Math.Pow(v, 5)) * (61 + 90 * Math.Tan(phi) * Math.Tan(phi) + 45 * Math.Pow(Math.Tan(phi), 4));
double x = (1/Math.Cos(phi))/v;
double xi = (1/Math.Cos(phi))/(6*Math.Pow(v, 3)) * (v/p + 2*Math.Pow(Math.Tan(phi), 2));
double xii = (1/Math.Cos(phi))/(120*Math.Pow(v, 5)) * (5 + 28*Math.Pow(Math.Tan(phi), 2) +24*Math.Pow(Math.Tan(phi), 4));
double xiia = (1/Math.Cos(phi))/(5040*Math.Pow(v, 7)) * (61 + 662*Math.Pow(Math.Tan(phi), 2) +1320*Math.Pow(Math.Tan(phi), 4)+ 720*Math.Pow(Math.Tan(phi), 6));

double e = (E-e0);
double lon = (phi - vii * e*e + viii*e*e*e*e-ix*e*e*e*e*e*e ) * 180 / Math.PI;
double lat = (lambda0 + x*e - xi*e*e*e + xii*e*e*e*e*e - xiia*e*e*e*e*e*e*e) *180 / Math.PI;



return new LatLon(lon, lat);
}
}

public class LatLon
{
public double Latitude;
public double Longitude;


public LatLon()
{
Latitude =0;
Longitude =0;
}

public LatLon(double lat, double lon)
{
Latitude =lat;
Longitude =lon;
}

}

}

You can test an implementation of this code using my OS2LatLong webservice.
1/25/2006 10:54:01 AM (GMT Standard Time, UTC+00:00)  #      .net | c-sharp | gmap  | 
 Friday, December 30, 2005
I wanted to have some fun with the Google Maps API I had a feed of data so I thought that I'd use the feed which comes with a little bit of information tagged to a postcode and use that power the google map.

Here's the link to view some posh vehicles on a gmap of the uk

I had some real fun converting the UK style OS map references to lat and long. Which I'll cover in the next post.

12/30/2005 12:19:22 PM (GMT Standard Time, UTC+00:00)  #      .net | gmap | google  | 
Copyright © 2008 Rhys Jeremiah. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: