Merge "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." into development

Former-commit-id: 466de62fc9 [formerly c2ae7fb131] [formerly 466de62fc9 [formerly c2ae7fb131] [formerly 7a7acfa055 [formerly 9345f2ebb0f870f187cc88ec597eac88f6b8ac13]]]
Former-commit-id: 7a7acfa055
Former-commit-id: f959eebd8a [formerly c9a16a0607]
Former-commit-id: a6fbbdbff7
This commit is contained in:
Ron Anderson 2012-09-25 11:30:22 -05:00 committed by Gerrit Code Review
commit 216e83f2cb

View file

@ -163,30 +163,37 @@ public class WorldWrapCorrector {
private void correct(List<Geometry> 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;
}
}