From 8c3deb1a9371aec8d1883f2f443715af4a229585 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Thu, 31 Jan 2013 17:05:47 -0600 Subject: [PATCH] Issue #1553 fix RenderableTileSet for round projections. Former-commit-id: 1e6d6ac799a90dbcb2e8356c61263cad4ee3baf9 [formerly 8bd997f193b4a8cc75fc6609b321b29f2524c08b] Former-commit-id: f31215a99996907017646ec993acb981a655b729 --- .../geospatial/util/EnvelopeIntersection.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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 ede1420869..dc4a2c9d32 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 @@ -174,6 +174,10 @@ public class EnvelopeIntersection { MathTransform latLonToTargetCRS = targetCRSToLatLon.inverse(); + // If we are able to create a polygon from the lineStrings, save it in + // this variable to use later if all else fails. + Geometry correctedPolygon = null; + int numStrings = lineStrings.size(); if (numStrings == 1) { // Check for one continuous line string that starts and ends at same @@ -182,7 +186,8 @@ public class EnvelopeIntersection { Coordinate[] coords = ls.getCoordinates(); if (coords[0].equals(coords[coords.length - 1])) { border = gf.createPolygon(gf.createLinearRing(coords), null); - border = JTS.transform(corrector.correct(JTS.transform(border, + border = correctedPolygon = JTS.transform(corrector.correct(JTS + .transform(border, targetCRSToLatLon)), latLonToTargetCRS); } } @@ -481,6 +486,28 @@ public class EnvelopeIntersection { } } + if ((border == null || border.isEmpty() || border.isValid() == false)) { + if (correctedPolygon != null) { + // buffering will make an invalid polygon valid. This is known + // to be the correct action for rounded grids such as lat/lon + // source on a polar stereographic target or radial data. + border = correctedPolygon.buffer(0); + } else if (lineStrings.size() == 1) { + // There is a last resort. There are no known envelopes that hit + // this but just in case we have problems this will be slightly + // better than nothing. + border = lineStrings.get(0).getEnvelope(); + } else { + // Also a last resort. + List envelopes = new ArrayList( + lineStrings.size()); + for (LineString ls : lineStrings) { + envelopes.add(ls.getEnvelope()); + } + gf.createGeometryCollection(envelopes.toArray(new Geometry[0])); + } + } + System.out.println("Time to create EnvelopeIntersection: " + (System.currentTimeMillis() - t0) + "ms"); return border;