1 |
torben |
2878 |
package dk.daoas.adressevedligehold.afstandandenrute;
|
2 |
|
|
|
3 |
|
|
import dk.daoas.adressevedligehold.beans.Address;
|
4 |
|
|
|
5 |
|
|
public class BoundingBox implements Cloneable{
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
public static class BoundingBoxException extends Exception{
|
9 |
|
|
public BoundingBoxException(String reason) {
|
10 |
|
|
super(reason);
|
11 |
|
|
}
|
12 |
|
|
|
13 |
|
|
private static final long serialVersionUID = 1L;
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
public double latitudeMax;
|
17 |
|
|
public double latitudeMin = Double.MAX_VALUE;
|
18 |
|
|
|
19 |
|
|
public double longitudeMax;
|
20 |
|
|
public double longitudeMin = Double.MAX_VALUE;
|
21 |
|
|
|
22 |
torben |
2884 |
public BoundingBox() {
|
23 |
|
|
}
|
24 |
torben |
2878 |
|
25 |
torben |
2884 |
|
26 |
|
|
public BoundingBox(BoundingBox other) { //Copy constructor
|
27 |
|
|
this.latitudeMax = other.latitudeMax;
|
28 |
|
|
this.longitudeMax = other.longitudeMax;
|
29 |
|
|
|
30 |
|
|
this.latitudeMin = other.latitudeMin;
|
31 |
|
|
this.longitudeMin = other.longitudeMin;
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
|
35 |
torben |
2878 |
@Override
|
36 |
|
|
public String toString() {
|
37 |
|
|
return "bbox: Latitude=" + latitudeMin +"/" + latitudeMax + " longitude=" + longitudeMin + "/" + longitudeMax;
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
public void validateBbox() throws BoundingBoxException {
|
41 |
|
|
|
42 |
|
|
double latDiff = Math.abs(latitudeMax - latitudeMin);
|
43 |
|
|
if ( latDiff > 1.1) {
|
44 |
|
|
throw new BoundingBoxException("For stor latitude forskel / " + latDiff);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
double lngDiff = Math.abs(longitudeMax - longitudeMin);
|
48 |
|
|
if ( lngDiff > 1.1) {
|
49 |
|
|
throw new BoundingBoxException("For stor longitude forskel / " + lngDiff);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
Address min = new Address(latitudeMin, longitudeMin);
|
53 |
|
|
Address max = new Address(latitudeMax, longitudeMax);
|
54 |
|
|
double afstand = GeoPointHelper.beregnAfstand(min, max);
|
55 |
|
|
|
56 |
|
|
if (afstand >= 125.0) { //hvis cross afstand er over X km - så er postnummeret for stort
|
57 |
|
|
throw new BoundingBoxException("For stor cross afstand " + afstand);
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
torben |
2884 |
|
62 |
torben |
2878 |
|
63 |
|
|
|
64 |
|
|
}
|