1 |
package dk.daoas.fulddaekning;
|
2 |
|
3 |
public class BoundingBox implements Cloneable{
|
4 |
|
5 |
|
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 |
public double latitudeMax;
|
15 |
public double latitudeMin = Double.MAX_VALUE;
|
16 |
|
17 |
public double longitudeMax;
|
18 |
public double longitudeMin = Double.MAX_VALUE;
|
19 |
|
20 |
|
21 |
@Override
|
22 |
public String toString() {
|
23 |
return "bbox: Latitude=" + latitudeMin +"/" + latitudeMax + " longitude=" + longitudeMin + "/" + longitudeMax;
|
24 |
}
|
25 |
|
26 |
public void validateBbox() throws BoundingBoxException {
|
27 |
|
28 |
double latDiff = Math.abs(latitudeMax - latitudeMin);
|
29 |
if ( latDiff > 1.1) {
|
30 |
throw new BoundingBoxException("For stor latitude forskel / " + latDiff);
|
31 |
}
|
32 |
|
33 |
double lngDiff = Math.abs(longitudeMax - longitudeMin);
|
34 |
if ( lngDiff > 1.1) {
|
35 |
throw new BoundingBoxException("For stor longitude forskel / " + lngDiff);
|
36 |
}
|
37 |
|
38 |
Adresse min = new Adresse(latitudeMin, longitudeMin);
|
39 |
Adresse max = new Adresse(latitudeMax, longitudeMax);
|
40 |
double afstand = GeoPointHelper.beregnAfstand(min, max);
|
41 |
|
42 |
if (afstand >= 125.0) { //hvis cross afstand er over X km - så er postnummeret for stort
|
43 |
throw new BoundingBoxException("For stor cross afstand " + afstand);
|
44 |
}
|
45 |
}
|
46 |
|
47 |
|
48 |
@Override
|
49 |
public BoundingBox clone() {
|
50 |
BoundingBox bb = new BoundingBox();
|
51 |
bb.latitudeMax = this.latitudeMax;
|
52 |
bb.longitudeMax = this.longitudeMax;
|
53 |
|
54 |
bb.latitudeMin = this.latitudeMin;
|
55 |
bb.longitudeMin = this.longitudeMin;
|
56 |
|
57 |
return bb;
|
58 |
}
|
59 |
|
60 |
|
61 |
}
|