source: DPPP/kml/python/csml2kml/csml2kml/ @ 3743

Subversion URL:
Revision 3743, 2.6 KB checked in by spascoe, 11 years ago (diff)

In progress changes to make csml2kml compatible with the HiGEM WMS (i.e. WMSs
based on the latest pylons stack). See the new config file for the WMS to
test on.

There are a couple of work arounds marked as "#!TODO" that need cleaning up.

2Contains the class C{WMSLayerConvertor}.
[3595]5from WMSLayer import *
7class WMSLayerConvertor:
[3612]8    '''
9    Encapsulates conversion from WMS layers to a KML file hierarchy.
10    '''
[3595]12    def __init__(self, topWmsLayer, wmsRequestConfigElement, baseKmlOutputDirectory, baseKmlOutputUrl):
[3612]13        '''
14        The constructor.
15        @param topWmsLayer: The top WMS layer to be converted.
16        @type topWmsLayer: C{WMSLayer.WMSLayer}
17        @param wmsRequestConfigElement: The I{<WMSRequest>} element from the config file (containing information
18        about how WMS requests are to be made, e.g. which server to use, what resolution to use, etc.)
19        @type wmsRequestConfigElement: C{cElementTree.Element}
20        @param baseKmlOutputDirectory: A directory to be used as the root of the output.
21        The KMZ file corresponding to the uppermost layer will be contained directly in this directory.
22        @type baseKmlOutputDirectory: C{str}
23        @param baseKmlOutputUrl: The URL from which the output will be served, corresponding to the root output directory.
24        @type baseKmlOutputUrl: C{str}
25        '''
[3595]26        self.topWmsLayer = topWmsLayer
27        self.wmsRequestConfigElement = wmsRequestConfigElement
28        self.baseKmlOutputDirectory = baseKmlOutputDirectory
29        self.baseKmlOutputUrl = baseKmlOutputUrl
31    def convert(self):
[3743]32        """
[3612]33        Perform the conversion.
35        This will create a hierarchy of KMZ files embedded in directories.
36        Each KMZ files encodes a single I{<wms:Layer>} element, as follows:
37          - Each KMZ file encoding a {non-bottom WMS layer} contains a number of I{<kml:NetworkLink>}'s mapping
38            to the KMZ files in a lower directory.
39            The I{<kml:NetworkLink>} contains an absolute URL of the target on the machine from the KMZ file
40            is being served.
41          - Each KML file encoding a I{bottom WMS layer} contains views of the data in the bottom layer,
42            with the views specified by the C{viewTypes} parameter.
44        The convertor uses the following 3 types of views, as defined in the C{WMSLayer} module:
45        C{ViewWholeTimecourse}, C{ViewSplittedByMonth}, C{ViewSplittedByPeriod}.
46        However, more views can be created (by extending {WMSLayer.View}) and added later.
[3743]47        """
48        #!TODO: make viewTypes configurable.
49        #viewTypes = [ViewWholeTimecourse, ViewSplittedByMonth, ViewSplittedByPeriod]
50        viewTypes = [ViewWholeTimecourse]
[3595]51        self.topWmsLayer.toKML(self.wmsRequestConfigElement, viewTypes, self.baseKmlOutputDirectory, self.baseKmlOutputUrl)
Note: See TracBrowser for help on using the repository browser.