def run_lucz_plan(): for l in LUCZ_plan: arcpy.AddField_management(os.path.join(out_path, out_name), l['col_name'] + '_acr', 'DOUBLE') arcpy.AddField_management(os.path.join(out_path, out_name), l['col_name'] + '_pct', 'DOUBLE') arcpy.AddField_management(os.path.join(out_path, out_name), l['col_name_septic'], 'DOUBLE') arcpy.AddField_management(os.path.join(out_path, out_name), l['col_name_septic'], 'DOUBLE') calc_acre(l) septic_calc_fields_plan.append(l['col_name_septic']) calc_LUCZ_septic_plan(l) arcpy.DeleteField_management(os.path.join(out_path, out_name), l['col_name'] + '_acr') arcpy.DeleteField_management(os.path.join(out_path, out_name), l['col_name'] + '_pct') arcpy.AddField_management(os.path.join(out_path, out_name), septic_calc_fields_plan[0], 'DOUBLE') with arcpy.da.UpdateCursor(hl_rsc, septic_calc_fields_plan) as cursor: for row in cursor: row[0] = math.floor((row[1] or 0) + (row[2] or 0) + (row[3] or 0)) cursor.updateRow(row)
def go(): # Set which functions to process calc_crit_habitat = True calc_values = True calc_septic_density = True calc_rsc_area = True fms = arcpy.FieldMappings() print('Adding Field Mappings') for p in parcel_fields_tokeep: print(p) fm = arcpy.FieldMap() fm.addInputField(parcels, p) fms.addFieldMap(fm) arcpy.FeatureClassToFeatureClass_conversion(parcels, out_path, out_name, '', fms) arcpy.AddIndex_management(os.path.join(out_path, out_name), "PCL_GUID", "GUIDIndex", "UNIQUE", "ASCENDING") print('Recalculating geometry...') arcpy.CalculateField_management(hl_rsc, parcel_ac, "!shape.area@acres!", "PYTHON_9.3", "#") # get the plan conformance status print('\n*Getting plan conformance values*') get_pc(hl_rsc) if calc_crit_habitat: species_field_exist = False field_list = arcpy.ListFields(hl_rsc) print('Getting fields...') for field in field_list: if field.name == species_field: species_field_exist = True if not species_field_exist: print("\nAdding species field...") arcpy.AddField_management(hl_rsc, species_field, 'TEXT', field_length=600) print('Addding index to LINKID..') try: arcpy.AddIndex_management(os.path.join(out_path, fc['Critical Wildlife Habitat']), "LINKID", "LINK", "NON_UNIQUE", "NON_ASCENDING") arcpy.AddIndex_management(os.path.join(out_path, ft['Species Table']), "LINKID;COMNAME", "LINK", "NON_UNIQUE", "NON_ASCENDING") except: print('error adding index. Already exists?') crit_habitat_species() else: print(species_field + " field already exists. ") crit_habitat_species() if calc_values: get_values() if calc_septic_density: calc_septic() if calc_rsc_area: for f in area_features: arcpy.AddField_management(os.path.join(out_path, out_name), f['col_name'] + '_acr', 'DOUBLE') arcpy.AddField_management(os.path.join(out_path, out_name), f['col_name'] + '_pct', 'DOUBLE') calc_acre(f) # populate null municipalities and county names print('\n*Checking for null municipal and county names*') check_val(hl_rsc) print('\n*Checking for null pams pin (gis_pin)*') check_pamspin(hl_rsc)