AnsweredAssumed Answered

Help refining a script

Question asked by bradleyglennjones on Jul 9, 2015
Latest reply on Jul 10, 2015 by bradleyglennjones

I'm building a tool where a coworker can enter an ID# (called PWS ID) and then go through choose from a list of features (about 15) they want added from to the map based on the ID#. The tool will select the features based on the ID number, add them as a layer to the map and add the symbology. It wont create any new data, just what is stored in the map memory while it is open. I'm just working on the code at this point. I have a script with A LOT of variables and iterations of arcpy.MakefeatureLayer_management and arcpy.ApplySymbologyFromLayer_managment functions.  I know I can hardcode the path to the .lyr files used for symbology, but  I'm drawing a blank from there.  I'm very much a Python novice and I cant figure out if it can be done by a for loop with arcpy.mapping.ListLayers (for symbology) or some other way.


Also, I didn't add the whole script.  I left out the code for labels and applying the extent of a layer.





# Import module(s)

import arcpy

from arcpy import env


# Set overwrite option

env.overwriteOutput = True


# Local variables. Reduce number of variables. Hardcode path for ApplySymbologyFromLayer function or create a list or dictionary?

pws = "PWS_ID='465'" # SQL query.

***_pws = "PWS_ID1 = '465'" # SQL query. Assessment table has different firle dname for PWS ID.

mtr_recpws = "REC_ID = '465'" # SQL query. 'REC_ID" is PWS ID of PWS receiving water through master meter, I assume.

sources = "V:\\Source Water Protection\\SWAP Model\\SWAP.code_newrasters\\GIS\\SWAP.gdb\\sources" # Will need to change if used outside           of SWPP staff because of directory permissions.

assessment = "V:\\Source Water Protection\\SWAP Model\\SWAP.code_newrasters\\GIS\\SWAP.gdb\\assessment_areas" # Will need to change           if used outside of SWPP staff because of directory permissions. Assessments not in WATER_FACILITY.gdb.









waterline = "V:\\WATER_FACILITY\\WATERLINES.gdb"





src_layer = "Sources"

***_layer = "Assessment Area"

srvc_layer = "Service Area"

bacti_layer = "Bacti"

wtp_layer = "WTP"

dbp_layer = "DBP"

dbp2_layer = "DBP Stage 2"

tank_layer = "Tank"

valve_layer = "Valve"

mtr_layer = "Master Meter"

line_layer = "Waterline"

pump_layer = "Pump Station"

prv_layer = "PRV"

press_layer = "Pressure Plane"

ofc_layer = "Office"

src_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\SOURCE.lyr"

***_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\ASSESSMENT.lyr"

wtp_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\WTP.lyr"

valve_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\VALVE.lyr"

tank_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\TANK.lyr"

dbp_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\DBP.lyr"

dbp2_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\DBP2.lyr"

bacti_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\BACTI.lyr"

mtr_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\MASTER_METER.lyr"

ofc_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\OFFICE.lyr"

prv_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\PRV.lyr"

pump_symb = "V:\\Source Water Protection\\PWS_ID_Tool\\PUMP.lyr"


# Make feature layers

arcpy.MakeFeatureLayer_management(office, ofc_layer, pws)

arcpy.MakeFeatureLayer_management(press_plane, press_layer, pws)

arcpy.MakeFeatureLayer_management(srvc_area, srvc_layer, pws)

arcpy.MakeFeatureLayer_management(mstr_mtr, mtr_layer, mtr_recpws)

arcpy.MakeFeatureLayer_management(pumpstn, pump_layer, pws)

arcpy.MakeFeatureLayer_management(prv, prv_layer, pws)

arcpy.MakeFeatureLayer_management(tank, tank_layer, pws)

arcpy.MakeFeatureLayer_management(valve, valve_layer, pws)

arcpy.MakeFeatureLayer_management(wtp, wtp_layer, pws)

arcpy.MakeFeatureLayer_management(dbp, dbp_layer, pws)

arcpy.MakeFeatureLayer_management(dbp2, dbp2_layer, pws)

arcpy.MakeFeatureLayer_management(bacti, bacti_layer, pws)

arcpy.MakeFeatureLayer_management(sources, src_layer, pws)

arcpy.MakeFeatureLayer_management(assessment, ***_layer, ***_pws)



# Apply the symbology from the symbology layer to the input layers

arcpy.ApplySymbologyFromLayer_management(src_layer, src_symb)

arcpy.ApplySymbologyFromLayer_management(***_layer, ***_symb)

arcpy.ApplySymbologyFromLayer_management(bacti_layer, bacti_symb)

arcpy.ApplySymbologyFromLayer_management(wtp_layer, wtp_symb)

arcpy.ApplySymbologyFromLayer_management(valve_layer, valve_symb)

arcpy.ApplySymbologyFromLayer_management(dbp_layer, dbp_symb)

arcpy.ApplySymbologyFromLayer_management(dbp2_layer, dbp2_symb)

arcpy.ApplySymbologyFromLayer_management(tank_layer, tank_symb)

arcpy.ApplySymbologyFromLayer_management(valve_layer, valve_symb)

arcpy.ApplySymbologyFromLayer_management(mtr_layer, mtr_symb)

arcpy.ApplySymbologyFromLayer_management(ofc_layer, ofc_symb)

arcpy.ApplySymbologyFromLayer_management(prv_layer, prv_symb)

arcpy.ApplySymbologyFromLayer_management(pump_layer, pump_symb)