Skip to content

Commit 96bd86e

Browse files
committed
JP2000 RGB download (range subsetting + bands ordering).
1 parent 0010994 commit 96bd86e

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

app/scripts/util.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var getCoverageXML = function(coverageid, options) {
8888
options = options || {};
8989
subsetCRS = options.subsetCRS || "http://www.opengis.net/def/crs/EPSG/0/4326";
9090
var params = [
91-
'<wcs:GetCoverage service="WCS" version="2.0.0" xmlns:wcs="http://www.opengis.net/wcs/2.0" xmlns:wcscrs="http://www.opengis.net/wcs/crs/1.0" xmlns:wcsmask="http://www.opengis.net/wcs/mask/1.0">',
91+
'<wcs:GetCoverage service="WCS" version="2.0.0" xmlns:wcs="http://www.opengis.net/wcs/2.0" xmlns:wcscrs="http://www.opengis.net/wcs/crs/1.0" xmlns:wcsmask="http://www.opengis.net/wcs/mask/1.0" xmlns:wcsrsub="http://www.opengis.net/wcs/range-subsetting/1.0">',
9292
'<wcs:CoverageId>' + coverageid + '</wcs:CoverageId>',
9393
], extension = [];
9494

@@ -98,6 +98,14 @@ var getCoverageXML = function(coverageid, options) {
9898
options.subsetX = [options.bbox[0], options.bbox[2]];
9999
options.subsetY = [options.bbox[1], options.bbox[3]];
100100
}
101+
if (options.rangeSubset) {
102+
params.push('<wcs:Extension><wcsrsub:RangeSubset>');
103+
for (var i = 0; i < options.rangeSubset.length; i++) {
104+
params.push('<wcsrsub:RangeItem><wcsrsub:RangeComponent>'+
105+
options.rangeSubset[i]+'</wcsrsub:RangeComponent></wcsrsub:RangeItem>');
106+
}
107+
params.push('</wcsrsub:RangeSubset></wcs:Extension>');
108+
}
101109
if (options.subsetX) {
102110
params.push('<wcs:DimensionTrim><wcs:Dimension>x</wcs:Dimension>' +
103111
"<wcs:TrimLow>" + options.subsetX[0] + "</wcs:TrimLow>" +

app/scripts/views/DownloadView.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,7 @@
232232
*/
233233

234234
// Raise an alert in case of non-native output-CRS applied for referenceable data-sets.
235-
236235
var cbx_list = this.$("#download-list").find('input[type="checkbox"]') ;
237-
238236
if (options.outputCRS) {
239237
var refds_count = 0;
240238
cbx_list.each(_.bind(function(index) {
@@ -250,10 +248,49 @@
250248
}
251249
}
252250

251+
// raise an alert in case of JP2000 requests
252+
if (options.format == 'image/jp2')
253+
{
254+
window.alert("JP2000 download is limited to 8bit Grayscale or RGB imagery. The number of bands is therefore "+
255+
"reduced to 1 or 3. 12 or 16bits output is not supported. \nThe current draft of the WCS JP2000 encoding specification "+
256+
"does not define a way how to pass any encoding parameters (e.g., quality factor). The imagery is encoded using the "+
257+
"server default values.");
258+
}
259+
260+
// JP2000 RGB range subsetting
261+
var _jp2_rgb = function(rtlist){
262+
if (!rtlist.length) { return rtlist; }
263+
if (rtlist.length < 3) { return [rtlist[0]]; }
264+
265+
//Try to interpret the range-type.
266+
var idx_red = rtlist.indexOf('Red');
267+
var idx_green = rtlist.indexOf('Green');
268+
var idx_blue = rtlist.indexOf('Blue');
269+
var idx_nir = rtlist.indexOf('NIR');
270+
271+
if ((idx_blue >= 0) && (idx_green >= 0) && (idx_red >= 0)) {
272+
return ['Red', 'Green', 'Blue'] ;
273+
}
274+
275+
if ((idx_nir >= 0) && (idx_green >= 0) && (idx_red >= 0)) {
276+
return ['NIR', 'Red', 'Green'];
277+
}
278+
279+
// Fallback to the firts 3 bands.
280+
return [rtlist[0],rtlist[1],rtlist[2]];
281+
}
282+
283+
options.format = this.$("#select-output-format").val();
284+
253285
cbx_list.each(_.bind(function(index) {
254286
if (cbx_list[index].checked){
255287
var model = this.coverages.models[index];
256288
options.coverageSubtype = model.get('coverageSubtype');
289+
if (options.format == 'image/jp2')
290+
options.rangeSubset = _jp2_rgb(_.map(model.get('rangeType'), function(rt) { return rt.name } ));
291+
else {
292+
options.rangeSubset = null ;
293+
}
257294
var xml = getCoverageXML(model.get('coverageId'), options);
258295
var owsUrl = model.get('url').split('?')[0];
259296
var $form = $(CoverageDownloadPostTmpl({url: owsUrl, xml: xml}));

0 commit comments

Comments
 (0)