|
From: Adam B. <ab...@us...> - 2005-04-06 23:39:51
|
Update of /cvsroot/hipgmap/gmap/com/trileet/gmap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15703 Modified Files: Point.java Log Message: You can now ask a Point for its KeyHole (KH) coordinates. See the wiki for discussions of this. Next I'm going to start playing with some of the Photo tiles.... Index: Point.java =================================================================== RCS file: /cvsroot/hipgmap/gmap/com/trileet/gmap/Point.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Point.java 3 Apr 2005 11:21:53 -0000 1.3 --- Point.java 6 Apr 2005 23:39:42 -0000 1.4 *************** *** 81,91 **** } public static void main(String[] argv) { // A little test routine ! Point p = new Point(3256000,-11824000); ! System.out.println(p.toString()); ! Point q = fromString(p.toString()); ! System.out.println(q.toString()); ! System.out.println(q.lat.toString()); } } --- 81,115 ---- } + /** + * We can convert the point's lat/lng to KeyHole (KH) coordinates. + * See Eric's writeup of the KH system on the wiki, and my + * explanation of the algorithm on the talk:Satellite page. + */ + + private static final hipfloat h180 = new hipfloat(180); + private static final hipfloat h360 = new hipfloat(360); + private static final hipfloat h2p18 = new hipfloat(1<<19); + private static final char[] KHCHARS = {'t','q','s','r'}; + public static String latLngToKH(hipfloat lat, hipfloat lng) { + int y = lat.add(h180).div(h360).mul(h2p18).toint(); + int x = lng.add(h180).div(h360).mul(h2p18).toint(); + + char[] outArr = new char[20]; + for (int i=0; i<19; i++) { + int index = ((x & 1<<(19-i))>>(18-i)); + index |= ((y & 1<<(19-i))>>(19-i)); + outArr[i] = KHCHARS[index]; + } + return new String(outArr); + //return String.valueOf(x) + " " + String.valueOf(y); + } + public String getKH() { + return latLngToKH(this.lat,this.lng); + } + public static void main(String[] argv) { // A little test routine ! Point p = new Point(3787206,-12227688); ! System.out.println(p.getKH()); } } |