/[projects]/dao/NaermestePakkeshop/src/geocode/GeoPoint.java
ViewVC logotype

Contents of /dao/NaermestePakkeshop/src/geocode/GeoPoint.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2582 - (show annotations) (download)
Sun Jun 14 07:53:37 2015 UTC (8 years, 11 months ago) by torben
File size: 3260 byte(s)
Initial import.
1 /*
2 The MIT License (MIT)
3 [OSI Approved License]
4 The MIT License (MIT)
5
6 Copyright (c) 2014 Daniel Glasson
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 THE SOFTWARE.
25 */
26
27 package geocode;
28
29 import geocode.kdtree.KDNodeComparator;
30 import static java.lang.Math.cos;
31 import static java.lang.Math.sin;
32 import static java.lang.Math.toRadians;
33
34 import java.util.Comparator;
35
36 /**
37 * Created by Daniel Glasson on 18/05/2014.
38 * This class works with a placenames files from http://download.geonames.org/export/dump/
39 */
40
41 public class GeoPoint extends KDNodeComparator<GeoPoint> {
42 public double latitude;
43 public double longitude;
44 public double point[] = new double[3]; // The 3D coordinates of the point
45
46
47 public GeoPoint(Double latitude, Double longitude) {
48 this.latitude = latitude;
49 this.longitude = longitude;
50 setPoint();
51 }
52
53 private void setPoint() {
54 point[0] = cos(toRadians(latitude)) * cos(toRadians(longitude));
55 point[1] = cos(toRadians(latitude)) * sin(toRadians(longitude));
56 point[2] = sin(toRadians(latitude));
57 }
58
59
60
61 @Override
62 protected double squaredDistance(GeoPoint other) {
63 double x = this.point[0] - other.point[0];
64 double y = this.point[1] - other.point[1];
65 double z = this.point[2] - other.point[2];
66 return (x*x) + (y*y) + (z*z);
67 }
68
69 @Override
70 protected double axisSquaredDistance(GeoPoint other, int axis) {
71 double distance = point[axis] - other.point[axis];
72 return distance * distance;
73 }
74
75 @Override
76 protected Comparator<GeoPoint> getComparator(int axis) {
77 return GeoNameComparator.values()[axis];
78 }
79
80 protected static enum GeoNameComparator implements Comparator<GeoPoint> {
81 x {
82 @Override
83 public int compare(GeoPoint a, GeoPoint b) {
84 return Double.compare(a.point[0], b.point[0]);
85 }
86 },
87 y {
88 @Override
89 public int compare(GeoPoint a, GeoPoint b) {
90 return Double.compare(a.point[1], b.point[1]);
91 }
92 },
93 z {
94 @Override
95 public int compare(GeoPoint a, GeoPoint b) {
96 return Double.compare(a.point[2], b.point[2]);
97 }
98 };
99 }
100 }

  ViewVC Help
Powered by ViewVC 1.1.20