def upload_fusion_table(): def copy_template_table(service): template_ID = gen.get_tableId_by_table_name('Template_NCSS', service, google_service='fusion') request = service.table().copy(tableId = template_ID) response = request.execute() return response def rename_copied_table(service, response): group_table_ID = response['tableId'] body = response body['name'] = 'NCSS' request = service.table().update(tableId = group_table_ID, body = body) response = request.execute() return(group_table_ID) def insert_rows_into_table(service, file_name, group_table_ID): media = gac.http.MediaFileUpload(file_name, resumable=True) request = service.table().importRows(tableId = group_table_ID, media_body = media) response = request.execute() service = gen.authenticate_fusion_api() copied_table = copy_template_table(service) group_table_ID = rename_copied_table(service, copied_table) insert_rows_into_table(service, dirs.int_ncss_output, group_table_ID) return group_table_ID
def feature_to_list(group_table_ID, feature, start_index, end_index): service = gen.authenticate_fusion_api() n_rows = service.query().sql(sql='SELECT COUNT() FROM ' + group_table_ID).execute()['rows'][0][0] feature_list = [ee.Feature(feature.toList(1,i).get(0)) for i in xrange(int(n_rows))] if(end_index > len(feature_list)): end_index = len(feature_list) feature_list = feature_list[start_index: end_index] return(feature_list)
def upload_fusion_table(group, group_name, kml_name): print("Uploading table " + str(group)) service = gen.authenticate_fusion_api() copied_table = copy_template_table(service) group_table_ID = rename_copied_table(service, copied_table, group) placemarks = read_in_kml(kml_name) kml_to_csv(placemarks, group_name) insert_rows_into_table(service, group_table_ID, group_name) return group_table_ID