Issue #189 changes from code review comments for gridcoverage.

Former-commit-id: 94e4f2adb6 [formerly cfac5882643a0bde47c6f81623dd80ec41604a82]
Former-commit-id: 7f99750ba5
This commit is contained in:
Ben Steffensmeier 2012-10-01 12:49:28 -05:00
parent 2f6b9f6188
commit 57d35bb700
6 changed files with 135 additions and 37 deletions

View file

@ -106,13 +106,12 @@ public class GribSpatialCache {
private Map<Integer, Set<String>> gridNameMap;
/**
* Map containing the subGrid coverage based on a model name.
* Map containing the subGrid coverage based on a subGridKey
*/
private Map<String, GridCoverage> subGridCoverageMap;
/**
* Map containing the subGrid based on a model name and the base coverage
* name
* Map containing the subGrid based on a the subGridKey
*/
private Map<String, SubGrid> definedSubGridMap;
@ -172,6 +171,16 @@ public class GribSpatialCache {
return rval;
}
/**
* For a grib model name return all GridCoverages that are defined in the
* gribModels file for that model. For models which use subgrids this will
* return the subgridded coverages. For models that are not defined or
* models that do not specify a specific grid this will return an empty
* list.
*
* @param modelName
* @return
*/
public List<GridCoverage> getGridsForModel(String modelName) {
List<GridCoverage> rval = new ArrayList<GridCoverage>();
if (modelName != null) {
@ -216,6 +225,18 @@ public class GribSpatialCache {
return coverage;
}
/**
* This method provides a way to get the names from the definiton files for
* looking up a grib model. It will return all the names of any coverages
* defined in the grid definition files that are spatially equivalent to the
* passed in coverage. This is useful when there are multiple grid
* definition files with the same spatial attributes but different names or
* for cases where the name in the definition file does not match what is
* currently in the db.
*
* @param coverage
* @return
*/
public Set<String> getGribCoverageNames(GridCoverage coverage) {
Set<String> rval = gridNameMap.get(coverage.getId());
if (rval == null) {
@ -228,6 +249,15 @@ public class GribSpatialCache {
return rval;
}
/**
* For a given modelName and coverage this will return the SubGrid used for
* slicing data if there is a subGrid file for this model. If this model
* does not require subgridding this method will return null.
*
* @param modelName
* @param coverage
* @return
*/
public SubGrid getSubGrid(String modelName, GridCoverage coverage) {
SubGrid subGrid = definedSubGridMap
.get(subGridKey(modelName, coverage));
@ -240,6 +270,15 @@ public class GribSpatialCache {
return subGrid;
}
/**
* For a given modelName and coverage this will return the sub-GridCoverage
* which should be used for this data. If this model does not require
* subgridding this method will return null.
*
* @param modelName
* @param coverage
* @return
*/
public GridCoverage getSubGridCoverage(String modelName,
GridCoverage coverage) {
GridCoverage subGrid = subGridCoverageMap.get(subGridKey(modelName,
@ -253,6 +292,14 @@ public class GribSpatialCache {
return subGrid;
}
/**
* If a sub grid area is defined for this model than this will process that
* defintion and piopulate the subGridCoverageMap and definedSubGridMap.
*
* @param modelName
* @param coverage
* @return true if this model is subgridded, false otherwise
*/
private boolean loadSubGrid(String modelName, GridCoverage coverage) {
SubGridDef subGridDef = subGridDefMap.get(modelName);
if (subGridDef != null) {

View file

@ -17,12 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
CREATE INDEX "gridCoverageType_idx"
CREATE INDEX "gridCoverageTypeNxNy_idx"
ON gridcoverage
USING btree
(dtype);
CREATE INDEX "gridCoverageNxNy_idx"
ON gridcoverage
USING btree
(nx, ny);
(dtype, nx, ny);

View file

@ -580,7 +580,6 @@ public abstract class GridCoverage extends PersistableDataObject implements
protected void generateGeometry() throws GridCoverageException {
if ("degree".equals(spacingUnit)) {
// lower left is cell center, we want cell corners.
// special case in data delivery
double minLat = getLowerLeftLat() - dy / 2;
double maxLat = minLat + dy * ny;
double minLon = getLowerLeftLon() - dx / 2;

View file

@ -123,7 +123,7 @@ public class MercatorGridCoverage extends GridCoverage {
@Override
public void initialize() throws GridCoverageException {
double meridian = 0;
if (la2 == null || lo2 == null) {
if (true || la2 == null || lo2 == null) {
initializeSecondCorner();
}
@ -177,28 +177,28 @@ public class MercatorGridCoverage extends GridCoverage {
fromLatLon.transform(new DirectPosition2D(lo1, la1), firstPosition);
// move firstPosition from cell center to cell corner
firstPosition.x -= 0.5 * dx;
firstPosition.y -= 0.5 * dy;
firstPosition.x -= 0.5 * dx * 1000;
firstPosition.y -= 0.5 * dy * 1000;
// Determine the other corner point using the given dx,dy,nx, and
// ny in meters
DirectPosition2D position = null;
switch (firstGridPointCorner) {
case LowerLeft:
position = new DirectPosition2D(firstPosition.x + dx * nx,
firstPosition.y + dy * ny);
position = new DirectPosition2D(firstPosition.x + dx * 1000
* nx, firstPosition.y + dy * 1000 * ny);
break;
case UpperLeft:
position = new DirectPosition2D(firstPosition.x + dx * nx,
firstPosition.y - dy * ny);
position = new DirectPosition2D(firstPosition.x + dx * 1000
* nx, firstPosition.y - dy * 1000 * ny);
break;
case LowerRight:
position = new DirectPosition2D(firstPosition.x - dx * nx,
firstPosition.y - dy * ny);
position = new DirectPosition2D(firstPosition.x - dx * 1000
* nx, firstPosition.y - dy * 1000 * ny);
break;
case UpperRight:
position = new DirectPosition2D(firstPosition.x - dx * nx,
firstPosition.y - dy * ny);
position = new DirectPosition2D(firstPosition.x - dx * 1000
* nx, firstPosition.y - dy * 1000 * ny);
break;
default:
throw new GridCoverageException(
@ -208,6 +208,11 @@ public class MercatorGridCoverage extends GridCoverage {
// Convert the corner points from meters to lat/lon
DirectPosition2D cornerPosition = new DirectPosition2D();
toLatLon.transform(position, cornerPosition);
System.err.println("dx = " + (lo2 - cornerPosition.x));
System.err.println("dy = " + (la2 - cornerPosition.y));
if (Math.abs(lo2 - cornerPosition.x) > 4) {
System.err.println();
}
lo2 = cornerPosition.x;
la2 = cornerPosition.y;
} catch (Exception e) {

View file

@ -82,6 +82,9 @@ public class GridCoverageLookup {
idToCoverage.put(coverage.getId(), coverage);
}
} catch (Exception e) {
// do not rethrow, the lookup is not broken at this point so if the
// problems persist then more exceptions will come from the actual
// lookup methods themselves.
statusHandler.handle(Priority.PROBLEM,
"Error occurred retrieving coverages from server.", e);
}
@ -94,7 +97,7 @@ public class GridCoverageLookup {
.synchronizedMap(new GridCoverageSpatialMap());
}
public GridCoverage getCoverage(int id) {
public GridCoverage getCoverage(int id) throws GridCoverageLookupException {
GridCoverage result = idToCoverage.get(id);
if (result != null) {
return result;
@ -115,8 +118,7 @@ public class GridCoverageLookup {
return result;
}
} catch (Exception e) {
statusHandler
.handle(Priority.PROBLEM,
throw new GridCoverageLookupException(
"Error occurred retrieving GridCoverage information from server.",
e);
}
@ -131,7 +133,8 @@ public class GridCoverageLookup {
* @param ids
* @return
*/
public Map<Integer, GridCoverage> getCoverages(List<Integer> ids) {
public Map<Integer, GridCoverage> getCoverages(List<Integer> ids)
throws GridCoverageLookupException {
RequestConstraint idConstraint = new RequestConstraint(null,
ConstraintType.IN);
Map<Integer, GridCoverage> result = new HashMap<Integer, GridCoverage>(
@ -161,16 +164,15 @@ public class GridCoverageLookup {
result.put(respCov.getId(), respCov);
}
} catch (Exception e) {
statusHandler
.handle(Priority.PROBLEM,
throw new GridCoverageLookupException(
"Error occurred retrieving GridCoverage information from server.",
e);
// this will still return a partial list of any cache hits.
}
return result;
}
public GridCoverage getCoverage(GridCoverage coverage, boolean create) {
public GridCoverage getCoverage(GridCoverage coverage, boolean create)
throws GridCoverageLookupException {
Integer id = coverageToId.get(coverage);
if (id != null) {
return getCoverage(id);
@ -184,10 +186,10 @@ public class GridCoverageLookup {
}
return result;
} catch (Exception e) {
statusHandler.handle(Priority.PROBLEM,
"Error occured checking GridCoverage.", e);
throw new GridCoverageLookupException(
"Error occurred retrieving GridCoverage information from server.",
e);
}
return null;
}
}

View file

@ -0,0 +1,50 @@
/**
* 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.lookup;
/**
* Exception is thrown when GridCoverageLookup cannot execute IServerRequest
* using the RequestRouter. This is a RuntimeException because code that uses
* the GridCoverageLookup cannot reasonably be expected to recover from
* connection failure.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Oct 1, 2012 bsteffen Initial creation
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class GridCoverageLookupException extends RuntimeException {
private static final long serialVersionUID = 1145174965583445888L;
public GridCoverageLookupException(String message, Throwable cause) {
super(message, cause);
}
}