Changeset 3315 for DPPP/kml


Ignore:
Timestamp:
06/02/08 10:14:21 (12 years ago)
Author:
mkochan
Message:

Added comments to QuadTree?.py and PointSeriesConvertor?.py.

Location:
DPPP/kml/csml2kml/python/csml2kml
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DPPP/kml/csml2kml/python/csml2kml/PointSeriesConvertor.py

    r3312 r3315  
    1010 
    1111class Station: 
    12  
     12    '''Represents a ground meteorological station, identified by id, with description, desc, at (lon,lat) ''' 
    1313    def __init__(self, id, desc, lon, lat): 
    1414        self.id = id 
     
    2020 
    2121class PointSeriesConvertor: 
     22    ''' 
     23    Converter from GML+CSML to KML. Contains functionality for converting GML containing a collection of Station elements into KML. 
     24    ''' 
    2225     
    2326    def __init__(self, config, kmlFilename): 
     
    3437        ''' 
    3538 
    36         def _parseGMLStationsCollection(textGml): 
     39       def _parseGMLStationsCollection(textGml): 
    3740            ''' 
    3841            Parse the GML returned from GeoServer and yield Station objects with info about each station. 
     
    4952 
    5053        def _buildKmlDocumentDirectly(kmlDocument, stations, placemarkKmlStyle, stationData): 
     54            ''' 
     55            Returns an object of the KMLDocument class, kmlDocument, which will contain each station 
     56            represented by a placemark directly contained in the document (i.e. no intermediate folders). 
     57            ''' 
    5158            for station in stations: 
    5259                kmlStation = KMLPlacemark(station.id, station.desc, station.lon, station.lat, 
     
    5663            return kmlDocument 
    5764 
    58         def _buildKmlDocumentUsingQuadTree(kmlDocument, stations, placemarkKmlStyle, stationData): 
     65        def _buildKmlDocumentUsingSections(kmlDocument, stations, placemarkKmlStyle, stationData): 
     66            ''' 
     67            Returns an object of the KMLDocument class, kmlDocument, which contains the stations 
     68            organized into a hierarchy of folders, each containing ever smaller section of land.  
     69            The root of this hierarchy, a KMLFolder object, gets attached to the document, 
     70            and is "closed" i.e. it is not possible to open it in Google Earth's list view. 
     71            ''' 
    5972 
    60             def _quadTreeToKMLElement(t): 
     73            def _quadTreeToKMLFolder(t): 
    6174                ''' 
    62                 Convert the quad-tree into a KMLElement instance containing a folder hierarchy with placemark leaves. 
     75                Convert the quad-tree into a KMLElement instance being a folder hierarchy with placemark leaves. 
    6376                ''' 
    6477                if isinstance(t, NilLeaf):                      # Do nothing 
     
    7992                    kmlFolder = KMLFolder(repr(t.bbox), [], region = kmlRegion) 
    8093                    for i in t.children: 
    81                         kmlChild = _quadTreeToKMLElement(i) 
     94                        kmlChild = _quadTreeToKMLFolder(i) 
    8295                        if kmlChild: 
    8396                            kmlFolder.children.append(kmlChild) 
     
    88101                locations.append( Location(station.lon, station.lat, station) ) 
    89102            quadTree = build_quadtree(locations) 
    90             kmlFolder = _quadTreeToKMLElement(quadTree) 
     103            kmlFolder = _quadTreeToKMLFolder(quadTree) 
    91104 
    92105            lockedFolderStyle = KMLStyle('locked_folder_style', listItemType = 'checkHideChildren') 
     
    109122            datumValue = datum.text 
    110123            stationData[datumName] = datumValue 
    111         useQuadTree = self.config.find('UseQuadTree').text == 'yes' 
     124        useSections = self.config.find('UseSection').text == 'yes' 
    112125 
    113         # Perform the conversion 
     126        # Read in GML containing the stations, and extract them into a list of Station objects 
    114127        textGml = wget(url) 
     128        stations = _parseGMLStationsCollection(textGml) 
     129 
     130        # Create a KML style for each station/placemark -- can contain appropriate HTML balloon template 
    115131        placemarkKmlStyle = createDefaultPlacemarKMLStyle(balloonTemplate = balloonTemplate) 
    116132 
    117         stations = _parseGMLStationsCollection(textGml) 
    118  
     133        # Create a KML document and attach the stations either directly to it, or using a folder hierarchy  
     134        # of KML sections (derived by means of quad-tree) 
    119135        kmlDocument = KMLDocument(documentName, [placemarkKmlStyle]) 
    120         if useQuadTree: 
    121             kmlDocument = _buildKmlDocumentUsingQuadTree(kmlDocument, stations, placemarkKmlStyle, stationData) 
     136        if useSections: 
     137            kmlDocument = _buildKmlDocumentUsingSections(kmlDocument, stations, placemarkKmlStyle, stationData) 
    122138        else: 
    123139            kmlDocument = _buildKmlDocumentDirectly(kmlDocument, stations, placemarkKmlStyle, stationData) 
  • DPPP/kml/csml2kml/python/csml2kml/QuadTree.py

    r3312 r3315  
    11''' 
    2 Functionality (classes and functions) for producing geographic quat trees, i.e. trees which 
    3 enable quadric recursive space splitting.  
     2Classes and functions for producing geographic quat trees, i.e. trees which enable quadric recursive space splitting. 
    43''' 
    54 
     
    133132        t4 = build_quadtree(l4, bbox.ne()) 
    134133        return Node([t1, t2, t3, t4],bbox) 
    135  
Note: See TracChangeset for help on using the changeset viewer.