Exemple #1
0
	def startElement(self, namespaceURI, localName, qName, attr):
		if localName == "Placemark":
			self.item = Placemark()
		elif localName == "Data":
			self.__parentDataName = attr.value("name")
		self.currentText = ""
		return True
Exemple #2
0
class KmlHandler(QtXml.QXmlDefaultHandler):
	def __init__(self):
		QtXml.QXmlDefaultHandler.__init__(self)
		self.__parentDataName = ""
		self.currentText = ""
		self.items = []
		self.item = None

	def startElement(self, namespaceURI, localName, qName, attr):
		if localName == "Placemark":
			self.item = Placemark()
		elif localName == "Data":
			self.__parentDataName = attr.value("name")
		self.currentText = ""
		return True

	def endElement(self, namespaceURI, localName, qName):
		if localName == "value":
			if self.__parentDataName == "accuracy":
				self.item.setAccuracy(self.currentText)
			elif self.__parentDataName == "timestamp":
				self.item.setTimestamp(int(self.currentText))
		elif localName == "Point":
			self.item.setCoordinate(self.currentText)
		elif localName == "Placemark":
			self.items.append(self.item)
		return True
	
	def endDocument(self):
		self.items = sorted(self.items, key=lambda placemark: placemark.getTimestamp())
		return True

	def characters(self, ch):
		self.currentText += ch
		return True

	def fatalError(self, exception):
		print "Fatal error on line %d, column %d:%s" % (exception.lineNumber(), exception.columnNumber(), exception.message())
		return False