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 |
|
|
public double latitudeMin;
|
19 |
|
|
|
20 |
|
|
public double longitudeMax;
|
21 |
|
|
public double longitudeMin;
|
22 |
|
|
|
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 |
2211 |
|
31 |
torben |
2145 |
if ( Math.abs(latitudeMax-latitudeMin)> 1.0)
|
32 |
|
|
throw new BoundingBoxException("For stor latitude forskel");
|
33 |
|
|
|
34 |
|
|
if ( Math.abs(longitudeMax-longitudeMin)> 1.0)
|
35 |
torben |
2211 |
throw new BoundingBoxException("For stor longitude forskel");
|
36 |
|
|
|
37 |
|
|
GeoPoint min = new GeoPoint(latitudeMin, longitudeMin);
|
38 |
|
|
GeoPoint max = new GeoPoint(latitudeMax, longitudeMax);
|
39 |
|
|
double afstand = GeoPoint.beregnAfstand(min, max);
|
40 |
|
|
|
41 |
torben |
2221 |
if (afstand >= 80.0) { //hvis cross afstand er over 80 km - så er postnummeret for stort
|
42 |
torben |
2211 |
throw new BoundingBoxException("For stor cross afstand " + afstand);
|
43 |
|
|
}
|
44 |
torben |
2145 |
}
|
45 |
|
|
|
46 |
|
|
public void adjustToMargin() {
|
47 |
torben |
2200 |
Constants consts = Constants.getInstance();
|
48 |
torben |
2145 |
|
49 |
torben |
2200 |
latitudeMax += consts.getLatitudeMargin();
|
50 |
|
|
latitudeMin -= consts.getLatitudeMargin();
|
51 |
|
|
|
52 |
|
|
longitudeMax += consts.getLongitudeMargin();
|
53 |
|
|
longitudeMin -= consts.getLongitudeMargin();
|
54 |
torben |
2145 |
}
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
}
|