/[projects]/dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/GeoPointHelper.java
ViewVC logotype

Contents of /dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/GeoPointHelper.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2585 - (show annotations) (download)
Sun Jun 14 14:28:21 2015 UTC (8 years, 11 months ago) by torben
File size: 2615 byte(s)
Switch to a K-d tree based implementation

1 package dk.daoas.fulddaekning;
2
3 import geocode.GeoPoint;
4
5 public class GeoPointHelper {
6
7 @Deprecated
8 public static double beregnAfstand_old(GeoPoint point1, GeoPoint point2) {
9 // (62.8*sqrt(3.1*(Power(a.Latitude-x.Latitude,2)+Power(a.Longitude-x.Longitude,2))))
10 // as Afstand,
11
12 double pwrLat = Math.pow(point1.latitude - point2.latitude, 2);
13 double pwrLng = Math.pow(point1.longitude - point2.longitude, 2);
14
15 return 62.8 * Math.sqrt(3.1 * (pwrLat + pwrLng));
16 }
17
18
19
20 // Latitude (horizonal), longitude(vertical) so
21 // 1 degree latitude is ~ 111320 meters, since the distance between the
22 // horizonal lines is always the same
23 // 1 degree longitude is ~111320 meters at equator but gets shorter as we
24 // get closer to the poles.
25 // so 1 degree longitude is 64.5 km at denmarks southern point
26 // (gedser=54.55,11.95)
27 // and is 59.4km at northern point (skagen = 57.75,10.65)
28
29 public static double kmToLatitude(double km) {
30 return km / 111.320;
31 }
32
33 public static double kmToLongitude(double km) {// denne er kun ca
34 return km / 62.0;
35 }
36
37 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38
39 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
40 /* :: This function converts decimal degrees to radians : */
41 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
42 private static double deg2rad(double deg) {
43 return (deg * Math.PI / 180.0);
44 }
45
46 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
47 /* :: This function converts radians to decimal degrees : */
48 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
49 private static double rad2deg(double rad) {
50 return (rad * 180 / Math.PI);
51 }
52
53 // http://www.geodatasource.com/developers/java
54 private static double distanceHaversine(double lat1, double lon1,
55 double lat2, double lon2) {
56 double theta = lon1 - lon2;
57 double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
58 + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2))
59 * Math.cos(deg2rad(theta));
60 dist = Math.acos(dist);
61 dist = rad2deg(dist);
62 dist = dist * 60 * 1.1515;
63
64 // indtil nu er dist i miles - så vi omregner lige til km
65 dist = dist * 1.609344;
66 return (dist);
67 }
68
69 public static double beregnAfstand(GeoPoint p1, GeoPoint p2) {
70 if (p1.latitude == p2.latitude && p1.longitude == p2.longitude) {
71 return 0.00; //Haversine går i baglås hvis p1 og p2 er samme position
72 }
73
74
75 return distanceHaversine(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
76 }
77
78 }

  ViewVC Help
Powered by ViewVC 1.1.20