示例#1
0
# -*- coding: utf-8 -*-
"""
	geo/__init__.py
	~~~~~~~~~~~~~~~~~~~~
	:By Michael Geary - http://mg.to/
	:See UNLICENSE or http://unlicense.org/ for public domain notice.
"""

#import xml.etree.ElementTree as ET
import elementtree.ElementTree as ET

#ET._namespace_map['http://www.opengis.net/kml/2.2'] = 'kml'
ET.register_namespace( 'kml', 'http://www.opengis.net/kml/2.2' )

class Kml( object ):
	
	def __init__( self, kml ):
		'''	Parse a KML file.
		'''
		self.kml = ET.parse( kml )
		self.ns = self.kml.getroot().tag[1:-4]
	
	def toGeo( self ):
		'''	Return a GeoJSON-compatible dict with each KML folder
			converted to a Feature with the name of that folder,
			and each Feature containing a single MultiPolygon with
			either the MultiGeometry or Polygon from the KML.
			TODO: the bbox doesn't work if you cross the
			180 meridian, but that's OK for the moment.
			TODO: use dict/list comprenhensions for some of the loops.
		'''