--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/BoundingBox.java 2014/04/30 08:15:48 2145 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/BoundingBox.java 2015/09/27 13:21:45 2707 @@ -1,6 +1,7 @@ package dk.daoas.fulddaekning; -public class BoundingBox { +public class BoundingBox implements Cloneable{ + public static class BoundingBoxException extends Exception{ public BoundingBoxException(String reason) { @@ -9,36 +10,51 @@ private static final long serialVersionUID = 1L; } - - public static final double LATITUDE_MARGIN = 0.02702703; - public static final double LONGUTUDE_MARGIN = 0.046875; - + public double latitudeMax; - public double latitudeMin; + public double latitudeMin = Double.MAX_VALUE; public double longitudeMax; - public double longitudeMin; + public double longitudeMin = Double.MAX_VALUE; @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"); + + double latDiff = Math.abs(latitudeMax - latitudeMin); + if ( latDiff > 1.1) { + throw new BoundingBoxException("For stor latitude forskel / " + latDiff); + } - if ( Math.abs(longitudeMax-longitudeMin)> 1.0) - throw new BoundingBoxException("For stor longitude forskel"); + double lngDiff = Math.abs(longitudeMax - longitudeMin); + if ( lngDiff > 1.1) { + throw new BoundingBoxException("For stor longitude forskel / " + lngDiff); + } + + Adresse min = new Adresse(latitudeMin, longitudeMin); + Adresse max = new Adresse(latitudeMax, longitudeMax); + double afstand = GeoPointHelper.beregnAfstand(min, max); + + if (afstand >= 125.0) { //hvis cross afstand er over X km - så er postnummeret for stort + throw new BoundingBoxException("For stor cross afstand " + afstand); + } } - public void adjustToMargin() { - latitudeMax += LATITUDE_MARGIN; - latitudeMin -= LATITUDE_MARGIN; + + @Override + public BoundingBox clone() { + BoundingBox bb = new BoundingBox(); + bb.latitudeMax = this.latitudeMax; + bb.longitudeMax = this.longitudeMax; + + bb.latitudeMin = this.latitudeMin; + bb.longitudeMin = this.longitudeMin; - longitudeMax += LONGUTUDE_MARGIN; - longitudeMin -= LONGUTUDE_MARGIN; + return bb; }