Issue #189 move stereographic grid coverage to common so ti can be stored in the db and parsed from a URI using the standard mechanisms.

Former-commit-id: 721d3ad5bb7a6007dafba91283814e83590c972a
This commit is contained in:
Ben Steffensmeier 2012-10-24 11:45:49 -05:00
parent 392e64f33e
commit d349cb2dbf
5 changed files with 203 additions and 169 deletions

View file

@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.ui,
com.raytheon.uf.common.serialization.comm,
com.raytheon.uf.viz.productbrowser;bundle-version="1.11.31",
com.raytheon.uf.common.dataplugin.radar;bundle-version="1.0.0",
com.raytheon.uf.viz.points;bundle-version="1.0.0"
com.raytheon.uf.viz.points;bundle-version="1.0.0",
com.raytheon.uf.common.gridcoverage
Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.viz.grid,
com.raytheon.viz.grid.inv,

View file

@ -1,122 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.grid.spatial;
import org.apache.commons.lang.builder.HashCodeBuilder;
import com.raytheon.uf.common.gridcoverage.GridCoverage;
import com.raytheon.uf.common.gridcoverage.subgrid.SubGrid;
/**
* Stereographic Coverage used by radar data.
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 7, 2010 #4473 rjpeter Initial creation
*
* </pre>
*
* @author rjpeter
* @version 1.0
*/
public class StereographicCoverage extends GridCoverage {
private Integer nx;
private Integer ny;
@Override
public String getProjectionType() {
return "Stereographic";
}
@Override
public void initialize() {
}
@Override
public GridCoverage trim(SubGrid subGrid) {
// NOT SUPPORTED
return null;
}
@Override
public Integer getNx() {
return nx;
}
@Override
public Integer getNy() {
return ny;
}
public void setNx(Integer nx) {
this.nx = nx;
}
public void setNy(Integer ny) {
this.ny = ny;
}
@Override
public int generateHash() {
HashCodeBuilder hashBuilder = new HashCodeBuilder();
hashBuilder.append(nx);
hashBuilder.append(ny);
hashBuilder.append(gridGeometry);
hashBuilder.append(crs);
return hashBuilder.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
StereographicCoverage other = (StereographicCoverage) obj;
if (nx == null) {
if (other.nx != null)
return false;
} else if (!nx.equals(other.nx))
return false;
if (ny == null) {
if (other.ny != null)
return false;
} else if (!ny.equals(other.ny))
return false;
if (gridGeometry == null) {
if (other.gridGeometry != null)
return false;
} else if (!gridGeometry.equals(other.gridGeometry))
return false;
if (crs == null) {
if (other.crs != null)
return false;
} else if (!crs.equals(other.crs))
return false;
return true;
}
}

View file

@ -28,9 +28,7 @@ import java.util.Set;
import javax.measure.unit.Unit;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.geometry.DirectPosition2D;
import org.opengis.geometry.DirectPosition;
import org.opengis.referencing.crs.ProjectedCRS;
import org.opengis.referencing.operation.MathTransform;
@ -47,6 +45,11 @@ import com.raytheon.uf.common.derivparam.tree.LevelNode;
import com.raytheon.uf.common.derivparam.tree.ParameterNode;
import com.raytheon.uf.common.derivparam.tree.SourceNode;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.common.gridcoverage.Corner;
import com.raytheon.uf.common.gridcoverage.GridCoverage;
import com.raytheon.uf.common.gridcoverage.StereographicGridCoverage;
import com.raytheon.uf.common.gridcoverage.exception.GridCoverageException;
import com.raytheon.uf.common.gridcoverage.lookup.GridCoverageLookup;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
@ -66,7 +69,6 @@ import com.raytheon.viz.core.drawables.ColorMapParameterFactory;
import com.raytheon.viz.grid.data.TopoRequestableData;
import com.raytheon.viz.grid.inv.RadarRequestableLevelNode;
import com.raytheon.viz.grid.inv.RadarUpdater;
import com.raytheon.viz.grid.spatial.StereographicCoverage;
import com.raytheon.viz.radar.util.StationUtils;
/**
@ -117,11 +119,7 @@ public class RadarAdapter {
private RadarStation configuredRadar = null;
private ProjectedCRS crs = null;
private GridGeometry2D gridGeometry = null;
private StereographicCoverage coverage = null;
private GridCoverage coverage = null;
static {
instance = new RadarAdapter();
@ -143,37 +141,41 @@ public class RadarAdapter {
|| !configuredRadar.getRdaId().equals(station.getRdaId())) {
configuredRadar = station;
RadarUpdater.getInstance().clearCache();
crs = RadarUtil
.constructCRS(station.getLat(), station.getLon());
gridGeometry = RadarUtil.constructGridGeometry(crs,
(double) GRID_SPACING * GRID_SIZE / 2, GRID_SIZE);
coverage = new StereographicCoverage();
ProjectedCRS crs = RadarUtil.constructCRS(station.getLat(),
station.getLon());
StereographicGridCoverage coverage = new StereographicGridCoverage();
coverage.setNx(GRID_SIZE);
coverage.setNy(GRID_SIZE);
coverage.setCrs(crs);
coverage.setDx(GRID_SPACING);
coverage.setDy(GRID_SPACING);
coverage.setLov(station.getLon());
coverage.setLad(station.getLat());
coverage.setSpacingUnit("m");
coverage.setGridGeometry(gridGeometry);
coverage.setName(station.getRdaId() + " Generated Coverage");
try {
MathTransform toLatLon = MapUtil.getTransformToLatLon(crs);
DirectPosition lowerCorner = gridGeometry.getEnvelope()
.getLowerCorner();
DirectPosition upperCorner = gridGeometry.getEnvelope()
.getUpperCorner();
DirectPosition2D lowerCornerLL = new DirectPosition2D();
DirectPosition2D upperCornerLL = new DirectPosition2D();
toLatLon.transform(lowerCorner, lowerCornerLL);
toLatLon.transform(upperCorner, upperCornerLL);
// TODO verify upper left vs upper right
coverage.setGeometry(MapUtil.createGeometry(
upperCornerLL.y, upperCornerLL.x, lowerCornerLL.y,
lowerCornerLL.x));
int minExtent = -1 * GRID_SPACING * GRID_SIZE / 2;
DirectPosition2D lowerLeft = new DirectPosition2D(
minExtent, minExtent);
toLatLon.transform(lowerLeft, lowerLeft);
coverage.setFirstGridPointCorner(Corner.LowerLeft);
coverage.setLa1(lowerLeft.getY());
coverage.setLo1(lowerLeft.getX());
} catch (Exception e) {
// shouldn't occur since parsing well known geometry
}
CoverageUtils.getInstance().setCoverage(RADAR_SOURCE, coverage);
try {
coverage.initialize();
} catch (GridCoverageException e) {
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
configuredRadar = null;
return status;
}
this.coverage = GridCoverageLookup.getInstance().getCoverage(
coverage, true);
CoverageUtils.getInstance().setCoverage(RADAR_SOURCE,
this.coverage);
System.out.println("Home RADAR set to "
+ configuredRadar.getRdaId());
@ -266,11 +268,8 @@ public class RadarAdapter {
if (gridLevelNode == null) {
DerivParamMethod method = new DerivParamMethod();
method.setName("Supplement");
gridLevelNode = new OrLevelNode(
l,
desc,
method,
RADAR_SOURCE,
gridLevelNode = new OrLevelNode(l, desc,
method, RADAR_SOURCE,
new ArrayList<AbstractRequestableNode>(
productCodes.size()), false);
gridParameterNode.addChildNode(gridLevelNode);
@ -362,10 +361,6 @@ public class RadarAdapter {
return rval;
}
public ProjectedCRS getCrs() {
return crs;
}
public static int getGridSize() {
return GRID_SIZE;
}
@ -374,11 +369,7 @@ public class RadarAdapter {
return GRID_SPACING;
}
public GridGeometry2D getGridGeometry() {
return gridGeometry;
}
public StereographicCoverage getCoverage() {
public GridCoverage getCoverage() {
return coverage;
}

View file

@ -1,4 +1,5 @@
com.raytheon.uf.common.gridcoverage.LatLonGridCoverage
com.raytheon.uf.common.gridcoverage.MercatorGridCoverage
com.raytheon.uf.common.gridcoverage.PolarStereoGridCoverage
com.raytheon.uf.common.gridcoverage.LambertConformalGridCoverage
com.raytheon.uf.common.gridcoverage.LambertConformalGridCoverage
com.raytheon.uf.common.gridcoverage.StereographicGridCoverage

View file

@ -0,0 +1,163 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.common.gridcoverage;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.commons.lang.builder.HashCodeBuilder;
import com.raytheon.uf.common.dataplugin.annotations.DataURI;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.common.gridcoverage.exception.GridCoverageException;
import com.raytheon.uf.common.gridcoverage.subgrid.SubGrid;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
/**
* Stereographic Coverage used by radar data.
*
* <pre>
*
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 7, 2010 #4473 rjpeter Initial creation
*
* </pre>
*
* @author rjpeter
* @version 1.0
*/
@Entity
@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize
public class StereographicGridCoverage extends GridCoverage {
private static final long serialVersionUID = -3420227375272208743L;
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(StereographicGridCoverage.class);
/** Orientation of the grid */
@Column
@XmlElement
@DynamicSerializeElement
private double lov;
@Column
@XmlElement
@DynamicSerializeElement
private double lad;
public double getLov() {
return lov;
}
public void setLov(double lov) {
this.lov = lov;
}
public double getLad() {
return lad;
}
public void setLad(double lad) {
this.lad = lad;
}
@Override
public String getProjectionType() {
return "Stereographic";
}
@Override
public void initialize() throws GridCoverageException {
crs = MapUtil.constructStereographic(MapUtil.AWIPS_EARTH_RADIUS,
MapUtil.AWIPS_EARTH_RADIUS, lad, lov);
crsWKT = crs.toWKT();
generateGeometry();
}
@Override
public GridCoverage trim(SubGrid subGrid) {
statusHandler
.handle(Priority.ERROR,
"StereographicGridCoverage does not currently support subgridding");
return null;
}
@Override
public int generateHash() {
HashCodeBuilder hashBuilder = new HashCodeBuilder();
hashBuilder.append(super.generateHash());
hashBuilder.append(lov);
hashBuilder.append(lad);
return hashBuilder.toHashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
StereographicGridCoverage other = (StereographicGridCoverage) obj;
if (Double.doubleToLongBits(lad) != Double.doubleToLongBits(other.lad))
return false;
if (Double.doubleToLongBits(lov) != Double.doubleToLongBits(other.lov))
return false;
return true;
}
public boolean spatialEquals(GridCoverage other) {
if (super.spatialEquals(other)) {
StereographicGridCoverage otherStereo = (StereographicGridCoverage) other;
if (Math.abs(lad - otherStereo.lad) > SPATIAL_TOLERANCE) {
return false;
} else if (Math.abs(lov - otherStereo.lov) > SPATIAL_TOLERANCE) {
return false;
}
return true;
}
return false;
}
@Override
public String spatialKey() {
StringBuilder key = new StringBuilder(96);
key.append(super.spatialKey());
key.append(DataURI.SEPARATOR);
key.append(lov);
key.append(DataURI.SEPARATOR);
key.append(lad);
return key.toString();
}
}