1 |
torben |
2145 |
package dk.daoas.fulddaekning;
|
2 |
|
|
|
3 |
|
|
public class BoundingBox {
|
4 |
torben |
2200 |
|
5 |
torben |
2145 |
|
6 |
|
|
public static class BoundingBoxException extends Exception{
|
7 |
|
|
public BoundingBoxException(String reason) {
|
8 |
|
|
super(reason);
|
9 |
|
|
}
|
10 |
|
|
|
11 |
|
|
private static final long serialVersionUID = 1L;
|
12 |
|
|
}
|
13 |
|
|
|
14 |
torben |
2200 |
//public static final double LATITUDE_MARGIN = 0.02702703;
|
15 |
|
|
//public static final double LONGUTUDE_MARGIN = 0.046875;
|
16 |
torben |
2145 |
|
17 |
|
|
public double latitudeMax;
|
18 |
torben |
2328 |
public double latitudeMin = Double.MAX_VALUE;
|
19 |
torben |
2145 |
|
20 |
|
|
public double longitudeMax;
|
21 |
torben |
2328 |
public double longitudeMin = Double.MAX_VALUE;
|
22 |
torben |
2145 |
|
23 |
|
|
|
24 |
|
|
@Override
|
25 |
|
|
public String toString() {
|
26 |
torben |
2146 |
return "bbox: Latitude=" + latitudeMin +"/" + latitudeMax + " longitude=" + longitudeMin + "/" + longitudeMax;
|
27 |
torben |
2145 |
}
|
28 |
|
|
|
29 |
|
|
public void validateBbox() throws BoundingBoxException {
|
30 |
torben |
2328 |
|
31 |
torben |
2239 |
double latDiff = Math.abs(latitudeMax - latitudeMin);
|
32 |
torben |
2264 |
if ( latDiff > 1.1) {
|
33 |
torben |
2239 |
throw new BoundingBoxException("For stor latitude forskel / " + latDiff);
|
34 |
|
|
}
|
35 |
torben |
2211 |
|
36 |
torben |
2239 |
double lngDiff = Math.abs(longitudeMax - longitudeMin);
|
37 |
torben |
2264 |
if ( lngDiff > 1.1) {
|
38 |
torben |
2239 |
throw new BoundingBoxException("For stor longitude forskel / " + lngDiff);
|
39 |
|
|
}
|
40 |
|
|
|
41 |
torben |
2211 |
GeoPoint min = new GeoPoint(latitudeMin, longitudeMin);
|
42 |
|
|
GeoPoint max = new GeoPoint(latitudeMax, longitudeMax);
|
43 |
|
|
double afstand = GeoPoint.beregnAfstand(min, max);
|
44 |
|
|
|
45 |
torben |
2240 |
if (afstand >= 125.0) { //hvis cross afstand er over 80 km - så er postnummeret for stort
|
46 |
torben |
2211 |
throw new BoundingBoxException("For stor cross afstand " + afstand);
|
47 |
|
|
}
|
48 |
torben |
2145 |
}
|
49 |
|
|
|
50 |
torben |
2330 |
public void adjustToMargin(double kmMargin) {
|
51 |
|
|
double latMargin = GeoPoint.kmToLatitude(kmMargin);
|
52 |
|
|
double lngMargin = GeoPoint.kmToLongitude(kmMargin);
|
53 |
torben |
2145 |
|
54 |
torben |
2330 |
latitudeMax += latMargin;
|
55 |
|
|
latitudeMin -= latMargin;
|
56 |
torben |
2200 |
|
57 |
torben |
2330 |
longitudeMax += lngMargin;
|
58 |
|
|
longitudeMin -= lngMargin;
|
59 |
torben |
2145 |
}
|
60 |
|
|
|
61 |
torben |
2247 |
@Override
|
62 |
|
|
public BoundingBox clone() {
|
63 |
|
|
BoundingBox bb = new BoundingBox();
|
64 |
|
|
bb.latitudeMax = this.latitudeMax;
|
65 |
|
|
bb.longitudeMax = this.longitudeMax;
|
66 |
|
|
|
67 |
|
|
bb.latitudeMin = this.latitudeMin;
|
68 |
|
|
bb.longitudeMin = this.longitudeMin;
|
69 |
|
|
|
70 |
|
|
return bb;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
torben |
2145 |
|
74 |
|
|
}
|