Issue #1555 - initial generic geometry resource

- refactored viz data access resources
- updated hydro factory based on existing hydro code
- geometric lines and polygons are now both rendered using wireframe shapes and the same logic
- relocated the data used to render the geometries to the resource
- points are created instead of circles for geometric points
- do not store legend text as a static variable in the abstract data access resource
- addressed peer review comments

Change-Id: Ic7792aede9e24445af541f01631886645a8cf1f0

Former-commit-id: 04179bd343c3ec976c601e2856a3949e4515b472
This commit is contained in:
Bryan Kowal 2013-01-31 17:32:00 -06:00 committed by Gerrit Code Review
parent 4bc8e9ab5c
commit a86d2b5769
12 changed files with 825 additions and 215 deletions

View file

@ -14,7 +14,10 @@ Require-Bundle: org.eclipse.ui,
com.raytheon.uf.common.dataaccess;bundle-version="1.0.0",
com.raytheon.viz.core;bundle-version="1.12.1174",
com.raytheon.uf.common.colormap;bundle-version="1.12.1174",
javax.measure;bundle-version="1.0.0"
javax.measure;bundle-version="1.0.0",
org.apache.commons.lang;bundle-version="2.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.viz.dataaccess.rsc
Export-Package: com.raytheon.viz.dataaccess.rsc,
com.raytheon.viz.dataaccess.rsc.geometry,
com.raytheon.viz.dataaccess.rsc.grid

View file

@ -1 +1,2 @@
com.raytheon.viz.dataaccess.rsc.GenericGridResourceData
com.raytheon.viz.dataaccess.rsc.grid.GenericGridResourceData
com.raytheon.viz.dataaccess.rsc.geometry.GenericGeometryResourceData

View file

@ -0,0 +1,141 @@
/**
* 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.dataaccess.rsc;
import org.apache.commons.lang.StringUtils;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.map.MapDescriptor;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
/**
* Abstracts the rendering of data retrieved using the Data Access Framework.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 31, 2013 bkowal Initial creation
*
* </pre>
*
* @author bkowal
* @version 1.0
*/
public abstract class AbstractDataAccessResource<T extends AbstractDataAccessResourceData<?, ?>>
extends AbstractVizResource<T, MapDescriptor> {
protected static final String _SPACE_ = " ";
private String legendText;
/**
* Constructor
*
* @param resourceData
* the data associated with the resource
* @param loadProperties
* the load properties associated with the resource
* @param genericLegendText
* the default legend text associated with the resource
*/
protected AbstractDataAccessResource(T resourceData,
LoadProperties loadProperties, String genericLegendText) {
super(resourceData, loadProperties);
this.buildLegendText(genericLegendText);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractVizResource#initInternal(com.raytheon
* .uf.viz.core.IGraphicsTarget)
*/
@Override
protected void initInternal(IGraphicsTarget target) throws VizException {
this.prepareData(target);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.uf.viz.core.rsc.AbstractVizResource#getName()
*/
@Override
public String getName() {
return this.legendText;
}
/**
* Extracts pertinent information from the retrieved data and stores it; the
* extracted data will generally be used to render the resource
*
* @param target
* @throws VizException
*/
protected abstract void prepareData(IGraphicsTarget target)
throws VizException;
/**
* Adds request-type specific information to the default legend text
*
* @return additions to the legend text
*/
protected abstract String buildLegendTextInternal();
/**
* Initializes the legend text.
*
* @param genericLegendText
* the request-type specific legend text
*/
private final void buildLegendText(String genericLegendText) {
StringBuilder stringBuilder = new StringBuilder(genericLegendText);
stringBuilder.append(this.padWithSeparator(this
.buildLegendTextInternal()));
if (this.resourceData.getFirstDataElement().getDataTime() != null) {
stringBuilder.append(this.resourceData.getFirstDataElement()
.getDataTime().getLegendString());
}
this.legendText = stringBuilder.toString();
}
/**
* Adds an additional space to the end of the specified string if there is
* not already one present
*
* @param text
* the string to potentially pad with a space
* @return the string padded with a space or the original string
*/
private String padWithSeparator(String text) {
if (text.isEmpty() || text.endsWith(_SPACE_)) {
return text;
}
return StringUtils.rightPad(text, text.length() + 1);
}
}

View file

@ -0,0 +1,184 @@
/**
* 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.dataaccess.rsc;
import com.raytheon.uf.common.dataaccess.DataAccessLayer;
import com.raytheon.uf.common.dataaccess.IData;
import com.raytheon.uf.common.dataaccess.IDataRequest;
import com.raytheon.uf.common.dataaccess.exception.TimeAgnosticDataException;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.exception.NoDataAvailableException;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
/**
* Abstracts the retrieval of data using the Data Access Framework.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 31, 2013 bkowal Initial creation
*
* </pre>
*
* @author bkowal
* @version 1.0
*/
public abstract class AbstractDataAccessResourceData<T extends IDataRequest<X>, X extends IData>
extends AbstractResourceData {
private X[] data;
/**
* Constructor
*/
public AbstractDataAccessResourceData() {
this.data = null;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractResourceData#construct(com.raytheon
* .uf.viz.core.rsc.LoadProperties,
* com.raytheon.uf.viz.core.drawables.IDescriptor)
*/
@Override
public AbstractVizResource<?, ?> construct(LoadProperties loadProperties,
IDescriptor descriptor) throws VizException {
this.retrieveData(this.getRequest());
return this.constructResource(loadProperties, descriptor);
}
/**
* Retrieves and stores the data associated using the specified request.
*
* @param request
* the request
* @param clazz
* the class that is requesting the data; will always be a
* subclass of AbstractDataAccessResourceData
*/
private void retrieveData(T request) throws NoDataAvailableException {
this.data = null;
boolean timeAgnostic = false;
DataTime[] dataTimes = null;
try {
dataTimes = DataAccessLayer.getAvailableTimes(request);
} catch (TimeAgnosticDataException e1) {
timeAgnostic = true;
}
if (timeAgnostic) {
/*
* If we were a legitimate resource, we would want to cache time
* agnostic data that was retrieved. The cache could be a simple Map
* or even the cache provided by GOOG in the guava library.
*/
this.data = DataAccessLayer.getData(request);
} else {
if (dataTimes == null || dataTimes.length <= 0) {
throw new NoDataAvailableException(this.getClass());
}
/* Just use the latest time since this is a sample / test resource */
this.data = DataAccessLayer.getData(request, dataTimes[0]);
}
if (this.data == null || this.data.length <= 0) {
throw new NoDataAvailableException(this.getClass());
}
}
/**
* Retrieves the data access framework request associated with the resource data
*
* @return the data access framework request to execute
*/
protected abstract T getRequest();
/**
* Constructs the resource
*
* @param loadProperties
* @param descriptor
* @return the resource
* @throws VizException
*/
protected abstract AbstractVizResource<?, ?> constructResource(
LoadProperties loadProperties, IDescriptor descriptor) throws VizException;
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractResourceData#update(java.lang.Object
* )
*/
@Override
public void update(Object updateData) {
/* Do Nothing. */
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractResourceData#equals(java.lang.Object
* )
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (getClass() != obj.getClass()) {
return false;
}
return true;
}
/**
* Returns all of the data that was retrieved
*
* @return all of the data that was retrieved
*/
public X[] getData() {
return data;
}
/**
* Returns the first data element that has been retrieved
*
* @return the first data element that has been retrieved
*/
public X getFirstDataElement() {
return (this.data == null) ? null : this.data[0];
}
}

View file

@ -1,134 +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.dataaccess.rsc;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.common.dataaccess.impl.DefaultGridRequest;
import com.raytheon.uf.common.dataaccess.DataAccessLayer;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
/**
* Uses the Data Access Framework to execute a default grid data request.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 bkowal Initial creation
*
* </pre>
*
* @author bkowal
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
public class GenericGridResourceData extends AbstractResourceData {
@XmlElement
private DefaultGridRequest defaultGridRequest;
private IGridData gridData = null;
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractResourceData#construct(com.raytheon
* .uf.viz.core.rsc.LoadProperties,
* com.raytheon.uf.viz.core.drawables.IDescriptor)
*/
@Override
public AbstractVizResource<?, ?> construct(LoadProperties loadProperties,
IDescriptor descriptor) throws VizException {
/*
* Use the Data Access Framework to retrieve the data.
*
* TODO: move to a parent class?
*/
// First, get the available data times based on the request
DataTime[] dataTimes = DataAccessLayer
.getAvailableTimes(this.defaultGridRequest);
if (dataTimes.length > 0) {
this.getData(dataTimes[0]);
}
return new GenericGridResource(this, loadProperties);
}
private void getData(DataTime dataTime) {
// Now, retrieve the data using the latest data time
IGridData[] data = DataAccessLayer.getData(this.defaultGridRequest,
dataTime);
if (data.length > 0) {
this.gridData = data[0];
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractResourceData#update(java.lang.Object
* )
*/
@Override
public void update(Object updateData) {
/* Do Nothing. */
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractResourceData#equals(java.lang.Object
* )
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (getClass() != obj.getClass()) {
return false;
}
return true;
}
/**
* Returns the grid data that was retrieved
*
* @return the grid data
*/
public IGridData getGridData() {
return gridData;
}
}

View file

@ -0,0 +1,236 @@
/**
* 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.dataaccess.rsc.geometry;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
import com.raytheon.uf.viz.core.drawables.PaintProperties;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability;
import com.raytheon.uf.viz.core.rsc.capabilities.OutlineCapability;
import com.raytheon.viz.core.rsc.jts.JTSCompiler;
import com.raytheon.viz.core.rsc.jts.JTSCompiler.PointStyle;
import com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource;
/**
* Renders various geometric entities based on geometry data that is retrieved
* using the Data Access Framework.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 30, 2013 bkowal Initial creation
*
* </pre>
*
* @author bkowal
* @version 1.0
*/
public class GenericGeometryResource extends
AbstractDataAccessResource<GenericGeometryResourceData> {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(GenericGeometryResource.class);
private static final String GENERIC_LEGEND_TEXT = "Generic Geometry ";
private boolean geometriesReady;
private List<double[]> pointsToRender;
private IWireframeShape shape;
/**
* Constructor
*
* @param resourceData
* @param loadProperties
*/
protected GenericGeometryResource(GenericGeometryResourceData resourceData,
LoadProperties loadProperties) {
super(resourceData, loadProperties, GENERIC_LEGEND_TEXT);
this.geometriesReady = false;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource#disposeResource
* ()
*/
@Override
protected void disposeInternal() {
this.purgeDrawableStorage();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractVizResource#paintInternal(com.raytheon
* .uf.viz.core.IGraphicsTarget,
* com.raytheon.uf.viz.core.drawables.PaintProperties)
*/
@Override
protected void paintInternal(IGraphicsTarget target,
PaintProperties paintProps) throws VizException {
if (this.geometriesReady == false) {
this.prepareData(target);
}
// First, draw the points
if (this.pointsToRender.size() > 0) {
target.drawPoints(this.pointsToRender,
getCapability(ColorableCapability.class).getColor(),
IGraphicsTarget.PointStyle.CIRCLE,
getCapability(MagnificationCapability.class)
.getMagnification().floatValue());
}
OutlineCapability outlineCapability = getCapability(OutlineCapability.class);
// Finally, draw the shape
if (this.shape != null && outlineCapability.isOutlineOn()) {
target.drawWireframeShape(this.shape,
getCapability(ColorableCapability.class).getColor(),
outlineCapability.getOutlineWidth(),
outlineCapability.getLineStyle());
}
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource#reprojectResource
* (org.opengis.referencing.crs.CoordinateReferenceSystem)
*/
@Override
public void project(CoordinateReferenceSystem mapData) throws VizException {
this.purgeDrawableStorage();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource#prepareData
* (com.raytheon.uf.viz.core.IGraphicsTarget)
*/
@Override
protected void prepareData(IGraphicsTarget target) throws VizException {
this.initDrawableStorage();
int numberOfPoints = 0;
List<Geometry> shapeGeometries = new ArrayList<Geometry>();
for (IGeometryData geometryData : this.resourceData.getData()) {
Geometry geometry = geometryData.getGeometry();
if (geometry instanceof Point) {
double[] pixels = this.descriptor
.worldToPixel(new double[] {
geometry.getCoordinate().x,
geometry.getCoordinate().y });
this.pointsToRender.add(pixels);
} else {
// Calculate the number of points; build the list of geometries
// we will be adding to the shape.
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Geometry _geometry = geometry.getGeometryN(i);
numberOfPoints += _geometry.getNumPoints();
shapeGeometries.add((Geometry) _geometry.clone());
}
}
}
if (numberOfPoints > 0) {
// create the wireframe shape
this.shape = target.createWireframeShape(false, this.descriptor,
0.0f);
JTSCompiler jtsCompiler = new JTSCompiler(null, this.shape,
this.descriptor, PointStyle.CROSS);
this.shape.allocate(numberOfPoints);
// add the geometries
for (Geometry geometry : shapeGeometries) {
try {
jtsCompiler.handle(geometry);
} catch (VizException e1) {
statusHandler.handle(UFStatus.Priority.ERROR,
"Failed to handle Geometry "
+ geometry.getClass().getName(), e1);
}
}
// compile
this.shape.compile();
}
this.geometriesReady = true;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource#buildLegendText
* ()
*/
@Override
protected String buildLegendTextInternal() {
return StringUtils.EMPTY;
}
/**
* Initializes the lists that will track the geometric entities that we will
* be drawing.
*/
private void initDrawableStorage() {
this.pointsToRender = new ArrayList<double[]>();
}
/**
* Normally invoked when the resource is disposed; purges all saved
* geometric entities
*/
public void purgeDrawableStorage() {
this.pointsToRender = null;
if (this.shape != null) {
this.shape.dispose();
}
this.shape = null;
this.geometriesReady = false;
}
}

View file

@ -0,0 +1,88 @@
/**
* 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.dataaccess.rsc.geometry;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.common.dataaccess.impl.DefaultGeometryRequest;
import com.raytheon.uf.common.dataaccess.geom.IGeometryData;
import com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResourceData;
/**
* Uses the Data Access Framework to execute a default geometry data request.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 30, 2013 bkowal Initial creation
*
* </pre>
*
* @author bkowal
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
public class GenericGeometryResourceData extends
AbstractDataAccessResourceData<DefaultGeometryRequest, IGeometryData> {
@XmlElement
private DefaultGeometryRequest request;
/**
* Constructor
*/
public GenericGeometryResourceData() {
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResourceData#
* constructResource(com.raytheon.uf.viz.core.rsc.LoadProperties,
* com.raytheon.uf.viz.core.drawables.IDescriptor)
*/
@Override
protected AbstractVizResource<?, ?> constructResource(
LoadProperties loadProperties, IDescriptor descriptor)
throws VizException {
return new GenericGeometryResource(this, loadProperties);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResourceData#getRequest
* ()
*/
@Override
protected DefaultGeometryRequest getRequest() {
return this.request;
}
}

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.dataaccess.rsc;
package com.raytheon.viz.dataaccess.rsc.grid;
import java.nio.Buffer;
@ -26,19 +26,17 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.uf.common.geospatial.interpolation.data.ByteBufferWrapper;
import com.raytheon.uf.common.time.DataTime;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.drawables.ColorMapLoader;
import com.raytheon.uf.viz.core.drawables.ColorMapParameters;
import com.raytheon.uf.viz.core.drawables.PaintProperties;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.map.MapDescriptor;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability;
import com.raytheon.uf.viz.core.style.level.SingleLevel;
import com.raytheon.viz.core.drawables.ColorMapParameterFactory;
import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay2;
import com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource;
/**
* Renders a generic grid image based on grid data that is retrieved using the
@ -51,6 +49,7 @@ import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay2;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 bkowal Initial creation
* Jan 31, 2013 #1555 bkowal Refactor
*
* </pre>
*
@ -59,29 +58,17 @@ import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay2;
*/
public class GenericGridResource extends
AbstractVizResource<GenericGridResourceData, MapDescriptor> {
AbstractDataAccessResource<GenericGridResourceData> {
private static final String GRID_COLORMAP = "Grid/gridded data";
private static final String GENERIC_GRID_LEGEND_TEXT = "Generic Grid ";
private static final String NODATA_LEGEND_TEXT = GENERIC_GRID_LEGEND_TEXT
+ " No Data Available";
private static final String GENERIC_LEGEND_TEXT = "Generic Grid ";
private GriddedImageDisplay2 griddedImageDisplay;
private boolean noData = false;
private Buffer buffer = null;
private GridGeometry2D gridGeometry;
private DataTime dataTime;
protected GenericGridResource(GenericGridResourceData resourceData,
LoadProperties loadProperties) {
super(resourceData, loadProperties);
this.griddedImageDisplay = null;
super(resourceData, loadProperties, GENERIC_LEGEND_TEXT);
}
/**
@ -91,95 +78,97 @@ public class GenericGridResource extends
*
* @throws VizException
*/
private void prepareData() throws VizException {
IGridData gridData = this.resourceData.getGridData();
if (gridData == null) {
this.noData = true;
return;
}
@Override
protected void prepareData(IGraphicsTarget target) throws VizException {
IGridData gridData = this.resourceData.getFirstDataElement();
this.gridGeometry = gridData.getGridGeometry();
GridGeometry2D gridGeometry = gridData.getGridGeometry();
// Extract the raw data
ByteBufferWrapper byteBufferWrapper = new ByteBufferWrapper(
this.gridGeometry);
gridGeometry);
byteBufferWrapper = gridData.populateData(byteBufferWrapper);
this.buffer = byteBufferWrapper.getBuffer();
this.dataTime = gridData.getDataTime();
Buffer buffer = byteBufferWrapper.getBuffer();
// Prepare the Color Map
SingleLevel singleLevel = null;
if ((gridData.getLevel() == null) == false) {
if (gridData.getLevel() != null) {
// TODO: convert level to single level
}
ColorMapParameters colorMapParameters = ColorMapParameterFactory.build(
this.buffer.array(), gridData.getParameter(),
gridData.getUnit(), singleLevel);
buffer.array(), gridData.getParameter(), gridData.getUnit(),
singleLevel);
colorMapParameters.setColorMapName(GRID_COLORMAP);
colorMapParameters.setColorMap(ColorMapLoader
.loadColorMap(colorMapParameters.getColorMapName()));
getCapability(ColorMapCapability.class).setColorMapParameters(
colorMapParameters);
this.griddedImageDisplay = new GriddedImageDisplay2(buffer,
gridGeometry, this);
}
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource#
* buildLegendTextInternal()
*/
@Override
public String getName() {
if (this.noData) {
return NODATA_LEGEND_TEXT;
}else if(this.dataTime == null){
return GENERIC_GRID_LEGEND_TEXT;
} else {
StringBuilder legend = new StringBuilder(GENERIC_GRID_LEGEND_TEXT);
IGridData gridData = resourceData.getGridData();
if (gridData != null) {
if (gridData.getParameter() != null) {
legend.append(" ");
legend.append(gridData.getParameter());
}
if (gridData.getLevel() != null) {
legend.append(" ");
legend.append(gridData.getLevel());
}
}
legend.append(this.dataTime.getLegendString());
return legend.toString();
protected String buildLegendTextInternal() {
StringBuilder stringBuilder = new StringBuilder();
IGridData gridData = this.resourceData.getFirstDataElement();
if (gridData.getParameter() != null) {
stringBuilder.append(gridData.getParameter());
stringBuilder.append(_SPACE_);
}
if (gridData.getLevel() != null) {
stringBuilder.append(gridData.getLevel());
stringBuilder.append(_SPACE_);
}
return stringBuilder.toString();
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResource#disposeResource
* ()
*/
@Override
protected void disposeInternal() {
if ((this.griddedImageDisplay == null) == false) {
if (this.griddedImageDisplay != null) {
this.griddedImageDisplay.dispose();
}
this.griddedImageDisplay = null;
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractVizResource#paintInternal(com.raytheon
* .uf.viz.core.IGraphicsTarget,
* com.raytheon.uf.viz.core.drawables.PaintProperties)
*/
@Override
protected void paintInternal(IGraphicsTarget target,
PaintProperties paintProps) throws VizException {
if (this.noData) {
return;
}
if (this.griddedImageDisplay == null) {
this.griddedImageDisplay = new GriddedImageDisplay2(this.buffer,
this.gridGeometry, this);
}
this.griddedImageDisplay.paint(target, paintProps);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.core.rsc.AbstractVizResource#project(org.opengis.
* referencing.crs.CoordinateReferenceSystem)
*/
@Override
public void project(CoordinateReferenceSystem mapData) throws VizException {
if ((this.griddedImageDisplay == null) == false) {
this.griddedImageDisplay.dispose();
this.griddedImageDisplay = null;
}
}
@Override
protected void initInternal(IGraphicsTarget target) throws VizException {
this.prepareData();
this.griddedImageDisplay.project(this.descriptor.getGridGeometry());
}
}

View file

@ -0,0 +1,83 @@
/**
* 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.dataaccess.rsc.grid;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractVizResource;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.common.dataaccess.impl.DefaultGridRequest;
import com.raytheon.uf.common.dataaccess.grid.IGridData;
import com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResourceData;
/**
* Uses the Data Access Framework to execute a default grid data request.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 8, 2013 bkowal Initial creation
* Jan 31, 2013 #1555 bkowal Refactor
*
* </pre>
*
* @author bkowal
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
public class GenericGridResourceData extends
AbstractDataAccessResourceData<DefaultGridRequest, IGridData> {
@XmlElement
private DefaultGridRequest request;
/*
* (non-Javadoc)
*
* @see com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResourceData#
* constructResource(com.raytheon.uf.viz.core.rsc.LoadProperties,
* com.raytheon.uf.viz.core.drawables.IDescriptor)
*/
@Override
protected AbstractVizResource<?, ?> constructResource(
LoadProperties loadProperties, IDescriptor descriptor)
throws VizException {
return new GenericGridResource(this, loadProperties);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.dataaccess.rsc.AbstractDataAccessResourceData#getRequest
* ()
*/
@Override
protected DefaultGridRequest getRequest() {
return this.request;
}
}

View file

@ -19,7 +19,13 @@
**/
package com.raytheon.uf.common.dataaccess.impl;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.raytheon.uf.common.dataaccess.geom.IGeometryRequest;
import com.raytheon.uf.common.serialization.adapters.JTSEnvelopeAdapter;
import com.vividsolutions.jts.geom.Envelope;
/**
@ -32,18 +38,21 @@ import com.vividsolutions.jts.geom.Envelope;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 5, 2012 njensen Initial creation
* Jan 30, 2013 #1555 bkowal Added XML Annotations
*
* </pre>
*
* @author njensen
* @version 1.0
*/
@XmlAccessorType(XmlAccessType.NONE)
public class DefaultGeometryRequest extends AbstractDataRequest implements
IGeometryRequest {
@XmlJavaTypeAdapter(value = JTSEnvelopeAdapter.class)
protected Envelope envelope;
@XmlElement(name="locationName")
protected String[] locationNames;
@Override

View file

@ -51,7 +51,8 @@ import com.raytheon.uf.common.localization.IPathManager;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 03, 2012 bkowal Initial creation
* Jan 03, 2013 bkowal Initial creation
* Jan 31, 2013 #1555 bkowal Made hdf5 variable generic
*
* </pre>
*
@ -71,13 +72,13 @@ public final class PDOUtil {
final IPersistable persistable = (IPersistable) pdo;
IHDFFilePathProvider pathProvider = pdo.getHDFPathProvider();
String satelliteHDF5Path = pathProvider.getHDFPath(pluginName,
String hdf5Path = pathProvider.getHDFPath(pluginName,
persistable);
String satelliteHDF5File = pathProvider.getHDFFileName(pluginName,
String hdf5File = pathProvider.getHDFFileName(pluginName,
persistable);
File file = new File(pluginName + IPathManager.SEPARATOR
+ satelliteHDF5Path + IPathManager.SEPARATOR
+ satelliteHDF5File);
+ hdf5Path + IPathManager.SEPARATOR
+ hdf5File);
return DataStoreFactory.getDataStore(file);
}
@ -116,4 +117,4 @@ public final class PDOUtil {
return MapUtil.getGridGeometry(((ISpatialEnabled) pdo)
.getSpatialObject());
}
}
}

View file

@ -47,6 +47,7 @@ import com.vividsolutions.jts.geom.GeometryFactory;
* ------------ ---------- ----------- --------------------------
* Nov 13, 2012 njensen Initial creation
* Jan 30, 2012 1551 bkowal Refactored
* Jan 31, 2012 1555 bkowal Modification based on existing hydro code
*
* </pre>
*
@ -109,6 +110,14 @@ public class HydroGeometryFactory extends AbstractGeometryDatabaseFactory {
Timestamp date = (Timestamp) data[1];
double lat = (Double) data[2];
double lon = (Double) data[3];
/*
* Assuming that this applies to all ihfs data Refer to GageData.java
*
* method: setLon
*/
if (lon > 0) {
lon *= -1;
}
// intentionally setting level as null until hydrologists determine
// something better