Issue #189 changes from code review comments for gridcoverage.
Former-commit-id: cfac5882643a0bde47c6f81623dd80ec41604a82
This commit is contained in:
parent
8682b30383
commit
7f99750ba5
6 changed files with 135 additions and 37 deletions
|
@ -106,13 +106,12 @@ public class GribSpatialCache {
|
||||||
private Map<Integer, Set<String>> gridNameMap;
|
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;
|
private Map<String, GridCoverage> subGridCoverageMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map containing the subGrid based on a model name and the base coverage
|
* Map containing the subGrid based on a the subGridKey
|
||||||
* name
|
|
||||||
*/
|
*/
|
||||||
private Map<String, SubGrid> definedSubGridMap;
|
private Map<String, SubGrid> definedSubGridMap;
|
||||||
|
|
||||||
|
@ -172,6 +171,16 @@ public class GribSpatialCache {
|
||||||
return rval;
|
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) {
|
public List<GridCoverage> getGridsForModel(String modelName) {
|
||||||
List<GridCoverage> rval = new ArrayList<GridCoverage>();
|
List<GridCoverage> rval = new ArrayList<GridCoverage>();
|
||||||
if (modelName != null) {
|
if (modelName != null) {
|
||||||
|
@ -216,6 +225,18 @@ public class GribSpatialCache {
|
||||||
return coverage;
|
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) {
|
public Set<String> getGribCoverageNames(GridCoverage coverage) {
|
||||||
Set<String> rval = gridNameMap.get(coverage.getId());
|
Set<String> rval = gridNameMap.get(coverage.getId());
|
||||||
if (rval == null) {
|
if (rval == null) {
|
||||||
|
@ -228,6 +249,15 @@ public class GribSpatialCache {
|
||||||
return rval;
|
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) {
|
public SubGrid getSubGrid(String modelName, GridCoverage coverage) {
|
||||||
SubGrid subGrid = definedSubGridMap
|
SubGrid subGrid = definedSubGridMap
|
||||||
.get(subGridKey(modelName, coverage));
|
.get(subGridKey(modelName, coverage));
|
||||||
|
@ -240,6 +270,15 @@ public class GribSpatialCache {
|
||||||
return subGrid;
|
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,
|
public GridCoverage getSubGridCoverage(String modelName,
|
||||||
GridCoverage coverage) {
|
GridCoverage coverage) {
|
||||||
GridCoverage subGrid = subGridCoverageMap.get(subGridKey(modelName,
|
GridCoverage subGrid = subGridCoverageMap.get(subGridKey(modelName,
|
||||||
|
@ -253,6 +292,14 @@ public class GribSpatialCache {
|
||||||
return subGrid;
|
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) {
|
private boolean loadSubGrid(String modelName, GridCoverage coverage) {
|
||||||
SubGridDef subGridDef = subGridDefMap.get(modelName);
|
SubGridDef subGridDef = subGridDefMap.get(modelName);
|
||||||
if (subGridDef != null) {
|
if (subGridDef != null) {
|
||||||
|
|
|
@ -17,12 +17,7 @@
|
||||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
* further licensing information.
|
* further licensing information.
|
||||||
**/
|
**/
|
||||||
CREATE INDEX "gridCoverageType_idx"
|
CREATE INDEX "gridCoverageTypeNxNy_idx"
|
||||||
ON gridcoverage
|
ON gridcoverage
|
||||||
USING btree
|
USING btree
|
||||||
(dtype);
|
(dtype, nx, ny);
|
||||||
|
|
||||||
CREATE INDEX "gridCoverageNxNy_idx"
|
|
||||||
ON gridcoverage
|
|
||||||
USING btree
|
|
||||||
(nx, ny);
|
|
|
@ -580,7 +580,6 @@ public abstract class GridCoverage extends PersistableDataObject implements
|
||||||
protected void generateGeometry() throws GridCoverageException {
|
protected void generateGeometry() throws GridCoverageException {
|
||||||
if ("degree".equals(spacingUnit)) {
|
if ("degree".equals(spacingUnit)) {
|
||||||
// lower left is cell center, we want cell corners.
|
// lower left is cell center, we want cell corners.
|
||||||
// special case in data delivery
|
|
||||||
double minLat = getLowerLeftLat() - dy / 2;
|
double minLat = getLowerLeftLat() - dy / 2;
|
||||||
double maxLat = minLat + dy * ny;
|
double maxLat = minLat + dy * ny;
|
||||||
double minLon = getLowerLeftLon() - dx / 2;
|
double minLon = getLowerLeftLon() - dx / 2;
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class MercatorGridCoverage extends GridCoverage {
|
||||||
@Override
|
@Override
|
||||||
public void initialize() throws GridCoverageException {
|
public void initialize() throws GridCoverageException {
|
||||||
double meridian = 0;
|
double meridian = 0;
|
||||||
if (la2 == null || lo2 == null) {
|
if (true || la2 == null || lo2 == null) {
|
||||||
initializeSecondCorner();
|
initializeSecondCorner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,28 +177,28 @@ public class MercatorGridCoverage extends GridCoverage {
|
||||||
fromLatLon.transform(new DirectPosition2D(lo1, la1), firstPosition);
|
fromLatLon.transform(new DirectPosition2D(lo1, la1), firstPosition);
|
||||||
|
|
||||||
// move firstPosition from cell center to cell corner
|
// move firstPosition from cell center to cell corner
|
||||||
firstPosition.x -= 0.5 * dx;
|
firstPosition.x -= 0.5 * dx * 1000;
|
||||||
firstPosition.y -= 0.5 * dy;
|
firstPosition.y -= 0.5 * dy * 1000;
|
||||||
|
|
||||||
// Determine the other corner point using the given dx,dy,nx, and
|
// Determine the other corner point using the given dx,dy,nx, and
|
||||||
// ny in meters
|
// ny in meters
|
||||||
DirectPosition2D position = null;
|
DirectPosition2D position = null;
|
||||||
switch (firstGridPointCorner) {
|
switch (firstGridPointCorner) {
|
||||||
case LowerLeft:
|
case LowerLeft:
|
||||||
position = new DirectPosition2D(firstPosition.x + dx * nx,
|
position = new DirectPosition2D(firstPosition.x + dx * 1000
|
||||||
firstPosition.y + dy * ny);
|
* nx, firstPosition.y + dy * 1000 * ny);
|
||||||
break;
|
break;
|
||||||
case UpperLeft:
|
case UpperLeft:
|
||||||
position = new DirectPosition2D(firstPosition.x + dx * nx,
|
position = new DirectPosition2D(firstPosition.x + dx * 1000
|
||||||
firstPosition.y - dy * ny);
|
* nx, firstPosition.y - dy * 1000 * ny);
|
||||||
break;
|
break;
|
||||||
case LowerRight:
|
case LowerRight:
|
||||||
position = new DirectPosition2D(firstPosition.x - dx * nx,
|
position = new DirectPosition2D(firstPosition.x - dx * 1000
|
||||||
firstPosition.y - dy * ny);
|
* nx, firstPosition.y - dy * 1000 * ny);
|
||||||
break;
|
break;
|
||||||
case UpperRight:
|
case UpperRight:
|
||||||
position = new DirectPosition2D(firstPosition.x - dx * nx,
|
position = new DirectPosition2D(firstPosition.x - dx * 1000
|
||||||
firstPosition.y - dy * ny);
|
* nx, firstPosition.y - dy * 1000 * ny);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new GridCoverageException(
|
throw new GridCoverageException(
|
||||||
|
@ -208,6 +208,11 @@ public class MercatorGridCoverage extends GridCoverage {
|
||||||
// Convert the corner points from meters to lat/lon
|
// Convert the corner points from meters to lat/lon
|
||||||
DirectPosition2D cornerPosition = new DirectPosition2D();
|
DirectPosition2D cornerPosition = new DirectPosition2D();
|
||||||
toLatLon.transform(position, cornerPosition);
|
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;
|
lo2 = cornerPosition.x;
|
||||||
la2 = cornerPosition.y;
|
la2 = cornerPosition.y;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -82,6 +82,9 @@ public class GridCoverageLookup {
|
||||||
idToCoverage.put(coverage.getId(), coverage);
|
idToCoverage.put(coverage.getId(), coverage);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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,
|
statusHandler.handle(Priority.PROBLEM,
|
||||||
"Error occurred retrieving coverages from server.", e);
|
"Error occurred retrieving coverages from server.", e);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +97,7 @@ public class GridCoverageLookup {
|
||||||
.synchronizedMap(new GridCoverageSpatialMap());
|
.synchronizedMap(new GridCoverageSpatialMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridCoverage getCoverage(int id) {
|
public GridCoverage getCoverage(int id) throws GridCoverageLookupException {
|
||||||
GridCoverage result = idToCoverage.get(id);
|
GridCoverage result = idToCoverage.get(id);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -115,10 +118,9 @@ public class GridCoverageLookup {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
statusHandler
|
throw new GridCoverageLookupException(
|
||||||
.handle(Priority.PROBLEM,
|
"Error occurred retrieving GridCoverage information from server.",
|
||||||
"Error occurred retrieving GridCoverage information from server.",
|
e);
|
||||||
e);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,8 @@ public class GridCoverageLookup {
|
||||||
* @param ids
|
* @param ids
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Map<Integer, GridCoverage> getCoverages(List<Integer> ids) {
|
public Map<Integer, GridCoverage> getCoverages(List<Integer> ids)
|
||||||
|
throws GridCoverageLookupException {
|
||||||
RequestConstraint idConstraint = new RequestConstraint(null,
|
RequestConstraint idConstraint = new RequestConstraint(null,
|
||||||
ConstraintType.IN);
|
ConstraintType.IN);
|
||||||
Map<Integer, GridCoverage> result = new HashMap<Integer, GridCoverage>(
|
Map<Integer, GridCoverage> result = new HashMap<Integer, GridCoverage>(
|
||||||
|
@ -161,16 +164,15 @@ public class GridCoverageLookup {
|
||||||
result.put(respCov.getId(), respCov);
|
result.put(respCov.getId(), respCov);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
statusHandler
|
throw new GridCoverageLookupException(
|
||||||
.handle(Priority.PROBLEM,
|
"Error occurred retrieving GridCoverage information from server.",
|
||||||
"Error occurred retrieving GridCoverage information from server.",
|
e);
|
||||||
e);
|
|
||||||
// this will still return a partial list of any cache hits.
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridCoverage getCoverage(GridCoverage coverage, boolean create) {
|
public GridCoverage getCoverage(GridCoverage coverage, boolean create)
|
||||||
|
throws GridCoverageLookupException {
|
||||||
Integer id = coverageToId.get(coverage);
|
Integer id = coverageToId.get(coverage);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
return getCoverage(id);
|
return getCoverage(id);
|
||||||
|
@ -184,10 +186,10 @@ public class GridCoverageLookup {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
statusHandler.handle(Priority.PROBLEM,
|
throw new GridCoverageLookupException(
|
||||||
"Error occured checking GridCoverage.", e);
|
"Error occurred retrieving GridCoverage information from server.",
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue