def main(): print '== This is %s' % sys.argv[0] factory = kmldom.KmlFactory_GetFactory() print 'Coordinates is a vector of Vec3...' coordinates = factory.CreateCoordinates() coordinates.add_latlng(1, 1) coordinates.add_latlng(2, 2) coordinates.add_latlng(3, 3) for i in range(coordinates.get_coordinates_array_size()): print 'longitude', coordinates.get_coordinates_array_at( i).get_longitude() print 'latitude', coordinates.get_coordinates_array_at( i).get_latitude() print 'altitude', coordinates.get_coordinates_array_at( i).get_altitude() print kmldom.SerializePretty(coordinates) # Python deletes coordinates. print 'Create a Folder with some Features...' folder = factory.CreateFolder() folder.add_feature(factory.CreatePlacemark()) folder.add_feature(factory.CreateFolder()) for i in range(folder.get_feature_array_size()): print 'feature Type', folder.get_feature_array_at(i).Type() print kmldom.SerializePretty(folder)
def main(): print '== This is %s' % sys.argv[0] factory = kmldom.KmlFactory_GetFactory() print 'Create a Point Placemark...' print 'Create coordinates...' coordinates = factory.CreateCoordinates() coordinates.add_latlng(37.38, -122.123) print 'Create Point and set coordinates...' point = factory.CreatePoint() point.set_coordinates(coordinates) print 'Create Placemark and set geometry...' placemark = factory.CreatePlacemark() placemark.set_geometry(point) print placemark.has_geometry() print 'Create kml and set feature...' kml = factory.CreateKml() kml.set_feature(placemark) print 'Serialize to xml...' print kmldom.SerializePretty(kml)
def main(): print '== This is %s' % sys.argv[0] factory = kmldom.KmlFactory_GetFactory() # <Document> document = factory.CreateDocument() # Each Create*Placemark() creates and returns a Placemark. document.add_feature(CreatePointPlacemark('pt0', 1, 2)) document.add_feature(CreatePointPlacemark('pt1', 3, 4)) lnglat = [(1, 2), (3, 4), (5, 6), (7, 8)] document.add_feature(CreateSimple2dLineStringPlacemark('line', lnglat)) document.add_feature(CreateSimple2dPolygonPlacemark('box')) document.add_feature(Create2HolePolygonPlacemark('2 holes')) # <Placemark><MultiGeometry><Point>... <LineString>... placemark = factory.CreatePlacemark() multigeometry = factory.CreateMultiGeometry() multigeometry.add_geometry(factory.CreatePoint()) multigeometry.add_geometry(factory.CreateLineString()) placemark.set_geometry(multigeometry) document.add_feature(placemark) # <kml> kml = factory.CreateKml() kml.set_feature(document) print 'Serialize to xml...' print kmldom.SerializePretty(kml)
def main(): print '== This is %s' % sys.argv[0] factory = kmldom.KmlFactory_GetFactory() print 'Create a LookAt with altitudeMode...' lookat = factory.CreateLookAt() lookat.set_altitudemode(kmldom.ALTITUDEMODE_RELATIVETOGROUND) print 'lookat.has_altitudemode()', lookat.has_altitudemode() print 'lookat.altitudemode()', lookat.get_altitudemode() if lookat.get_altitudemode() == kmldom.ALTITUDEMODE_RELATIVETOGROUND: print 'Yes, it is relativeToGround' print 'Serialize it to pretty xml...' lookat_kml = kmldom.SerializePretty(lookat) print lookat_kml
def CNML2KML(cnmlp, filename='mycnml.kml'): if not KMLDOM_ENABLED: print _('CNML2KML: function not available. kmldom module not found') return factory = kmldom.KmlFactory.GetFactory() doc = factory.CreateDocument() for node in cnmlp.getNodes(): coordinates = factory.CreateCoordinates() coordinates.add_latlng(node.latitude, node.longitude) point = factory.CreatePoint() point.set_coordinates(coordinates) placemark = factory.CreatePlacemark() placemark.set_name(node.title) placemark.set_geometry(point) doc.add_feature(placemark) xml = kmldom.SerializePretty(doc) with open(filename, 'w') as kmlfp: kmlfp.write(xml)
import kmldom import urllib2 import re factory = kmldom.KmlFactory_GetFactory() folder = factory.CreateFolder() coords = urllib2.urlopen( "https://www.debian.org/devel/developers.coords").readlines() for line in coords: coord = line.strip()[:-2].strip() lat, lon = re.split(" *", coord) placemark = factory.CreatePlacemark() placemark.set_name('Debian Developer') coordinates = factory.CreateCoordinates() coordinates.add_latlng(float(lat), float(lon)) point = factory.CreatePoint() point.set_coordinates(coordinates) placemark.set_geometry(point) folder.add_feature(placemark) document = factory.CreateDocument() document.add_feature(folder) kml = factory.CreateKml() kml.set_feature(document) with open("/srv/map.debian.net/html/data/developers.kml", "w") as out: out.write(kmldom.SerializePretty(kml))
def printKml(self): print kmldom.SerializePretty(self.kml)