Merge "Issue #2947 Fixes for derived products with multiple records per frame." into development

Former-commit-id: 99036341f3 [formerly 026575b202] [formerly e10434a727 [formerly 820dfe6db6a1a7abf3c753aebe3d51ead31cd3cc]]
Former-commit-id: e10434a727
Former-commit-id: b4226666be
This commit is contained in:
Richard Peter 2014-04-23 17:25:25 -05:00 committed by Gerrit Code Review
commit 4d2ee42fc9
2 changed files with 117 additions and 28 deletions

View file

@ -19,10 +19,11 @@
**/
package com.raytheon.viz.satellite.inventory;
import java.awt.geom.Rectangle2D;
import org.geotools.coverage.grid.GridEnvelope2D;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.geometry.Envelope2D;
import org.opengis.geometry.BoundingBox;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.common.dataplugin.satellite.SatMapCoverage;
@ -65,16 +66,46 @@ public class ComparableSatMapCoverage implements
@Override
public IGridGeometryProvider compare(IGridGeometryProvider other) {
if (other.equals(this)) {
return this;
}
if (other instanceof ComparableSatMapCoverage) {
ComparableSatMapCoverage otherCoverage = (ComparableSatMapCoverage) other;
if (otherCoverage.getCRS().equals(getCRS())
&& otherCoverage.getBoundingBox().intersects(
getBoundingBox())){
if(getResolution() > otherCoverage.getResolution()){
if (compatibleArea(otherCoverage)) {
if (getResolution() > otherCoverage.getResolution()) {
return this;
}else{
} else if (getResolution() < otherCoverage.getResolution()) {
return other;
}
/* Resolutions are the same */
Envelope2D env = getEnvelope();
Envelope2D otherEnv = otherCoverage.getEnvelope();
if (area(env) < area(otherEnv)) {
return this;
} else if (area(env) > area(otherEnv)) {
return other;
}
/* Area is the same. */
/*
* there is no meaningful way to pick one so start checking
* meaningless things.
*/
if (env.x < otherEnv.x) {
return this;
} else if (env.x > otherEnv.x) {
return other;
}
if (env.y < otherEnv.y) {
return this;
} else if (env.y > otherEnv.y) {
return other;
}
if (env.width < otherEnv.width) {
return this;
} else if (env.width > otherEnv.width) {
return other;
}
/* This is nuts, why aren't they equal, give up. */
}
}
return null;
@ -88,7 +119,24 @@ public class ComparableSatMapCoverage implements
return coverage.getGridGeometry().getCoordinateReferenceSystem();
}
protected BoundingBox getBoundingBox() {
protected boolean compatibleArea(ComparableSatMapCoverage other) {
if (!other.getCRS().equals(getCRS())) {
return false;
}
Rectangle2D i = other.getEnvelope().createIntersection(getEnvelope());
if (i == null || i.isEmpty()) {
return false;
}
/* Intersection must cover at least 25% of area. */
double a = area(i) * 4;
if (a > area(getEnvelope()) || a > area(other.getEnvelope())) {
return true;
} else {
return false;
}
}
protected Envelope2D getEnvelope() {
return coverage.getGridGeometry().getEnvelope2D();
}
@ -100,7 +148,7 @@ public class ComparableSatMapCoverage implements
GridGeometry2D gg = coverage.getGridGeometry();
Envelope2D e = gg.getEnvelope2D();
GridEnvelope2D r = gg.getGridRange2D();
return (r.width * r.height) / (e.width * e.height);
return area(r) / area(e);
}
@Override
@ -129,4 +177,8 @@ public class ComparableSatMapCoverage implements
return true;
}
private static double area(Rectangle2D r) {
return r.getHeight() * r.getWidth();
}
}

View file

@ -21,9 +21,12 @@ package com.raytheon.viz.satellite.rsc;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -34,11 +37,14 @@ import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.RecordFactory;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.IResourceDataChanged.ChangeType;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.viz.satellite.inventory.SatelliteDataCubeAdapter;
/**
* Resource data for satellite data
@ -46,10 +52,12 @@ import com.raytheon.uf.viz.core.rsc.LoadProperties;
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 17, 2009 njensen Initial creation
* Feb 20, 2000 2032 jsanchez Added @XmlAccessorType(XmlAccessType.NONE).
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Feb 17, 2009 njensen Initial creation
* Feb 20, 2000 2032 jsanchez Added @XmlAccessorType(XmlAccessType.NONE).
* Apr 23, 2013 2947 bsteffen Fix updates for derived products with
* multiple records per frame.
*
* </pre>
*
@ -81,33 +89,42 @@ public class SatResourceData extends AbstractRequestableResourceData {
return new SatResource(this, loadProperties);
}
@Override
public void update(Object updateData) {
if (updateData instanceof PluginDataObject[]) {
// This is here because derived updates will send us records that we
// don't want, so filter them.
/*
* This is here because derived updates will send us records that we
* don't want, so filter them.
*/
PluginDataObject[] pdos = (PluginDataObject[]) updateData;
List<PluginDataObject> wrongPDOs = new ArrayList<PluginDataObject>();
Set<DataTime> invalidTimes = new HashSet<DataTime>();
for (PluginDataObject pdo : (PluginDataObject[]) updateData) {
try {
Map<String, Object> pdoMap = RecordFactory.getInstance()
.loadMapFromUri(pdo.getDataURI());
for (Entry<String, RequestConstraint> entry : metadataMap
.entrySet()) {
if (entry.getKey().equals("DERIVED")) {
if (entry.getKey().equals(
SatelliteDataCubeAdapter.DERIVED)) {
continue;
}
Object pdoItem = pdoMap.get(entry.getKey());
RequestConstraint rc = entry.getValue();
// Record Factor automatically replaces space with
// underscore, but some derived parameters have
// underscore in them
/*
* Record Factory automatically replaces space with
* underscore, but some derived parameters have
* underscore in them
*/
String pdoItemStr = pdoItem.toString()
.replace(" ", "_");
if (pdoItem == null
|| !(rc.evaluate(pdoItem) || rc
if (!(rc.evaluate(pdoItem) || rc
.evaluate(pdoItemStr))) {
wrongPDOs.add(pdo);
DataTime time = pdo.getDataTime();
if (binOffset != null) {
time = binOffset.getNormalizedTime(time);
}
invalidTimes.add(time);
break;
}
}
@ -116,15 +133,35 @@ public class SatResourceData extends AbstractRequestableResourceData {
e.getLocalizedMessage(), e);
}
}
if (wrongPDOs.size() == pdos.length) {
invalidateAvailableTimesCache();
return;
} else if (!wrongPDOs.isEmpty()) {
if (!invalidTimes.isEmpty()) {
/* Next time query should requery */
invalidateAvailableTimesCache();
/* Remove times from resources where three is new derived data. */
for (DataTime time : invalidTimes) {
fireChangeListeners(ChangeType.DATA_REMOVE, time);
}
/*
* Don't send updates for PDO's with invalidTimes, the time
* matcher will pull in all the records including derived
* records.
*/
List<PluginDataObject> pdoList = new ArrayList<PluginDataObject>(
Arrays.asList(pdos));
pdoList.removeAll(wrongPDOs);
updateData = pdoList.toArray(new PluginDataObject[0]);
Iterator<PluginDataObject> it = pdoList.iterator();
while (it.hasNext()) {
DataTime t = it.next().getDataTime();
if (binOffset != null) {
t = binOffset.getNormalizedTime(t);
}
if (invalidTimes.contains(t)) {
it.remove();
}
}
if (pdoList.isEmpty()) {
return;
} else {
updateData = pdoList.toArray(new PluginDataObject[0]);
}
}
}
super.update(updateData);