def insert_lines(line_fc, list_lines, fields_for_lines, is_del, writer): counter = 0 with arcpy.da.InsertCursor(line_fc, tuple(fields_for_lines)) as iCursor: for line in list_lines: corrected_company = cobb_common.extract_vendor(line[1][0][3], line[1][0][2]) array = arcpy.Array() array.add(arcpy.Point(line[0][0][0], line[0][0][1], line[0][0][2])) array.add(arcpy.Point(line[0][1][0], line[0][1][1], line[0][1][2])) row = (line[3], # Footage None, # OID corrected_company, # Vendor line[1][0][-3], # Facility Type 'Mummichog', # Algo version None, # Equipment line[1][0][5] if is_del else line[1][0][6], # Report Date line[1][0][7], # Job File Name line[1][0][8], # Job Order Number line[1][0][9], # Operator Name line[1][0][10], # Collection Type line[1][0][11], # Collection Date line[0][2], # Aban Indic arcpy.Polyline(array, None, True) ) iCursor.insertRow(row) writer.writerow((line[1][0][8], corrected_company, line[1][0][7], line[1][0][11], line[1][0][-3], line[3]) ) counter += 1 return counter
a_ext = arcpy.da.TableToNumPyArray(fc, ['ESTIMATEDFOOTAGE', 'COMPANY'], where_clause_ext) for vendor in vendor_dict.keys(): vendor_dict[vendor].append(sum_feet_by_vendor(a_ext, vendor)) a_int = arcpy.da.TableToNumPyArray(fc, ['ESTIMATEDFOOTAGE', 'COMPANY'], where_clause_int) for vendor in vendor_dict.keys(): vendor_dict[vendor].append(sum_feet_by_vendor(a_int, vendor)) for f in vendor_dict: total_output = (current_state, f) + tuple(vendor_dict[f]) + (vendor_dict[f][-2] + vendor_dict[f][-1], end_date) csv_writer.writerow(tuple(total_output)) states = ['OH', 'PA', 'VA'] fc = 'GPSWorkAreaPolygon' start, end, boy, bot = cobb_common.satandsun(datetime.date.today()) c_file = open('Cobb0_EstFeet.csv', 'wb') c_writer = csv.writer(c_file, quoting=csv.QUOTE_NONNUMERIC, dialect='excel') heading = ('State', 'Vendor', 'Work Area Est Footage', 'External FAA Footage', 'Internal FAA Footage', 'Total FAA Footage', 'End Date') c_writer.writerow(heading) for current_state in states: dest_env_folder = 'E:/Richard/FileGBs/' # dest_env_db = "{}_Cobbler_{}.gdb".format(current_state, datetime.datetime.now().strftime("%m%d")) dest_env_db = "{}_Cobbler_0815.gdb".format(current_state) arcpy.env.workspace = dest_env_folder + dest_env_db vendors = build_vendor_list(fc)
line_fcs = ['GPS_GasMain_Line_Delivered', 'GPS_ServiceLine_G_Line_Delivered', 'GPS_GasMain_Line_Approved', 'GPS_ServiceLine_G_Line_Approved', ] c_file = open('Cobb0_Footages.csv', 'wb') c_writer = csv.writer(c_file, quoting=csv.QUOTE_NONNUMERIC, dialect='excel') heading = ('State', 'Vendor', 'Main Del', 'Service Del', 'Main App', 'Service App', 'End Date') c_writer.writerow(heading) for current_state in states: dest_env_folder = 'E:/Richard/FileGBs/' # dest_env_db = "{}_Cobbler_{}.gdb".format(current_state, datetime.datetime.now().strftime("%m%d")) dest_env_db = "{}_Cobbler_0815.gdb".format(current_state) arcpy.env.workspace = dest_env_folder + dest_env_db vendors = cobb_common.build_vendor_list(line_fcs) start, end, boy, bot = cobb_common.satandsun(datetime.date.today()) calc_feet(current_state, bot, end, line_fcs, vendors, c_writer) # for day in cobb_common.datespan(datetime.date(2016, 1, 2), datetime.date.today(), delta=datetime.timedelta(days=7)): # # start = day - datetime.timedelta(days=6) # # print current_state, start.isoformat(), day.isoformat() # calc_feet(current_state, bot, day.isoformat(), line_fcs, vendors, c_writer) c_file.close()
'GPS_ServiceLine_G_Point_Delivered', 'GPS_ChallengePoint_Delivered', 'GPS_CustomerConnection_G_Delivered', 'GPS_GasValve_Delivered', 'GPS_GasMain_Point_Approved', 'GPS_ServiceLine_G_Point_Approved', 'GPS_ChallengePoint_Approved', 'GPS_CustomerConnection_G_Approved', 'GPS_GasValve_Approved', ] states = ["OH", "PA", "VA"] fc_fields = ['VENDOR_FOLDER', 'GPS_OPERATORCOMPANY', 'WORKLOCATIONID'] where_clause = """"VENDOR_FOLDER" IS NOT NULL""" for current_state in states: print current_state dest_env_folder = 'E:/Richard/FileGBs/' # dest_env_db = "{}_Cobbler_{}.gdb".format(current_state, datetime.datetime.now().strftime("%m%d")) dest_env_db = "{}_Cobbler_0815.gdb".format(current_state) arcpy.env.workspace = dest_env_folder + dest_env_db for fc in point_fcs: with arcpy.da.UpdateCursor(fc, fc_fields, where_clause) as cursor: for row in cursor: corrected_company = cobb_common.extract_vendor(row[0], row[1]) row[2] = row[1] row[1] = corrected_company cursor.updateRow(row) print 'Done!'
def make(state_name, spatial_reference): dest_env_folder = 'E:/Richard/FileGBs/' dest_env_db = "{}_Cobbler_{}.gdb".format(state_name, datetime.datetime.now().strftime("%m%d")) dest_env = dest_env_folder + dest_env_db fcs = [ ('GPS_GasMain_Line_Delivered', 'GPS Gas Main Line Delivered'), ('GPS_ServiceLine_G_Line_Delivered', 'GPS Gas Service Line Delivered'), ('GPS_GasMain_Line_Approved', 'GPS Gas Main Line Approved'), ('GPS_ServiceLine_G_Line_Approved', 'GPS Gas Service Line Approved') ] arcpy.CreateFileGDB_management(dest_env_folder, dest_env_db) arcpy.env.workspace = dest_env # create feature class for fc_pair in fcs: fc = fc_pair[0] safe_add_feature_class(dest_env, fc, 'POLYLINE', None, 'DISABLED', 'ENABLED', spatial_reference) arcpy.AlterAliasName(fc, fc_pair[1]) # add global id arcpy.AddGlobalIDs_management(fc) # add fields field_names = [f.name for f in arcpy.ListFields(fc)] safe_add_field(fc, "FOOTAGE3D", "DOUBLE", 32, 2, "", "3D Footage", None, None, None, field_names) safe_add_field(fc, "GPS_POINTCOLLECTIONDATE", "DATE", "", "", "", "GPS Point Collection Date", None, None, None, field_names) safe_add_field(fc, "COLLECTIONTYPE", "LONG", 10, 0, "", "Collection Type Category", None, None, 'GPS_Collection_Type', field_names) safe_add_field(fc, "FACILITYTYPE", "TEXT", "", "", 50, "Facility Type", None, None, None, field_names) safe_add_field(fc, "GPS_OPERATORCOMPANY", "TEXT", "", "", 30, "GPS Collector Company", None, None, None, field_names) safe_add_field(fc, "GPS_OPERATORNAME", "TEXT", "", "", 20, "GPS Operator Name", None, None, None, field_names) safe_add_field(fc, "GPS_JOBORDERNUMBER", "TEXT", "", "", 9, "GPS Job Order Number", None, None, None, field_names) safe_add_field(fc, "JOB_FILENAME", "TEXT", "", "", 50, "Job File Name", None, None, None, field_names) safe_add_field(fc, "REPORT_DATE", "DATE", "", "", "", "Date Used for Reporting", None, None, None, field_names) safe_add_field(fc, "CREATIONUSER", "TEXT", "", "", 20, "Creation User", None, None, None, field_names) safe_add_field(fc, "DATECREATED", "DATE", "", "", "", "Date Created", None, None, None, field_names) safe_add_field(fc, "DATEMODIFIED", "DATE", "", "", "", "Date Modified", None, None, None, field_names) safe_add_field(fc, "LASTUSER", "TEXT", "", "", 20, "Last User", None, None, None, field_names) safe_add_field(fc, "ALGORITHM_VERSION", "TEXT", "", "", 15, "Algorithm Version", None, None, None, field_names) safe_add_field(fc, "GISID", "LONG", 10, 0, "", "GISID", None, None, None, field_names) safe_add_field(fc, "EQUIPMENT", "TEXT", "", "", 20, "Equipment", None, None, None, field_names) safe_add_field(fc, "ABANDON_INDICATOR", "TEXT", "", "", 5, "Abandoned Indicator", None, None, 'Yes_No Indicator_G', field_names) safe_add_field(fc, "MXASSETUID", "DOUBLE", 12, 0, "", "Maximo Asset Unique ID", None, None, None, field_names) safe_add_field(fc, "MXASSETNUM", "TEXT", "", "", 20, "Maximo Asset Number", None, None, None, field_names) safe_add_field(fc, "MXCREATIONSTATE", "SHORT", 5, 0, "", "Maximo Creation State", None, None, None, field_names) safe_add_field(fc, "WORKREQUESTID", "TEXT", "", "", 20, "Work Request ID", None, None, None, field_names) safe_add_field(fc, "DESIGNID", "TEXT", "", "", 20, "Design ID", None, None, None, field_names) safe_add_field(fc, "WORKLOCATIONID", "TEXT", "", "", 20, "Work Location ID", None, None, None, field_names) safe_add_field(fc, "WORKFLOWSTATUS", "SHORT", 10, 0, "", "Work Flow Status", None, None, 'MM Work Flow Status', field_names) safe_add_field(fc, "WORKFUNCTION", "SHORT", 10, 0, "", "Work Function", None, None, None, field_names) cobb_common.add_index(fc, ["JOB_FILENAME"]) arcpy.EnableEditorTracking_management(fc, "CREATIONUSER", "DATECREATED", "LASTUSER", "DATEMODIFIED", "ADD_FIELDS", "UTC")
'Service <> 100', 'Service = 500:600:700', 'Service = 700', 'Service = 600', 'CHPO <> 100', 'CHPO = 500:600:700', 'CHPO = 700', 'CHPO = 600', 'CusConn <> 100', 'CusConn = 500:600:700', 'CusConn = 700', 'CusConn = 600', 'Valve <> 100', 'Valve = 500:600:700', 'Valve = 700', 'Valve = 600', 'Main <> 600', 'Main = 1000', 'Service <> 600', 'Service = 1000', 'CHPO <> 600', 'CHPO = 1000', 'CusConn <> 600', 'CusConn = 1000', 'Valve <> 600', 'Valve = 1000', 'End Date') c_writer.writerow(heading) for current_state in states: dest_env_folder = 'E:/Richard/FileGBs/' # dest_env_db = "{}_Cobbler_{}.gdb".format(current_state, datetime.datetime.now().strftime("%m%d")) dest_env_db = "{}_Cobbler_0815.gdb".format(current_state) arcpy.env.workspace = dest_env_folder + dest_env_db vendors = cobb_common.build_vendor_list(point_fcs, """"POINTRECORD_ID" IS NOT NULL""") start, end, boy, bot = cobb_common.satandsun(datetime.date.today()) calc_points(current_state, bot, end, point_fcs, vendors, c_writer) # for day in cobb_common.datespan(datetime.date(2016, 1, 2), datetime.date.today(), delta=datetime.timedelta(days=7)): # # start = day - datetime.timedelta(days=6) # # print current_state, start.isoformat(), day.isoformat() # calc_points(current_state, bot, day, point_fcs, vendors, c_writer) c_file.close()