From 5e09aa6178a841282d196a251e6bc7fc2ab54e60 Mon Sep 17 00:00:00 2001 From: Jonathan Sanchez Date: Thu, 31 Jan 2013 15:11:17 -0600 Subject: [PATCH] Issue #1557 Added allowDuplicates XML element to point source configuration. Change-Id: I20a05413ef93c4b1268a5b9d3d5541375a47523b Former-commit-id: f72968824a50cc591bc2f38a7b25513389fbe654 [formerly da1061baa657c7471794988e8f5c4f38025ed223 [formerly 945b2e64b971fc31691d550e6c629f43db9a9c99]] Former-commit-id: da1061baa657c7471794988e8f5c4f38025ed223 Former-commit-id: b2870a012e0fdc9dba051126cc07d08baa5b70e0 --- .../src/com/raytheon/viz/warngen/gis/Wx.java | 84 +++++++++++++------ .../config/PointSourceConfiguration.java | 12 +++ 2 files changed, 72 insertions(+), 24 deletions(-) diff --git a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gis/Wx.java b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gis/Wx.java index f80698498e..fc157905b8 100644 --- a/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gis/Wx.java +++ b/cave/com.raytheon.viz.warngen/src/com/raytheon/viz/warngen/gis/Wx.java @@ -100,7 +100,8 @@ import com.vividsolutions.jts.geom.Point; * in pathcast. * Oct 05, 2012 DR15429 Qinglu Lin Updated code to keep duplicate names of cities * which are at different locations in pathcast. - * Oct 17, 2012 jsanchez Moved the path cast data collecting to a seperate class. + * Oct 17, 2012 jsanchez Moved the path cast data collecting to a separate class. + * Jan 31, 2013 1557 jsanchez Used allowDuplicates flag to collect points with duplicate names. * * * @@ -618,6 +619,7 @@ public class Wx { // All configs should have the same "isWithinPolygon" flag boolean isWithinPolygon = pointConfigs[0].isWithinPolygon(); + boolean allowDuplicates = pointConfigs[0].isAllowDuplicates(); // Sort by fields should have been validated to be same as well List fields = pointConfigs[0].getSortBy() != null ? Arrays @@ -702,12 +704,14 @@ public class Wx { GeodeticCalculator gc = new GeodeticCalculator(); Map nameMap = new HashMap( (int) (availablePoints.size() * 1.3)); + List pointsWithinDistance = new ArrayList(); for (int i = 0; i < coords.length; ++i) { Coordinate coord = localCoords[i]; Geometry localDistanceGeom = dimensions == 1 ? localSearchArea : gf .createPoint(coord); Geometry distanceGeom = dimensions == 1 ? searchArea : gf .createPoint(coords[i]); + pointsWithinDistance.clear(); nameMap.clear(); for (ClosestPoint cp : availablePoints) { @@ -716,33 +720,31 @@ public class Wx { double distance = localDistanceGeom.distance(localPt); if (distance <= thresholdInMeters) { - // check map of currently added points for closer point with - // the same name - ClosestPoint existingPt = nameMap.get(cp.name); - if (existingPt == null || distance < existingPt.distance) { - // Set the distances - ClosestPoint cp2 = new ClosestPoint(cp); - cp2.distance = distance; - cp2.roundedDistance = (int) metersToDistance - .convert(distance); - gc.setStartingGeographicPoint(cp2.point.x, cp2.point.y); - Coordinate cen = distanceGeom.getCentroid() - .getCoordinate(); - cen = GisUtil.restoreAlaskaLon(cen); - gc.setDestinationGeographicPoint(cen.x, cen.y); - cp2.azimuth = gc.getAzimuth(); - cp2.oppositeAzimuth = ClosestPoint - .adjustAngle(cp2.azimuth + 180); - cp2.roundedAzimuth = GeoUtil.roundAzimuth(cp2.azimuth); - cp2.oppositeRoundedAzimuth = ClosestPoint - .adjustAngle(cp2.roundedAzimuth + 180); - nameMap.put(cp2.name, cp2); + if (allowDuplicates) { + // collect all points that are within the threshold + ClosestPoint cp2 = createClosestPoint(cp, distance, + metersToDistance, distanceGeom, gc); + pointsWithinDistance.add(cp2); + } else { + // check map of currently added points for closer point + // with the same name + ClosestPoint existingPt = nameMap.get(cp.name); + if (existingPt == null + || distance < existingPt.distance) { + ClosestPoint cp2 = createClosestPoint(cp, distance, + metersToDistance, distanceGeom, gc); + nameMap.put(cp2.name, cp2); + } } } } - List pts = new ArrayList( - nameMap.values()); + List pts = null; + if (allowDuplicates) { + pts = new ArrayList(pointsWithinDistance); + } else { + pts = new ArrayList(nameMap.values()); + } if (fields.isEmpty() == false) { // Sort the points based on sortBy fields Collections.sort(pts, new ClosestPointComparator(fields)); @@ -817,6 +819,40 @@ public class Wx { return null; } + /** + * Helper method to create a ClosestPoint object. + * + * @param cp + * @param distance + * between the cp to the + * @param metersToDistance + * Unit converter to calculate the rounded distance. + * @param distanceGeom + * Geometry search area. + * @param gc + * Geodetic Calculator to determine the azimuth + * @return ClosestPoint object set with roundedDistance, azimuth, etc. + */ + private ClosestPoint createClosestPoint(ClosestPoint cp, double distance, + UnitConverter metersToDistance, Geometry distanceGeom, + GeodeticCalculator gc) { + // Set the distances + ClosestPoint cp2 = new ClosestPoint(cp); + cp2.distance = distance; + cp2.roundedDistance = (int) metersToDistance.convert(distance); + gc.setStartingGeographicPoint(cp2.point.x, cp2.point.y); + Coordinate cen = GisUtil.restoreAlaskaLon(distanceGeom.getCentroid() + .getCoordinate()); + gc.setDestinationGeographicPoint(cen.x, cen.y); + cp2.azimuth = gc.getAzimuth(); + cp2.oppositeAzimuth = ClosestPoint.adjustAngle(cp2.azimuth + 180); + cp2.roundedAzimuth = GeoUtil.roundAzimuth(cp2.azimuth); + cp2.oppositeRoundedAzimuth = ClosestPoint + .adjustAngle(cp2.roundedAzimuth + 180); + + return cp2; + } + public double getMovementSpeed() { return getMovementSpeed(null); } diff --git a/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/config/PointSourceConfiguration.java b/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/config/PointSourceConfiguration.java index 0ec069c298..c193e92ff6 100644 --- a/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/config/PointSourceConfiguration.java +++ b/edexOsgi/com.raytheon.uf.common.dataplugin.warning/src/com/raytheon/uf/common/dataplugin/warning/config/PointSourceConfiguration.java @@ -26,6 +26,7 @@ import com.raytheon.uf.common.dataquery.requests.RequestableMetadataMarshaller; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Aug 17, 2011 mschenke Initial creation + * Jan 31, 2013 1557 jsanchez Added the XMLElement allowDuplicates. * * * @@ -80,6 +81,9 @@ public class PointSourceConfiguration { @XmlElement private double distanceThreshold = 10; + @XmlElement + protected boolean allowDuplicates = false; + @XmlElementWrapper(name = "sortBy") @XmlElement(name = "sort") private String[] sortBy; @@ -173,4 +177,12 @@ public class PointSourceConfiguration { this.type = type; } + public boolean isAllowDuplicates() { + return allowDuplicates; + } + + public void setAllowDuplicates(boolean allowDuplicates) { + this.allowDuplicates = allowDuplicates; + } + }