public static Sector boundingSector(Iterable<? extends LatLon> locations) { if (locations == null) { throw new IllegalArgumentException("Positions List Is Null"); } if (!locations.iterator().hasNext()) { return EMPTY_SECTOR; // TODO: should be returning null } double minLat = Angle.POS90.getDegrees(); double minLon = Angle.POS180.getDegrees(); double maxLat = Angle.NEG90.getDegrees(); double maxLon = Angle.NEG180.getDegrees(); for (LatLon p : locations) { double lat = p.getLatitude().getDegrees(); if (lat < minLat) { minLat = lat; } if (lat > maxLat) { maxLat = lat; } double lon = p.getLongitude().getDegrees(); if (lon < minLon) { minLon = lon; } if (lon > maxLon) { maxLon = lon; } } return Sector.fromDegrees(minLat, maxLat, minLon, maxLon); }
public static Sector[] splitBoundingSectors(Iterable<? extends LatLon> locations) { if (locations == null) { throw new IllegalArgumentException("Location In List Is Null"); } if (!locations.iterator().hasNext()) { return null; } double minLat = Angle.POS90.getDegrees(); double minLon = Angle.POS180.getDegrees(); double maxLat = Angle.NEG90.getDegrees(); double maxLon = Angle.NEG180.getDegrees(); LatLon lastLocation = null; for (LatLon ll : locations) { double lat = ll.getLatitude().getDegrees(); if (lat < minLat) { minLat = lat; } if (lat > maxLat) { maxLat = lat; } double lon = ll.getLongitude().getDegrees(); if (lon >= 0 && lon < minLon) { minLon = lon; } if (lon <= 0 && lon > maxLon) { maxLon = lon; } if (lastLocation != null) { double lastLon = lastLocation.getLongitude().getDegrees(); if (Math.signum(lon) != Math.signum(lastLon)) { if (Math.abs(lon - lastLon) < 180) { // Crossing the zero longitude line too maxLon = 0; minLon = 0; } } } lastLocation = ll; } if (minLat == maxLat && minLon == maxLon) { return null; } return new Sector[] { Sector.fromDegrees(minLat, maxLat, minLon, 180), // Sector on eastern hemisphere. Sector.fromDegrees(minLat, maxLat, -180, maxLon) // Sector on western hemisphere. }; }