def assign_fc_gisids(workspace, fc): running_total = 0 cursor_counter = 0 batch_size = 100000 run_again = True while run_again: gisid = MC.read_gisid_seed() edit = arcpy.da.Editor(workspace) edit.startEditing(False, True) edit.startOperation() run_again = False # UpdateCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}) with arcpy.da.UpdateCursor(fc, ["OID@", "GISID"], """"GISID" IS NULL OR "GISID" = 0""") as cursor: for row in cursor: if cursor_counter > batch_size: cursor_counter = 0 run_again = True break else: row[1] = gisid cursor.updateRow(row) cursor_counter += 1 running_total += 1 gisid += 1 if cursor_counter > 0 and cursor_counter % 10000 == 0: print cursor_counter MC.write_gisid_seed(gisid) edit.stopOperation() edit.stopEditing(True) logger.info(fc + "|" + str(running_total))
def move_workarea(move_logger, source_workspace, target_workspace, state_of_interest): fc = "NISOURCE.GPSWorkAreaPolygon" source_fc = os.path.join(source_workspace, fc) target_fc = os.path.join(target_workspace, fc) # MC.disable_editor_tracking(target_workspace, fc) arcpy.env.workspace = target_workspace dsc = arcpy.Describe(source_fc) fields = dsc.fields fieldnames = [field.name for field in fields if field.name != dsc.OIDFieldName and field.name != 'GLOBALID' and field.name != 'SHAPE'] fieldnames = fieldnames + ["SHAPE@"] fieldnames_oid = fieldnames + ["OID@"] fieldnames_insert = fieldnames + ["GISID"] state_index = fieldnames.index("WORKAREASTATE") sql_clause = (None, 'ORDER BY "OBJECTID"') running_total = 0 gisid = mc.read_gisid_seed() edit = arcpy.da.Editor(target_workspace) edit.startEditing(False, True) edit.startOperation() with arcpy.da.SearchCursor(source_fc, fieldnames_oid, "", None, False, sql_clause) as sCur: with arcpy.da.InsertCursor(target_fc, fieldnames_insert) as iCur: for row in sCur: insert_row = mc.tuple_without(row, -1) if state_of_interest == sCur[state_index]: insert_row += [gisid] inserted_oid = iCur.insertRow(insert_row) # print 'Match:', state_of_interest, sCur[-1] running_total += 1 gisid += 1 edit.stopOperation() edit.stopEditing(True) move_logger.info("Total|" + str(running_total)) del sCur, iCur mc.write_gisid_seed(gisid)
def assign_gisid_matches(preprod_workspace, prod_workspace, feature_class, preprod_final_list, prod_final_list, gisid, p_fw): pp_where = '"POINTRECORD_ID" IS NOT NULL AND "QASTATUS" = 600 AND "GISID" IS NULL' pp_list = get_list_null_gisids(preprod_workspace, feature_class, pp_where) p_where = '"POINTRECORD_ID" IS NOT NULL AND "GISID" IS NULL' p_list = get_list_null_gisids(prod_workspace, feature_class, p_where) # sort by the QA Status so the most important is always first pp_list = sorted(pp_list, key=lambda x: (x[0], x[1], -x[2], -x[3])) p_list = sorted(p_list, key=lambda x: (x[0], x[1], -x[2], -x[3])) logger.info('|'.join(["Total_Queried", str(len(pp_list)), str(len(p_list))])) # uniqueify pp_uni = pp_list_2_dict_with_lists(pp_list) p_uni = p_list # f7(p_list) logger.info('|'.join(["Total_Uniqued", str(len(pp_uni)), str(len(p_uni))])) local_count = 0 for p_item in p_uni: if p_item[1] in pp_uni: list_gisids_for_pp_point = pp_uni[p_item[1]] if list_gisids_for_pp_point: # if empty, this is false curr_pp_gisid = list_gisids_for_pp_point.pop(0) # pop off the top match prod_final_list.append((p_item, gisid)) preprod_final_list.append((curr_pp_gisid, gisid)) print_tup2(p_fw, curr_pp_gisid, p_item, gisid) gisid += 1 local_count += 1 logger.info('|'.join(["Total_Matched", str(local_count), str(local_count)])) MC.write_gisid_seed(gisid) return gisid, local_count
logger.info('|'.join(["Total_Matched", str(local_count), str(local_count)])) MC.write_gisid_seed(gisid) return gisid, local_count # # start of program # logger = MC.setup_logging('migrate1') logger.info("Starting program...") # setting this as it should start with this number for Migration 1 gisid_seed = 70000001 # MC.read_gisid_seed() MC.write_gisid_seed(gisid_seed) pp_workspace = MC.get_preprod_workspace() p_workspace = MC.get_prod_workspace() pp_final_list = [] p_final_list = [] total_matched_count = 0 with open("results/mig1_results.txt", "w+") as p_f: for fc in MC.get_gps_fcs(p_workspace): # fc = 'GPS_ControllableFitting' logger.info(fc) gisid_seed, fc_count = assign_gisid_matches(pp_workspace, p_workspace, fc, pp_final_list, p_final_list, gisid_seed, p_f)