Merge "Issue #2235 Added Caching version of TopoQuery. Change-Id: I0e17028921faa40e85134c79074655900bd8358c" into development

Former-commit-id: 17ed074c5e [formerly 896b5333d1] [formerly 216b2a5c86] [formerly 0a9068e6d3 [formerly 216b2a5c86 [formerly 4e9a02fcd4931d2a26b10b3e695a7fa99d1ef972]]]
Former-commit-id: 0a9068e6d3
Former-commit-id: 72056a95440f5bfa6c34f417686f4cf38ac5b799 [formerly fcb78e78d3]
Former-commit-id: 44c10c798d
This commit is contained in:
Ron Anderson 2013-08-07 14:05:36 -05:00 committed by Gerrit Code Review
commit 441702e186
12 changed files with 442 additions and 92 deletions

View file

@ -27,7 +27,8 @@ Require-Bundle: org.eclipse.ui,
com.raytheon.uf.common.colormap;bundle-version="1.0.0",
com.raytheon.uf.common.serialization.comm,
org.eclipse.core.expressions,
com.raytheon.uf.viz.application;bundle-version="1.0.0"
com.raytheon.uf.viz.application;bundle-version="1.0.0",
com.raytheon.uf.common.topo;bundle-version="1.12.1174"
Eclipse-BuddyPolicy: ext, registered, global
Eclipse-RegisterBuddy: org.apache.velocity, com.raytheon.uf.common.geospatial, com.raytheon.uf.common.serialization, com.raytheon.uf.common.status
Export-Package:

View file

@ -23,7 +23,6 @@ package com.raytheon.viz.core.topo;
import java.io.File;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Map;
import javax.measure.converter.UnitConverter;
import javax.measure.unit.NonSI;
@ -31,23 +30,15 @@ import javax.measure.unit.SI;
import javax.measure.unit.Unit;
import javax.measure.unit.UnitFormat;
import org.geotools.coverage.grid.GeneralGridEnvelope;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.coverage.grid.GridEnvelope;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters;
import com.raytheon.uf.common.colormap.prefs.ColorMapParameters.PersistedParameters;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.datastorage.Request;
import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.geospatial.CRSCache;
import com.raytheon.uf.common.geospatial.ReferencedCoordinate;
import com.raytheon.uf.common.topo.TopoUtils;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.drawables.ColorMapLoader;
import com.raytheon.uf.viz.core.drawables.PaintProperties;
@ -77,8 +68,9 @@ import com.raytheon.viz.core.style.image.SamplePreferences;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 14, 2007 chammack Initial Creation.
* Apr 03, 2013 1562 mschenke Fix for custom colormaps
* Apr 24, 2013 1638 mschenke Made topo configurable for source data
* Apr 03, 2013 1562 mschenke Fix for custom colormaps
* Apr 24, 2013 1638 mschenke Made topo configurable for source data
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*
@ -234,44 +226,9 @@ public class TopoResource extends
private GridGeometry2D getTopoGeometry() throws VizException {
IDataStore ds = DataStoreFactory.getDataStore(dataFile);
Request request = Request.buildSlab(new int[] { 0, 0 }, new int[] { 1,
1 });
try {
IDataRecord record = ds.retrieve("/", "full", request);
Map<String, Object> attributes = record.getDataAttributes();
int width = (Integer) attributes.get("Width");
int height = (Integer) attributes.get("Height");
double ulLat = (Double) attributes.get("ulLat");
double ulLon = (Double) attributes.get("ulLon");
double lrLat = (Double) attributes.get("lrLat");
double lrLon = (Double) attributes.get("lrLon");
String crsString = (String) attributes.get("CRS");
// Construct CRS for topo data
CoordinateReferenceSystem crs = CRSCache.getInstance()
.getCoordinateReferenceSystem(crsString);
// Grid range
GridEnvelope gridRange = new GeneralGridEnvelope(
new int[] { 0, 0 }, new int[] { width, height });
// Convert ulLat/ulLon to crs space
MathTransform mt = CRS.findMathTransform(
DefaultGeographicCRS.WGS84, crs);
double[] in = new double[] { ulLon, ulLat, lrLon, lrLat };
double[] out = new double[in.length];
mt.transform(in, 0, out, 0, 2);
GeneralEnvelope gridEnvelope = new GeneralEnvelope(2);
gridEnvelope.setCoordinateReferenceSystem(crs);
gridEnvelope.setRange(0, Math.min(out[0], out[2]),
Math.max(out[0], out[2]));
gridEnvelope.setRange(1, Math.min(out[1], out[3]),
Math.max(out[1], out[3]));
return new GridGeometry2D(gridRange, gridEnvelope);
return TopoUtils.getTopoGeometry(ds,
TopoUtils.getDatasetForLevel(0));
} catch (Exception e) {
throw new VizException("Error getting grid geometry", e);
}

View file

@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.topo.TopoUtils;
import com.raytheon.uf.viz.core.drawables.IDescriptor;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.AbstractNameGenerator;
@ -42,7 +43,8 @@ import com.raytheon.uf.viz.core.rsc.LoadProperties;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 19, 2009 chammack Initial creation
* Apr 24, 2013 1638 mschenke Made topo configurable for source data
* Apr 24, 2013 1638 mschenke Made topo configurable for source data
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*
@ -52,10 +54,8 @@ import com.raytheon.uf.viz.core.rsc.LoadProperties;
@XmlAccessorType(XmlAccessType.NONE)
public class TopoResourceData extends AbstractResourceData {
protected static final String TOPO_DIR = "topo";
@XmlElement
private String topoFile = "srtm30.hdf";
private String topoFile = TopoUtils.getDefaultTopoFile().getName();
/** The human readable name */
@XmlElement
@ -84,7 +84,8 @@ public class TopoResourceData extends AbstractResourceData {
@Override
public TopoResource construct(LoadProperties loadProperties,
IDescriptor descriptor) throws VizException {
return new TopoResource(this, loadProperties, new File(TOPO_DIR
return new TopoResource(this, loadProperties, new File(TopoUtils
.getDefaultTopoFile().getParent()
+ IPathManager.SEPARATOR + getTopoFile()));
}

View file

@ -23,6 +23,7 @@ import java.io.File;
import org.geotools.coverage.grid.GeneralGridGeometry;
import com.raytheon.uf.common.topo.TopoUtils;
import com.raytheon.uf.viz.core.DrawableImage;
import com.raytheon.uf.viz.core.IGraphicsTarget;
import com.raytheon.uf.viz.core.IGraphicsTarget.RasterMode;
@ -47,7 +48,8 @@ import com.raytheon.uf.viz.core.tile.TileSetRenderable.TileImageCreator;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jan 31, 2013 mschenke Initial creation
* Jan 31, 2013 mschenke Initial creation
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*
@ -90,11 +92,7 @@ public class TopoTileImageCreator implements TileImageCreator {
protected IColorMapDataRetrievalCallback createColormapImageCallback(
Tile tile) {
int level = tile.tileLevel;
String dataset = "/full";
if (level > 0) {
dataset = "/interpolated/" + level;
}
String dataset = TopoUtils.getDatasetForLevel(tile.tileLevel);
return new HDF5DataRetriever(dataFile, dataset, tile.getRectangle());
}
}

View file

@ -30,7 +30,7 @@ import com.raytheon.uf.common.dataplugin.radar.util.RadarDataInterrogator;
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.topo.TopoQuery;
import com.raytheon.uf.common.topo.CachedTopoQuery;
import com.vividsolutions.jts.geom.Coordinate;
/**
@ -41,11 +41,12 @@ import com.vividsolutions.jts.geom.Coordinate;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 4, 2010 mnash Initial creation
* Feb 15, 2013 1638 mschenke Got rid of viz/edex topo classes
* and moved into common
* Aug 04, 2010 mnash Initial creation
* Feb 15, 2013 1638 mschenke Got rid of viz/edex topo classes and
* moved into common
* Jul 31, 2013 2190 mschenke Made "msl" interrogate key return
* height unformatted height data value
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*
@ -99,7 +100,7 @@ public class RadarRadialInterrogator extends RadarDefaultInterrogator implements
/ 1.7e7;
double topoHeight = Double.NaN;
if (useTopo) {
TopoQuery topoQuery = TopoQuery.getInstance();
CachedTopoQuery topoQuery = CachedTopoQuery.getInstance();
if (topoQuery != null) {
topoHeight = topoQuery.getHeight(latLon);
} else {

View file

@ -0,0 +1,75 @@
/**
* 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.geospatial.interpolation;
import org.geotools.coverage.grid.GeneralGridGeometry;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.geometry.DirectPosition2D;
import org.geotools.referencing.operation.DefaultMathTransformFactory;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.common.geospatial.MapUtil;
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
/**
* Similar to a regular GridSampler but inputs to sample method are Lat/Lon
* coordinates that get transformed to grid space.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 5, 2013 bsteffen Initial creation
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class LatLonGridSampler {
private final GridSampler sampler;
private final MathTransform fromLatLon;
public LatLonGridSampler(GeneralGridGeometry sourceGeometry,
DataSource source, Interpolation interpolation)
throws FactoryException {
sampler = new GridSampler(source, interpolation);
MathTransform ll2crs = MapUtil.getTransformFromLatLon(sourceGeometry
.getCoordinateReferenceSystem());
MathTransform crs2grid = GridGeometry2D.wrap(sourceGeometry)
.getCRSToGrid2D();
fromLatLon = new DefaultMathTransformFactory()
.createConcatenatedTransform(ll2crs, crs2grid);
}
public double sample(double lon, double lat) throws TransformException {
DirectPosition2D pt = new DirectPosition2D(lon, lat);
fromLatLon.transform(pt, pt);
return sampler.sample(pt.x, pt.y);
}
}

View file

@ -0,0 +1,178 @@
/**
* 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.topo;
import java.io.File;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Map;
import org.geotools.coverage.grid.GridGeometry2D;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.geospatial.interpolation.GridReprojection;
import com.raytheon.uf.common.geospatial.interpolation.LatLonGridSampler;
import com.raytheon.uf.common.geospatial.interpolation.NearestNeighborInterpolation;
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.vividsolutions.jts.geom.Coordinate;
/**
* Replacement for TopoQuery that uses cached tiles. If the cache is not
* populated then requests may take slightly longer as tiles are retrieved but
* for doing multiple requests in the same area the cache will provide very fast
* results.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 2, 2013 bsteffen Initial creation
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class CachedTopoQuery {
private static final int TILE_SIZE = 256;
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(CachedTopoQuery.class);
private static Map<Integer, CachedTopoQuery> topoQueryMap;
/**
* @return Initialized TopoQuery instance
*/
public static synchronized CachedTopoQuery getInstance() {
return getInstance(0);
}
/**
* @return Initialized TopoQuery instance
*/
public static synchronized CachedTopoQuery getInstance(int topoLevel) {
return getInstance(TopoUtils.getDefaultTopoFile(), topoLevel);
}
public static synchronized CachedTopoQuery getInstance(File hdf5File,
int topoLevel) {
if (topoQueryMap == null) {
topoQueryMap = new Hashtable<Integer, CachedTopoQuery>();
}
CachedTopoQuery query = topoQueryMap.get(topoLevel);
if (query == null) {
try {
query = new CachedTopoQuery(hdf5File, topoLevel);
topoQueryMap.put(topoLevel, query);
} catch (TopoException e) {
statusHandler.handle(Priority.PROBLEM, e.getMessage(), e);
}
}
return query;
}
private final TiledTopoSource source;
private final LatLonGridSampler latLonSampler;
private CachedTopoQuery(File hdf5File, int level) throws TopoException {
IDataStore dataStore = DataStoreFactory.getDataStore(hdf5File);
try {
String dataset = TopoUtils.getDatasetForLevel(level);
GridGeometry2D gridGeometry = TopoUtils.getTopoGeometry(
dataStore, dataset);
source = new TiledTopoSource(TILE_SIZE, gridGeometry, dataStore,
dataset);
latLonSampler = new LatLonGridSampler(source.getGridGeometry(), source,
new NearestNeighborInterpolation());
} catch (Exception e) {
throw new TopoException(e);
}
}
/**
* Retrieves topo height in meters above mean sea level for the specified
* coordinate.
*
* @param latLon
* should contain lon/lat in degrees
* @return topo height in meters MSL
*/
public double getHeight(Coordinate latLon) {
try {
return latLonSampler.sample(latLon.x, latLon.y);
} catch (TransformException e) {
statusHandler.handle(Priority.PROBLEM,
"Error retriving topo value for lat/lons", e);
return Double.NaN;
}
}
/**
* Retrieves topo height in meters above mean sea level for the specified
* coordinates.
*
* @param coords
* should contain lon/lat in degrees
* @return topo height in meters MSL
*/
public double[] getHeight(Coordinate[] coords) {
double[] result = new double[coords.length];
for (int i = 0; i < result.length; i += 1) {
try {
result[i] = latLonSampler.sample(coords[i].x, coords[i].y);
} catch (TransformException e) {
statusHandler.handle(Priority.PROBLEM,
"Error retriving topo value for lat/lons", e);
result[i] = Double.NaN;
}
}
return result;
}
/**
* Retrieves topo height in meters above mean sea level reprojected and
* interpolated to the specified grid geometry.
*
* @param targetGeom
* @return the topo data array in row major order
*/
public float[] getHeight(GridGeometry2D targetGeom) {
FloatArrayWrapper destination = new FloatArrayWrapper(targetGeom);
GridReprojection reprojection = new GridReprojection(source.getGridGeometry(), targetGeom);
try {
reprojection.reprojectedGrid(new NearestNeighborInterpolation(), source, destination);
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
Arrays.fill(destination.getArray(), Float.NaN);
}
return destination.getArray();
}
}

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.edex.grid.staticdata.topo;
package com.raytheon.uf.common.topo;
import java.awt.Point;
import java.io.FileNotFoundException;
@ -32,9 +32,12 @@ import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.datastorage.Request;
import com.raytheon.uf.common.datastorage.StorageException;
import com.raytheon.uf.common.datastorage.records.FloatDataRecord;
import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.datastorage.records.ShortDataRecord;
import com.raytheon.uf.common.geospatial.interpolation.data.AbstractTiledDataSource;
import com.raytheon.uf.common.geospatial.interpolation.data.DataSource;
import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
import com.raytheon.uf.common.geospatial.interpolation.data.ShortArrayWrapper;
/**
* Tiled data source for loading topo tiles and caching tiles as soft reference
@ -46,7 +49,8 @@ import com.raytheon.uf.common.geospatial.interpolation.data.FloatArrayWrapper;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 11, 2012 bsteffen Initial creation
* Dec 11, 2012 bsteffen Initial creation
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*
@ -110,12 +114,21 @@ public class TiledTopoSource extends AbstractTiledDataSource {
protected DataSource requestTile(int startX, int startY, int width,
int height) {
try {
float[] array = ((FloatDataRecord) dataStore.retrieve(
IDataRecord record = dataStore.retrieve(
"/",
dataset,
Request.buildSlab(new int[] { startX, startY }, new int[] {
startX + width, startY + height }))).getFloatData();
return new FloatArrayWrapper(array, width, height);
startX + width, startY + height }));
if (record instanceof FloatDataRecord) {
return new FloatArrayWrapper((float[]) record.getDataObject(),
width, height);
} else if (record instanceof ShortDataRecord) {
return new ShortArrayWrapper((short[]) record.getDataObject(),
width, height);
} else {
throw new DataRetrievalException("Unrecognized record type: "
+ record.getClass().getSimpleName());
}
} catch (FileNotFoundException e) {
throw new DataRetrievalException(e);
} catch (StorageException e) {
@ -131,6 +144,10 @@ public class TiledTopoSource extends AbstractTiledDataSource {
super(cause);
}
public DataRetrievalException(String message) {
super(message);
}
}
}

View file

@ -80,12 +80,14 @@ import com.vividsolutions.jts.geom.Coordinate;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 11/19/2007 #377 randerso Initial creation
* Jun 13, 2008 #1160 randerso Moved to server side
* 03/09/2012 DR 14581 D. Friedman Fix grid referencing and use custom
* Nov 19, 2007 377 randerso Initial creation
* Jun 13, 2008 1160 randerso Moved to server side
* Mar 09, 2012 14581 D. Friedman Fix grid referencing and use custom
* nearest-neighbor resampling.i
* 01/14/2013 #1469 bkowal Removed the hdf5 data directory.
* Feb 15, 2013 1638 mschenke Moved from edex.topo project (not edex specific)
* Jan 14, 2013 1469 bkowal Removed the hdf5 data directory.
* Feb 15, 2013 1638 mschenke Moved from edex.topo project (not edex
* specific)
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*
@ -98,8 +100,6 @@ public class TopoQuery {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(TopoQuery.class);
private static final String TOPO_FILE = "/topo/srtm30.hdf";
private static final int TOPO_LIMIT = 4096 * 4096;
private static Map<Integer, TopoQuery> topoQueryMap;
@ -116,7 +116,7 @@ public class TopoQuery {
* @return Initialized TopoQuery instance
*/
public static synchronized TopoQuery getInstance(int topoLevel) {
return getInstance(new File(TOPO_FILE), topoLevel);
return getInstance(TopoUtils.getDefaultTopoFile(), topoLevel);
}
public static synchronized TopoQuery getInstance(File hdf5File,
@ -180,11 +180,7 @@ public class TopoQuery {
1 });
try {
if (topoLevel == 0) {
dataset = "/full";
} else {
dataset = "/interpolated/" + topoLevel;
}
dataset = TopoUtils.getDatasetForLevel(topoLevel);
IDataRecord record = dataStore.retrieve("", dataset, request);
Map<String, Object> attributes = record.getDataAttributes();

View file

@ -0,0 +1,122 @@
/**
* 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.topo;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import org.geotools.coverage.grid.GeneralGridEnvelope;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.referencing.CRS;
import org.geotools.referencing.crs.DefaultGeographicCRS;
import org.opengis.coverage.grid.GridEnvelope;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import com.raytheon.uf.common.datastorage.IDataStore;
import com.raytheon.uf.common.datastorage.Request;
import com.raytheon.uf.common.datastorage.StorageException;
import com.raytheon.uf.common.datastorage.records.IDataRecord;
import com.raytheon.uf.common.geospatial.CRSCache;
/**
* Common utility methods that can be shared among different areas of the system
* using topo.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 2, 2013 bsteffen Initial creation
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class TopoUtils {
private static final String DEFAULT_TOPO_PATH = "/topo/srtm30.hdf";
private static final String FULL_TOPO_DATASET = "/full";
private static final String INTERPOLATED_DATASET_PREFIX = "/interpolated/";
public static GridGeometry2D getTopoGeometry(IDataStore topoDataStore,
String dataset) throws FileNotFoundException, StorageException,
FactoryException, TransformException {
Request request = Request.buildSlab(new int[] { 0, 0 }, new int[] { 1,
1 });
IDataRecord record = topoDataStore.retrieve("/", dataset, request);
Map<String, Object> attributes = record.getDataAttributes();
int width = (Integer) attributes.get("Width");
int height = (Integer) attributes.get("Height");
double ulLat = (Double) attributes.get("ulLat");
double ulLon = (Double) attributes.get("ulLon");
double lrLat = (Double) attributes.get("lrLat");
double lrLon = (Double) attributes.get("lrLon");
String crsString = (String) attributes.get("CRS");
// Construct CRS for topo data
CoordinateReferenceSystem crs = CRSCache.getInstance()
.getCoordinateReferenceSystem(crsString);
// Grid range
GridEnvelope gridRange = new GeneralGridEnvelope(new int[] { 0, 0 },
new int[] { width, height });
// Convert ulLat/ulLon to crs space
MathTransform mt = CRS.findMathTransform(DefaultGeographicCRS.WGS84,
crs);
double[] in = new double[] { ulLon, ulLat, lrLon, lrLat };
double[] out = new double[in.length];
mt.transform(in, 0, out, 0, 2);
GeneralEnvelope gridEnvelope = new GeneralEnvelope(2);
gridEnvelope.setCoordinateReferenceSystem(crs);
gridEnvelope.setRange(0, Math.min(out[0], out[2]),
Math.max(out[0], out[2]));
gridEnvelope.setRange(1, Math.min(out[1], out[3]),
Math.max(out[1], out[3]));
return new GridGeometry2D(gridRange, gridEnvelope);
}
public static String getDatasetForLevel(int level) {
if (level == 0) {
return FULL_TOPO_DATASET;
} else {
return INTERPOLATED_DATASET_PREFIX + level;
}
}
public static File getDefaultTopoFile() {
return new File(DEFAULT_TOPO_PATH);
}
}

View file

@ -15,6 +15,7 @@ Require-Bundle: javax.measure;bundle-version="1.0.0",
com.raytheon.uf.edex.decodertools;bundle-version="1.12.1174",
com.raytheon.edex.common;bundle-version="1.12.1174",
com.raytheon.edex.plugin.gfe;bundle-version="1.12.1174",
com.raytheon.uf.common.comm;bundle-version="1.12.1174"
com.raytheon.uf.common.comm;bundle-version="1.12.1174",
com.raytheon.uf.common.topo;bundle-version="1.12.1174"
Export-Package: com.raytheon.uf.edex.grid.staticdata,
com.raytheon.uf.edex.grid.staticdata.topo

View file

@ -65,6 +65,7 @@ import com.raytheon.uf.common.serialization.SerializationException;
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.topo.TiledTopoSource;
import com.raytheon.uf.common.util.RunProcess;
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils;
import com.raytheon.uf.edex.database.cluster.ClusterLockUtils.LockState;
@ -78,13 +79,15 @@ import com.vividsolutions.jts.geom.Coordinate;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* 09/27/2010 6394 bphillip Initial creation
* 10/08/2010 6394 bphillip Rewrote sections for optimal reading and writing performance
* 09/19/2011 10955 rferrel Use RunProcess
* 04/18/2012 DR 14694 D. Friedman Fixes for static topography generation
* 05/09/2012 DR 14939 D. Friedman Fix errors in DR 14694
* 01/14/2013 1469 bkowal Removed the hdf5 data directory
* 02/12/2013 #1608 randerso Changed to call deleteDatasets
* Sep 27, 2010 6394 bphillip Initial creation
* Oct 08, 2010 6394 bphillip Rewrote sections for optimal reading and
* writing performance
* Sep 19, 2011 10955 rferrel Use RunProcess
* Apr 18, 2012 14694 D. Friedman Fixes for static topography generation
* May 09, 2012 14939 D. Friedman Fix errors in DR 14694
* Jan 14, 2013 1469 bkowal Removed the hdf5 data directory
* Feb 12, 2013 1608 randerso Changed to call deleteDatasets
* Aug 06, 2013 2235 bsteffen Added Caching version of TopoQuery.
*
* </pre>
*