Skip to content

Commit

Permalink
[GEOS-8564]: Add support for writing parameters to WPS-Download
Browse files Browse the repository at this point in the history
  • Loading branch information
dromagnoli committed Feb 6, 2018
1 parent 53ae0c3 commit a7052cd
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 13 deletions.
48 changes: 47 additions & 1 deletion doc/en/user/source/community/wps-download/rawDownload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The parameters to set are
* ``targetSizeX`` : size X in pixels of the output (optional, applies for raster input only)
* ``targetSizeY`` : size Y in pixels of the output (optional, applies for raster input only)
* ``selectedBands`` : a set of the band indices of the original raster that will be used for producing the final result (optional, applies for raster input only)
* ``writeParameters`` : a set of writing parameters (optional, applies for raster input only). See :ref:`writing_params` below section for more details on writing parameters defintion.

The ``targetCRS`` and ``RoiCRS`` parameters are using EPSG code terminology, so, valid parameters are literals like ``EPSG:4326`` (if we are referring to a the Geogaphic WGS84 CRS), ``EPSG:3857`` (for WGS84 Web Mercator CRS), etc.

Expand Down Expand Up @@ -151,7 +152,7 @@ A ``filter`` parameter is a definition of a vector filter operation:

* as ``TEXT``, in various textual formats/representations
* as ``REFERENCE``, which is the textual result of an HTTP GET/POST request to a specific url
* as a ``SUPPROCESS`` result: the format produced as result of the process execution must be a compatible geometry textual format.
* as a ``SUBPROCESS`` result: the format produced as result of the process execution must be a compatible geometry textual format.

Compatible text formats for filter definitions are:

Expand Down Expand Up @@ -378,3 +379,48 @@ This time, when issued (and process has finished on the server), the GET request
</wps:Output>
</wps:ProcessOutputs>
</wps:ExecuteResponse>
.. _writing_params:

Writing parameters
++++++++++++++++++

The ``writeParameters`` input element of a process execution allows to specify parameters to be applied by the ``outputFormat`` encoder when producing the output file.
Writing parameters are listed as multiple ``<dwn:Parameter key="writingParameterName">value</dwn:Parameter>`` within a ``<dwn:Parameters>`` parent element.
See the below xml containing full syntax of a valid example for TIFF output format:

.. code-block:: xml
<wps:Input>
<ows:Identifier>writeParameters</ows:Identifier>
<wps:Data>
<wps:ComplexData xmlns:dwn="http://geoserver.org/wps/download">
<dwn:Parameters>
<dwn:Parameter key="tilewidth">128</dwn:Parameter>
<dwn:Parameter key="tileheight">128</dwn:Parameter>
<dwn:Parameter key="compression">JPEG</dwn:Parameter>
<dwn:Parameter key="quality">0.75</dwn:Parameter>
</dwn:Parameters>
</wps:ComplexData>
</wps:Data>
</wps:Input>
GeoTIFF/TIFF supported writing parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The supported writing parameters are:

* ``tilewidth`` : Width of internal tiles, in pixels
* ``tileheight`` : Height of internal tiles, in pixels
* ``compression`` : Compression type used to store internal tiles. Supported values are:

* ``CCITT RLE`` (Lossless) (Huffman)
* ``LZW`` (Lossless)
* ``JPEG`` (Lossy)
* ``ZLib`` (Lossless)
* ``PackBits`` (Lossless)
* ``Deflate`` (Lossless)


* ``quality`` : Compression quality for lossy compression (JPEG). Value is in the range [0 : 1] where 0 is for worst quality/higher compression and 1 is for best quality/lower compression

Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public DownloadProcess(GeoServer geoServer, DownloadEstimatorProcess estimator,
* @param targetSizeX the size of the target image along the X axis
* @param targetSizeY the size of the target image along the Y axis
* @param bandIndices the band indices selected for output, in case of raster input
* @param writeParameters optional writing parameters
* @param progressListener the progress listener
* @return the file
* @throws ProcessException the process exception
Expand All @@ -118,6 +119,7 @@ public File execute(
@DescribeParameter(name = "targetSizeX", min = 0, minValue = 1, description = "X Size of the Target Image (applies to raster data only)") Integer targetSizeX,
@DescribeParameter(name = "targetSizeY", min = 0, minValue = 1, description = "Y Size of the Target Image (applies to raster data only)") Integer targetSizeY,
@DescribeParameter(name = "selectedBands", description = "Band Selection Indices", min = 0) int[] bandIndices,
@DescribeParameter(name = "writeParameters", description = "Optional writing parameters", min = 0) Parameters writeParameters,
final ProgressListener progressListener) throws ProcessException {

try {
Expand Down Expand Up @@ -226,7 +228,7 @@ public File execute(
// convert/reproject/crop if needed the coverage
internalOutput = new RasterDownload(limits, resourceManager, context).execute(
mimeType, progressListener, cInfo, roi, targetCRS, clip, filter,
interpolation, targetSizeX, targetSizeY, bandIndices);
interpolation, targetSizeX, targetSizeY, bandIndices, writeParameters);
} else {

// wrong type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.wps.gs.download;


import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* (c) 2018 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.wps.gs.download;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.builder.ToStringBuilder;

@XmlRootElement(name="Parameters")
public class Parameters {

public static final String NAMESPACE = "http://geoserver.org/wps/download";

List<Parameter> parameters = new ArrayList<>();

@XmlElement(name = "Parameter")
public List<Parameter> getParameters() {
return parameters;
}

public void setParameters(List<Parameter> parameters) {
this.parameters = parameters;
}

public Map<String, String> getParametersMap() {
Map<String, String> result = new HashMap<>();
for (Parameter parameter : parameters) {
result.put(parameter.key, parameter.value);
}

return result;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -107,17 +108,17 @@ public RasterDownload(DownloadServiceConfiguration limits, WPSResourceManager re
* @param roi input ROI object
* @param targetCRS CRS of the file to write
* @param clip indicates if the clipping geometry must be exactly that of the ROI or simply its envelope
* @param filter the {@link Filter} to load the data
* @param interpolation interpolation method to use when reprojecting / scaling
* @param targetSizeX the size of the target image along the X axis
* @param targetSizeY the size of the target image along the Y axis
* @param bandIndices the indices of the bands used for the final result
* @param filter the {@link Filter} to load the data
*
* @param writeParams optional writing params
*/
public Resource execute(String mimeType, final ProgressListener progressListener,
CoverageInfo coverageInfo, Geometry roi, CoordinateReferenceSystem targetCRS,
boolean clip, Filter filter, Interpolation interpolation, Integer targetSizeX,
Integer targetSizeY, int[] bandIndices) throws Exception {
Integer targetSizeY, int[] bandIndices, Parameters writeParams) throws Exception {

GridCoverage2D scaledGridCoverage = null, clippedGridCoverage = null, reprojectedGridCoverage = null, bandFilteredCoverage = null, originalGridCoverage = null;
try {
Expand Down Expand Up @@ -322,7 +323,7 @@ public Resource execute(String mimeType, final ProgressListener progressListener
//
// STEP 4 - Writing
//
return writeRaster(mimeType, coverageInfo, scaledGridCoverage);
return writeRaster(mimeType, coverageInfo, scaledGridCoverage, writeParams);
} finally {
if (originalGridCoverage != null) {
resourceManager.addResource(new GridCoverageResource(originalGridCoverage));
Expand All @@ -345,10 +346,12 @@ public Resource execute(String mimeType, final ProgressListener progressListener
* @param mimeType result mimetype
* @param coverageInfo resource associated to the input coverage
* @param gridCoverage gridcoverage to write
* @param writeParams writing parameters
* @return a {@link File} that points to the GridCoverage we wrote.
*
*/
private Resource writeRaster(String mimeType, CoverageInfo coverageInfo, GridCoverage2D gridCoverage)
private Resource writeRaster(String mimeType, CoverageInfo coverageInfo,
GridCoverage2D gridCoverage, Parameters writeParams)
throws Exception {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Writing raster");
Expand Down Expand Up @@ -406,7 +409,8 @@ protected void raiseError(long pSizeMax, long pCount) throws IOException {
os = fileImageOutputStreamExtImpl;
}
// Encoding the GridCoverage
complexPPIO.encode(gridCoverage, new OutputStreamAdapter(os));
Map encodingParams = writeParams != null ? writeParams.getParametersMap() : null;
complexPPIO.encode(gridCoverage, encodingParams, new OutputStreamAdapter(os));
os.flush();
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<constructor-arg index="1" ref="entityResolverProvider"/>
</bean>

<bean id="downloadParametersPPIO" class="org.geoserver.wps.gs.download.JaxbPPIO">
<constructor-arg index="0" value="org.geoserver.wps.gs.download.Parameters"/>
<constructor-arg index="1" ref="entityResolverProvider"/>
</bean>

<bean id="downloadFormatPPIO" class="org.geoserver.wps.gs.download.JaxbPPIO">
<constructor-arg index="0" value="org.geoserver.wps.gs.download.Format"/>
<constructor-arg index="1" ref="entityResolverProvider"/>
Expand Down

0 comments on commit a7052cd

Please sign in to comment.