예제 #1
0
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall('Capability//OnlineResource')
            for element in elements:
                element.set('xlink:href', self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find('Capability/Layer')

            rootlayername = ElementTree.Element('Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)

            latlonbb = ElementTree.Element('LatLonBoundingBox')
            latlonbb.set('minx', str(self.mapfactory.latlonbb.minx))
            latlonbb.set('miny', str(self.mapfactory.latlonbb.miny))
            latlonbb.set('maxx', str(self.mapfactory.latlonbb.maxx))
            latlonbb.set('maxy', str(self.mapfactory.latlonbb.maxy))
            rootlayerelem.append(latlonbb)

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('SRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                llp = layerproj.inverse(Coord(env.minx, env.miny))
                urp = layerproj.inverse(Coord(env.maxx, env.maxy))
                latlonbb = ElementTree.Element('LatLonBoundingBox')
                latlonbb.set('minx', str(llp.x))
                latlonbb.set('miny', str(llp.y))
                latlonbb.set('maxx', str(urp.x))
                latlonbb.set('maxy', str(urp.y))
                layerbbox = ElementTree.Element('BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('SRS', layer.wms_srs)
                else:
                    layerbbox.set('SRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('Title')
                if hasattr(layer,'title'):
                    layertitle.text = to_unicode(layer.title)
                    if layertitle.text == '':
                        layertitle.text = to_unicode(layer.name)
                else:
                    layertitle.text = to_unicode(layer.name)
                layere.append(layertitle)
                layerabstract = ElementTree.Element('Abstract')
                if hasattr(layer,'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(latlonbb)
                layere.append(layerbbox)
                style_count = len(layer.wmsextrastyles)
                if style_count > 0:
                    extrastyles = layer.wmsextrastyles
                    if style_count > 1:
                        extrastyles = ['default'] + [x for x in extrastyles if x != 'default']
                    for extrastyle in extrastyles:
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        if style_count > 1 and extrastyle == 'default':
                            styleabstract = ElementTree.Element('Abstract')
                            styleabstract.text = to_unicode('This layer\'s default style that combines all its other named styles.')
                            style.append(styleabstract)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = ElementTree.tostring(capetree,encoding='UTF-8')
        response = Response('application/vnd.ogc.wms_xml', self.capabilities)
        return response
예제 #2
0
파일: wms111.py 프로젝트: nimix/OGCServer
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall('Capability//OnlineResource')
            for element in elements:
                element.set('xlink:href', self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find('Capability/Layer')

            rootlayername = ElementTree.Element('Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(
                    self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(
                    self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(
                    self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)

            latlonbb = ElementTree.Element('LatLonBoundingBox')
            latlonbb.set('minx', str(self.mapfactory.latlonbb.minx))
            latlonbb.set('miny', str(self.mapfactory.latlonbb.miny))
            latlonbb.set('maxx', str(self.mapfactory.latlonbb.maxx))
            latlonbb.set('maxy', str(self.mapfactory.latlonbb.maxy))
            rootlayerelem.append(latlonbb)

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('SRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for epsgcode in self.allowedepsgcodes:
                rootbbox = ElementTree.Element('BoundingBox')
                rootbbox.set('SRS', epsgcode.upper())
                proj = Projection('+init=' + epsgcode)
                bb = self.mapfactory.latlonbb
                minCoord = Coord(bb.minx, bb.miny).forward(proj)
                maxCoord = Coord(bb.maxx, bb.maxy).forward(proj)
                rootbbox.set('minx', str(minCoord.x))
                rootbbox.set('miny', str(minCoord.y))
                rootbbox.set('maxx', str(maxCoord.x))
                rootbbox.set('maxy', str(maxCoord.y))
                rootlayerelem.append(rootbbox)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                llp = layerproj.inverse(Coord(env.minx, env.miny))
                urp = layerproj.inverse(Coord(env.maxx, env.maxy))
                latlonbb = ElementTree.Element('LatLonBoundingBox')
                latlonbb.set('minx', str(llp.x))
                latlonbb.set('miny', str(llp.y))
                latlonbb.set('maxx', str(urp.x))
                latlonbb.set('maxy', str(urp.y))
                layerbbox = ElementTree.Element('BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('SRS', layer.wms_srs)
                else:
                    layerbbox.set('SRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('Title')
                if hasattr(layer, 'title'):
                    layertitle.text = to_unicode(layer.title)
                    if layertitle.text == '':
                        layertitle.text = to_unicode(layer.name)
                else:
                    layertitle.text = to_unicode(layer.name)
                layere.append(layertitle)
                layerabstract = ElementTree.Element('Abstract')
                if hasattr(layer, 'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(latlonbb)
                layere.append(layerbbox)
                style_count = len(layer.wmsextrastyles)
                if style_count > 0:
                    extrastyles = layer.wmsextrastyles
                    if style_count > 1:
                        extrastyles = ['default'] + [
                            x for x in extrastyles if x != 'default'
                        ]
                    for extrastyle in extrastyles:
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        if style_count > 1 and extrastyle == 'default':
                            styleabstract = ElementTree.Element('Abstract')
                            styleabstract.text = to_unicode(
                                'This layer\'s default style that combines all its other named styles.'
                            )
                            style.append(styleabstract)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = ElementTree.tostring(capetree,
                                                     encoding='UTF-8')
        response = Response('application/vnd.ogc.wms_xml', self.capabilities)
        return response
예제 #3
0
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall(
                '{http://www.opengis.net/wms}Capability//{http://www.opengis.net/wms}OnlineResource'
            )
            for element in elements:
                element.set('{http://www.w3.org/1999/xlink}href',
                            self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find(
                '{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer'
            )

            rootlayername = ElementTree.Element('Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(
                    self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(
                    self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(
                    self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('CRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                layerexgbb = ElementTree.Element('EX_GeographicBoundingBox')
                ll = layerproj.inverse(Coord(env.minx, env.miny))
                ur = layerproj.inverse(Coord(env.maxx, env.maxy))
                exgbb_wbl = ElementTree.Element('westBoundLongitude')
                exgbb_wbl.text = str(ll.x)
                layerexgbb.append(exgbb_wbl)
                exgbb_ebl = ElementTree.Element('eastBoundLongitude')
                exgbb_ebl.text = str(ur.x)
                layerexgbb.append(exgbb_ebl)
                exgbb_sbl = ElementTree.Element('southBoundLatitude')
                exgbb_sbl.text = str(ll.y)
                layerexgbb.append(exgbb_sbl)
                exgbb_nbl = ElementTree.Element('northBoundLatitude')
                exgbb_nbl.text = str(ur.y)
                layerexgbb.append(exgbb_nbl)
                layerbbox = ElementTree.Element('BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('CRS', layer.wms_srs)
                else:
                    layerbbox.set('CRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('Title')
                if hasattr(layer, 'title'):
                    layertitle.text = to_unicode(layer.title)
                else:
                    layertitle.text = to_unicode(layer.name)
                layere.append(layertitle)
                layerabstract = ElementTree.Element('Abstract')
                if hasattr(layer, 'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(layerexgbb)
                layere.append(layerbbox)
                if len(layer.wmsextrastyles) > 0:
                    for extrastyle in [layer.wmsdefaultstyle] + list(
                            layer.wmsextrastyles):
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = '<?xml version="1.0" encoding="UTF-8"?>' + ElementTree.tostring(
                capetree, encoding='UTF-8', pretty_print=True)
        response = Response('text/xml', self.capabilities)
        return response
예제 #4
0
파일: wms130.py 프로젝트: ckey/ogcserver-b
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall('{http://www.opengis.net/wms}Capability//{http://www.opengis.net/wms}OnlineResource')
            for element in elements:
                element.set('xlink:href', self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find('{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer')

            rootlayername = ElementTree.Element('{http://www.opengis.net/wms}Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('{http://www.opengis.net/wms}Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('{http://www.opengis.net/wms}Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)

            layerexgbb = ElementTree.Element('{http://www.opengis.net/wms}EX_GeographicBoundingBox')
            exgbb_wbl = ElementTree.Element('{http://www.opengis.net/wms}westBoundLongitude')
            exgbb_wbl.text = str(self.mapfactory.latlonbb.minx)
            layerexgbb.append(exgbb_wbl)
            exgbb_ebl = ElementTree.Element('{http://www.opengis.net/wms}eastBoundLongitude')
            exgbb_ebl.text = str(self.mapfactory.latlonbb.maxx)
            layerexgbb.append(exgbb_ebl)
            exgbb_sbl = ElementTree.Element('{http://www.opengis.net/wms}southBoundLatitude')
            exgbb_sbl.text = str(self.mapfactory.latlonbb.miny)
            layerexgbb.append(exgbb_sbl)
            exgbb_nbl = ElementTree.Element('{http://www.opengis.net/wms}northBoundLatitude')
            exgbb_nbl.text = str(self.mapfactory.latlonbb.maxy)
            layerexgbb.append(exgbb_nbl)
            rootlayerelem.append(layerexgbb)

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('{http://www.opengis.net/wms}CRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('{http://www.opengis.net/wms}Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                layerexgbb = ElementTree.Element('{http://www.opengis.net/wms}EX_GeographicBoundingBox')
                ll = layerproj.inverse(Coord(env.minx, env.miny))
                ur = layerproj.inverse(Coord(env.maxx, env.maxy))
                exgbb_wbl = ElementTree.Element('{http://www.opengis.net/wms}westBoundLongitude')
                exgbb_wbl.text = str(ll.x)
                layerexgbb.append(exgbb_wbl)
                exgbb_ebl = ElementTree.Element('{http://www.opengis.net/wms}eastBoundLongitude')
                exgbb_ebl.text = str(ur.x)
                layerexgbb.append(exgbb_ebl)
                exgbb_sbl = ElementTree.Element('{http://www.opengis.net/wms}southBoundLatitude')
                exgbb_sbl.text = str(ll.y)
                layerexgbb.append(exgbb_sbl)
                exgbb_nbl = ElementTree.Element('{http://www.opengis.net/wms}northBoundLatitude')
                exgbb_nbl.text = str(ur.y)
                layerexgbb.append(exgbb_nbl)
                layerbbox = ElementTree.Element('{http://www.opengis.net/wms}BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('CRS', layer.wms_srs)
                else:
                    layerbbox.set('CRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('{http://www.opengis.net/wms}Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('{http://www.opengis.net/wms}Title')
                if hasattr(layer,'title'):
                    layertitle.text = to_unicode(layer.title)
                    if layertitle.text == '':
                        layertitle.text = to_unicode(layer.name)
                else:
                    layertitle.text = to_unicode(layer.name)
                layere.append(layertitle)
                layerabstract = ElementTree.Element('{http://www.opengis.net/wms}Abstract')
                if hasattr(layer,'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(layerexgbb)
                layere.append(layerbbox)
                style_count = len(layer.wmsextrastyles)
                if style_count > 0:
                    extrastyles = layer.wmsextrastyles
                    if style_count > 1:
                        extrastyles = ['default'] + [x for x in extrastyles if x != 'default']
                    for extrastyle in extrastyles:
                        style = ElementTree.Element('{http://www.opengis.net/wms}Style')
                        stylename = ElementTree.Element('{http://www.opengis.net/wms}Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('{http://www.opengis.net/wms}Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        if style_count > 1 and extrastyle == 'default':
                            styleabstract = ElementTree.Element('{http://www.opengis.net/wms}Abstract')
                            styleabstract.text = to_unicode('This layer\'s default style that combines all its other named styles.')
                            style.append(styleabstract)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = ElementTree.tostring(capetree,encoding='UTF-8')
        response = Response('text/xml', self.capabilities)
        return response
예제 #5
0
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)
    
            elements = capetree.findall('{http://www.opengis.net/wms}Capability//{http://www.opengis.net/wms}OnlineResource')
            for element in elements:
                element.set('{http://www.w3.org/1999/xlink}href', self.opsonlineresource)
    
            self.processServiceCapabilities(capetree)
    
            rootlayerelem = capetree.find('{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer')

            rootlayername = ElementTree.Element('Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)
    
            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('CRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)
    
            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                layerexgbb = ElementTree.Element('EX_GeographicBoundingBox')
                ll = layerproj.inverse(Coord(env.minx, env.miny))
                ur = layerproj.inverse(Coord(env.maxx, env.maxy))
                exgbb_wbl = ElementTree.Element('westBoundLongitude')
                exgbb_wbl.text = str(ll.x)
                layerexgbb.append(exgbb_wbl)
                exgbb_ebl = ElementTree.Element('eastBoundLongitude')
                exgbb_ebl.text = str(ur.x)
                layerexgbb.append(exgbb_ebl)
                exgbb_sbl = ElementTree.Element('southBoundLatitude')
                exgbb_sbl.text = str(ll.y)
                layerexgbb.append(exgbb_sbl)
                exgbb_nbl = ElementTree.Element('northBoundLatitude')
                exgbb_nbl.text = str(ur.y)
                layerexgbb.append(exgbb_nbl)
                layerbbox = ElementTree.Element('BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('CRS', layer.wms_srs)
                else:
                    layerbbox.set('CRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('Title')
                if hasattr(layer,'title'):
                    layertitle.text = to_unicode(layer.title)
                else:
                    layertitle.text = to_unicode(layer.name)                    
                layere.append(layertitle)
                layerabstract = ElementTree.Element('Abstract')
                if hasattr(layer,'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'                
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(layerexgbb)
                layere.append(layerbbox)
                if len(layer.wmsextrastyles) > 0:
                    for extrastyle in [layer.wmsdefaultstyle] + list(layer.wmsextrastyles):
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = '<?xml version="1.0" encoding="UTF-8"?>' + ElementTree.tostring(capetree,encoding='UTF-8',pretty_print=True)
        response = Response('text/xml', self.capabilities)
        return response
예제 #6
0
    def GetCapabilities(self, params):
        if not self.capabilities:
            capetree = ElementTree.fromstring(self.capabilitiesxmltemplate)

            elements = capetree.findall('Capability//OnlineResource')
            for element in elements:
                element.set('{http://www.w3.org/1999/xlink}href', self.opsonlineresource)

            self.processServiceCapabilities(capetree)

            rootlayerelem = capetree.find('Capability/Layer')

            rootlayername = ElementTree.Element('Name')
            if self.conf.has_option('map', 'wms_name'):
                rootlayername.text = to_unicode(self.conf.get('map', 'wms_name'))
            else:
                rootlayername.text = '__all__'
            rootlayerelem.append(rootlayername)

            rootlayertitle = ElementTree.Element('Title')
            if self.conf.has_option('map', 'wms_title'):
                rootlayertitle.text = to_unicode(self.conf.get('map', 'wms_title'))
            else:
                rootlayertitle.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayertitle)

            rootlayerabstract = ElementTree.Element('Abstract')
            if self.conf.has_option('map', 'wms_abstract'):
                rootlayerabstract.text = to_unicode(self.conf.get('map', 'wms_abstract'))
            else:
                rootlayerabstract.text = 'OGCServer WMS Server'
            rootlayerelem.append(rootlayerabstract)

            latlonbb = ElementTree.Element('LatLonBoundingBox')
            latlonbb.set('minx', str(self.mapfactory.latlonbb.minx))
            latlonbb.set('miny', str(self.mapfactory.latlonbb.miny))
            latlonbb.set('maxx', str(self.mapfactory.latlonbb.maxx))
            latlonbb.set('maxy', str(self.mapfactory.latlonbb.maxy))
            rootlayerelem.append(latlonbb)

            for epsgcode in self.allowedepsgcodes:
                rootlayercrs = ElementTree.Element('SRS')
                rootlayercrs.text = epsgcode.upper()
                rootlayerelem.append(rootlayercrs)

            for epsgcode in self.allowedepsgcodes:
                rootbbox = ElementTree.Element('BoundingBox')
                rootbbox.set('SRS', epsgcode.upper())
                proj = Projection('+init='+epsgcode)
                bb = self.mapfactory.latlonbb
                minCoord = Coord(bb.minx, bb.miny).forward(proj)
                maxCoord = Coord(bb.maxx, bb.maxy).forward(proj)
                rootbbox.set('minx', str(minCoord.x))
                rootbbox.set('miny', str(minCoord.y))
                rootbbox.set('maxx', str(maxCoord.x))
                rootbbox.set('maxy', str(maxCoord.y))
                rootlayerelem.append(rootbbox)

            for layer in self.mapfactory.ordered_layers:
                layerproj = Projection(layer.srs)
                layername = ElementTree.Element('Name')
                layername.text = to_unicode(layer.name)
                env = layer.envelope()
                llp = layerproj.inverse(Coord(env.minx, env.miny))
                urp = layerproj.inverse(Coord(env.maxx, env.maxy))
                latlonbb = ElementTree.Element('LatLonBoundingBox')
                latlonbb.set('minx', str(llp.x))
                latlonbb.set('miny', str(llp.y))
                latlonbb.set('maxx', str(urp.x))
                latlonbb.set('maxy', str(urp.y))
                layerbbox = ElementTree.Element('BoundingBox')
                if layer.wms_srs:
                    layerbbox.set('SRS', layer.wms_srs)
                else:
                    layerbbox.set('SRS', layerproj.epsgstring())
                layerbbox.set('minx', str(env.minx))
                layerbbox.set('miny', str(env.miny))
                layerbbox.set('maxx', str(env.maxx))
                layerbbox.set('maxy', str(env.maxy))
                layere = ElementTree.Element('Layer')
                layere.append(layername)
                layertitle = ElementTree.Element('Title')
                if hasattr(layer,'title'):
                    layertitle.text = to_unicode(layer.title)
                else:
                    layertitle.text = to_unicode(layer.name)
                layere.append(layertitle)
                layerabstract = ElementTree.Element('Abstract')
                if hasattr(layer,'abstract'):
                    layerabstract.text = to_unicode(layer.abstract)
                else:
                    layerabstract.text = 'no abstract'
                layere.append(layerabstract)
                if layer.queryable:
                    layere.set('queryable', '1')
                layere.append(latlonbb)
                layere.append(layerbbox)
                if len(layer.wmsextrastyles) > 0:
                    for extrastyle in [layer.wmsdefaultstyle] + list(layer.wmsextrastyles):
                        style = ElementTree.Element('Style')
                        stylename = ElementTree.Element('Name')
                        stylename.text = to_unicode(extrastyle)
                        styletitle = ElementTree.Element('Title')
                        styletitle.text = to_unicode(extrastyle)
                        style.append(stylename)
                        style.append(styletitle)
                        layere.append(style)
                rootlayerelem.append(layere)
            self.capabilities = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n' + ElementTree.tostring(capetree,encoding='UTF-8',pretty_print=True)
        response = Response('application/vnd.ogc.wms_xml', self.capabilities)
        return response