From 5b51795a184fa1041af33f95be0786596c4ab29c Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Mon, 12 Aug 2013 16:07:17 -0500 Subject: [PATCH] Issue #1133 Better error handling for invalid polygons in map resource. Change-Id: Ib935f3c4fee42dae21eb52adf19ea9e2e9d76442 Former-commit-id: 27594e6808e828752c632f058c0bdbd1ad9a5cbf [formerly 68f1b06c79639874b94b87e4f4365f1fe36c7bac] Former-commit-id: 7f9bbf3d52657e3c6f0ebae59b05064616f30113 --- .../uf/viz/core/maps/rsc/DbMapResource.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/cave/com.raytheon.uf.viz.core.maps/src/com/raytheon/uf/viz/core/maps/rsc/DbMapResource.java b/cave/com.raytheon.uf.viz.core.maps/src/com/raytheon/uf/viz/core/maps/rsc/DbMapResource.java index 1791fc58b4..5443a4246a 100644 --- a/cave/com.raytheon.uf.viz.core.maps/src/com/raytheon/uf/viz/core/maps/rsc/DbMapResource.java +++ b/cave/com.raytheon.uf.viz.core.maps/src/com/raytheon/uf/viz/core/maps/rsc/DbMapResource.java @@ -27,9 +27,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; import org.apache.commons.lang.StringUtils; @@ -75,6 +77,7 @@ import com.raytheon.viz.core.spatial.GeometryCache; import com.vividsolutions.jts.geom.Envelope; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.TopologyException; import com.vividsolutions.jts.io.WKBReader; /** @@ -85,8 +88,10 @@ import com.vividsolutions.jts.io.WKBReader; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Feb 19, 2009 randerso Initial creation - * Sep 18, 2012 #1019 randerso improved error handling + * Feb 19, 2009 randerso Initial creation + * Sep 18, 2012 1019 randerso improved error handling + * Aug 12, 2013 1133 bsteffen Better error handling for invalid + * polygons in map resource. * * * @@ -383,6 +388,9 @@ public class DbMapResource extends List resultingGeoms = new ArrayList( mappedResult.getResultCount()); + + Set unlabelablePoints = new HashSet(0); + int numPoints = 0; for (int i = 0; i < mappedResult.getResultCount(); ++i) { if (canceled) { @@ -426,11 +434,19 @@ public class DbMapResource extends }); for (Geometry poly : gList) { - Point point = poly.getInteriorPoint(); - if (point.getCoordinate() != null) { - LabelNode node = new LabelNode(label, - point, req.target); - newLabels.add(node); + try { + Point point = poly.getInteriorPoint(); + if (point.getCoordinate() != null) { + LabelNode node = new LabelNode(label, + point, req.target); + newLabels.add(node); + } + } catch (TopologyException e) { + statusHandler.handle(Priority.VERBOSE, + "Invalid geometry cannot be labeled: " + + label, + e); + unlabelablePoints.add(label); } } } @@ -445,6 +461,12 @@ public class DbMapResource extends } } + if (!unlabelablePoints.isEmpty()) { + statusHandler.handle(Priority.WARN, + "Invalid geometries cannot be labeled: " + + unlabelablePoints.toString()); + } + newOutlineShape.allocate(numPoints); for (Geometry g : resultingGeoms) {