1 ###############################################################################
2 # Copyright (c) 2008 Rico Schulte, 3c5x9. All rights reserved.
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the "Software"),
6 # to deal in the Software without restriction, including without limitation
7 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 # DEALINGS IN THE SOFTWARE.
21 ###############################################################################
23 from globalmaptiles import GlobalMercator
24 from xml.dom.minidom import parse
25 from os import listdir
28 def __init__(self,kmlnode):
29 self.kmlnode = kmlnode
30 self.name = kmlnode.getElementsByTagName('name')[0].firstChild.data.encode("utf-8")
31 lons = kmlnode.getElementsByTagName('LookAt')[0].getElementsByTagName('longitude')[0].firstChild.data.encode("utf-8")
32 lats = kmlnode.getElementsByTagName('LookAt')[0].getElementsByTagName('latitude')[0].firstChild.data.encode("utf-8")
43 def getTile(self,zoomlevel):
44 mercator = GlobalMercator()
45 mx, my = mercator.LatLonToMeters( self.lat, self.lon )
46 tminx, tminy = mercator.MetersToTile( mx, my, zoomlevel )
47 gx, gy = mercator.GoogleTile(tminx, tminy, zoomlevel)#+1?
48 return gx,gy,zoomlevel
51 return "KmlPlace ('"+self.name+"','"+str(self.lat)+"','"+str(self.lon)+"')"
55 def __init__(self,kmlnode):
56 self.kmlnode = kmlnode
57 self.name = kmlnode.getElementsByTagName('name')[0].firstChild.data.encode("utf-8")
61 for i in self.kmlnode.getElementsByTagName('Folder'):
68 def getPlacemarks(self):
70 for i in self.kmlnode.getElementsByTagName('Placemark'):
72 try: # test if we can handle this coords
73 point.getTile(15)# 15 is just a zoomlevel in the middle :)
76 print "Import Error: ",point.name,e
84 def getFolderFromFile(self,filepath):
85 return KmlFolder(self.parseFile(filepath))
87 def parseFile(self,filepath):
88 print "parsing ",filepath
89 return parse(filepath)
91 def getFiles(self,path):
93 for file in listdir(path):
94 if file.endswith(self.extension):
95 list.append((file.split('.')[0],path+file))