Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WCS DescribeCoverage #66

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions lib/GeoExt.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
"GeoExt/data/WFSCapabilitiesReader.js",
"GeoExt/data/WFSCapabilitiesStore.js",
"GeoExt/data/WMSDescribeLayerReader.js",
"GeoExt/data/WCSCapabilitiesReader.js",
"GeoExt/data/WCSCapabilitiesStore.js",
"GeoExt/data/WCSDescribeCoverageReader.js",
"GeoExt/data/WCSDescribeCoverageStore.js",
"GeoExt/data/WMSDescribeLayerStore.js",
"GeoExt/data/WMCReader.js",
"GeoExt/data/CSWRecordsReader.js",
Expand Down
121 changes: 121 additions & 0 deletions lib/GeoExt/data/WCSCapabilitiesReader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* Copyright (c) 2008-2011 The Open Source Geospatial Foundation
*
* Published under the BSD license.
* See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
* of the license.
*/

/**
* @require OpenLayers/Format/WCSCapabilities.js
* @require OpenLayers/Format/WCSCapabilities/v1_0_0.js
* @require OpenLayers/Format/WCSCapabilities/v1_1_0.js
*/

/** api: (define)
* module = GeoExt.data
* class = WCSSCapabilitiesReader
* base_link = `Ext.data.DataReader <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DataReader>`_
*/
Ext.namespace("GeoExt.data");

/** api: constructor
* .. class:: WCSCapabilitiesReader(meta, recordType)
*
* :param meta: ``Object`` Reader configuration from which:
* ``fields`` is a list of fields to be extracted from the WCS GetCapabilities request.
* :param recordType: ``Array | Ext.data.Record`` An array of field
* configuration objects or a record object. Default is
* :class:`GeoExt.data.LayerRecord`.
*
* Data reader class to create an array of
* :class:`Ext.data.Record` objects from a WCS GetCapabilities
* response.
*/
GeoExt.data.WCSCapabilitiesReader = function(meta, recordType) {
meta = meta || {};
if(!meta.format) {
meta.format = new OpenLayers.Format.WCSCapabilities();
}
// Create some default items if recordType is not specified
if(!(typeof recordType === "function")) {
fields = recordType || meta.fields || [
{name: "title", type: "string"},
{name: "abstract", type: "string"}
];

// Make sure we always have an name attribute;
// this will be needed by readRecords.
fields.push({name: "name", type: "string", mapping: "identifier"});
recordType = Ext.data.Record.create(fields);
}

GeoExt.data.WCSCapabilitiesReader.superclass.constructor.call(
this, meta, recordType
);
};

Ext.extend(GeoExt.data.WCSCapabilitiesReader, Ext.data.DataReader, {

/** private: method[read]
* :param request: ``Object`` The XHR object which contains the parsed XML
* document.
* :return: ``Object`` A data block which is used by an ``Ext.data.Store``
* as a cache of ``Ext.data.Record`` objects.
*/
read: function(request) {
var data = request.responseXML;
if(!data || !data.documentElement) {
data = request.responseText;
}
return this.readRecords(data);
},

/** private: method[readRecords]
* :param data: ``DOMElement | String | Object`` A document element or XHR
* response string. As an alternative to fetching capabilities data
* from a remote source, an object representing the capabilities can
* be provided given that the structure mirrors that returned from the
* capabilities parser.
* :return: ``Object`` A data block which is used by an ``Ext.data.Store``
* as a cache of ``Ext.data.Record`` objects.
*
* Create a data block containing Ext.data.Records from an XML document.
*/
readRecords: function(data) {
if(typeof data === "string" || data.nodeType) {
data = this.meta.format.read(data);
}

var contents = data.contentMetadata;
var fields = this.recordType.prototype.fields;

var coverageSummary, values, field, v;

var records = [];

for(var i=0, lenI=contents.length; i<lenI; i++) {
coverageSummary = contents[i];
var name = coverageSummary.identifier;

if(name) {
values = {};

for(var j=0, lenJ=fields.length; j<lenJ; j++) {
field = fields.items[j];
v = coverageSummary[field.mapping || field.name] ||
field.defaultValue;
v = field.convert(v);
values[field.name] = v;
}

records.push(new this.recordType(values, name));
}
}
return {
totalRecords: records.length,
success: true,
records: records
};
}
});
58 changes: 58 additions & 0 deletions lib/GeoExt/data/WCSCapabilitiesStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2008-2012 The Open Source Geospatial Foundation
*
* Published under the BSD license.
* See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
* of the license.
*/

/**
* @include GeoExt/data/WCSCapabilitiesReader.js
*/

/** api: (define)
* module = GeoExt.data
* class = WCSCapabilitiesStore
* base_link = `Ext.data.Store <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store>`_
*/
Ext.namespace("GeoExt.data");

/** api: constructor
* .. class:: WCSCapabilitiesStore
*
* Small helper class to make creating stores for remote WCS metadata
* easier. The store is pre-configured with a built-in
* ``Ext.data.HttpProxy`` and :class:`GeoExt.data.WCSCapabilitiesReader`.
* The proxy is configured to allow caching and issues requests via GET.
*/

/** api: config[format]
* ``OpenLayers.Format``
* A parser for transforming the XHR response into an array of objects
* representing attributes. Defaults to an ``OpenLayers.Format.WCSCapabilities``
* parser.
*/

/** api: config[fields]
* ``Array | Function``
* Either an Array of field definition objects as passed to
* ``Ext.data.Record.create``, or a record constructor created using
* ``Ext.data.Record.create``. Defaults to ``["name", "type"]``.
*/

GeoExt.data.WCSCapabilitiesStore = function(c) {
c = c || {};
GeoExt.data.WCSCapabilitiesStore.superclass.constructor.call(
this,
Ext.apply(c, {
proxy: c.proxy || (!c.data ?
new Ext.data.HttpProxy({url: c.url, disableCaching: false, method: "GET"}) :
undefined
),
reader: new GeoExt.data.WCSCapabilitiesReader(
c, c.fields
)
})
);
};
Ext.extend(GeoExt.data.WCSCapabilitiesStore, Ext.data.Store);
138 changes: 138 additions & 0 deletions lib/GeoExt/data/WCSDescribeCoverageReader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Copyright (c) 2008-2011 The Open Source Geospatial Foundation
*
* Published under the BSD license.
* See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
* of the license.
*/

/**
* @require OpenLayers/Format/WCSDescribeCoverage.js
* @require OpenLayers/Format/WCSDescribeCoverage/v1_0_0.js
* @require OpenLayers/Format/WCSDescribeCoverage/v1_1_0.js
*/

/** api: (define)
* module = GeoExt.data
* class = WCSDescribeCoverageReader
* base_link = `Ext.data.DataReader <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DataReader>`_
*/
Ext.namespace("GeoExt.data");

/** api: constructor
* .. class:: WCSDescribeCoverageReader(meta, recordType)
*
* :param meta: ``Object`` Reader configuration from which:
* ``fields`` is a list of fields to be extracted from the WCS DescribeCoverage request.
* :param recordType: ``Array | Ext.data.Record`` An array of field
* configuration objects or a record object. Default is
* :class:`GeoExt.data.LayerRecord`.
*
* Data reader class to create an array of
* :class:`Ext.data.Record` objects from a WCS DescribeCoverage
* response.
*/
GeoExt.data.WCSDescribeCoverageReader = function(meta, recordType) {
meta = meta || {};
if(!meta.format) {
meta.format = new OpenLayers.Format.WCSDescribeCoverage();
}
// Create some default items if recordType is not specified
if(!(typeof recordType === "function")) {
fields = recordType || meta.fields || [
{name: "title", type: "string"},
{name: "nativeCRS", type: "string"},
{name: "nativeBoundingBox", mapping: function(data) {
return data.domain.spatialDomain.boundingBoxes[data.nativeCRS];
}},
{name: "supportedCRSs"}, // array
{name: "supportedFormats"}, // array
{name: "gridOffsets", mapping: function(data) {
return data.domain.spatialDomain.gridCRS &&
data.domain.spatialDomain.gridCRS.gridOffsets || undefined;
}}
];

// Make sure we always have an name attribute;
// this will be needed by readRecords.
fields.push({name: "name", type: "string", mapping: "identifier"});
recordType = Ext.data.Record.create(fields);
}

GeoExt.data.WCSDescribeCoverageReader.superclass.constructor.call(
this, meta, recordType
);
};

Ext.extend(GeoExt.data.WCSDescribeCoverageReader, Ext.data.DataReader, {

/** private: method[read]
* :param request: ``Object`` The XHR object which contains the parsed XML
* document.
* :return: ``Object`` A data block which is used by an ``Ext.data.Store``
* as a cache of ``Ext.data.Record`` objects.
*/
read: function(request) {
var data = request.responseXML;
if(!data || !data.documentElement) {
data = request.responseText;
}
return this.readRecords(data);
},

/** private: method[readRecords]
* :param data: ``DOMElement | String | Object`` A document element or XHR
* response string. As an alternative to fetching capabilities data
* from a remote source, an object representing the capabilities can
* be provided given that the structure mirrors that returned from the
* capabilities parser.
* :return: ``Object`` A data block which is used by an ``Ext.data.Store``
* as a cache of ``Ext.data.Record`` objects.
*
* Create a data block containing Ext.data.Records from an XML document.
*/
readRecords: function(data) {
if(typeof data === "string" || data.nodeType) {
data = this.meta.format.read(data);
}

var descriptions = data.coverageDescriptions;
var keys = data.coverageDescriptionKeys;
var fields = this.recordType.prototype.fields;

var values, field, v;

var records = [];

for(var i=0, lenI=keys.length; i<lenI; i++) {
var descr = descriptions[keys[i]];
var name = descr.identifier;

if(name) {
values = {};

for(var j=0, lenJ=fields.length; j<lenJ; j++) {
field = fields.items[j];
// Allow mapping to be a function or a field name
if(typeof field.mapping === 'function') {
v = field.mapping(descr);
}
else {
v = descr[field.mapping || field.name] ||
field.defaultValue;
}

v = field.convert(v);
values[field.name] = v;
}

records.push(new this.recordType(values, name));
}
}
return {
totalRecords: records.length,
success: true,
records: records
};
}
});
58 changes: 58 additions & 0 deletions lib/GeoExt/data/WCSDescribeCoverageStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2008-2012 The Open Source Geospatial Foundation
*
* Published under the BSD license.
* See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
* of the license.
*/

/**
* @include GeoExt/data/WCSDescribeCoverageReader.js
*/

/** api: (define)
* module = GeoExt.data
* class = WCSDescribeCoverageStore
* base_link = `Ext.data.Store <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.Store>`_
*/
Ext.namespace("GeoExt.data");

/** api: constructor
* .. class:: WCSDescribeCoverageStore
*
* Small helper class to make creating stores for remote WCS metadata
* easier. The store is pre-configured with a built-in
* ``Ext.data.HttpProxy`` and :class:`GeoExt.data.WCSDescribeCoverageReader`.
* The proxy is configured to allow caching and issues requests via GET.
*/

/** api: config[format]
* ``OpenLayers.Format``
* A parser for transforming the XHR response into an array of objects
* representing attributes. Defaults to an ``OpenLayers.Format.WCSDescribeCoverage``
* parser.
*/

/** api: config[fields]
* ``Array | Function``
* Either an Array of field definition objects as passed to
* ``Ext.data.Record.create``, or a record constructor created using
* ``Ext.data.Record.create``. Defaults to ``["name", "type"]``.
*/

GeoExt.data.WCSDescribeCoverageStore = function(c) {
c = c || {};
GeoExt.data.WCSDescribeCoverageStore.superclass.constructor.call(
this,
Ext.apply(c, {
proxy: c.proxy || (!c.data ?
new Ext.data.HttpProxy({url: c.url, disableCaching: false, method: "GET"}) :
undefined
),
reader: new GeoExt.data.WCSDescribeCoverageReader(
c, c.fields
)
})
);
};
Ext.extend(GeoExt.data.WCSDescribeCoverageStore, Ext.data.Store);
1 change: 1 addition & 0 deletions lib/GeoExt/data/WFSCapabilitiesReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Ext.extend(GeoExt.data.WFSCapabilitiesReader, Ext.data.DataReader, {
var featureType, values, field, v, parts, layer;
var layerOptions, protocolOptions;

// Will fail with WFS 1.1.0
var protocolDefaults = {
url: data.capability.request.getfeature.href.post
};
Expand Down
Loading