Issue #2619 Fix rare dateline bug.

Former-commit-id: 1b99b5aca0 [formerly 45e4b4bbad] [formerly 399c579671] [formerly 1b99b5aca0 [formerly 45e4b4bbad] [formerly 399c579671] [formerly 607b5edb69 [formerly 399c579671 [formerly 8231fde4fdcb25ad19e31dd8e4f5716becba347c]]]]
Former-commit-id: 607b5edb69
Former-commit-id: 6a35407957 [formerly 58dabbfc87] [formerly fc52d111900f81c3257ff7f1b3c079e152fb00d3 [formerly d0f4b18b78]]
Former-commit-id: 9fc0459f3f576463d2cc040689f06ba824bcec45 [formerly a92f15a8fa]
Former-commit-id: 463ad8e8fa
This commit is contained in:
Ben Steffensmeier 2013-12-11 14:39:56 -06:00
parent b53a3d614d
commit c41c64ce5b
2 changed files with 47 additions and 11 deletions

View file

@ -47,9 +47,11 @@ import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* ------------- -------- ----------- -----------------------------------------
* Oct 12, 2011 mschenke Initial creation
* May 30, 2013 #2028 randerso Changed to return simple geometry or multi-geometry if possible
* May 30, 2013 2028 randerso Changed to return simple geometry or
* multi-geometry if possible
* Dec 11, 2013 2619 bsteffen Fix rare dateline bug in flattenGeometry.
*
* </pre>
*
@ -318,14 +320,14 @@ public class WorldWrapCorrector {
Coordinate a = coords[i];
Coordinate b = coords[ip1];
b.x += currOffset;
double testX = b.x + currOffset;
Boolean low = null;
if (a.x - b.x > 180.0) {
if (a.x - testX > 180.0) {
low = false;
} else if (b.x - a.x > 180.0) {
} else if (testX - a.x > 180.0) {
low = true;
} else if (checker.check(a.x, b.x)) {
} else if (checker.check(a.x, testX)) {
handle = true;
}
@ -334,18 +336,20 @@ public class WorldWrapCorrector {
// we wrap either low end or high
if (low) {
currOffset -= 360;
b.x -= 360.0;
if (currOffset < minOffset) {
minOffset = currOffset;
}
} else {
currOffset += 360;
b.x += 360;
if (currOffset > maxOffset) {
maxOffset = currOffset;
}
}
b.x += currOffset;
} else {
b.x = testX;
}
}
return handle ? new double[] { minOffset, maxOffset } : null;
}

View file

@ -57,9 +57,10 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* ------------- -------- ----------- -----------------------------------------
* Sep 13, 2013 2309 bsteffen Initial creation
* Nov 18, 2013 2528 bsteffen Add test for geostationary.
* Dec 11, 2013 2619 bsteffen Add alaska test for dateline issues.
*
* </pre>
*
@ -148,6 +149,24 @@ public class EnvelopeIntersectionTest {
"Unable to create geostationary projection", e);
}
}
},
/*
* This envelope has really weird issues with the dataline. Specifically
* the lower left corner longitude is just right so if you convert it to
* LatLon space, add 360 to longitude and then subtract 360 from
* longitude you will get a slightly different LatLon point. This
* combined with the fact that the lewer left corner ends up being the
* last point in a polygon and the second to last point is on the
* opposite side of the dataline results in strange problems.
*/
ALASKA {
public Envelope getEnvelope() {
return new ReferencedEnvelope(-2047000.023104792,
999.9768952080049, -3879539.946249751,
-1831539.946249751, MapUtil.constructNorthPolarStereo(
6371200, 6371200, 52.5, -149.5));
}
};
public abstract Envelope getEnvelope();
@ -330,6 +349,19 @@ public class EnvelopeIntersectionTest {
19097.596365784917, 64, 49, expected);
}
@Test
public final void testAlaskaToUkmet() throws TransformException,
FactoryException {
/* This was created using printSimplePolygon. */
float[] expected = { 3703712, 5337060, 3317194, 5775708, 2834468,
6206521, 2222747, 6619845, 1439512, 7001657, 2352844, 7380677,
3551651, 7694056, 5063542, 7906556, 6800513, 7982537, 6798676,
5836944, 5962640, 5803467, 5154389, 5704811, 4396584, 5546637,
3703712, 5337060 };
test(KNOWN_ENVELOPES.ALASKA, KNOWN_ENVELOPES.UKMET, 29863.10130618981,
16, 16, 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