def main(): # GET PARAMETER VALUES Analysis_Area = arcpy.GetParameterAsText(0) Current_Anthro_Features_Provided = arcpy.GetParameterAsText(1) # optional Dist_Lek = arcpy.GetParameterAsText(2) # DEFINE DIRECTORIES # Get the pathname to this script scriptPath = sys.path[0] arcpy.AddMessage("Script folder: " + scriptPath) # Construct pathname to workspace workspace = arcpy.Describe(Analysis_Area).path arcpy.AddMessage("Project geodatabase: " + workspace) # Instantiate a ccsStandard object ccsStandard = ccslib.ccsStandard(workspace, scriptPath) # ENVIRONMENT SETTINGS # Set workspaces arcpy.env.workspace = workspace scratch_folder = os.path.join(arcpy.Describe(workspace).path, 'scratch') if arcpy.Exists(scratch_folder): pass else: arcpy.CreateFolder_management( arcpy.Describe(workspace).path, 'scratch') arcpy.env.scratchWorkspace = scratch_folder # Overwrite outputs arcpy.env.overwriteOutput = True # DEFINE VARIABLES FOR INPUT DATA AnthroAttributeTable = ccsStandard.AnthroAttributeTable emptyRaster = ccsStandard.EmptyRaster inputDataPath = ccsStandard.InputDataPath # Filenames for feature classes and raster used by this script ELIGIBLE_PROPOSED_FEATURES = "Proposed_Surface_Disturbance_Eligible" DEBIT_PROJECT_AREA = "Debit_Project_Area" # Filenames for feature classes and rasters created by this script CURRENT_ANTHRO_FEATURES = "Current_Anthro_Features" PROJECTED_ANTHRO_FEATURES = "Projected_Anthro_Features" PERMANENT_ANTHRO_FEATURES = "Permanent_Anthro_Features" CURRENT_ANTHRO_DISTURBANCE = "Current_Anthro_Disturbance" PROJECTED_ANTHRO_DISTURBANCE = "Projected_Anthro_Disturbance" PERMANENT_ANTHRO_DISTURBANCE = "Permanent_Anthro_Disturbance" MAP_UNITS = "Map_Units" # ------------------------------------------------------------------------ # FUNCTION CALLS # Check tool version ccslib.CheckToolVersion() # Check out Spatial Analyst extension ccslib.CheckOutSpatialAnalyst() # Check Analysis_Area expected_fcs = [ELIGIBLE_PROPOSED_FEATURES, DEBIT_PROJECT_AREA] ccslib.CheckPolygonInput(Analysis_Area, expected_fcs=expected_fcs) # Create Current_Anthro_Features layer, or copy provided into geodatabase if Current_Anthro_Features_Provided: # Clear selection, if present ccslib.ClearSelectedFeatures(Current_Anthro_Features_Provided) # Check Current_Anthro_Features required_fields = [ "Type", "Subtype", "Overlap_Status", "Returned", "Subtype_As_Modified" ] no_null_fields = None expected_fcs = None ccslib.CheckPolygonInput(Current_Anthro_Features_Provided, required_fields, expected_fcs, no_null_fields) # Update message arcpy.AddMessage("Copying Current_Anthro_Features to project " "geodatabase") # Copy Current_Anthro_Features to geodatabase provided_input = Current_Anthro_Features_Provided parameter_name = CURRENT_ANTHRO_FEATURES Current_Anthro_Features = ccslib.AdoptParameter(provided_input, parameter_name, preserve_existing=True) else: # Update message arcpy.AddMessage("Merging all clipped anthropogenic features to " "create the Current_Anthro_Features layer") # Merge features (selecting only polygon features) fileList = arcpy.ListFeatureClasses("Anthro*Clip", feature_type="Polygon") out_name = CURRENT_ANTHRO_FEATURES Current_Anthro_Features = ccslib.MergeFeatures(fileList, out_name) # Simplify fields. critical to remove any fields named # 'Surface_Disturbance' in Current_Anthro_Features before joining # Proposed_Surface_Disturbance to create Projected_Anthro_Features allowable_fields = [ "Type", "Subtype", "SubtypeID", "Subtype_As_Modified", "Overlap_Status", "Returned" ] ccslib.SimplifyFields(Current_Anthro_Features, allowable_fields) # Remove subtypes from Current_Anthro_Features feature = Current_Anthro_Features subtypes = arcpy.da.ListSubtypes(feature) try: if len(subtypes) == 1 and subtypes[0]['SubtypeField'] == '': pass else: for subtype in subtypes: arcpy.RemoveSubtype_management(feature, subtype) arcpy.AddMessage("Subtype removed") except arcpy.ExecuteError: arcpy.AddMessage("Could not remove Subtype Domain from " "Current_Anthro_Features") # Add Domains for Type and Subtype try: arcpy.RemoveDomainFromField_management(feature, "Type") arcpy.AssignDomainToField_management(feature, "Type", "Type") except arcpy.ExecuteError: arcpy.AddMessage("Could not update Type Domain for " "Current_Anthro_Features") try: arcpy.RemoveDomainFromField_management(feature, "Subtype") arcpy.AssignDomainToField_management(feature, "Subtype", "Subtype") except arcpy.ExecuteError: arcpy.AddMessage("Could not update Subtype Domain for " "Current_Anthro_Features") try: arcpy.RemoveDomainFromField_management(feature, "Subtype_As_Modified") arcpy.AssignDomainToField_management(feature, "Subtype", "Subtype") except arcpy.ExecuteError: arcpy.AddMessage("Could not update Type Domain for " "Current_Anthro_Features") # Calculate Current_Anthro_Disturbance extent_fc = Analysis_Area anthro_features = Current_Anthro_Features term = ccsStandard.DebitTerms[0] Current_Anthro_Disturbance = ccslib.CalcAnthroDist(extent_fc, anthro_features, emptyRaster, AnthroAttributeTable, term) Current_Anthro_Disturbance.save(CURRENT_ANTHRO_DISTURBANCE) # Update message arcpy.AddMessage("Current_Anthro_Disturbance Calculated") arcpy.AddMessage("Removing any anthropogenic features from the " "Current_Anthro_Features layer that will be " "replaced or upgraded from one subtype to another " "by the debit project") # Calculate post-project anthropogenic disturbance mod_field = "Overlap_Status" removed_code = "Removed" subtype_mod_field = "Subtype_As_Modified" out_name = PROJECTED_ANTHRO_FEATURES Projected_Anthro_Features = ccslib.SelectProposed( Current_Anthro_Features, ELIGIBLE_PROPOSED_FEATURES, mod_field, removed_code, subtype_mod_field, out_name) # Simplify fields (do not remove Surface Disturbance or Reclassified # Subtype field for use in SelectPermanent()) allowable_fields = [ "Type", "Subtype", "SubtypeID", "Overlap_Status", "Returned", "Subtype_As_Modified" "Surface_Disturbance", "Reclassified_Subtype" ] ccslib.SimplifyFields(Projected_Anthro_Features, allowable_fields) # Calculate Projected_Anthro_Disturbance extent_fc = Analysis_Area anthro_features = Projected_Anthro_Features term = ccsStandard.DebitTerms[1] Projected_Anthro_Disturbance = ccslib.CalcAnthroDist( extent_fc, anthro_features, emptyRaster, AnthroAttributeTable, term) Projected_Anthro_Disturbance.save(PROJECTED_ANTHRO_DISTURBANCE) # Update message arcpy.AddMessage("Projected_Anthro_Disturbance Calculated") arcpy.AddMessage("Creating Permanent Anthro Features and calculating " "disturbance") # Calculate permanent anthropogenic disturbance # Select permanent anthropogenic features from Projected Anthro Features mod_field = "Overlap_Status" returned_field = "Returned" subtype_mod_field = "Subtype_As_Modified" duration_field = "Surface_Disturbance" permanent_codes = ["Term_Reclassified", "Permanent"] reclass_code = "Term_Reclassified" reclass_subtype_field = "Reclassified_Subtype" out_name = PERMANENT_ANTHRO_FEATURES Permanent_Anthro_Features = ccslib.SelectPermanent( Current_Anthro_Features, ELIGIBLE_PROPOSED_FEATURES, mod_field, returned_field, subtype_mod_field, duration_field, permanent_codes, reclass_code, reclass_subtype_field, out_name) # Simplify fields allowable_fields = [ "Type", "Subtype", "SubtypeID", "Overlap_Status", "Returned", "Subtype_As_Modified" "Surface_Disturbance", "Reclassified_Subtype" ] ccslib.SimplifyFields(Permanent_Anthro_Features, allowable_fields) # Calculate Permanent Anthro Disturbance extent_fc = Analysis_Area anthro_features = Permanent_Anthro_Features term = ccsStandard.DebitTerms[2] Permanent_Anthro_Disturbance = ccslib.CalcAnthroDist( extent_fc, anthro_features, emptyRaster, AnthroAttributeTable, term) Permanent_Anthro_Disturbance.save(PERMANENT_ANTHRO_DISTURBANCE) # Update message arcpy.AddMessage("Permanent_Anthro_Disturbance Calculated") # Calculate local scale modifiers for Current, Projected, and # Permanent condition extent_fc = Analysis_Area terms = ccsStandard.DebitTerms for term in terms: anthro_disturbance = term + "_Anthro_Disturbance" ccslib.CalcModifiers(extent_fc, inputDataPath, Dist_Lek, anthro_disturbance, term) # Calculate impact intensity for debit project try: ccslib.calcDebitImpact(inputDataPath) # Add debit project impact to map layerFile = ccsStandard.getLayerFile("Debit_Project_Impact.lyr") ccslib.AddToMap("Debit_Project_Impact", layerFile, zoom_to=True) except: pass # Update message arcpy.AddMessage("Creating Map Units layer") # Create Map_Units layer Project_Area = DEBIT_PROJECT_AREA out_name = MAP_UNITS Map_Units = ccslib.CreateMapUnits(Project_Area, out_name) # Update message arcpy.AddMessage("Creating pre-defined map units of Wet Meadows") # Intersect the Map_Units layer with the NV Wet Meadows layer in_feature = ccsStandard.Wet_Meadows field_name = "Meadow" na_value = "No Meadow" ccslib.CreatePreDefinedMapUnits(Map_Units, in_feature, field_name, na_value) # Update message arcpy.AddMessage("Creating pre-defined map units of PJ") # Intersect the Map_Units layer with the Phase III PJ layer in_feature = ccsStandard.PJ_Phase_III field_name = "Conifer_Phase" ccslib.CreatePreDefinedMapUnits(Map_Units, in_feature, field_name) # Update message arcpy.AddMessage("Creating pre-defined map units of proposed surface " "disturbance") # Intersect the Map_Units layer with the proposed surface disturbance in_features = ELIGIBLE_PROPOSED_FEATURES ccslib.CreatePreDefinedMapUnits(Map_Units, in_features, field_name) # Remove unwanted fields from Map Units feature class allowable_fields = [ "Disturbance_Type", "BROTEC", "Conifer_Phase", "Meadow" ] ccslib.SimplifyFields(Map_Units, allowable_fields) # Populate empty attributes with Indirect feature = Map_Units fieldName = "Disturbance_Type" where_clause = "{} = ''".format( arcpy.AddFieldDelimiters(feature, fieldName)) with arcpy.da.UpdateCursor(feature, fieldName, where_clause) as cursor: for row in cursor: row[0] = "Indirect" cursor.updateRow(row) # Add Map_Units to map layerFile = ccsStandard.getLayerFile("Map_Units.lyr") ccslib.AddToMap(Map_Units, layerFile) # Add fields Map_Unit_ID, Map_Unit_Name, and Precip to map unit input_feature = Map_Units fields = ["Map_Unit_ID", "Map_Unit_Name", "Notes"] fieldTypes = ["SHORT", "TEXT", "TEXT"] ccslib.AddFields(input_feature, fields, fieldTypes, copy_existing=True) # Add Domains to Map_Units layer # Create Domain for Map_Unit_ID attributes input_feature = Map_Units domainName = "Map_Unit_ID" range_low = 0 range_high = 10000 ccslib.AddRangeDomain(input_feature, workspace, domainName, range_low, range_high) # Create Domain for Meadow attributes featureList = [Map_Units] domainName = "Meadow" codeList = ["Altered", "Unaltered", "No Meadow"] ccslib.AddCodedTextDomain(featureList, workspace, domainName, codeList) # Clean up arcpy.Delete_management("in_memory") # Save map document and exit if arcpy.ListInstallations()[0] == 'arcgispro': p = arcpy.mp.ArcGISProject("CURRENT") p.save() else: mxd = arcpy.mapping.MapDocument("CURRENT") mxd.save()
def main(): # GET PARAMETER VALUES Map_Units_Dissolve_Provided = arcpy.GetParameterAsText(0) Transects_Provided = arcpy.GetParameterAsText(1) Project_Folder = arcpy.GetParameterAsText(2) Project_Name = arcpy.GetParameterAsText(3) # optional # DEFINE DIRECTORIES & PATH NAMES FOR FOLDERS & GBDs scriptPath = sys.path[0] arcpy.AddMessage("Script folder: " + scriptPath) arcpy.AddMessage("Python version: " + sys.version) # Construct pathname to workspace workspace = arcpy.Describe(Map_Units_Dissolve_Provided).path arcpy.AddMessage("Project geodatabase: " + workspace) # ENVIRONMENT SETTINGS # Set workspaces arcpy.env.workspace = workspace arcpy.env.scratchWorkspace = workspace # Overwrite outputs arcpy.env.overwriteOutput = True # DEFINE GLOBAL VARIABLES # Filenames for feature classes or rasters used by this script # Filenames for feature classes or rasters created by this script TRANSECTS_SJ = "Transects_SpatialJoin" # ------------------------------------------------------------------------ # FUNCTION CALLS # Check tool version ccslib.CheckToolVersion() if Transects_Provided: # Update message arcpy.AddMessage("Executing spatial join of Transects and " "Map_Unit_Dissolve layer") # ccslib.AddTransectFields(Transects) Map_Units_Dissolve = Map_Units_Dissolve_Provided out_name = "in_memory/Transects" transects = ccslib.TransectJoin(Map_Units_Dissolve, Transects_Provided, out_name) else: arcpy.AddError("ERROR:: Please provide the transects feature" "class or shapefile provided by the SETT") sys.exit(0) # Update message arcpy.AddMessage("Preparing Transects Spatial Join for export") # Remove unnecessary fields allowable_fields = [ "Bearing1", "Bearing2", "Bearing3", "UTM_E", "UTM_N", "Map_Unit_ID", "Map_Unit_Name", "Meadow", "Indirect", "Acres", "Spring_HSI", "Summer_HSI", "Winter_HSI", "PJ_Cover", "Current_Breed", "Current_LBR", "Current_Winter", "Projected_Breed", "Projected_LBR", "Projected_Winter", "Permanent_Breed", "Permanent_LBR", "Permanent_Winter", "Transects", "Transect_Number", "Sample_Type", "Notes" ] allowable_fields_lower = [ allow_field.lower() for allow_field in allowable_fields ] for field in arcpy.ListFields(transects): if field.name.lower() not in allowable_fields_lower \ and field.required is False: try: arcpy.DeleteField_management(transects, field.name) except arcpy.ExecuteError: pass # ccslib.SimplifyFields(TRANSECTS_SJ, allowable_fields) # Sort fields by Transect ID arcpy.Sort_management(transects, TRANSECTS_SJ, [["Transect_Number", "ASCENDING"]]) # Add Transects to map ccslib.AddToMap(TRANSECTS_SJ) # Export data to Excel table = TRANSECTS_SJ ccslib.ExportToExcel(table, Project_Folder, Project_Name) # Save map document if arcpy.ListInstallations()[0] == 'arcgispro': p = arcpy.mp.ArcGISProject("CURRENT") p.save() else: mxd = arcpy.mapping.MapDocument("CURRENT") mxd.save()
def main(): # GET PARAMETER VALUES workspace = arcpy.GetParameterAsText(0) Provided_Disturbance = arcpy.GetParameterAsText(1) includes_anthro_mod = arcpy.GetParameterAsText(2) # optional Proposed_Modified_Features_Provided = arcpy.GetParameterAsText( 3) # optional # Update boolean parameters includes_anthro_mod = ccslib.Str2Bool(includes_anthro_mod) # DEFINE DIRECTORIES # Get the pathname to this script scriptPath = sys.path[0] arcpy.AddMessage("Script folder: " + scriptPath) arcpy.AddMessage("Python version: " + sys.version) # Instantiate a ccsStandard object ccsStandard = ccslib.ccsStandard(workspace, scriptPath) # ENVIRONMENT SETTINGS # Set workspaces arcpy.env.workspace = workspace arcpy.env.scratchWorkspace = workspace # Overwrite outputs arcpy.env.overwriteOutput = True # DEFINE GLOBAL VARIABLES AnthroAttributeTable = ccsStandard.AnthroAttributeTable coordinate_system = ccsStandard.CoorSystem # Filenames for feature classes and rasters created by this script PROPOSED_SURFACE_DISTURBANCE_DEBITS = "Proposed_Surface_Disturbance_Debits" PROPOSED_MODIFIED_FEATURES = "Proposed_Modified_Features" # ------------------------------------------------------------------------ # FUNCTION CALLS # Check tool version ccslib.CheckToolVersion() # Update includes_anthro_mod if Proposed_Modified_Features is # provided if Proposed_Modified_Features_Provided and not includes_anthro_mod: includes_anthro_mod = True # Check input features for existence of features and feature type; # create template if Proposed_Surface_Disturbance is not provided if Provided_Disturbance: # Check provided input ccslib.CheckPolygonInput(Provided_Disturbance) # Check provided input for 'Feature' field, error and exit if so existing_fields = [ field.name.lower() for field in arcpy.ListFields(Provided_Disturbance) ] if 'feature' in existing_fields: arcpy.AddError("ERROR:: The provided proposed surface " "disturbance layer includes a field named " "'Feature' in the attribute table. Please " "rename this field and re-run this tool. ") sys.exit(0) # Create a local copy of the provided disturbance in case it is # the output of the projected input from re-running Debit Tool 1 PSD_copy = arcpy.CopyFeatures_management(Provided_Disturbance, "in_memory/PSD_provided") # Update message arcpy.AddMessage("Projecting provided feature(s) to " + coordinate_system.name) # Project input to standard coordinate system inputFeature = PSD_copy out_name = PROPOSED_SURFACE_DISTURBANCE_DEBITS Proposed_Surface_Disturbance = ccslib.ProjectInput( inputFeature, out_name, coordinate_system) zoom_to = True else: # Update message arcpy.AddMessage("Creating template for digitizing proposed " "surface disturbance \nDigitize features in " "feature class named " "Proposed_Surface_Disturbance_Debits created within " "the project's unique geodatabase") # Create a template out_name = PROPOSED_SURFACE_DISTURBANCE_DEBITS Proposed_Surface_Disturbance = ccslib.CreateTemplate( workspace, out_name, coordinate_system) zoom_to = False if includes_anthro_mod: # Create a template for digitizing anthropogenic features proposed for # modification out_name = "Proposed_Modified_Features_tmp" Template_Features = ccslib.CreateTemplate(workspace, out_name, coordinate_system) if Proposed_Modified_Features_Provided: # Do not zoom to proposed surface disturbance zoom_to = False # Merge with the provided layer, if provided fileList = [Proposed_Modified_Features_Provided, Template_Features] out_name = "in_memory/tmp_Modified" merged_features = ccslib.MergeFeatures(fileList, out_name) # Rename the provided as merged (cannot merge two files with # equivalent filenames) as Proposed_Modified_Features in_data = merged_features out_data = PROPOSED_MODIFIED_FEATURES Proposed_Modified_Features = arcpy.CopyFeatures_management( in_data, out_data) else: # Save the template as Proposed_Modified_Features in_data = Template_Features out_data = PROPOSED_MODIFIED_FEATURES Proposed_Modified_Features = ccslib.RenameFeatureClass( in_data, out_data) # Update message arcpy.AddMessage("Adding fields Type and Subtype to " "the Proposed_Modified_Features layer") # Add fields Type and Subtype inputFeature = Proposed_Modified_Features fieldsToAdd = ["Type", "Subtype"] fieldTypes = ["TEXT", "TEXT"] ccslib.AddFields(inputFeature, fieldsToAdd, fieldTypes, copy_existing=True) # Clean up arcpy.Delete_management(Template_Features) # Create Domain for Subtype attributes and assign to Subtype field featureList = [Proposed_Modified_Features] ccslib.AddSubtypeDomains(featureList, workspace, AnthroAttributeTable) # Add layer to map for editing layerFile = ccsStandard.getLayerFile("SurfaceDisturbance.lyr") ccslib.AddToMap(Proposed_Modified_Features, layerFile) # Add layer to map document layerFile = ccsStandard.getLayerFile("SurfaceDisturbance.lyr") ccslib.AddToMap(Proposed_Surface_Disturbance, layerFile, zoom_to) # Update message arcpy.AddMessage("Adding fields to Proposed_Surface_Disturbance") # Add fields for Type, Subtype, Surface Disturbance, and Reclassifed Subtype input_feature = Proposed_Surface_Disturbance fields = ["Type", "Subtype", "Surface_Disturbance", "Reclassified_Subtype"] fieldTypes = ["TEXT", "TEXT", "TEXT", "TEXT"] ccslib.AddFields(input_feature, fields, fieldTypes, copy_existing=True) # Add Domains to Proposed_Surface_Disturbance_Debits layer featureList = [Proposed_Surface_Disturbance] domain_name = "Type" code_list = [ row[0] for row in arcpy.da.SearchCursor(AnthroAttributeTable, "Type") ] # Create Domain for Subtype attributes and assign to Subtype field ccslib.AddSubtypeDomains(featureList, workspace, AnthroAttributeTable) # Create Domain for Type attributes and assign to Type field ccslib.AddCodedTextDomain(featureList, workspace, domain_name, code_list) # Create Domain for Type attributes and assign to Surface Disturbance field domain_name = "Surface_Disturbance" code_list = [ "Term_Reclaimed", "Term_Retired", "Term_Reclassified", "Permanent" ] ccslib.AddCodedTextDomain(featureList, workspace, domain_name, code_list) # Create Domain for Type attributes and assign to Reclassified Subtype # field domain_name = "Reclassified_Subtype" code_list = [ row[0] for row in arcpy.da.SearchCursor(AnthroAttributeTable, "Subtype") ] ccslib.AddCodedTextDomain(featureList, workspace, domain_name, code_list) if includes_anthro_mod: # Extend type domain to Proposed_Modified_Features try: arcpy.AssignDomainToField_management(Proposed_Modified_Features, "Type", "Type") except arcpy.ExecuteError: arcpy.AddMessage("Type domain not updated for " "Proposed_Modified_Features") # Save map document and exit if arcpy.ListInstallations()[0] == 'arcgispro': p = arcpy.mp.ArcGISProject("CURRENT") p.save() else: mxd = arcpy.mapping.MapDocument("CURRENT") mxd.save()
def main(): # GET PARAMETER VALUES Proposed_Surface_Disturbance_Provided = arcpy.GetParameterAsText(0) Proposed_Modified_Features_Provided = arcpy.GetParameterAsText( 1) # optional Project_Folder = arcpy.GetParameterAsText(2) # DEFINE DIRECTORIES # Get the pathname to this script scriptPath = sys.path[0] arcpy.AddMessage("Script folder: " + scriptPath) arcpy.AddMessage("Python version: " + sys.version) # Construct pathname to workspace workspace = arcpy.Describe(Proposed_Surface_Disturbance_Provided).path arcpy.AddMessage("Project geodatabase: " + workspace) # Instantiate a ccsStandard object ccsStandard = ccslib.ccsStandard(workspace, scriptPath) # ENVIRONMENT SETTINGS # Set workspaces arcpy.env.workspace = workspace scratch_folder = os.path.join(arcpy.Describe(workspace).path, 'scratch') if arcpy.Exists(scratch_folder): pass else: arcpy.CreateFolder_management( arcpy.Describe(workspace).path, 'scratch') arcpy.env.scratchWorkspace = scratch_folder # Overwrite outputs arcpy.env.overwriteOutput = True # DEFINE VARIABLES FOR INPUT DATA AnthroAttributeTable = ccsStandard.AnthroAttributeTable habitat_bounds = ccsStandard.HabitatBounds public_land = ccsStandard.Public # Filenames for feature classes or rasters used by this script PROPOSED_SURFACE_DISTURBANCE_DEBITS = "Proposed_Surface_Disturbance_Debits" # Filenames for feature classes or rasters created by this script ELIGIBLE_PROPOSED_FEATURES = "Proposed_Surface_Disturbance_Eligible" ANALYSIS_AREA = "Analysis_Area" DEBIT_PROJECT_AREA = "Debit_Project_Area" INDIRECT_IMPACT_AREA = "Indirect_Impact_Area" INDIRECT_BENEFIT_AREA = "Indirect_Benefit_Area" PROPOSED_MODIFIED_FEATURES = "Proposed_Modified_Features" # ------------------------------------------------------------------------ # FUNCTION CALLS # Check tool version ccslib.CheckToolVersion() # Check for proposed modified features if not Proposed_Modified_Features_Provided: # Ensure Proposed_Modified_Features does not exist if arcpy.Exists("Proposed_Modified_Features"): arcpy.AddError("ERROR:: A 'Proposed_Modified_Features' layer " "was detected in the project's geodatabase. " "Provide the 'Proposed_Modified_Features' layer " "and re-run Debit Tool 2.") sys.exit(0) # Clear selection, if present ccslib.ClearSelectedFeatures(Proposed_Surface_Disturbance_Provided) # Check Proposed_Surface_Disturbance feature = Proposed_Surface_Disturbance_Provided required_fields = ["Type", "Subtype", "Surface_Disturbance"] no_null_fields = required_fields expected_fcs = None ccslib.CheckPolygonInput(feature, required_fields, expected_fcs, no_null_fields) # Update Proposed_Surface_Disturbance layer with provided layer provided_input = Proposed_Surface_Disturbance_Provided parameter_name = PROPOSED_SURFACE_DISTURBANCE_DEBITS Proposed_Surface_Disturbance_Debits = ccslib.AdoptParameter( provided_input, parameter_name, preserve_existing=False) # Replace Proposed_Surface_Disturbance_Debits layer on map layerFile = ccsStandard.getLayerFile("SurfaceDisturbance.lyr") ccslib.AddToMap(Proposed_Surface_Disturbance_Debits, layerFile) # Clip the Proposed Surface Disturbance to Public Lands input_features = PROPOSED_SURFACE_DISTURBANCE_DEBITS clip_features = public_land out_name = ELIGIBLE_PROPOSED_FEATURES Proposed_Surface_Disturbance = arcpy.Clip_analysis(input_features, clip_features, out_name) # Exit if no features on public land exist test = arcpy.GetCount_management(Proposed_Surface_Disturbance) count = int(test.getOutput(0)) if count < 1: arcpy.AddWarning(""" There are no proposed features located on public lands.\n Therefore, this project does not require mitigation.\n Please confirm with the SETT. """) sys.exit(0) # Add Surface_Disturbance_Eligible layer on map layerFile = ccsStandard.getLayerFile("SurfaceDisturbance.lyr") ccslib.AddToMap(Proposed_Surface_Disturbance, layerFile) # Add field for Disturbance_Type and populate. Values will be used in # Map_Units_Dissolve to identify map units of direct disturbance feature = Proposed_Surface_Disturbance fields = ["Disturbance_Type"] fieldTypes = ["TEXT"] ccslib.AddFields(feature, fields, fieldTypes) with arcpy.da.UpdateCursor(feature, ["Surface_Disturbance"] + fields) as cursor: for row in cursor: row[1] = "Direct_" + row[0] cursor.updateRow(row) # Update message arcpy.AddMessage("Creating the area of indirect impact") # Buffer proposed surface disturbance to create Indirect_Impact_Area in_data = Proposed_Surface_Disturbance out_name = INDIRECT_IMPACT_AREA Indirect_Impact_Area = ccslib.CreateIndirectImpactArea( in_data, AnthroAttributeTable, out_name) if Proposed_Modified_Features_Provided: # Clear selection, if present ccslib.ClearSelectedFeatures(Proposed_Modified_Features_Provided) # Check provided layer required_fields = ["Type", "Subtype"] no_null_fields = required_fields expected_fcs = None ccslib.CheckPolygonInput(Proposed_Modified_Features_Provided, required_fields, expected_fcs, no_null_fields) # Update Proposed_Modified_Features with provided layer and add to map provided_input = Proposed_Modified_Features_Provided parameterName = PROPOSED_MODIFIED_FEATURES preserve_existing = False Proposed_Modified_Features = ccslib.AdoptParameter( provided_input, parameterName, preserve_existing) # Add Proposed Modified Features layer to map layerFile = ccsStandard.getLayerFile("SurfaceDisturbance.lyr") ccslib.AddToMap(Proposed_Modified_Features, layerFile) # Update message arcpy.AddMessage("Creating the area of indirect benefit") # Create the Indirect_Impact_Area in_data = Proposed_Modified_Features out_name = INDIRECT_BENEFIT_AREA Indirect_Benefit_Area = ccslib.CreateIndirectImpactArea( in_data, AnthroAttributeTable, out_name) # Union the indirect benefit area and the indirect impact area in_features = [Indirect_Impact_Area, Indirect_Benefit_Area] out_name = "in_memory/Impact_Union" Impact_Union = arcpy.Union_analysis(in_features, out_name) # Dissolve the unioned indirect impact and benefit areas as # Indirect Impact Area in_features = Impact_Union out_feature_class = INDIRECT_IMPACT_AREA Indirect_Impact_Area = arcpy.Dissolve_management( in_features, out_feature_class) # Update message arcpy.AddMessage("Determining project area - eliminating areas of non-" "habitat from the Project Area") # Eliminate non-habitat project_area = Indirect_Impact_Area out_name = DEBIT_PROJECT_AREA Debit_Project_Area = ccslib.EliminateNonHabitat(project_area, out_name, habitat_bounds) # Update message arcpy.AddMessage("Copying Debit_Project_Area as shapefile into project " "folder") # Export feature class to shapefile in project folder so it can be sent to # NDOW for Dist_Lek layer arcpy.FeatureClassToShapefile_conversion(Debit_Project_Area, Project_Folder) # Update message arcpy.AddMessage("Creating Analysis Area") # Create Analysis_Area out_name = ANALYSIS_AREA Analysis_Area = ccslib.CreateAnalysisArea(Debit_Project_Area, AnthroAttributeTable, out_name) # Add Analysis_Area to map layerFile = ccsStandard.getLayerFile("Analysis_Area.lyr") ccslib.AddToMap(Analysis_Area, layerFile, zoom_to=True) # Save map document and exit if arcpy.ListInstallations()[0] == 'arcgispro': p = arcpy.mp.ArcGISProject("CURRENT") p.save() else: mxd = arcpy.mapping.MapDocument("CURRENT") mxd.save()
def main(): # GET PARAMETER VALUES Proposed_Surface_Disturbance_Eligible = arcpy.GetParameterAsText(0) # DEFINE DIRECTORIES # Get the pathname to this script scriptPath = sys.path[0] arcpy.AddMessage("Script folder: " + scriptPath) # Construct pathname to workspace workspace = arcpy.Describe(Proposed_Surface_Disturbance_Eligible).path arcpy.AddMessage("Project geodatabase: " + workspace) # Instantiate a ccsStandard object ccsStandard = ccslib.ccsStandard(workspace, scriptPath) # ENVIRONMENT SETTINGS # Set workspaces arcpy.env.workspace = workspace scratch_folder = os.path.join(arcpy.Describe(workspace).path, 'scratch') if arcpy.Exists(scratch_folder): pass else: arcpy.CreateFolder_management( arcpy.Describe(workspace).path, 'scratch') arcpy.env.scratchWorkspace = scratch_folder # Overwrite outputs arcpy.env.overwriteOutput = True # DEFINE VARIABLES FOR INPUT DATA # Filenames for feature classes or rasters used by this script ELIGIBLE_PROPOSED_FEATURES = "Proposed_Surface_Disturbance_Eligible" # Filenames for feature classes or rasters created by this script ANALYSIS_AREA = "Analysis_Area" # ------------------------------------------------------------------------ # FUNCTION CALLS # Check tool version ccslib.CheckToolVersion() # Clear selection, if present ccslib.ClearSelectedFeatures(Proposed_Surface_Disturbance_Eligible) # Check Proposed_Surface_Disturbance_Eligible feature = Proposed_Surface_Disturbance_Eligible required_fields = ["Type", "Subtype", "Surface_Disturbance"] no_null_fields = required_fields expected_fcs = None ccslib.CheckPolygonInput(feature, required_fields, expected_fcs, no_null_fields) # Update Proposed_Surface_Disturbance_Elligible layer with provided layer provided_input = Proposed_Surface_Disturbance_Eligible parameter_name = ELIGIBLE_PROPOSED_FEATURES Proposed_Surface_Disturbance_Eligible = ccslib.AdoptParameter( provided_input, parameter_name, preserve_existing=False) # Replace Proposed_Surface_Disturbance_Elibible layer on map layerFile = ccsStandard.getLayerFile("SurfaceDisturbance.lyr") ccslib.AddToMap(Proposed_Surface_Disturbance_Eligible, layerFile) # Update message arcpy.AddMessage("Clipping all anthropogenic features to Analysis Area " "and adding templates for digitizing new anthropogenic " "features") # Clip all provided anthropogenic feature layers and add to map clip_features = ANALYSIS_AREA anthroFeaturePath = ccsStandard.AnthroFeaturePath proposed_anthro = Proposed_Surface_Disturbance_Eligible fieldsToAdd = ["Overlap_Status", "Returned", "Subtype_As_Modified"] fieldTypes = ["TEXT", "TEXT", "TEXT"] mod_field = fieldsToAdd[0] removed_code = "Removed" retained_code = "Retained" ccslib.ClipAnthroFeaturesDebit(clip_features, anthroFeaturePath, proposed_anthro, fieldsToAdd, fieldTypes, mod_field, removed_code, retained_code) # Apply domains for Overlap_Status field and populate default featureList = arcpy.ListFeatureClasses("Anthro_*_Clip") domain_name = fieldsToAdd[0] code_list = ["Retained", "Removed"] ccslib.AddCodedTextDomain(featureList, workspace, domain_name, code_list, assign_default=True, populate_default=True) # Apply domains for Returned field domain_name = fieldsToAdd[1] code_list = ["True", "False"] ccslib.AddCodedTextDomain(featureList, workspace, domain_name, code_list, assign_default=True, populate_default=True) # Add all Subtype anthro domains because ArcGIS doesn't transfer them # consistently desc_c = arcpy.Describe(workspace) current_domains = desc_c.domains desc_w = arcpy.Describe(ccsStandard.AnthroFeaturePath) anthro_domains = desc_w.domains for domain_name in anthro_domains: if domain_name not in current_domains and "Subtype" in domain_name: source_workspace = ccsStandard.AnthroFeaturePath code_field = 'code' description_field = 'description' domain_table = arcpy.DomainToTable_management( source_workspace, domain_name, domain_name, code_field, description_field) arcpy.TableToDomain_management(domain_table, code_field, description_field, workspace, domain_name) arcpy.Delete_management(domain_table) # Apply domains for each anthro feature for feature in featureList: # Apply for each Subtype field field = "Subtype" domainName = feature[7:-5] + "_Subtypes" arcpy.AssignDomainToField_management(feature, field, domainName) subtypes = arcpy.da.ListSubtypes(feature) if len(subtypes) == 1 and subtypes[0]['SubtypeField'] == '': pass else: st_codes = [ str(stcode) for stcode, stdict in list(subtypes.items()) ] arcpy.AssignDomainToField_management(feature, field, domainName, st_codes) # Apply for each Subtype As Modified Field field = fieldsToAdd[-1] domainName = feature[7:-5] + "_Subtypes" arcpy.AssignDomainToField_management(feature, field, domainName) subtypes = arcpy.da.ListSubtypes(feature) if len(subtypes) == 1 and subtypes[0]['SubtypeField'] == '': pass else: st_codes = [ str(stcode) for stcode, stdict in list(subtypes.items()) ] arcpy.AssignDomainToField_management(feature, field, domainName, st_codes) # Copy current subtype to Subtype as Modified field arcpy.CalculateField_management(feature, field, "!Subtype!", "PYTHON_9.3") # Add each feature to map for editing for feature in featureList: ccslib.AddAnthroToMap(workspace, feature) # Save map document and exit if arcpy.ListInstallations()[0] == 'arcgispro': p = arcpy.mp.ArcGISProject("CURRENT") p.save() else: mxd = arcpy.mapping.MapDocument("CURRENT") mxd.save()
def main(): # GET PARAMETER VALUES Map_Units_Provided = arcpy.GetParameterAsText(0) Project_Folder = arcpy.GetParameterAsText(1) Project_Name = arcpy.GetParameterAsText(2) # optional # DEFINE DIRECTORIES # Get the pathname to this script scriptPath = sys.path[0] arcpy.AddMessage("Script folder: " + scriptPath) arcpy.AddMessage("Python version: " + sys.version) # Construct pathname to workspace workspace = arcpy.Describe(Map_Units_Provided).path arcpy.AddMessage("Project geodatabase: " + workspace) # Instantiate a ccsStandard object ccsStandard = ccslib.ccsStandard(workspace, scriptPath) # ENVIRONMENT SETTINGS # Set workspaces arcpy.env.workspace = workspace scratch_folder = os.path.join(arcpy.Describe(workspace).path, 'scratch') if arcpy.Exists(scratch_folder): pass else: arcpy.CreateFolder_management(scratch_folder) arcpy.env.scratchWorkspace = scratch_folder # Overwrite outputs arcpy.env.overwriteOutput = True # DEFINE VARIABLES FOR INPUT DATA inputDataPath = ccsStandard.InputDataPath # Filenames of feature classes and rasters used by this script MAP_UNITS = "Map_Units" CURRENT_ANTHRO_FEATURES = "Current_Anthro_Features" # Filenames of feature classes and rasters created by this script MAP_UNITS_DISSOLVE = "Map_Units_Dissolve" CURRENT_MGMT_CAT = "Current_Mgmt_Cat" CURRENT_WMZ = "Current_WMZ" CURRENT_PMU = "Current_PMU" CURRENT_PRECIP = "Current_Precip" # ------------------------------------------------------------------------ # FUNCTION CALLS # Check tool version ccslib.CheckToolVersion() # Check out Spatial Analyst extension ccslib.CheckOutSpatialAnalyst() # Clear selection, if present ccslib.ClearSelectedFeatures(Map_Units_Provided) # Check Map_Units layer feature = Map_Units_Provided required_fields = ["Map_Unit_ID", "Map_Unit_Name", "Meadow"] no_null_fields = ["Map_Unit_ID"] expected_fcs = [CURRENT_ANTHRO_FEATURES] ccslib.CheckPolygonInput(feature, required_fields, expected_fcs, no_null_fields) # Update Map Units layer with provided layer and add to map Map_Units = ccslib.AdoptParameter(Map_Units_Provided, MAP_UNITS, preserve_existing=False) layerFile = ccsStandard.getLayerFile("Map_Units.lyr") ccslib.AddToMap(Map_Units, layerFile) # Update message arcpy.AddMessage("Dissolving all multi-part map units to create " "Map_Units_Dissolve") # Dissolve Map Units allowable_fields = [ "Map_Unit_ID", "Map_Unit_Name", "Meadow", "Disturbance_Type", "PJ", "BROTEC", "Conifer_Phase" ] out_name = MAP_UNITS_DISSOLVE anthro_features = CURRENT_ANTHRO_FEATURES Map_Units_Dissolve = ccslib.DissolveMapUnits(Map_Units, allowable_fields, out_name, anthro_features) # Update message arcpy.AddMessage("Adding Map_Units_Dissolve to map") # Add layer to map document feature = Map_Units_Dissolve layerFile = ccsStandard.getLayerFile("Map_Units.lyr") ccslib.AddToMap(feature, layerFile) # Update message arcpy.AddMessage("Calculating area in acres for each map unit") # Calculate Area ccslib.CalcAcres(Map_Units_Dissolve) # Initialize a list to track proportion feature classes prop_fcs = [] # Update message arcpy.AddMessage("Calculating Proportion within each precipitation zone") # Calculate Proportion of each map unit in each Precip Zone in_feature = os.path.join(inputDataPath, "Precip") out_feature_class = CURRENT_PRECIP field_name = "Precip_Proportion" ccslib.CalcProportion(Map_Units_Dissolve, in_feature, out_feature_class, field_name) prop_fcs.append(out_feature_class) # Update message arcpy.AddMessage("Calculating Management Importance Factor") # Calculate Proportion of each map unit in each Management Category in_feature = os.path.join(inputDataPath, "Mgmt_Cat") out_feature_class = CURRENT_MGMT_CAT field_name = "Mgmt_Proportion" ccslib.CalcProportion(Map_Units_Dissolve, in_feature, out_feature_class, field_name) prop_fcs.append(out_feature_class) # Update message arcpy.AddMessage("Calculating Proportion within each WAFWA Management " "Zone") # Calculate Proportion in each map unit in each WAFWA Zone in_feature = os.path.join(inputDataPath, "NV_WAFWA") out_feature_class = CURRENT_WMZ field_name = "WMZ_Proportion" ccslib.CalcProportion(Map_Units_Dissolve, in_feature, out_feature_class, field_name) prop_fcs.append(out_feature_class) # Update message arcpy.AddMessage("Calculating Proportion within each Priority Management " "Unit") # Calculate Proportion in each map unit in each PMU in_feature = os.path.join(inputDataPath, "NV_PMU") out_feature_class = CURRENT_PMU field_name = "PMU_Proportion" ccslib.CalcProportion(Map_Units_Dissolve, in_feature, out_feature_class, field_name) prop_fcs.append(out_feature_class) # Delete unnecessary fields in proportion feature classes allowable_fields = [ "Map_Unit_ID", "Management", "Mgmt_zone", "PMU_NAME", "Precip", "Mgmt_Proportion", "WMZ_Proportion", "PMU_Proportion", "Precip_Proportion" ] for feature in prop_fcs: ccslib.SimplifyFields(feature, allowable_fields) # Set processing extent to Map_Units layer arcpy.env.extent = arcpy.Describe(Map_Units_Dissolve).extent # Calculate the average HSI values per map unit for each map unit HSIseasons = ccsStandard.HSISeasons for season in HSIseasons: # Update message arcpy.AddMessage("Summarizing " + season + " HSI") # Calculate zonal statistics for each map unit inZoneData = Map_Units_Dissolve inValueRaster = os.path.join(inputDataPath, season + "_HSI") zoneField = "Map_Unit_ID" outTable = "ZonalStats_" + season + "_HSI" ccslib.CalcZonalStats(inZoneData, zoneField, inValueRaster, outTable) # Join the zonal statistic to the Map Units Dissolve table fieldName = season + "_HSI" ccslib.JoinMeanToTable(inZoneData, outTable, zoneField, fieldName) # Calculate the average seasonal modifier values per map unit and join to # Map_Units_Dissolve layer terms = ccsStandard.DebitTerms seasons = ccsStandard.Seasons for term in terms: for season in seasons: # Update message arcpy.AddMessage("Summarizing " + term + "_Local_" + season) # Calculate zonal statistics for each map unit inZoneData = Map_Units_Dissolve inValueRaster = term + "_Local_" + season zoneField = "Map_Unit_ID" outTable = "ZonalStats_" + term + season ccslib.CalcZonalStats(inZoneData, zoneField, inValueRaster, outTable) # Join the zonal statistic to the Map Units Dissolve table fieldName = term + "_" + season ccslib.JoinMeanToTable(inZoneData, outTable, zoneField, fieldName) # Add transect field to Map_Units_Dissolve input_feature = Map_Units_Dissolve fields = ["Transects"] fieldTypes = ["SHORT"] ccslib.AddFields(input_feature, fields, fieldTypes) # Export data to Excel input_Tables = [ MAP_UNITS_DISSOLVE, CURRENT_MGMT_CAT, CURRENT_WMZ, CURRENT_PMU, CURRENT_PRECIP ] for table in input_Tables: ccslib.ExportToExcel(table, Project_Folder, Project_Name) # Save map document if arcpy.ListInstallations()[0] == 'arcgispro': p = arcpy.mp.ArcGISProject("CURRENT") p.save() else: mxd = arcpy.mapping.MapDocument("CURRENT") mxd.save()