📄 coverageresponse.java
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
* This code is licensed under the GPL 2.0 license, availible at the root
* application directory.
*/
package org.vfny.geoserver.wcs.responses;
import org.geotools.coverage.grid.GeneralGridRange;
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridGeometry2D;
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.factory.Hints;
import org.geotools.geometry.GeneralEnvelope;
import org.geotools.referencing.CRS;
import org.geotools.resources.CRSUtilities;
import org.opengis.coverage.Coverage;
import org.opengis.coverage.grid.Format;
import org.opengis.coverage.grid.GridCoverage;
import org.opengis.parameter.ParameterValueGroup;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.cs.AxisDirection;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.TransformException;
import org.vfny.geoserver.Request;
import org.vfny.geoserver.Response;
import org.vfny.geoserver.ServiceException;
import org.vfny.geoserver.global.CoverageInfo;
import org.vfny.geoserver.global.Data;
import org.vfny.geoserver.global.GeoServer;
import org.vfny.geoserver.global.Service;
import org.vfny.geoserver.util.CoverageUtils;
import org.vfny.geoserver.util.WCSUtils;
import org.vfny.geoserver.wcs.WcsException;
import org.vfny.geoserver.wcs.requests.CoverageRequest;
import java.awt.Rectangle;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.jai.Interpolation;
/**
* DOCUMENT ME!
*
* @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
* modification)
* @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
* modification)
*/
public class CoverageResponse implements Response {
/** Standard logging instance for class */
private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.vfny.geoserver.responses");
private final static Hints LENIENT_HINT = new Hints(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE);
private final static Hints IGNORE_OVERVIEWS = new Hints(Hints.IGNORE_COVERAGE_OVERVIEW,
Boolean.TRUE);
private final static Hints hints = new Hints(new HashMap(5));
static {
// ///////////////////////////////////////////////////////////////////
//
// HINTS
//
// ///////////////////////////////////////////////////////////////////
hints.add(LENIENT_HINT);
hints.add(IGNORE_OVERVIEWS);
}
/**
* Tolerance for NOT drawing a coverage.
*
* If after a scaling a coverage has all dimensions smaller than
* {@link GridCoverageRenderer#MIN_DIM_TOLERANCE} we just do not draw it.
*/
private static final int MIN_DIM_TOLERANCE = 1;
/**
*
*/
CoverageResponseDelegate delegate;
/**
* This is the request provided to the execute( Request ) method.
*
* <p>
* We save it so we can access the handle provided by the user for error
* reporting during the writeTo( OutputStream ) opperation.
* </p>
*
* <p>
* This value will be <code>null</code> until execute is called.
* </p>
*
* @uml.property name="request"
* @uml.associationEnd multiplicity="(0 1)"
*/
private CoverageRequest request;
/**
* Empty constructor
*/
public CoverageResponse() {
request = null;
}
/**
* Returns any extra headers that this service might want to set in the HTTP response object.
* @see org.vfny.geoserver.Response#getResponseHeaders()
*/
public HashMap getResponseHeaders() {
return null;
}
/**
* DOCUMENT ME!
*
* @param gs
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public String getContentType(GeoServer gs) {
return /*delegate.getContentType(gs)*/ "";
}
public String getContentEncoding() {
return delegate.getContentEncoding();
}
public String getContentDisposition() {
return delegate.getContentDisposition();
}
/**
* Jody here with one pass replacement for writeTo.
*
* <p>
* This code is a discussion point, when everyone has had there input we
* will try and set things up properly.
* </p>
*
* <p>
* I am providing a mirror of the existing desing: - execute gathers the
* resultList - sets up the header
* </p>
*
* @param out
* DOCUMENT ME!
*
* @throws WcsException
* DOCUMENT ME!
* @throws IOException
* DOCUMENT ME!
* @throws IllegalStateException
* DOCUMENT ME!
*/
public void writeTo(OutputStream out) throws ServiceException, IOException {
if ((request == null) || (delegate == null)) {
throw new IllegalStateException("execute has not been called prior to writeTo");
}
delegate.encode(out);
}
/**
* Executes CoverageRequest.
*
* <p>
* Willing to execute a CoverageRequest.
* </p>
*
* @param req
* DOCUMENT ME!
*
* @throws WcsException
* DOCUMENT ME!
*/
public void execute(Request req) throws WcsException {
execute((CoverageRequest) req);
}
public void execute(CoverageRequest request) throws WcsException {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest(new StringBuffer("execute CoverageRequest response. Called request is: ").append(
request).toString());
}
this.request = request;
final String outputFormat = request.getOutputFormat();
try {
delegate = CoverageResponseDelegateFactory.encoderFor(outputFormat);
} catch (NoSuchElementException ex) {
WcsException newEx = new WcsException(new StringBuffer("output format: ").append(
outputFormat).append(" not ")
.append("supported by geoserver for this Coverage")
.toString(), ex);
throw newEx;
}
final Data catalog = request.getWCS().getData();
CoverageInfo meta = null;
GridCoverage coverage = null;
try {
meta = catalog.getCoverageInfo(request.getCoverage());
if (!meta.getSupportedFormats().contains(outputFormat.toUpperCase())) {
WcsException newEx = new WcsException(new StringBuffer("output format: ").append(
outputFormat).append(" not ")
.append("supported by geoserver for this Coverage")
.toString());
throw newEx;
}
final Format format = meta.getFormatInfo().getFormat();
final AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) meta
.createReader(hints);
// /////////////////////////////////////////////////////////
//
// Setting coverage reading params.
//
// /////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -