Merge "Omaha #4353: Remove log spam on Geometry validation errors." into omaha_16.1.1

Former-commit-id: cc0a1e2a68e46e744299bced73d5d217715fea6a
This commit is contained in:
Ron Anderson 2015-04-02 17:01:06 -05:00 committed by Gerrit Code Review
commit 45f633ee46
5 changed files with 348 additions and 285 deletions

View file

@ -50,10 +50,13 @@ import com.vividsolutions.jts.operation.valid.IsValidOp;
* This tool allows the user to hand draw/modify an edit area
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 16, 2008 #1075 randerso Initial creation
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 16, 2008 #1075 randerso Initial creation
* Apr 01, 2015 #4353 dgilling Improve logging of Geometry validation errors.
*
* </pre>
*
@ -97,27 +100,6 @@ public class SelectPointsTool extends AbstractFreeformTool {
polygonizer.add(nodedLines);
Collection<Polygon> polygons = polygonizer.getPolygons();
// Collection<?> dangles = polygonizer.getDangles();
// if (dangles != null && dangles.size() > 0) {
// StringBuilder s = new StringBuilder(
// "Edit area contains dangling lines.");
// for (Object g : dangles) {
// s.append("\n" + g);
// }
// UFStatus.handle(Priority.PROBLEM, Activator.PLUGIN_ID,
// StatusConstants.CATEGORY_GFE, null, s.toString());
// }
//
// Collection<?> cutEdges = polygonizer.getCutEdges();
// if (cutEdges != null && cutEdges.size() > 0) {
// StringBuilder s = new StringBuilder("Edit area contains cut edges.");
// for (Object g : cutEdges) {
// s.append("\n" + g);
// }
// UFStatus.handle(Priority.PROBLEM, Activator.PLUGIN_ID,
// StatusConstants.CATEGORY_GFE, null, s.toString());
// }
// create a multipolygon from the collection of polygons
Geometry g = gf.createMultiPolygon(polygons
.toArray(new Polygon[polygons.size()]));
@ -133,7 +115,8 @@ public class SelectPointsTool extends AbstractFreeformTool {
}
if (mp != null) {
if (mp.isValid()) {
IsValidOp validOp = new IsValidOp(mp);
if (validOp.isValid()) {
// create the reference data
ReferenceData refData = new ReferenceData(this.dataManager
.getParmManager().compositeGridLocation(),
@ -151,15 +134,8 @@ public class SelectPointsTool extends AbstractFreeformTool {
} else {
StringBuilder s = new StringBuilder();
s.append("Edit area contains invalid polygons.\n");
IsValidOp validOp = new IsValidOp(mp);
s.append(validOp.getValidationError());
for (int i = 0; i < mp.getNumGeometries(); i++) {
Polygon p = (Polygon) mp.getGeometryN(i);
if (!p.isValid()) {
s.append("\n" + p);
}
}
statusHandler.handle(Priority.PROBLEM, s.toString());
statusHandler.error(s.toString());
}
}
}

View file

@ -87,20 +87,23 @@ import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.prep.PreparedGeometry;
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
import com.vividsolutions.jts.operation.buffer.BufferParameters;
import com.vividsolutions.jts.operation.valid.IsValidOp;
import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
/**
* Creates edit areas for the currently selected WFO
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 10, 2008 #1075 randerso Initial creation
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 02, 2015 #1075 randerso Initial creation
* Jun 25, 2008 #1210 randerso Modified to get directories from UtilityContext
* Oct 13, 2008 #1607 njensen Added genCombinationsFiles()
* Sep 18, 2012 #1091 randerso Changed to use Maps.py and localMaps.py
* Mar 14, 2013 1794 djohnson Consolidate common FilenameFilter implementations.
* Mar 14, 2013 1794 djohnson Consolidate common FilenameFilter implementations.
* Mar 28, 2013 #1837 dgilling Better error reporting if a map table
* from localMaps.py could not be found,
* warnings clean up.
@ -109,6 +112,8 @@ import com.vividsolutions.jts.simplify.TopologyPreservingSimplifier;
* Aug 27, 2014 #3563 randerso Fix issue where edit areas are regenerated unnecessarily
* Oct 20, 2014 #3685 randerso Changed structure of editAreaAttrs to keep zones from different maps separated
* Feb 19, 2015 #4125 rjpeter Fix jaxb performance issue
* Apr 01, 2015 #4353 dgilling Improve logging of Geometry validation errors.
*
* </pre>
*
* @author randerso
@ -907,18 +912,12 @@ public class MapManager {
polygons = gf.createMultiPolygon(new Polygon[] {});
}
if (!polygons.isValid()) {
String error = "Table: "
+ shapeSource.getTableName()
+ " edit area:"
+ ean
+ " contains invalid polygons. This edit area will be skipped.";
for (int i = 0; i < polygons.getNumGeometries(); i++) {
Geometry g = polygons.getGeometryN(i);
if (!g.isValid()) {
error += "\n" + g;
}
}
IsValidOp polygonValidator = new IsValidOp(polygons);
if (!polygonValidator.isValid()) {
String error = String
.format("Table: %s edit area: %s contains invalid polygons: %s. This edit area will be skipped.",
shapeSource.getTableName(), ean,
polygonValidator.getValidationError());
statusHandler.error(error);
continue;
}

View file

@ -51,13 +51,16 @@ import com.vividsolutions.jts.operation.polygonize.Polygonizer;
import com.vividsolutions.jts.operation.valid.IsValidOp;
/**
* TODO Add Description
* Command line utility to convert A1 edit area files to A2 edit area files.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 02/07/2008
* Feb 07, 2008 Initial creation
* Apr 01, 2015 #4353 dgilling Improve logging of Geometry validation errors.
*
* </pre>
*
@ -119,8 +122,7 @@ public class TranslateReferenceSet {
public static ReferenceData translate(File file) {
ReferenceData refData = null;
try {
BufferedReader in = new BufferedReader(new FileReader(file));
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
String query = in.readLine();
if ("NOQUERY".equals(query)) {
query = null;
@ -160,7 +162,6 @@ public class TranslateReferenceSet {
excPolys.add(ls);
}
}
in.close();
Geometry mls = gf.buildGeometry(incPolys);
Point pt = gf.createPoint(mls.getCoordinate());
@ -188,17 +189,11 @@ public class TranslateReferenceSet {
MultiPolygon polygons = gf.createMultiPolygon(included
.toArray(new Polygon[included.size()]));
if (!polygons.isValid()) {
IsValidOp validOp = new IsValidOp(polygons);
if (!validOp.isValid()) {
System.out.println("WARNING: " + file.getAbsolutePath()
+ " contains invalid polygons.");
IsValidOp validOp = new IsValidOp(polygons);
System.out.println(validOp.getValidationError());
for (int i = 0; i < polygons.getNumGeometries(); i++) {
Polygon g = (Polygon) polygons.getGeometryN(i);
if (!g.isValid()) {
System.out.println(g);
}
}
}
mls = gf.buildGeometry(excPolys);
@ -228,15 +223,11 @@ public class TranslateReferenceSet {
if (excluded.size() > 0) {
MultiPolygon holes = gf.createMultiPolygon(excluded
.toArray(new Polygon[excPolys.size()]));
if (!holes.isValid()) {
validOp = new IsValidOp(holes);
if (!validOp.isValid()) {
System.out.println("WARNING: " + file.getAbsolutePath()
+ " contains invalid polygons.");
for (int i = 0; i < holes.getNumGeometries(); i++) {
Geometry g = holes.getGeometryN(i);
if (!g.isValid()) {
System.out.println(g);
}
}
System.out.println(validOp.getValidationError());
}
Geometry mp = polygons.difference(holes);
@ -247,15 +238,11 @@ public class TranslateReferenceSet {
.createMultiPolygon(new Polygon[] { (Polygon) mp });
}
if (!polygons.isValid()) {
validOp = new IsValidOp(polygons);
if (!validOp.isValid()) {
System.out.println("WARNING: " + file.getAbsolutePath()
+ " contains invalid polygons.");
for (int i = 0; i < polygons.getNumGeometries(); i++) {
Geometry g = polygons.getGeometryN(i);
if (!g.isValid()) {
System.out.println(g);
}
}
System.out.println(validOp.getValidationError());
}
}

View file

@ -41,6 +41,8 @@ import com.raytheon.uf.common.dataplugin.gfe.db.objects.DatabaseID;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.GridLocation;
import com.raytheon.uf.common.dataplugin.gfe.db.objects.ParmID;
import com.raytheon.uf.common.dataplugin.gfe.grid.Grid2DBit;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.time.TimeRange;
import com.raytheon.uf.common.util.Pair;
import com.vividsolutions.jts.geom.Coordinate;
@ -53,6 +55,7 @@ import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.prep.PreparedGeometry;
import com.vividsolutions.jts.geom.prep.PreparedGeometryFactory;
import com.vividsolutions.jts.operation.polygonize.Polygonizer;
import com.vividsolutions.jts.operation.valid.IsValidOp;
/**
* Utility class for performing miscellaneous tasks relating to GFE. This class
@ -68,6 +71,8 @@ import com.vividsolutions.jts.operation.polygonize.Polygonizer;
* 06/24/13 #2044 randerso Changed format of hdf5 group to include
* minutes for satellite data
* 10/08/14 #3684 randerso Removed NOTIFY
* 04/02/15 #4353 dgilling Log Geometry validation errors in
* createPolygon().
*
* </pre>
*
@ -76,12 +81,17 @@ import com.vividsolutions.jts.operation.polygonize.Polygonizer;
*/
public class GfeUtil {
private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(GfeUtil.class);;
private static final String FIELD_SEPARATOR = "_";
private static final String DATASTORE_FILE_EXTENSION = ".h5";
private static final String GROUP_SEPARATOR = "/";
private static final String INVALID_POLYGONS_MSG = "Edit area contains invalid polygons.";
/** Date formatter for generating correct group names */
private static final ThreadLocal<SimpleDateFormat> groupDateFormatter = new ThreadLocal<SimpleDateFormat>() {
@Override
@ -434,29 +444,6 @@ public class GfeUtil {
polygonizer.add(nodedLines);
Collection<Polygon> polygons = polygonizer.getPolygons();
// Collection<?> dangles = polygonizer.getDangles();
// if (dangles != null && dangles.size() > 0) {
// StringBuilder s = new StringBuilder(
// "Edit area contains dangling lines.");
// for (Object g : dangles) {
// s.append("\n" + g);
// }
// Activator.getDefault().getLog().log(
// new Status(Status.WARNING, Activator.PLUGIN_ID, s
// .toString()));
// }
//
// Collection<?> cutEdges = polygonizer.getCutEdges();
// if (cutEdges != null && cutEdges.size() > 0) {
// StringBuilder s = new StringBuilder("Edit area contains cut edges.");
// for (Object g : cutEdges) {
// s.append("\n" + g);
// }
// Activator.getDefault().getLog().log(
// new Status(Status.WARNING, Activator.PLUGIN_ID, s
// .toString()));
// }
// create a multipolygon from the collection of polygons
Geometry g = gf.createMultiPolygon(polygons
.toArray(new Polygon[polygons.size()]));
@ -469,26 +456,21 @@ public class GfeUtil {
mp = (MultiPolygon) g;
} else if (g instanceof Polygon) {
mp = gf.createMultiPolygon(new Polygon[] { (Polygon) g });
} else {
statusHandler.warn(INVALID_POLYGONS_MSG);
return gf.createMultiPolygon(new Polygon[0]);
}
if ((mp == null) || !mp.isValid()) {
// StringBuilder s = new StringBuilder();
// s.append("Edit area contains invalid polygons.\n");
// IsValidOp validOp = new IsValidOp(mp);
// s.append(validOp.getValidationError());
// for (int i = 0; i < mp.getNumGeometries(); i++) {
// Polygon p = (Polygon) mp.getGeometryN(i);
// if (!p.isValid()) {
// s.append("\n" + p);
// }
// }
// Activator.getDefault().getLog().log(
// new Status(Status.WARNING, Activator.PLUGIN_ID, s
// .toString()));
IsValidOp validOp = new IsValidOp(mp);
if (!validOp.isValid()) {
StringBuilder s = new StringBuilder(INVALID_POLYGONS_MSG).append(
'\n').append(validOp.getValidationError());
statusHandler.warn(s.toString());
// return an empty polygon
mp = gf.createMultiPolygon(new Polygon[0]);
}
return mp;
}