@Override public void write(Object value, OutputStream output, Operation operation) throws IOException, ServiceException { GridCoverage[] coverages = (GridCoverage[]) value; // grab the delegate for coverage encoding GetCoverageType request = (GetCoverageType) operation.getParameters()[0]; String outputFormat = request.getOutput().getFormat().getValue(); CoverageResponseDelegate delegate = getResponseDelegate(outputFormat); // grab the coverage info for Coverages document encoding final GridCoverage2D coverage = (GridCoverage2D) coverages[0]; // ImageIOUtilities.visualize(coverage.getRenderedImage()); // write the coverage try { delegate.encode(coverage, outputFormat, Collections.EMPTY_MAP, output); output.flush(); } finally { // if(output != null) output.close(); } } }
@Override public String getMimeType(Object value, Operation operation) throws ServiceException { if (!(operation.getParameters()[0] instanceof GetCoverageType)) throw new WcsException( "Cannot handle object of type: " + operation.getParameters()[0].getClass()); GetCoverageType getCoverage = (GetCoverageType) operation.getParameters()[0]; String outputFormat = getCoverage.getOutput().getFormat().getValue(); CoverageResponseDelegate delegate = getResponseDelegate(outputFormat); return delegate.getMimeType(outputFormat); }
@Override public boolean canHandle(Operation operation) { if (!(operation.getParameters()[0] instanceof GetCoverageType)) return false; GetCoverageType getCoverage = (GetCoverageType) operation.getParameters()[0]; String outputFormat = getCoverage.getOutput().getFormat().getValue(); CoverageResponseDelegate delegate = getResponseDelegate(outputFormat); return delegate.canProduce(outputFormat); }
/** * Checks that the elements of the Output part of the request do make sense by comparing them to * the coverage metadata * * @param info * @param rangeSubset */ private void checkOutput(CoverageInfo meta, OutputType output) { if (output == null) return; // check output format String format = output.getFormat().getValue(); String declaredFormat = getDeclaredFormat(meta.getSupportedFormats(), format); if (declaredFormat == null) throw new WcsException( "format " + format + " is not supported for this coverage", InvalidParameterValue, "format"); // check requested CRS // if (output.getCrs() != null) { // String requestedCRS = output.getCrs().getValue(); // if (getRequestResponseCRS(meta.getRequestCRSs(), requestedCRS) == null && // getRequestResponseCRS(meta.getResponseCRSs(), requestedCRS) == null) // throw new WcsException("CRS " + requestedCRS + " is not supported for this coverage", // InvalidParameterValue, "CRS"); // } else { // // The requested CRS was not specified ... what to do ??? // } }
@Override public String getAttachmentFileName(Object value, Operation operation) { if (!(operation.getParameters()[0] instanceof GetCoverageType)) throw new WcsException( "Cannot handle object of type: " + operation.getParameters()[0].getClass()); GetCoverageType getCoverage = (GetCoverageType) operation.getParameters()[0]; String outputFormat = getCoverage.getOutput().getFormat().getValue(); CoverageResponseDelegate delegate = getResponseDelegate(outputFormat); return getCoverage.getSourceCoverage() + "." + delegate.getFileExtension(outputFormat); }
public void testBasic() throws Exception { Map<String, Object> raw = baseMap(); final String layerId = getLayerId(TASMANIA_BM); raw.put("SourceCoverage", layerId); raw.put("version", "1.0.0"); raw.put("format", "image/tiff"); raw.put("BBOX", "-45,146,-42,147"); raw.put("CRS", "EPSG:4326"); raw.put("width", "150"); raw.put("height", "150"); GetCoverageType getCoverage = (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw); assertEquals(layerId, getCoverage.getSourceCoverage()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("EPSG:4326", getCoverage.getOutput().getCrs().getValue()); }
@Test public void testBasic() throws Exception { Map<String, Object> raw = baseMap(); final String layerId = getLayerId(TASMANIA_BM); raw.put("SourceCoverage", layerId); raw.put("version", "1.0.0"); raw.put("format", "image/tiff"); raw.put("BBOX", "-45,146,-42,147"); raw.put("CRS", "EPSG:4326"); raw.put("width", "150"); raw.put("height", "150"); GetCoverageType getCoverage = (GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw); assertEquals(layerId, getCoverage.getSourceCoverage()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("EPSG:4326", getCoverage.getOutput().getCrs().getValue()); }
assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("nearest neighbor", getCoverage.getInterpolationMethod().toString()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("bilinear", getCoverage.getInterpolationMethod().toString()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("nearest neighbor", getCoverage.getInterpolationMethod().toString()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue());
(GetCoverageType) reader.read(reader.createRequest(), parseKvp(raw), raw); assertEquals(layerId, getCoverage.getSourceCoverage()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("nearest neighbor", getCoverage.getInterpolationMethod().toString()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("bilinear", getCoverage.getInterpolationMethod().toString()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("nearest neighbor", getCoverage.getInterpolationMethod().toString()); assertEquals("image/tiff", getCoverage.getOutput().getFormat().getValue()); assertEquals("bicubic", getCoverage.getInterpolationMethod().toString());