def move_job_log(move_logger, source_workspace, target_workspace, state_of_interest): fc = "NISOURCE.GPSFMEJobLog" source_fc = os.path.join(source_workspace, fc) target_fc = os.path.join(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_oid = fieldnames + ["OID@"] state_index = fieldnames.index("TCCORGNAME") sql_clause = (None, 'ORDER BY "OBJECTID"') running_total = 0 with arcpy.da.SearchCursor(source_fc, fieldnames_oid, "", None, False, sql_clause) as sCur: with arcpy.da.InsertCursor(target_fc, fieldnames) as iCur: for row in sCur: insert_row = mc.tuple_without(row, -1) if (state_of_interest == 'OH' and sCur[state_index].lower() == 'nisourcecoh') or ( state_of_interest == 'PA' and sCur[state_index].lower() == 'nisourcefre') or ( state_of_interest == 'VA' and sCur[state_index].lower() == 'nisourcecgv'): inserted_oid = iCur.insertRow(insert_row) # print 'Match:', state_of_interest, sCur[-1] running_total += 1 move_logger.info("Total|" + 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 copy_fc(logger_local_fc, target_workspace, source_fc, target_fc, fc_gps_state): 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 + [dsc.OIDFieldName] where = """"GPS_STATE" ='{0}'""".format(fc_gps_state) where += """ AND "OBJECTID" >= {0}""" sql_clause = (None, 'ORDER BY "OBJECTID"') running_total = 0 cursor_counter = 0 batch_size = 100000 run_again = True start_oid = 0 # get the object id, query and sort by order id asc, keep the latest object id, then query ObjectID > that while run_again: edit = arcpy.da.Editor(target_workspace) edit.startEditing(False, True) edit.startOperation() run_again = False where_now = where.format(start_oid) with arcpy.da.SearchCursor(source_fc, fieldnames_oid, where_now, None, False, sql_clause) as sCur: with arcpy.da.InsertCursor(target_fc, fieldnames) as iCur: for row in sCur: if cursor_counter > batch_size: cursor_counter = 0 run_again = True start_oid = row[-1] break insert_row = MC.tuple_without(row, -1) inserted_oid = iCur.insertRow(insert_row) cursor_counter += 1 running_total += 1 if cursor_counter > 0 and cursor_counter % (batch_size / 10) == 0: print running_total edit.stopOperation() edit.stopEditing(True) logger_local_fc.info(source_fc + " | " + str(running_total))
def copy_line(copy_logger, target_workspace, source_fc, target_fc, fc_gps_state): 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@"] # where = """"OBJECTID" >= {0}""" sql_clause = (None, 'ORDER BY "OBJECTID"') running_total = 0 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) as iCur: for row in sCur: # insert_row = MC.tuple_without(MC.tuple_without(row, -1), -1) insert_row = mc.tuple_without(row, -1) if row[-2] is None: copy_logger.info(str(row[-1]) + " has None for Shape. Not copied.") continue if fc_gps_state == "OH" and row[-2].firstPoint.X < 4200000: inserted_oid = iCur.insertRow(insert_row) # print 'OH Match:', sCur[-1], sCur[-2].firstPoint.X, sCur[-2].firstPoint.Y running_total += 1 elif fc_gps_state == "VA" and row[-2].firstPoint.X >= 4200000 and row[-2].firstPoint.Y < 6440000: inserted_oid = iCur.insertRow(insert_row) # print 'VA Match:', sCur[-1], sCur[-2].firstPoint.X, sCur[-2].firstPoint.Y running_total += 1 elif fc_gps_state == "PA" and row[-2].firstPoint.X >= 4200000 and row[-2].firstPoint.Y >= 6440000: inserted_oid = iCur.insertRow(insert_row) # print 'PA Match:', sCur[-1], sCur[-2].firstPoint.X, sCur[-2].firstPoint.Y running_total += 1 edit.stopOperation() edit.stopEditing(True) copy_logger.info("Total|" + str(running_total))