📄 coverageresponse.java
字号:
final ParameterValueGroup params = reader.getFormat().getReadParameters();
final GridCoverage2D finalCoverage = getFinalCoverage(request, meta, reader,
CoverageUtils.getParametersKVP(params));
delegate.prepare(outputFormat, finalCoverage);
} catch (IOException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (NoSuchElementException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (IllegalArgumentException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (SecurityException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (WcsException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (FactoryException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (IndexOutOfBoundsException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
} catch (TransformException e) {
final WcsException newEx = new WcsException(e, "problem with CoverageResults",
request.getHandle());
throw newEx;
}
}
/**
* Release locks if we are into that sort of thing.
*
* @see org.vfny.geoserver.responses.Response#abort()
*/
public void abort(Service gs) {
if (request == null) {
return; // request was not attempted
}
Data catalog = gs.getData();
}
/**
* GetCroppedCoverage
*
* @param request CoverageRequest
* @param meta CoverageInfo
* @param parameters
* @param coverage GridCoverage
* @return GridCoverage2D
* @throws WcsException
* @throws IOException
* @throws IndexOutOfBoundsException
* @throws FactoryException
* @throws TransformException
*/
private static GridCoverage2D getFinalCoverage(CoverageRequest request, CoverageInfo meta,
AbstractGridCoverage2DReader coverageReader /*GridCoverage coverage*/, Map parameters)
throws WcsException, IOException, IndexOutOfBoundsException, FactoryException,
TransformException {
// This is the final Response CRS
final String responseCRS = request.getResponseCRS();
// - first check if the responseCRS is present on the Coverage
// ResponseCRSs list
if (!meta.getResponseCRSs().contains(responseCRS)) {
throw new WcsException("This Coverage does not support the requested Response-CRS.");
}
// - then create the Coordinate Reference System
final CoordinateReferenceSystem targetCRS = CRS.decode(responseCRS);
// This is the CRS of the requested Envelope
final String requestCRS = request.getCRS();
// - first check if the requestCRS is present on the Coverage
// RequestCRSs list
if (!meta.getResponseCRSs().contains(requestCRS)) {
throw new WcsException("This Coverage does not support the requested CRS.");
}
// - then create the Coordinate Reference System
final CoordinateReferenceSystem sourceCRS = CRS.decode(requestCRS);
// This is the CRS of the Coverage Envelope
final CoordinateReferenceSystem cvCRS = ((GeneralEnvelope) coverageReader
.getOriginalEnvelope()).getCoordinateReferenceSystem();
final MathTransform GCCRSTodeviceCRSTransformdeviceCRSToGCCRSTransform = CRS
.findMathTransform(cvCRS, sourceCRS, true);
final MathTransform GCCRSTodeviceCRSTransform = CRS.findMathTransform(cvCRS, targetCRS, true);
final MathTransform deviceCRSToGCCRSTransform = GCCRSTodeviceCRSTransformdeviceCRSToGCCRSTransform
.inverse();
com.vividsolutions.jts.geom.Envelope envelope = request.getEnvelope();
GeneralEnvelope destinationEnvelope;
final boolean lonFirst = sourceCRS.getCoordinateSystem().getAxis(0).getDirection().absolute()
.equals(AxisDirection.EAST);
// the envelope we are provided with is lon,lat always
if (!lonFirst) {
destinationEnvelope = new GeneralEnvelope(new double[] {
envelope.getMinY(), envelope.getMinX()
}, new double[] { envelope.getMaxY(), envelope.getMaxX() });
} else {
destinationEnvelope = new GeneralEnvelope(new double[] {
envelope.getMinX(), envelope.getMinY()
}, new double[] { envelope.getMaxX(), envelope.getMaxY() });
}
destinationEnvelope.setCoordinateReferenceSystem(sourceCRS);
// this is the destination envelope in the coverage crs
final GeneralEnvelope destinationEnvelopeInSourceCRS = (!deviceCRSToGCCRSTransform
.isIdentity()) ? CRSUtilities.transform(deviceCRSToGCCRSTransform, destinationEnvelope)
: new GeneralEnvelope(destinationEnvelope);
destinationEnvelopeInSourceCRS.setCoordinateReferenceSystem(cvCRS);
/**
* Reading Coverage on Requested Envelope
*/
Rectangle destinationSize = null;
if ((request.getGridLow() != null) && (request.getGridHigh() != null)) {
final int[] lowers = new int[] {
request.getGridLow()[0].intValue(), request.getGridLow()[1].intValue()
};
final int[] highers = new int[] {
request.getGridHigh()[0].intValue(), request.getGridHigh()[1].intValue()
};
destinationSize = new Rectangle(lowers[0], lowers[1], highers[0], highers[1]);
} else {
/*destinationSize = coverageReader.getOriginalGridRange().toRectangle();*/
throw new WcsException("Neither Grid Size nor Grid Resolution have been specified.");
}
/**
* Checking for supported Interpolation Methods
*/
Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
final String interpolationType = request.getInterpolation();
if (interpolationType != null) {
boolean interpolationSupported = false;
Iterator internal = meta.getInterpolationMethods().iterator();
while (internal.hasNext()) {
if (interpolationType.equalsIgnoreCase((String) internal.next())) {
interpolationSupported = true;
}
}
if (!interpolationSupported) {
throw new WcsException(
"The requested Interpolation method is not supported by this Coverage.");
} else {
if (interpolationType.equalsIgnoreCase("bilinear")) {
interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
} else if (interpolationType.equalsIgnoreCase("bicubic")) {
interpolation = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
}
}
}
// /////////////////////////////////////////////////////////
//
// Reading the coverage
//
// /////////////////////////////////////////////////////////
parameters.put(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
new GridGeometry2D(new GeneralGridRange(destinationSize), destinationEnvelopeInSourceCRS));
final GridCoverage coverage = coverageReader.read(CoverageUtils.getParameters(
coverageReader.getFormat().getReadParameters(), parameters, true));
if ((coverage == null) || !(coverage instanceof GridCoverage2D)) {
throw new IOException("The requested coverage could not be found.");
}
/**
* Band Select
*/
Coverage bandSelectedCoverage = null;
try {
bandSelectedCoverage = WCSUtils.bandSelect(request.getParameters(), coverage);
} catch (WcsException e) {
throw new WcsException(e.getLocalizedMessage());
}
/**
* Crop
*/
final GridCoverage2D croppedGridCoverage = WCSUtils.crop(bandSelectedCoverage,
(GeneralEnvelope) coverage.getEnvelope(), cvCRS, destinationEnvelopeInSourceCRS,
Boolean.TRUE);
/**
* Scale/Resampling (if necessary)
*/
GridCoverage2D subCoverage = croppedGridCoverage;
final GeneralGridRange newGridrange = new GeneralGridRange(destinationSize);
/*if (!newGridrange.equals(croppedGridCoverage.getGridGeometry()
.getGridRange())) {*/
subCoverage = WCSUtils.scale(croppedGridCoverage, newGridrange, croppedGridCoverage, cvCRS,
destinationEnvelopeInSourceCRS);
//}
/**
* Reproject
*/
subCoverage = WCSUtils.reproject(subCoverage, sourceCRS, targetCRS, interpolation);
return subCoverage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -