diff --git a/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/projection/Geostationary.java b/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/projection/Geostationary.java index dd5fc8e17b..f8014bc782 100644 --- a/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/projection/Geostationary.java +++ b/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/projection/Geostationary.java @@ -49,10 +49,11 @@ import org.opengis.referencing.operation.MathTransform; * * SOFTWARE HISTORY * - * Date Ticket# Engineer Description - * ------------ ---------- ----------- -------------------------- - * Jun 27, 2013 mschenke Initial creation - * Oct 02, 2013 2333 mschenke Converted from libproj to CGMS algorithm + * Date Ticket# Engineer Description + * ------------- -------- ----------- -------------------------- + * Jun 27, 2013 mschenke Initial creation + * Oct 02, 2013 2333 mschenke Converted from libproj to CGMS algorithm + * Nov 18, 2013 2528 bsteffen Add hashCode/equals. * * * @@ -212,6 +213,34 @@ public class Geostationary extends MapProjection { return ptDst; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + long temp; + temp = Double.doubleToLongBits(orbitalHeight); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + (swapAxis ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + Geostationary other = (Geostationary) obj; + if (Double.doubleToLongBits(orbitalHeight) != Double + .doubleToLongBits(other.orbitalHeight)) + return false; + if (swapAxis != other.swapAxis) + return false; + return true; + } + public static class Provider extends AbstractProvider { private static final long serialVersionUID = 3868187206568280453L; diff --git a/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/EnvelopeIntersection.java b/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/EnvelopeIntersection.java index 0cd70e7ca2..b14345305e 100644 --- a/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/EnvelopeIntersection.java +++ b/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/EnvelopeIntersection.java @@ -88,11 +88,30 @@ public class EnvelopeIntersection { int maxVertDivisions) throws TransformException, FactoryException { ReferencedEnvelope sourceREnvelope = reference(sourceEnvelope); ReferencedEnvelope targetREnvelope = reference(targetEnvelope); - Geometry border = null; - WorldWrapCorrector corrector = new WorldWrapCorrector(targetREnvelope); MathTransform sourceCRSToTargetCRS = CRS.findMathTransform( sourceREnvelope.getCoordinateReferenceSystem(), targetREnvelope.getCoordinateReferenceSystem()); + if (sourceCRSToTargetCRS.isIdentity()) { + com.vividsolutions.jts.geom.Envelope intersection = sourceREnvelope + .intersection(targetREnvelope); + if (intersection == null) { + return gf.createGeometryCollection(new Geometry[0]); + } else { + Coordinate[] border = new Coordinate[5]; + border[0] = new Coordinate(intersection.getMinX(), + intersection.getMinY()); + border[1] = new Coordinate(intersection.getMinX(), + intersection.getMaxY()); + border[2] = new Coordinate(intersection.getMaxX(), + intersection.getMaxY()); + border[3] = new Coordinate(intersection.getMaxX(), + intersection.getMinY()); + border[4] = border[0]; + return gf.createPolygon(gf.createLinearRing(border), null); + } + } + Geometry border = null; + WorldWrapCorrector corrector = new WorldWrapCorrector(targetREnvelope); MathTransform targetCRSToSourceCRS = sourceCRSToTargetCRS.inverse(); MathTransform targetCRSToLatLon = MapUtil .getTransformToLatLon(targetREnvelope diff --git a/tests/unit/com/raytheon/uf/common/geospatial/util/EnvelopeIntersectionTest.java b/tests/unit/com/raytheon/uf/common/geospatial/util/EnvelopeIntersectionTest.java index 58f52558d8..21ad716cdb 100644 --- a/tests/unit/com/raytheon/uf/common/geospatial/util/EnvelopeIntersectionTest.java +++ b/tests/unit/com/raytheon/uf/common/geospatial/util/EnvelopeIntersectionTest.java @@ -320,6 +320,16 @@ public class EnvelopeIntersectionTest { 19097.596365784917, 64, 49, expected); } + @Test + public final void testGeostationaryToGeostationary() + throws TransformException, FactoryException { + /* This was created using printSimplePolygon. */ + float[] expected = { -5434871, -3799600, -5434871, -721443, -2356714, + -721443, -2356714, -3799600, -5434871, -3799600 }; + test(KNOWN_ENVELOPES.GEOSTATIONARY, KNOWN_ENVELOPES.GEOSTATIONARY, + 19097.596365784917, 64, 49, expected); + } + /** * This method can be used to assist in generating test cases. It starts * with a known good result and minimizes the amount of text to put in the