source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wmc_util.py @ 3747

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wmc_util.py@3747
Revision 3747, 3.1 KB checked in by cbyrom, 13 years ago (diff)

Fix Con Terra integration of web client:
Added new template, conterra_xmlconfig.kid to do the creation of
the xmlConfig data to POST.
Changed conterra_aggregate to contain a form which automatically
POSTs a request with the xmlConfig data, when the template is rendered.
Extended selectedItems to include conterra_aggegrage.kid - so that
the selections page is redrawn following a POST to the conterra client.
Also updated the wms_util and WMC python scripts to extract the
required data for the new Con Terra input formats.

Line 
1# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
2# This software may be distributed under the terms of the
3# Q Public License, version 1.0 or later.
4# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
5"""
6Utils to aid use of wmc docs - including interfacing these with the con terra client
7and getting associated legend data
8
9@author: Calum Byrom
10"""
11from ows_server.lib.base import *
12from ows_server.lib.ndgInterface import interface
13from ndgUtils.DocumentRetrieve import genericHTTP
14from ndgUtils.ETxmlView import loadET,et2text, nsdumb
15from ows_server.models.WMC import WMC
16from ows_common import exceptions
17import urllib2, urllib
18
19def getConTerraDoc(wmcURLs):
20    """
21    Construct an aggregated XML file and display this as a temporary webpage; this will automatically be
22    POSTED so that the data is sent via POST to the Con Terra mapClient to visualise (as required by this client)
23    @param wmcURLS: An array of URLs pointing to WMC docs to visualise
24    """
25    # firstly, retrieve each WMC doc
26    wmcDocs = []
27    for wmcURL in wmcURLs:
28        wmcDocs.append(WMC(wmcURL))
29   
30    # now create a dictionary of WMS/layer from these docs - to avoid duplicate layers
31    c.wms = {}
32    for wmcDoc in wmcDocs:
33        for layer in wmcDoc.layers:
34            if layer.wmsURL not in c.wms:
35                c.wms[layer.wmsURL] = [layer.name]
36            else:
37                if layer.name not in c.wms[layer.wmsURL]:
38                    c.wms[layer.wmsURL].append(layer.name)
39   
40    # now create the form to post this data
41    logger.info('Creating form doc with data to post to Con Terra mapClient')
42    c.redirectToConterra = True;
43    response.write(render('selectedItems'))
44   
45
46   
47def GetWebMapContext(self):
48    """
49    Lookup a WMC doc and return it in the response
50    """
51    # retrieve context data from the specifiled url
52    wmcDoc = RetrieveWebMapContext(self, self.inputs['ENDPOINT'])
53   
54    response.headers['Content-Type'] = 'text/xml'
55    response.write(wmcDoc)
56   
57
58def GetLegend(self):
59    """
60    Lookup a legend for a WMS map
61    NB, all required parameters are already included in the endpoint by this stage
62    """
63    endpoint = self.inputs['ENDPOINT']
64    if not endpoint:
65        raise exceptions.MissingParameterValue, "ENDPOINT parameter required"
66    logger.info('Getting Legend from endpoint: ' + endpoint)
67
68    try:
69        filehandle = urllib2.urlopen(endpoint)
70    except IOError:
71        raise exceptions.URLUnavailable, "Could not access WMS endpoint: %s" % endpoint
72       
73    response.headers['Content-Type'] = 'text/xml'
74    response.write(filehandle.read())
75   
76def RetrieveWebMapContext(self, endpoint):
77    """
78    Get a WMC doc from a specified endpoint
79    @param endpoint: endpoint to retrieve WMC doc from
80    """
81    if not endpoint:
82        raise exceptions.MissingParameterValue, "ENDPOINT parameter required"
83    logger.info('Getting WebMapContext from endpoint: ' + endpoint)
84
85    try:
86        filehandle = urllib2.urlopen(endpoint)
87    except IOError:
88        raise exceptions.URLUnavailable, "Could not access WMC endpoint: %s" % endpoint
89
90    return filehandle.read()
91       
Note: See TracBrowser for help on using the repository browser.