/usr/lib/python2.7/dist-packages/owslib/wmc.py is in python-owslib 0.10.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | # -*- coding: ISO-8859-15 -*-
# =============================================================================
# Copyright (c) 2004 Sean C. Gillies
# Copyright (c) 2005 Nuxeo SARL <http://nuxeo.com>
#
# Authors : Sean Gillies <sgillies@frii.com>
# Julien Anguenot <ja@nuxeo.com>
#
# Contact email: sgillies@frii.com
# =============================================================================
"""Web Map Context (WMC)
Specification can be found over there :
https://portal.opengeospatial.org/files/?artifact_id=8618
"""
from __future__ import (absolute_import, division, print_function)
from .etree import etree
context_ns_uri = 'http://www.opengis.net/context'
context_schemas_uri = 'http://schemas.opengis.net/context/1.0.0/context.xsd'
def WMCElement(tag):
"""WMC based element
"""
return etree.Element("{%s}"%context_ns_uri + tag)
class MapContext:
""" Map Context abstraction
It uses a Map representation as input and export it as as map
context
"""
def __init__(self, map_):
self._map = map_
def _getRootElement(self):
root = WMCElement('ViewContext')
attrs = {
'{http://www.w3.org/2001/XMLSchema-instance}schemaLocation':
context_ns_uri + ' ' + context_schemas_uri,
'id' : self._map.id,
'version' : '1.0.0',
}
for k, v in attrs.items():
root.attrib[k] = v
return root
def _getGeneralElement(self):
general = WMCElement('General')
general.append(self._getWindowElement())
general.append(self._getBoundingBoxElement())
return general
def _getWindowElement(self):
window = WMCElement('Window')
window.attrib['width'] = str(self._map.size[0])
window.attrib['height'] = str(self._map.size[1])
return window
def _getBoundingBoxElement(self):
bbox = WMCElement('BoundingBox')
bbox.attrib['SRS'] = str(self._map.srs.split()[0])
bbox.attrib['minx'] = str(self._map.bounds[0])
bbox.attrib['miny'] = str(self._map.bounds[1])
bbox.attrib['maxx'] = str(self._map.bounds[2])
bbox.attrib['maxy'] = str(self._map.bounds[3])
return bbox
def _getLayerListElement(self):
layerlist = WMCElement('LayerList')
layering = zip(self._map.layernames, self._map.layertitles)
layer_infos = self._map.getLayerInfos()
# mapbuilder draws layers in bottom-top order
for name, title in layering:
# Layer
layer = WMCElement('Layer')
layer.attrib['queryable'] = '0'
layer.attrib['hidden'] = str(
int(name not in self._map.visible_layers))
# Layer styles
if layer_infos and layer_infos.get(title):
stylelist = WMCElement('StyleList')
# Get wms `Style` nodes for a given layer
for e_style in layer_infos.get(title):
e_style.attrib['current'] = '1'
# Change namespace to wmc
for node in e_style.getiterator():
tag_name = node.tag[node.tag.rfind('}')+1:]
node.tag = "{%s}"%context_ns_uri + tag_name
stylelist.append(e_style)
layer.append(stylelist)
# Server
server = WMCElement('Server')
server.attrib['service'] = 'OGC:WMS'
server.attrib['version'] = '1.1.1'
server.attrib['title'] = 'OGC:WMS'
# OnlineRessource
oressource = WMCElement('OnlineResource')
oressource.attrib[
'{http://www.w3.org/1999/xlink}type'] = 'simple'
oressource.attrib[
'{http://www.w3.org/1999/xlink}href'] = self._map.url
server.append(oressource)
layer.append(server)
# Name
e_name = WMCElement('Name')
e_name.text = name
layer.append(e_name)
# Title
e_title = WMCElement('Title')
e_title.text = title
layer.append(e_title)
# Format
formatlist = WMCElement('FormatList')
format = WMCElement('Format')
format.attrib['current'] = '1'
format.text = self._map.format
formatlist.append(format)
layer.append(formatlist)
layerlist.append(layer)
return layerlist
def __call__(self):
"""Export self._map to WMC
"""
wmc_doc_tree = self._getRootElement()
wmc_doc_tree.append(self._getGeneralElement())
wmc_doc_tree.append(self._getLayerListElement())
return etree.tostring(wmc_doc_tree)
class AggregateMapContext(MapContext):
""" Map Context abstraction
It uses a Map representation as input and export it as as map
context -- with aggregation of all layers accomplished through
overload of the Layer/Name property
"""
def _getLayerListElement(self):
layerlist = WMCElement('LayerList')
#layering = zip(self._map.layernames, self._map.layertitles)
layer_infos = self._map.getLayerInfos()
# Layer
layer = WMCElement('Layer')
layer.attrib['queryable'] = '0'
layer.attrib['hidden'] = '0'
# Server
server = WMCElement('Server')
server.attrib['service'] = 'OGC:WMS'
server.attrib['version'] = '1.1.1'
server.attrib['title'] = 'OGC:WMS'
# OnlineRessource
oressource = WMCElement('OnlineResource')
oressource.attrib['{http://www.w3.org/1999/xlink}type'] = 'simple'
oressource.attrib['{http://www.w3.org/1999/xlink}href'] = self._map.url
server.append(oressource)
layer.append(server)
# Name
e_name = WMCElement('Name')
e_name.text = ','.join(self._map.layernames)
layer.append(e_name)
# Title
e_title = WMCElement('Title')
e_title.text = 'Aggregate Layers'
layer.append(e_title)
# Format
formatlist = WMCElement('FormatList')
format = WMCElement('Format')
format.attrib['current'] = '1'
format.text = self._map.format
formatlist.append(format)
layer.append(formatlist)
layerlist.append(layer)
return layerlist
def mapToWebMapContext(map, aggregate_layers=False):
"""Helper
if the second argument evaluates to True, then all map layers are
aggregated into a single map context layer.
"""
if aggregate_layers:
return AggregateMapContext(map)()
else:
return MapContext(map)()
|