#NEWLINE# def _to_geojson( self , data , geo_col ) : #NEWLINE# #INDENT# def _parse_geopoint( raw ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# latlon = [ float ( k ) for k in re . split ( ' *,? *' , raw ) [ : 2 ] ] #NEWLINE# return [ latlon [ 1 ] , latlon [ 0 ] ] #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# metadata = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# def points( ) : #NEWLINE# #INDENT# for row in data : #NEWLINE# #INDENT# if ( '_meta' in row ) : #NEWLINE# #INDENT# metadata . update ( row [ '_meta' ] ) #NEWLINE# continue #NEWLINE# #UNINDENT# geo = row [ geo_col ] #NEWLINE# if ( geo is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# e = geo #NEWLINE# depth = 0 #NEWLINE# while hasattr ( e , '__iter__' ) : #NEWLINE# #INDENT# e = e [ 0 ] #NEWLINE# depth += 1 #NEWLINE# #UNINDENT# if ( depth < 2 ) : #NEWLINE# #INDENT# if ( depth == 0 ) : #NEWLINE# #INDENT# geo = _parse_geopoint ( geo ) #NEWLINE# if ( geo is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# feature_type = 'Point' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( depth == 2 ) : #NEWLINE# #INDENT# geo = [ geo ] #NEWLINE# depth += 1 #NEWLINE# #UNINDENT# feature_type = ( 'MultiPolygon' if ( depth == 4 ) else 'Polygon' ) #NEWLINE# #UNINDENT# properties = dict ( ( ( k , v ) for ( k , v ) in row . iteritems ( ) if ( k != geo_col ) ) ) #NEWLINE# display_props = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( k , v ) in properties . iteritems ( ) : #NEWLINE# #INDENT# if ( isinstance ( v , dict ) and ( set ( v . keys ( ) ) == set ( ( 'html' , 'sort_key' ) ) ) ) : #NEWLINE# #INDENT# properties [ k ] = v [ 'sort_key' ] #NEWLINE# display_props [ ( '__disp_%s' % k ) ] = v [ 'html' ] #NEWLINE# #UNINDENT# #UNINDENT# properties . update ( display_props ) #NEWLINE# ( yield { #NEWLINE# #INDENT# 'type' : 'Feature' , #NEWLINE# 'geometry' : { #NEWLINE# #INDENT# 'type' : feature_type , #NEWLINE# 'coordinates' : geo , #NEWLINE# #UNINDENT# } , #NEWLINE# 'properties' : properties , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# #UNINDENT# features = list ( points ( ) ) #NEWLINE# return { #NEWLINE# #INDENT# 'type' : 'FeatureCollection' , #NEWLINE# 'features' : features , #NEWLINE# 'metadata' : metadata , #NEWLINE# #UNINDENT# }