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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2748 - (show annotations) (download)
Thu Oct 8 11:45:29 2015 UTC (8 years, 7 months ago) by torben
File size: 2202 byte(s)
Remove the other old and unused K-d implementation
1 package dk.daoas.fulddaekning;
2
3
4
5 public class GeoPointHelper {
6
7
8
9 // Latitude (horizonal), longitude(vertical) so
10 // 1 degree latitude is ~ 111320 meters, since the distance between the
11 // horizonal lines is always the same
12 // 1 degree longitude is ~111320 meters at equator but gets shorter as we
13 // get closer to the poles.
14 // so 1 degree longitude is 64.5 km at denmarks southern point
15 // (gedser=54.55,11.95)
16 // and is 59.4km at northern point (skagen = 57.75,10.65)
17
18 public static double kmToLatitude(double km) {
19 return km / 111.320;
20 }
21
22 public static double kmToLongitude(double km) {// denne er kun ca
23 return km / 62.0;
24 }
25
26 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27
28 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
29 /* :: This function converts decimal degrees to radians : */
30 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
31 private static double deg2rad(double deg) {
32 return (deg * Math.PI / 180.0);
33 }
34
35 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
36 /* :: This function converts radians to decimal degrees : */
37 /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */
38 private static double rad2deg(double rad) {
39 return (rad * 180 / Math.PI);
40 }
41
42 // http://www.geodatasource.com/developers/java
43 private static double distanceHaversine(double lat1, double lon1,
44 double lat2, double lon2) {
45 double theta = lon1 - lon2;
46 double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
47 + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2))
48 * Math.cos(deg2rad(theta));
49 dist = Math.acos(dist);
50 dist = rad2deg(dist);
51 dist = dist * 60 * 1.1515;
52
53 // indtil nu er dist i miles - så vi omregner lige til km
54 dist = dist * 1.609344;
55 return (dist);
56 }
57
58 public static double beregnAfstand(Adresse p1, Adresse p2) {
59 if (p1.latitude == p2.latitude && p1.longitude == p2.longitude) {
60 return 0.00; //Haversine går i baglås hvis p1 og p2 er samme position
61 }
62
63
64 return distanceHaversine(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
65 }
66
67 }

  ViewVC Help
Powered by ViewVC 1.1.20