#NEWLINE# def add_element( self , elem ) : #NEWLINE# #INDENT# 'Add an element to the datastore.' #NEWLINE# self . db . store ( elem ) #NEWLINE# ns = elem . namespace #NEWLINE# backreference = make_backreference ( ns , elem . id ) #NEWLINE# if self . verbose : #NEWLINE# #INDENT# increment_stats ( ns ) #NEWLINE# #UNINDENT# if ( ns == C . NODE ) : #NEWLINE# #INDENT# self . geotable . add ( elem ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ns == C . WAY ) : #NEWLINE# #INDENT# for ( rstatus , node_or_key ) in self . db . fetch_keys ( C . NODE , map ( str , elem [ C . NODES ] ) ) : #NEWLINE# #INDENT# if rstatus : #NEWLINE# #INDENT# node = node_or_key #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# node = new_osm_element ( C . NODE , node_or_key ) #NEWLINE# #UNINDENT# node [ C . REFERENCES ] . add ( backreference ) #NEWLINE# self . db . store ( node ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ns == C . RELATION ) : #NEWLINE# #INDENT# def _retrieve( selector , members ) : #NEWLINE# #INDENT# return [ str ( mref ) for ( mref , mrole , mtype ) in members if ( mtype == selector ) ] #NEWLINE# #UNINDENT# members = elem [ C . MEMBERS ] #NEWLINE# elements = [ ] #NEWLINE# for ns in [ C . NODE , C . WAY , C . RELATIONS ] : #NEWLINE# #INDENT# elements . append ( ( ns , _retrieve ( ns , members ) ) ) #NEWLINE# #UNINDENT# for ( ns , refs ) in elements : #NEWLINE# #INDENT# if ( len ( refs ) == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for ( rstatus , node_or_key ) in self . db . fetch_keys ( ns , refs ) : #NEWLINE# #INDENT# if rstatus : #NEWLINE# #INDENT# elem = node_or_key #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# elem = new_osm_element ( ns , node_or_key ) #NEWLINE# #UNINDENT# elem [ C . REFERENCES ] . add ( backreference ) #NEWLINE# self . db . store ( elem )