/** * Prefills BBox with minimum values so that it can increase. */ public static BBox createInverse(boolean elevation) { if (elevation) { return new BBox(Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, true); } else { return new BBox(Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE, Double.NaN, Double.NaN, false); } }
BBox polygonBounds = BBox.createInverse(false); List<SpatialRule> spatialRules = new ArrayList<>(); spatialRules.add(spatialRule); for (Polygon polygon : spatialRule.getBorders()) { polygonBounds.update(polygon.getMinLat(), polygon.getMinLon()); polygonBounds.update(polygon.getMaxLat(), polygon.getMaxLon()); if (!polygonBounds.isValid()) { return SpatialRuleLookup.EMPTY; BBox calculatedBounds = polygonBounds.calculateIntersection(maxBBox); if (calculatedBounds == null) return SpatialRuleLookup.EMPTY;
/** * Calculates the intersecting BBox between this and the specified BBox * * @return the intersecting BBox or null if not intersecting */ public BBox calculateIntersection(BBox bBox) { if (!this.intersect(bBox)) return null; double minLon = Math.max(this.minLon, bBox.minLon); double maxLon = Math.min(this.maxLon, bBox.maxLon); double minLat = Math.max(this.minLat, bBox.minLat); double maxLat = Math.min(this.maxLat, bBox.maxLat); return new BBox(minLon, maxLon, minLat, maxLat); }
/** * Calculates the 2D bounding box of this route */ public BBox calcBBox2D() { check("calcRouteBBox"); BBox bounds = BBox.createInverse(false); for (int i = 0; i < pointList.getSize(); i++) { bounds.update(pointList.getLatitude(i), pointList.getLongitude(i)); } return bounds; }
List<String> lines = Helper.readFile(file); List<Integer> landmarkNodeIds = new ArrayList<>(); BBox bbox = BBox.createInverse(false); int lmSuggestionIdx = 0; String errors = ""; for (String lmStr : lines) { if (lmStr.startsWith("#BBOX:")) { bbox = BBox.parseTwoPoints(lmStr.substring("#BBOX:".length())); continue; } else if (lmStr.isEmpty() || Character.isAlphabetic(lmStr.charAt(0))) { bbox.update(point.lat, point.lon); landmarkNodeIds.add(result.getClosestNode());
@Test public void testBounds() throws IOException { final FileReader reader = new FileReader(COUNTRIES_FILE); SpatialRuleLookup spatialRuleLookup = SpatialRuleLookupBuilder.buildIndex(Jackson.newObjectMapper().readValue(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, new BBox(-180, 180, -90, 90)); BBox almostWorldWide = new BBox(-179, 179, -89, 89); // Might fail if a polygon is defined outside the above coordinates assertTrue("BBox seems to be not contracted", almostWorldWide.contains(spatialRuleLookup.getBounds())); }
/** * Calculates the bounding box of this route response */ public BBox calcRouteBBox(BBox _fallback) { check("calcRouteBBox"); BBox bounds = BBox.createInverse(_fallback.hasElevation()); int len = pointList.getSize(); if (len == 0) return _fallback; for (int i = 0; i < len; i++) { double lat = pointList.getLatitude(i); double lon = pointList.getLongitude(i); if (bounds.hasElevation()) { double ele = pointList.getEle(i); bounds.update(lat, lon, ele); } else { bounds.update(lat, lon); } } return bounds; }
public static int calcIndexSize(BBox graphBounds) { if (!graphBounds.isValid()) throw new IllegalArgumentException("Bounding box is not valid to calculate index size: " + graphBounds); double dist = DIST_EARTH.calcDist(graphBounds.maxLat, graphBounds.minLon, graphBounds.minLat, graphBounds.maxLon); // convert to km and maximum is 50000km => 1GB dist = Math.min(dist / 1000, 50000); return Math.max(2000, (int) (dist * dist)); }
this.bounds = BBox.createInverse(withElevation); this.nodeAccess = new GHNodeAccess(this, withElevation); this.extStorage = extendedStorage;
public void update(double lat, double lon, double elev) { if (elevation) { if (elev > maxEle) { maxEle = elev; } if (elev < minEle) { minEle = elev; } } else { throw new IllegalStateException("No BBox with elevation to update"); } update(lat, lon); }
@Override public boolean intersect(Shape s) { if (s instanceof BBox) { return intersect((BBox) s); } else if (s instanceof Circle) { return ((Circle) s).intersect(this); } throw new UnsupportedOperationException("unsupported shape"); }
protected int loadNodesHeader() { nodeEntryBytes = nodes.getHeader(1 * 4); nodeCount = nodes.getHeader(2 * 4); bounds.minLon = Helper.intToDegree(nodes.getHeader(3 * 4)); bounds.maxLon = Helper.intToDegree(nodes.getHeader(4 * 4)); bounds.minLat = Helper.intToDegree(nodes.getHeader(5 * 4)); bounds.maxLat = Helper.intToDegree(nodes.getHeader(6 * 4)); if (bounds.hasElevation()) { bounds.minEle = Helper.intToEle(nodes.getHeader(7 * 4)); bounds.maxEle = Helper.intToEle(nodes.getHeader(8 * 4)); } frozen = nodes.getHeader(9 * 4) == 1; return 10; }
public SpatialKeyAlgo bounds(BBox box) { bbox = box.clone(); return this; }
List<String> lines = Helper.readFile(file); List<Integer> landmarkNodeIds = new ArrayList<>(); BBox bbox = BBox.createInverse(false); int lmSuggestionIdx = 0; String errors = ""; for (String lmStr : lines) { if (lmStr.startsWith("#BBOX:")) { bbox = BBox.parseTwoPoints(lmStr.substring("#BBOX:".length())); continue; } else if (lmStr.isEmpty() || Character.isAlphabetic(lmStr.charAt(0))) { bbox.update(point.lat, point.lon); landmarkNodeIds.add(result.getClosestNode());
@Test public void testIntersection() throws IOException { /* We are creating a BBox smaller than Germany. We have the German Spatial rule activated by default. So the BBox should not contain a Point lying somewhere close in Germany. */ final FileReader reader = new FileReader(COUNTRIES_FILE); SpatialRuleLookup spatialRuleLookup = SpatialRuleLookupBuilder.buildIndex(Jackson.newObjectMapper().readValue(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, new BBox(9, 10, 51, 52)); assertFalse("BBox seems to be incorrectly contracted", spatialRuleLookup.getBounds().contains(49.9, 8.9)); }
/** * Calculates the bounding box of this route response */ public BBox calcRouteBBox( BBox _fallback ) { check("calcRouteBBox"); BBox bounds = BBox.createInverse(_fallback.hasElevation()); int len = pointList.getSize(); if (len == 0) return _fallback; for (int i = 0; i < len; i++) { double lat = pointList.getLatitude(i); double lon = pointList.getLongitude(i); if (bounds.hasElevation()) { double ele = pointList.getEle(i); bounds.update(lat, lon, ele); } else { bounds.update(lat, lon); } } return bounds; }
/** * Calculates the 2D bounding box of this route */ public BBox calcBBox2D() { check("calcRouteBBox"); BBox bounds = BBox.createInverse(false); for (int i = 0; i < pointList.getSize(); i++) { bounds.update(pointList.getLatitude(i), pointList.getLongitude(i)); } return bounds; }
@Override protected Result check() { boolean valid = graphHopperStorage.getBounds().isValid(); if (valid) { return Result.healthy(); } else { return Result.unhealthy("GraphHopperStorage has invalid bounds."); } } }