From 91fcf6f3bed52122a03390ed9f6ff71889b193b4 Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Tue, 25 Sep 2012 10:25:58 -0500 Subject: [PATCH] Issue #1170 Made checks so world wrap correct only occurs if polygon was actually flattened. If polygon was flattened and it is invalid, polygon will be skipped so we only attempt to correct valid polygons. If no correction is needed, we add invalid ones anyway since half of downscaled US invalid. Change-Id: I0c1ddf9f673ff1353f82dec42404985b7f269c10 Former-commit-id: 85e9749e9c6e16313fc3379846f7d62813cdeba0 [formerly a458e73cef5bb84c177fd9b4783be847a7fba194] [formerly 084ac453b0e3cab936254a77b74ad71de1898714] [formerly a47387a4669a1106e2868fce2b0f0a6a0e0b6645 [formerly 084ac453b0e3cab936254a77b74ad71de1898714 [formerly c57bd3a8e0015541f41cff4d2ec6b36e1067146c]]] Former-commit-id: a47387a4669a1106e2868fce2b0f0a6a0e0b6645 Former-commit-id: 9618fe6fc9de035dd85f3fb3dd6295de744fe9de [formerly 6c64fd0810a8be146d6eea56d8c6ce77524ebe00] Former-commit-id: 1cff0d63688e6830cfdb9683479ed70daf45ca5c --- .../geospatial/util/WorldWrapCorrector.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/WorldWrapCorrector.java b/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/WorldWrapCorrector.java index a0daa5d206..9771d4c39b 100644 --- a/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/WorldWrapCorrector.java +++ b/edexOsgi/com.raytheon.uf.common.geospatial/src/com/raytheon/uf/common/geospatial/util/WorldWrapCorrector.java @@ -163,30 +163,37 @@ public class WorldWrapCorrector { private void correct(List geoms, Geometry flattenedGeom, double inverseCentralMeridian, double minOffset, double maxOffset) { - GeometryFactory gf = flattenedGeom.getFactory(); - double delta = 0.00001; - double start = inverseCentralMeridian + minOffset - 360; - double end = inverseCentralMeridian + maxOffset + 360; - double minY = -90, maxY = 90; + if (minOffset == 0.0 && maxOffset == 0.0) { + // no offsets to apply, add and return + geoms.add(flattenedGeom); + return; + } else if (flattenedGeom.isValid()) { + // Only apply world wrap correcting to valid geometries + GeometryFactory gf = flattenedGeom.getFactory(); + double delta = 0.00001; + double start = inverseCentralMeridian + minOffset - 360; + double end = inverseCentralMeridian + maxOffset + 360; + double minY = -90, maxY = 90; - while (start < end) { - double useStart = start; - double useEnd = start + 360; - double minX = useStart + delta; - double maxX = (useEnd) - delta; + while (start < end) { + double useStart = start; + double useEnd = start + 360; + double minX = useStart + delta; + double maxX = (useEnd) - delta; - Geometry section = gf.createPolygon( - gf.createLinearRing(new Coordinate[] { - new Coordinate(minX, maxY), - new Coordinate(maxX, maxY), - new Coordinate(maxX, minY), - new Coordinate(minX, minY), - new Coordinate(minX, maxY) }), null); - section = section.intersection(flattenedGeom); - if (section.isEmpty() == false) { - geoms.add(section); + Geometry section = gf.createPolygon( + gf.createLinearRing(new Coordinate[] { + new Coordinate(minX, maxY), + new Coordinate(maxX, maxY), + new Coordinate(maxX, minY), + new Coordinate(minX, minY), + new Coordinate(minX, maxY) }), null); + section = section.intersection(flattenedGeom); + if (section.isEmpty() == false) { + geoms.add(section); + } + start += 360.0; } - start += 360.0; } }