private void adjustDateLineCrossingPoints() { ArrayList<LatLon> corners = new ArrayList<LatLon>(Arrays.asList(sw, se, nw, ne)); if (!LatLon.locationsCrossDateLine(corners)) return; double lonSign = 0; for (LatLon corner : corners) { if (Math.abs(corner.getLongitude().degrees) != 180) lonSign = Math.signum(corner.getLongitude().degrees); } if (lonSign == 0) return; if (Math.abs(sw.getLongitude().degrees) == 180 && Math.signum(sw.getLongitude().degrees) != lonSign) sw = new Position(sw.getLatitude(), sw.getLongitude().multiply(-1), sw.getElevation()); if (Math.abs(se.getLongitude().degrees) == 180 && Math.signum(se.getLongitude().degrees) != lonSign) se = new Position(se.getLatitude(), se.getLongitude().multiply(-1), se.getElevation()); if (Math.abs(nw.getLongitude().degrees) == 180 && Math.signum(nw.getLongitude().degrees) != lonSign) nw = new Position(nw.getLatitude(), nw.getLongitude().multiply(-1), nw.getElevation()); if (Math.abs(ne.getLongitude().degrees) == 180 && Math.signum(ne.getLongitude().degrees) != lonSign) ne = new Position(ne.getLatitude(), ne.getLongitude().multiply(-1), ne.getElevation()); }
public SquareSector( int UTMZone, String hemisphere, Sector UTMZoneSector, double SWEasting, double SWNorthing, double size) { this.UTMZone = UTMZone; this.hemisphere = hemisphere; this.UTMZoneSector = UTMZoneSector; this.SWEasting = SWEasting; this.SWNorthing = SWNorthing; this.size = size; // Compute corners positions this.sw = computePosition(this.UTMZone, this.hemisphere, SWEasting, SWNorthing); this.se = computePosition(this.UTMZone, this.hemisphere, SWEasting + size, SWNorthing); this.nw = computePosition(this.UTMZone, this.hemisphere, SWEasting, SWNorthing + size); this.ne = computePosition(this.UTMZone, this.hemisphere, SWEasting + size, SWNorthing + size); this.squareCenter = computePosition( this.UTMZone, this.hemisphere, SWEasting + size / 2, SWNorthing + size / 2); // Compute approximate bounding sector and center point if (this.sw != null && this.se != null && this.nw != null && this.ne != null) { adjustDateLineCrossingPoints(); this.boundingSector = Sector.boundingSector(Arrays.asList(sw, se, nw, ne)); if (!isInsideGridZone()) this.boundingSector = this.UTMZoneSector.intersection(this.boundingSector); this.centroid = this.boundingSector != null ? this.boundingSector.getCentroid() : this.squareCenter; // this.squareCenter = this.boundingSector.getCentroid(); } // Check whether this square is truncated by the grid zone boundary this.isTruncated = !isInsideGridZone(); }