1 |
package dk.daoas.fulddaekning; |
package dk.daoas.fulddaekning; |
2 |
|
|
3 |
public class BoundingBox { |
public class BoundingBox { |
4 |
|
|
5 |
|
|
6 |
public static class BoundingBoxException extends Exception{ |
public static class BoundingBoxException extends Exception{ |
7 |
public BoundingBoxException(String reason) { |
public BoundingBoxException(String reason) { |
10 |
|
|
11 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
12 |
} |
} |
13 |
|
|
|
public static final double LATITUDE_MARGIN = 0.02702703; |
|
|
public static final double LONGUTUDE_MARGIN = 0.046875; |
|
|
|
|
14 |
public double latitudeMax; |
public double latitudeMax; |
15 |
public double latitudeMin; |
public double latitudeMin = Double.MAX_VALUE; |
16 |
|
|
17 |
public double longitudeMax; |
public double longitudeMax; |
18 |
public double longitudeMin; |
public double longitudeMin = Double.MAX_VALUE; |
19 |
|
|
20 |
|
|
21 |
@Override |
@Override |
22 |
public String toString() { |
public String toString() { |
23 |
return "bbox: Latitude=" + latitudeMax +"/" + latitudeMin + " longitude=" + longitudeMax + "/" + longitudeMin; |
return "bbox: Latitude=" + latitudeMin +"/" + latitudeMax + " longitude=" + longitudeMin + "/" + longitudeMax; |
24 |
} |
} |
25 |
|
|
26 |
public void validateBbox() throws BoundingBoxException { |
public void validateBbox() throws BoundingBoxException { |
27 |
if ( Math.abs(latitudeMax-latitudeMin)> 1.0) |
|
28 |
throw new BoundingBoxException("For stor latitude forskel"); |
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 |
if ( Math.abs(longitudeMax-longitudeMin)> 1.0) |
GeoPoint min = new GeoPoint(latitudeMin, longitudeMin); |
39 |
throw new BoundingBoxException("For stor longitude forskel"); |
GeoPoint max = new GeoPoint(latitudeMax, longitudeMax); |
40 |
|
double afstand = GeoPoint.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 |
|
public void adjustToMargin(double kmMargin) { |
48 |
|
double latMargin = GeoPoint.kmToLatitude(kmMargin); |
49 |
|
double lngMargin = GeoPoint.kmToLongitude(kmMargin); |
50 |
|
|
51 |
|
latitudeMax += latMargin; |
52 |
|
latitudeMin -= latMargin; |
53 |
|
|
54 |
|
longitudeMax += lngMargin; |
55 |
|
longitudeMin -= lngMargin; |
56 |
} |
} |
57 |
|
|
58 |
public void adjustToMargin() { |
@Override |
59 |
latitudeMax += LATITUDE_MARGIN; |
public BoundingBox clone() { |
60 |
latitudeMin -= LATITUDE_MARGIN; |
BoundingBox bb = new BoundingBox(); |
61 |
|
bb.latitudeMax = this.latitudeMax; |
62 |
|
bb.longitudeMax = this.longitudeMax; |
63 |
|
|
64 |
|
bb.latitudeMin = this.latitudeMin; |
65 |
|
bb.longitudeMin = this.longitudeMin; |
66 |
|
|
67 |
longitudeMax += LONGUTUDE_MARGIN; |
return bb; |
|
longitudeMin -= LONGUTUDE_MARGIN; |
|
68 |
} |
} |
69 |
|
|
70 |
|
|