def import_bumi(file): print 'Bumi', file rows = DBSession.execute('SELECT d_nop, wkb_geometry geom FROM mi' + file) try: for row in rows: kode = get_kd_nop(row['d_nop']) qry = DBSession.query(SigBumi).\ filter_by( kd_propinsi=kode['kd_pro'], kd_dati2=kode['kd_dat'], kd_kecamatan=kode['kd_kec'], kd_kelurahan=kode['kd_kel'], kd_blok=kode['kd_blok'], no_urut=kode['no_urut'], kd_jns_op=kode['kd_jns'], ).first() if not qry: qry = SigBumi() qry.kd_propinsi = kode['kd_pro'] qry.kd_dati2 = kode['kd_dat'] qry.kd_kecamatan = kode['kd_kec'] qry.kd_kelurahan = kode['kd_kel'] qry.kd_blok = kode['kd_blok'] qry.no_urut = kode['no_urut'] qry.kd_jns_op = kode['kd_jns'] qry.geom = row.geom DBSession.add(qry) finally: DBSession.flush() DBSession.commit()
def import_bng(file): print 'Bangunan', file rows = DBSession.execute('SELECT d_nop, wkb_geometry geom FROM mi' + file) #try: for row in rows: kode = get_kd_bng(row['d_nop']) qry = DBSession.query(SigBng).\ filter_by( kd_propinsi=kode['kd_pro'], kd_dati2=kode['kd_dat'], kd_kecamatan=kode['kd_kec'], kd_kelurahan=kode['kd_kel'], kd_blok=kode['kd_blok'], no_urut=kode['no_urut'], kd_jns_op=kode['kd_jns'], no_bng=kode['no_bng'], ).first() if not qry: qry = SigBng() qry.kd_propinsi = kode['kd_pro'] qry.kd_dati2 = kode['kd_dat'] qry.kd_kecamatan = kode['kd_kec'] qry.kd_kelurahan = kode['kd_kel'] qry.kd_blok = kode['kd_blok'] qry.kd_no_urut = kode['no_urut'] qry.kd_jns_op = kode['kd_jns'] qry.no_bng = kode['no_bng'] qry.geom = row.geom DBSession.add(qry)
def import_kelurahan(file): print 'Kelurahan', file rows = DBSession.execute( 'SELECT d_kd_kel, d_nm_kel, wkb_geometry geom FROM mi' + file) try: for row in rows: kode = get_kd_kel(row['d_kd_kel']) qry = DBSession.query(SigKelurahan).\ filter_by( kd_propinsi=kode['kd_pro'], kd_dati2=kode['kd_dat'], kd_kecamatan=kode['kd_kec'], kd_kelurahan=kode['kd_kel'], ).first() if not qry: qry = SigKelurahan() qry.kd_propinsi = kode['kd_pro'] qry.kd_dati2 = kode['kd_dat'] qry.kd_kecamatan = kode['kd_kec'] qry.kd_kelurahan = kode['kd_kel'] qry.nm_kelurahan = row['d_nm_kel'] qry.geom = row.geom DBSession.add(qry) finally: DBSession.flush() DBSession.commit()