Merge branch 'master_14.1.2' into master_14.2.1 CM-MERGE:OB14.1.2-6,-7 into 14.2.1

Former-commit-id: c4b7b8dd74 [formerly dbd3bb54e8] [formerly d5a4669fc4 [formerly 19032f03b1d2166f4afd936bb2b56e0b4851d9f4]]
Former-commit-id: d5a4669fc4
Former-commit-id: f30bd7d9ae
This commit is contained in:
Brian.Dyke 2014-05-19 14:03:50 -04:00
commit f2885c9996
3 changed files with 52 additions and 3 deletions

View file

@ -75,6 +75,7 @@ import com.vividsolutions.jts.geom.prep.PreparedGeometry;
* May 2, 2013 1963 jsanchez Updated method to determine partOfArea.
* Aug 19, 2013 2177 jsanchez Used portionsUtil to calculate area portion descriptions.
* Apr 29, 2014 3033 jsanchez Updated method to retrieve files in localization.
* May 16, 2014 DR 17365 D. Friedman Reduce precision of warning area to avoid topology errors.
* </pre>
*
* @author chammack
@ -292,6 +293,15 @@ public class Area {
WarngenLayer warngenLayer) throws VizException {
Map<String, Object> areasMap = new HashMap<String, Object>();
try {
Geometry precisionReducedArea = PolygonUtil.reducePrecision(warnArea);
if (precisionReducedArea.isValid()) {
warnArea = precisionReducedArea;
}
} catch (Exception e) {
// ignore
}
String hatchedAreaSource = config.getHatchedAreaSource()
.getAreaSource();
for (AreaSourceConfiguration asc : config.getAreaSources()) {

View file

@ -47,13 +47,16 @@ import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateSequence;
import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryCollection;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineSegment;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.PrecisionModel;
import com.vividsolutions.jts.geom.prep.PreparedGeometry;
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
import com.vividsolutions.jts.precision.SimpleGeometryPrecisionReducer;
/**
* Utility for polygon operations
@ -81,6 +84,7 @@ import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
* 10/18/2013 DR 16632 Qinglu Lin Catch exception thrown when coords length is less than 4 and doing createLinearRing(coords).
* 01/09/2014 DR 16974 D. Friedman Improve followup redraw-from-hatched-area polygons.
* 04/15/2014 DR 17247 D. Friedman Prevent some invalid coordinates in adjustVertex.
* 05/16/2014 DR 17365 D. Friedman Prevent some Coordinate reuse. Add reducePrecision.
* </pre>
*
* @author mschenke
@ -99,6 +103,8 @@ public class PolygonUtil {
private MathTransform latLonToContour, contourToLatLon;
private static final PrecisionModel REDUCED_PRECISION = new PrecisionModel(10000000000.0);
public PolygonUtil(WarngenLayer layer, int nx, int ny, int maxVertices,
IExtent localExtent, MathTransform localToLatLon) throws Exception {
this.layer = layer;
@ -127,9 +133,15 @@ public class PolygonUtil {
* hatched area. If it does, that intersection can be used instead of
* generating a new contour.
*/
if (oldWarningPolygon != null) {
if (oldWarningPolygon != null && oldWarningPolygon.isValid()
&& origPolygon.isValid()) {
try {
Geometry intersection = origPolygon.intersection(oldWarningPolygon);
/*
* Create a clone to ensure we do not use a Coordinate from
* oldWarningPolygon.
*/
Geometry intersection = (Geometry) origPolygon
.intersection(oldWarningPolygon).clone();
if (intersection instanceof Polygon) {
Polygon polygonIntersection = (Polygon) intersection;
if (polygonIntersection.isValid() &&
@ -1657,4 +1669,27 @@ public class PolygonUtil {
}
return slope;
}
/** Creates a copy of a Geometry with reduced precision to reduce the chance of topology errors when used
* in intersection operations.
*
* @param g
* @return a new Geometry that is a copy of given Geometry with reduced
* precision. References to user data are copied. If there are GeometryCollection
* objects, user data is copied for each element.
*/
static public Geometry reducePrecision(Geometry g) {
Geometry result;
if (g instanceof GeometryCollection) {
Geometry[] list = new Geometry[g.getNumGeometries()];
for (int i = 0; i < list.length; ++i) {
list[i] = reducePrecision(g.getGeometryN(i));
}
GeometryFactory gf = new GeometryFactory();
result = gf.createGeometryCollection(list);
} else
result = SimpleGeometryPrecisionReducer.reduce(g, REDUCED_PRECISION);
result.setUserData(g.getUserData());
return result;
}
}

View file

@ -196,6 +196,7 @@ import com.vividsolutions.jts.io.WKTReader;
* 01/09/2014 DR 16974 D. Friedman Improve followup redraw-from-hatched-area polygons.
* 04/15/2014 DR 17247 D. Friedman Rework error handling in AreaHatcher.
* 04/28,2014 3033 jsanchez Properly handled back up configuration (*.xml) files. Set backupSite to null when backup site is not selected.
* 05/16/2014 DR 17365 D. Friedman Check if moved vertex results in polygon valid in both lat/lon and local coordinates.
* </pre>
*
* @author mschenke
@ -2734,7 +2735,10 @@ public class WarngenLayer extends AbstractStormTrackResource {
}
if (!intersectFlag) {
state.setWarningPolygon(gf.createPolygon(ring, null));
Polygon p = gf.createPolygon(ring, null);
if (p.isValid() && latLonToLocal(p).isValid()) {
state.setWarningPolygon(p);
}
}
} catch (Exception e) {