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 | """ |
---|
6 | Utils to aid use of wmc docs - including interfacing these with the con terra client |
---|
7 | and getting associated legend data |
---|
8 | |
---|
9 | @author: Calum Byrom |
---|
10 | """ |
---|
11 | from ows_server.lib.base import * |
---|
12 | from ows_server.lib.ndgInterface import interface |
---|
13 | from ndgUtils.DocumentRetrieve import genericHTTP |
---|
14 | from ndgUtils.ETxmlView import loadET,et2text, nsdumb |
---|
15 | from ows_server.models.WMC import WMC |
---|
16 | from ows_common import exceptions |
---|
17 | import urllib2, urllib |
---|
18 | |
---|
19 | def getConTerraDoc(wmcURLs): |
---|
20 | """ |
---|
21 | Construct an aggregated XML file and POST this data to the Con Terra mapClient to visualise |
---|
22 | @param wmcURLS: An array of URLs pointing to WMC docs to visualise |
---|
23 | """ |
---|
24 | c.wmcDocs = [] |
---|
25 | for wmcURL in wmcURLs: |
---|
26 | c.wmcDocs.append(WMC(wmcURL)) |
---|
27 | |
---|
28 | # need to send the aggregated data as POST data - so change the request method |
---|
29 | request.method = "POST" |
---|
30 | |
---|
31 | # now add the required data, using the aggregate template |
---|
32 | logger.info('Creating XML Config doc for use with Con Terra mapClient') |
---|
33 | request.POST.add('xmlConfig', "<?xml version='1.0' encoding='UTF-8'?><pos:IMCPostConfig SRS='EPSG:4326' xmlns:pos='http://www.conterra.de/mapclient/businesstier/configuration/postinit'><pos:Map ImageFormat='image/png'><pos:WMService url='http://ogc.bgs.ac.uk/cgi-bin/GBR_625k_BGS_Bedrock_and_Superficial_Geology/wms?'></pos:WMService><pos:InitialExtent MinX='-100' MinY='-50' MaxX='100' MaxY='50'></pos:InitialExtent></pos:Map><pos:OverviewMap ImageFormat='image/png'><pos:WMService url='http://www.geographynetwork.com/servlet/com.esri.wms.Esrimap'><pos:AddLayer visible='true'>Continents</pos:AddLayer></pos:WMService></pos:OverviewMap></pos:IMCPostConfig>")#render('conterra_aggregate', format='xml')) |
---|
34 | logger.info('Posting request to mapClient for visualisation') |
---|
35 | h.redirect_to('http://www.gis.bgs.ac.uk:8080/mapClient/postInit.do')#http://www.conterra.de/mapclient/businesstier/configuration/postinit') |
---|
36 | |
---|
37 | # response.headers['Content-Type'] = 'text/xml' |
---|
38 | # response.headers['Content-Disposition'] = 'attachment;filename=wmcAggregate.xml' |
---|
39 | # return render('conterra_aggregate', format='xml') |
---|
40 | |
---|
41 | |
---|
42 | def GetWebMapContext(self): |
---|
43 | """ |
---|
44 | Lookup a WMC doc and return it in the response |
---|
45 | """ |
---|
46 | # retrieve context data from the specifiled url |
---|
47 | endpoint = self.inputs['ENDPOINT'] |
---|
48 | if not endpoint: |
---|
49 | raise exceptions.MissingParameterValue, "ENDPOINT parameter required" |
---|
50 | logger.info('Getting WebMapContext from endpoint: ' + endpoint) |
---|
51 | |
---|
52 | try: |
---|
53 | filehandle = urllib2.urlopen(endpoint) |
---|
54 | except IOError: |
---|
55 | raise exceptions.URLUnavailable, "Could not access WMC endpoint: %s" % endpoint |
---|
56 | |
---|
57 | response.headers['Content-Type'] = 'text/xml' |
---|
58 | response.write(filehandle.read()) |
---|
59 | |
---|
60 | |
---|
61 | def GetLegend(self): |
---|
62 | """ |
---|
63 | Lookup a legend for a WMS map |
---|
64 | NB, all required parameters are already included in the endpoint by this stage |
---|
65 | """ |
---|
66 | endpoint = self.inputs['ENDPOINT'] |
---|
67 | if not endpoint: |
---|
68 | raise exceptions.MissingParameterValue, "ENDPOINT parameter required" |
---|
69 | logger.info('Getting Legend from endpoint: ' + endpoint) |
---|
70 | |
---|
71 | try: |
---|
72 | filehandle = urllib2.urlopen(endpoint) |
---|
73 | except IOError: |
---|
74 | raise exceptions.URLUnavailable, "Could not access WMS endpoint: %s" % endpoint |
---|
75 | |
---|
76 | response.headers['Content-Type'] = 'text/xml' |
---|
77 | response.write(filehandle.read()) |
---|
78 | |
---|