--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/BoundingBox.java 2014/04/30 08:15:48 2145 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/BoundingBox.java 2014/12/10 07:36:40 2239 @@ -1,6 +1,7 @@ package dk.daoas.fulddaekning; public class BoundingBox { + public static class BoundingBoxException extends Exception{ public BoundingBoxException(String reason) { @@ -10,8 +11,8 @@ private static final long serialVersionUID = 1L; } - public static final double LATITUDE_MARGIN = 0.02702703; - public static final double LONGUTUDE_MARGIN = 0.046875; + //public static final double LATITUDE_MARGIN = 0.02702703; + //public static final double LONGUTUDE_MARGIN = 0.046875; public double latitudeMax; public double latitudeMin; @@ -22,23 +23,38 @@ @Override public String toString() { - return "bbox: Latitude=" + latitudeMax +"/" + latitudeMin + " longitude=" + longitudeMax + "/" + longitudeMin; + return "bbox: Latitude=" + latitudeMin +"/" + latitudeMax + " longitude=" + longitudeMin + "/" + longitudeMax; } public void validateBbox() throws BoundingBoxException { - if ( Math.abs(latitudeMax-latitudeMin)> 1.0) - throw new BoundingBoxException("For stor latitude forskel"); - if ( Math.abs(longitudeMax-longitudeMin)> 1.0) - throw new BoundingBoxException("For stor longitude forskel"); + double latDiff = Math.abs(latitudeMax - latitudeMin); + if ( latDiff > 1.0) { + throw new BoundingBoxException("For stor latitude forskel / " + latDiff); + } + + double lngDiff = Math.abs(longitudeMax - longitudeMin); + if ( lngDiff > 1.0) { + throw new BoundingBoxException("For stor longitude forskel / " + lngDiff); + } + + GeoPoint min = new GeoPoint(latitudeMin, longitudeMin); + GeoPoint max = new GeoPoint(latitudeMax, longitudeMax); + double afstand = GeoPoint.beregnAfstand(min, max); + + if (afstand >= 80.0) { //hvis cross afstand er over 80 km - så er postnummeret for stort + throw new BoundingBoxException("For stor cross afstand " + afstand); + } } public void adjustToMargin() { - latitudeMax += LATITUDE_MARGIN; - latitudeMin -= LATITUDE_MARGIN; + Constants consts = Constants.getInstance(); + + latitudeMax += consts.getLatitudeMargin(); + latitudeMin -= consts.getLatitudeMargin(); - longitudeMax += LONGUTUDE_MARGIN; - longitudeMin -= LONGUTUDE_MARGIN; + longitudeMax += consts.getLongitudeMargin(); + longitudeMin -= consts.getLongitudeMargin(); }