Source code for sos.gmlparser

# -*- coding: utf-8 -*-
"""
This module includes GML...Parser classes.
"""

from xmlparser import XMLParser
import qgstime

[docs]class GMLTimeInstantParser (XMLParser): """ Parse an xml node to extract timePosition as QgsTimeInstant """
[docs] def parse (self, xml): xml = XMLParser.parse(self, xml) _, time = self.searchFirst(xml, 'timePosition') return qgstime.QgsTimeInstant (time)
[docs]class GMLTimePeriodParser (XMLParser): """ Parse an xml node to extract beginPosition and endPosition as QgsTimePeriod """
[docs] def parse (self, xml): xml = XMLParser.parse(self, xml) _, begin = self.searchFirst(xml, 'beginPosition') _, end = self.searchFirst(xml, 'endPosition') return qgstime.QgsTimePeriod(begin, end)
[docs]class GMLTimeParser (XMLParser): """ Parse an xml node to extract type and process it with correct parser """
[docs] def parse (self, xml): xml = XMLParser.parse(self, xml) xml, timeType = self.searchFirst(xml, '*@type') if timeType == 'gml:TimePeriodType': return GMLTimePeriodParser().parse(xml) elif timeType == 'gml:TimeInstantType': return GMLTimeInstantParser().parse(xml) else: return qgstime.QgsTime()