def main(): arcpy.env.overwriteOutput = True arcpy.env.workspace = 'C:\Users\owner\Downloads\Sample_scripts\ch06' inRaster = 'C:\Users\owner\Downloads\Sample_scripts\ch06\bbn.tif' inField = 'Value' outRaster = arcpy.Reclassify_3d( inRaster, inField, ) outRaster.save('koko.tif') del (outRaster) arcpy.env.overwriteOutput = False
def convert_afe_to_final_tiles(phyreg_ids): ''' This function converts AFE outputs to final TIFF files. phyreg_ids: list of physiographic region IDs to process ''' phyregs_layer = canopy_config.phyregs_layer naipqq_layer = canopy_config.naipqq_layer naipqq_phyregs_field = canopy_config.naipqq_phyregs_field snaprast_path = canopy_config.snaprast_path results_path = canopy_config.results_path arcpy.env.addOutputsToMap = False arcpy.env.snapRaster = snaprast_path arcpy.SelectLayerByAttribute_management(phyregs_layer, where_clause='PHYSIO_ID in (%s)' % ','.join(map(str, phyreg_ids))) with arcpy.da.SearchCursor(phyregs_layer, ['NAME', 'PHYSIO_ID']) as cur: for row in cur: name = row[0] print(name) # CreateRandomPoints cannot create a shapefile with - in its # filename name = name.replace(' ', '_').replace('-', '_') phyreg_id = row[1] outdir_path = '%s/%s/Outputs' % (results_path, name) if len(os.listdir(outdir_path)) == 0: continue arcpy.SelectLayerByAttribute_management(naipqq_layer, where_clause="%s like '%%,%d,%%'" % (naipqq_phyregs_field, phyreg_id)) with arcpy.da.SearchCursor(naipqq_layer, ['FileName']) as cur2: for row2 in sorted(cur2): filename = row2[0][:-13] rshpfile_path = '%s/r%s.shp' % (outdir_path, filename) rtiffile_path = '%s/r%s.tif' % (outdir_path, filename) frtiffile_path = '%s/fr%s.tif' % (outdir_path, filename) if os.path.exists(frtiffile_path): continue if os.path.exists(rshpfile_path): arcpy.FeatureToRaster_conversion(rshpfile_path, 'CLASS_ID', frtiffile_path, 1) elif os.path.exists(rtiffile_path): arcpy.Reclassify_3d(rtiffile_path, 'Value', '1 0;2 1', frtiffile_path) # clear selection arcpy.SelectLayerByAttribute_management(phyregs_layer, 'CLEAR_SELECTION') arcpy.SelectLayerByAttribute_management(naipqq_layer, 'CLEAR_SELECTION') print('Completed')
def remapRaster(inRaster, outRaster, recField, statList): R1 = statList[0] - statList[1] R2 = statList[0] + statList[1] rasterMin = arcpy.GetRasterProperties_management( inRaster, "MINIMUM") rasterMax = arcpy.GetRasterProperties_management( inRaster, "MAXIMUM") if R1 < rasterMin: R1 = rasterMin if R2 > rasterMax: R2 = rasterMax remap = str(rasterMin) + " " + str(R1) + " 0;" + str( R1) + " " + str(R2) + " 1;" + str(R2) + " " + str( rasterMax) + " 0" arcpy.Reclassify_3d(inRaster, recField, remap, outRaster, "NODATA") return outRaster
# save to your destination future.save("C:\\Users") # Process: Reclassify (5) arcpy.gp.Reclassify_sa(nestream, "VALUE", "6 0;6 7 0;7 8 0;NODATA 1", Reclass_stream, "DATA") # Process: Reclassify (3) arcpy.gp.Reclassify_sa(nelu95__2_, "VALUE", "111 194 0;194 429 1;429 625 0", reclass_nelu95_avail, "DATA") # Process: Times arcpy.gp.Times_sa(reclass_nelu95_avail, Reclass_stream, Times_nelu95_avastream) # Process: Reclassify arcpy.Reclassify_3d(nelu95, "VALUE", "111 200 1;200 300 2;300 625 3", Nelu_relassified, "DATA") # Process: Over arcpy.gp.Over_sa(future, Nelu_relassified, Over_futureland) # Process: Times (2) arcpy.gp.Times_sa(Times_nelu95_avastream, Over_futureland, Times2) # Process: Reclassify (4) arcpy.Reclassify_3d(Times2, "VALUE", "0 NODATA;0 1 1;1 2 2;2 3 3", Reclass_Time2, "DATA") # Process: Slice arcpy.Slice_3d(Reclass_Time2, Slice_futureland, "100", "EQUAL_AREA", "1") #conflict
# reklasyfikacja for raster in rastry: rok = str(raster)[:4] filename_reklas = os.path.join(folder_rastry_reklas, str(rok) + ".tif") arcpy.Reclassify_3d(in_raster=raster, reclass_field="VALUE", remap= "-20,0 -9,0 -10;" "-9,0 -8,0 -9;" "-8,0 -7,0 -8;" "-7,0 -6,0 -7;" "-6,0 -5,0 -6;" "-5,0 -4,0 -5;" " -4,0 -3,0 -4;" " -3,0 -2,0 -3;" " -2,0 -1,0 -2;" " -1,0 -0,25 -1;" " -0,25 0,25 0;" " 0,25 1,0 1;" " 1,0 2,0 2;" " 2,0 3,0 3;" " 3,0 4,0 4;" " 4,0 5,0 5;" " 5,0 6,0 6;" " 6,0 7,0 7;" " 7,0 8,0 8;" " 8,0 9,0 9;" " 9,0 20,0 10", out_raster=filename_reklas, missing_values="DATA") env.workspace = folder_rastry_reklas rastry = arcpy.ListRasters()
# TIN to Raster arcpy.AddMessage("Converting TIN to raster for {0}".format(stage)) input_cell_size = "CELLSIZE {0}".format(Cell_Size) arcpy.TinRaster_3d(TIN, RasterFromTIN, "FLOAT", "LINEAR", input_cell_size, "1") # Raster subtraction arcpy.AddMessage( "Subtracting the raster from TIN with the input DEM for {0}".format( stage)) arcpy.Minus_3d(RasterFromTIN, DEM, Subtracted) # Reclassify raster arcpy.AddMessage( "Reclassifing the subtracted raster for {0}".format(stage)) arcpy.Reclassify_3d(Subtracted, "Value", "-999 0.01 1;0.01 999 0", Reclassified, "DATA") # Extract by Attributes arcpy.AddMessage("Extracting by attributes for {0}".format(stage)) arcpy.gp.ExtractByAttributes_sa(Reclassified, "\"Value\" = 0", ExtractedRaster) # Create depth grid arcpy.AddMessage("Creating depthgrid for {0}".format(stage)) depth_grid_name = "{0}_DepthGrid".format(stage) outExtractByMask = arcpy.sa.ExtractByMask(Subtracted, ExtractedRaster) outExtractByMask.save(depth_grid_name) # Convert Raster to Polygon arcpy.AddMessage("Converting depthgrid to polygon for {0}".format(stage)) converted_polygon = "{0}_ConvertedPolygon".format(stage)
# Input: nestream # Output: Agr_Dis_stream # Function: get the ecuclidean distance of the nestream based on cell size 30. arcpy.gp.EucDistance_sa(nestream, Agr_Dis_stream, "", "30") # Process: Euclidean Distance (4) # Input nesandp # Output: EucDist_Clay # Function: get the ecuclidean distance of the nestream based on cell size 30. arcpy.gp.EucDistance_sa(nesandp, EucDist_Clay, "", "30") # Process: Reclassify # Input; value of nelu95 # Output: reclass_nelu1 # Function: reclassify nelu95 raster based on its value property arcpy.Reclassify_3d(nelu95, "VALUE", "111 194 0;194 429 1;429 740 0", Reclass_nelu1, "DATA") # Process: Slope # Input: nedem # Output: Agr_slope # Function: bsaed on degree, calculate the slope of nedem arcpy.gp.Slope_sa(nedem, Agr_slope, "DEGREE", "0.3048", "PLANAR", "METER") # Process: Slice (3) # Input: Agr_slope # Output: Agr_slope_slice # Function: bsaed on equal interval method, slice the agriculture slope to 100 pieces. arcpy.gp.Slice_sa(Agr_slope, Agr_slope_slice, "100", "EQUAL_INTERVAL", "1") # Process: Minus # Input: Input_raster_or_constant_value_1, Agr_slope_slice
NTLimg_Path = os.path.join(root, file) print NTLimg_Path env.workspace = maskPath rasters = arcpy.ListRasters('*', 'TIF') for raster_1 in rasters: if "NDVI_otsu" in raster_1: NDVI_raster = raster_1 for raster_2 in rasters: if "MNDWI_otsu" in raster_2: MNDWI_raster = raster_2 os.chdir(trainpath) field = "VALUE" as_remapString = "0 81.01102941 0;81.01102941 276 1" arcpy.Reclassify_3d(NTLimg_Path, field, as_remapString, trainpath + '\\aspotential_trainsample.tif', 'NODATA') nonas_remapString = "-1 0 1;0 276 0" arcpy.Reclassify_3d(NTLimg_Path, field, nonas_remapString, trainpath + '\\nonas_trainsample.tif', 'NODATA') Target_remapString = "-1 6.480882353 0;6.480882353 276 1" arcpy.Reclassify_3d(NTLimg_Path, field, Target_remapString, trainpath + '\\Target_area_NTL.tif', 'NODATA') for as_ntl_root, dirs, files in os.walk(trainpath): for as_ntl_name in files: if 'aspotential_trainsample.tif' in as_ntl_name and as_ntl_name.endswith( '.tif'): train_as_ntl_mask = os.path.join(as_ntl_root, as_ntl_name) print train_as_ntl_mask train_as = Raster(NDVI_raster) & Raster(train_as_ntl_mask) & Raster(
def liczenie_atrybutow(maup_kopia): inZoneData = maup_kopia zoneField = "ajdi" ## przerobic to zeby bylo w petli jak czlowiek pole = "przyd" pole2 = "przyd_rel" pole3 = "przyd_wo" pole4 = "prz_wo_rel" pole5 = "les_mod_po" pole6 = "nr_modelu" lista_pol = [pole, pole2, pole3, pole4, pole5] for pol in lista_pol: try: arcpy.AddField_management(maup_kopia, pol, "FLOAT") except: print "bla" arcpy.AddField_management(maup_kopia, pole6, "TEXT") nazwa_tabeli = "przydatnosc" outTable = folder_tabele + "\\" + nazwa_tabeli + ".dbf" outZSaT = arcpy.sa.ZonalStatisticsAsTable(inZoneData, zoneField, przydatnosc_lesna, outTable, "DATA", "MEAN") # Create a feature layer from the vegtype featureclass maup_lyr = "maup_lyr" arcpy.MakeFeatureLayer_management(maup_kopia, maup_lyr) # Join the feature layer to a table arcpy.AddJoin_management(maup_lyr, "ajdi", outTable, "ajdi") # Populate the newly created field with values from the joined table arcpy.CalculateField_management(maup_lyr, pole, "!MEAN!", "PYTHON") arcpy.RemoveJoin_management(maup_lyr, "przydatnosc") fields = [pole, pole2] cursor = arcpy.UpdateCursor(maup_kopia, fields) for cur in cursor: przyd_relatywna = cur.getValue(pole) / przyd_mean cur.setValue(pole2, przyd_relatywna) cursor.updateRow(cur) # Process: Reclassify las01 = mapa_les_path + "\\reklas.tif" rastercalc = mapa_les_path + "\\las01_przyd.tif" arcpy.Reclassify_3d(las_rol, "Value", "0 1;1 0", las01, "DATA") outTimes = Times(las01, przydatnosc_lesna) outTimes.save(rastercalc) nazwa_tabeli = "przydatnosc_wo" outTable2 = folder_tabele + "\\" + nazwa_tabeli + ".dbf" outZSaT = arcpy.sa.ZonalStatisticsAsTable(inZoneData, zoneField, rastercalc, outTable2, "DATA", "MEAN") arcpy.AddJoin_management(maup_lyr, "ajdi", outTable2, "ajdi") # Populate the newly created field with values from the joined table arcpy.CalculateField_management(maup_lyr, pole3, "!MEAN!", "PYTHON") fields = [pole3, pole4] rast_przyd_wo = arcpy.Raster(rastercalc) ## parametry rastra przydatnosci przyd_wo_mean = rast_przyd_wo.mean cursor = arcpy.UpdateCursor(maup_kopia, fields) for cur in cursor: przyd_relatywna = cur.getValue(pole3) / przyd_wo_mean cur.setValue(pole4, przyd_relatywna) cursor.updateRow(cur) arcpy.RemoveJoin_management(maup_lyr, "przydatnosc_wo") raster_lesny = arcpy.Raster(las_rol) les_mod = raster_lesny.mean #les_mod = licz_procent(las_rol1) #arcpy.CalculateField_management (maup_lyr, pole5, les_mod, "PYTHON") fields = [pole, pole5] cursor = arcpy.UpdateCursor(maup_kopia, fields) for cur in cursor: cur.setValue(pole5, les_mod) cursor.updateRow(cur) nazwa_modelu2 = "kon_" + nazwa_modelu arcpy.CalculateField_management(maup_lyr, pole6, "'" + nazwa_modelu2 + "'", "PYTHON")
nhd_flowline_r = str(here('./results/nhd_f_raster.tif', warn=False)) arcpy.PolylineToRaster_conversion( nhd_flowline_p, "Enabled", nhd_flowline_r, "MAXIMUM_LENGTH", "NONE") # reclass to 0 / height nhd_flowline_rc = str(here('./results/nhd_f_rasterrc.tif', warn=False)) stream_burn_height = 5 arcpy.Reclassify_3d( nhd_flowline_r, "Value", "1 {};NODATA 0".format(stream_burn_height), nhd_flowline_rc, "DATA") # burn in the hydrography with raster calculator ea.logger.send("burning in hydrography") dem_b = str(here('./results/dem_burned.tif', warn=False)) in_mem = arcpy.Raster(dem_clipped) - arcpy.Raster(nhd_flowline_rc) in_mem.save(dem_b) # now start working through watershed creation
Over50pt.save(TrailPT_OverSlope) print ("Trail 50% violation points complete.") # Trail_Segment - 50% Rule Violations Over50seg = arcpy.sa.ZonalStatistics(in_zone_data=Trail_Seg, zone_field="Value", in_value_raster=TrailPT_OverSlope, statistics_type="MAXIMUM", ignore_nodata="DATA") Over50seg.save(TrailSeg_OverSlope) print ("Trail 50% violation segments complete.") # Process: Calculate Time of Concentration (Minutes) Time_C = arcpy.sa.Raster(((0.007*arcpy.sa.Power((arcpy.sa.Raster(Mann_N)*arcpy.sa.Raster(Flow_LenRas)),0.8)/(arcpy.sa.Power(arcpy.sa.Raster(CN_P),0.5)*arcpy.sa.Power(arcpy.sa.Raster(WSF_Slope),0.4))))*60) Time_C.save(Time_Concen) print ("Time of Concentration complete.") # Process: Calculate Precipitation Intensity (mm per hour) remapString = "0 5 460; 5 10 370; 10 15 319; 15 20 282; 20 25 248; 25 30 222" arcpy.Reclassify_3d(Time_Concen,"Value", remapString, TC_Reclas_in, "NODATA") Intens_mm = arcpy.sa.Raster(arcpy.sa.Raster(TC_Reclas_in)/3.937) Intens_mm.save(Intensity) print ("Intensity complete.") # MaxFlow Watershed Area (in hectares) Fl_Const = arcpy.sa.Con(arcpy.sa.Raster(T_FlowMax) > 0, 1) FlMax_Meter = arcpy.sa.ZonalStatistics(in_zone_data=T_FlowMax, zone_field="Value", in_value_raster=Fl_Const, statistics_type="SUM", ignore_nodata="DATA") FlMax_Area = arcpy.sa.Raster((FlMax_Meter)/10000) FlMax_Area.save(WSF_Area) print ("Trail Max Flow watershed area complete.") # Process: Calculate Peak Runoff Velocity (cubic meter per second) P_Velo = arcpy.sa.Raster((arcpy.sa.Raster(Soil_Rat_C)*arcpy.sa.Raster(Intensity)*arcpy.sa.Raster(WSF_Area))/360) FloatRas = arcpy.sa.Float(P_Velo) FloatRas.save(Flow_Velocity)
def convert_afe_to_final_tiles(config): ''' This function converts AFE outputs to final TIFF files. ''' phyregs_layer = config.phyregs_layer naipqq_layer = config.naipqq_layer naipqq_phyregs_field = config.naipqq_phyregs_field results_path = config.results_path snaprast_path = config.snaprast_path arcpy.env.addOutputsToMap = False arcpy.env.snapRaster = snaprast_path arcpy.SelectLayerByAttribute_management( phyregs_layer, where_clause='PHYSIO_ID in (%s)' % ','.join(map(str, config.phyreg_ids))) with arcpy.da.SearchCursor(phyregs_layer, ['NAME', 'PHYSIO_ID']) as cur: for row in cur: name = row[0] print(name) # CreateRandomPoints cannot create a shapefile with - in its # filename name = name.replace(' ', '_').replace('-', '_') phyreg_id = row[1] # Check and ensure that FA has classified all files. outdir_path = '%s/%s/Outputs' % (results_path, name) # Path for reprojected tiles inputs_path = '%s/%s/Inputs' % (results_path, name) if len(os.listdir(outdir_path)) == 0: continue # File names for all reprojected inputs inputs_check = [ os.path.basename(x) for x in glob.glob(f"{inputs_path}/rm_*.tif") ] # File names for all classified outputs output_class_check = [ os.path.basename(x) for x in glob.glob(f"{outdir_path}/rm_*.tif") ] # Check and get file names of those missing. missing = [] for i in inputs_check: if i not in output_class_check: missing.append(i) # If any are missing then the length of each list will be # different. Raise I/O error and return missing file names. if len(inputs_check) != len(output_class_check): # Format the same way FA specifies batch inputs. missing_formated = " ".join(missing).replace(' ', '; ') raise IOError(f"Missing classified file: {missing_formated}") arcpy.SelectLayerByAttribute_management( naipqq_layer, where_clause="%s like '%%,%d,%%'" % (naipqq_phyregs_field, phyreg_id)) with arcpy.da.SearchCursor(naipqq_layer, ['FileName']) as cur2: for row2 in sorted(cur2): filename = row2[0][:-13] rshpfile_path = '%s/r%s.shp' % (outdir_path, filename) rtiffile_path = '%s/r%s.tif' % (outdir_path, filename) frtiffile_path = '%s/fr%s.tif' % (outdir_path, filename) if os.path.exists(frtiffile_path): continue if os.path.exists(rshpfile_path): arcpy.FeatureToRaster_conversion( rshpfile_path, 'CLASS_ID', frtiffile_path) # Compare output tif cell size to snap raster check_snap(frtiffile_path, snaprast_path) elif os.path.exists(rtiffile_path): # Compare input tif cell size to snap raster check_snap(rtiffile_path, snaprast_path) arcpy.Reclassify_3d(rtiffile_path, 'Value', '1 0;2 1', frtiffile_path) # clear selection arcpy.SelectLayerByAttribute_management(phyregs_layer, 'CLEAR_SELECTION') arcpy.SelectLayerByAttribute_management(naipqq_layer, 'CLEAR_SELECTION') print('Completed')
def execute(self, params, messages): deleteInMemory() Limit = params[14].value strLimit = params[14].ValueAsText arcpy.AddMessage("Target Data Capture = " + strLimit) rawPath = os.path.dirname( params[1].valueAsText) + "\\" + os.path.basename( params[1].valueAsText) + "_Raw_Data" finalPath = os.path.dirname( params[1].valueAsText) + "\\" + os.path.basename( params[1].valueAsText) + "_Final_Data" if not os.path.exists(rawPath): os.mkdir(rawPath) if not os.path.exists(finalPath): os.mkdir(finalPath) poly = arcpy.MakeFeatureLayer_management(params[0].valueAsText) outRaw = rawPath + "\\" + os.path.basename(params[1].valueAsText) outFinal = finalPath + "\\" + os.path.basename(params[1].valueAsText) outMain = params[1].valueAsText arcpy.env.workspace = os.path.dirname(params[1].valueAsText) arcpy.env.scratchWorkspace = os.path.dirname(params[1].valueAsText) DEM = params[5].valueAsText Geology = arcpy.MakeFeatureLayer_management(params[7].valueAsText) geoField = params[8].valueAsText Soils = arcpy.MakeFeatureLayer_management(params[9].valueAsText) soilField = params[10].valueAsText Vegetation = arcpy.MakeFeatureLayer_management(params[11].valueAsText) vegField = params[12].valueAsText Streams = arcpy.MakeFeatureLayer_management(params[13].valueAsText) Sites = arcpy.MakeFeatureLayer_management(params[2].valueAsText) zFactor = params[6].value try: #Multipart Handling lyr = finalPath + "\\" + os.path.basename( params[1].valueAsText) + "_Poly.shp" polyParts = int(arcpy.GetCount_management(poly).getOutput(0)) if polyParts > 1: arcpy.Dissolve_management(poly, lyr) else: arcpy.CopyFeatures_management(poly, lyr) #Create and calcualte POLY_ACRES arcpy.AddField_management(lyr, "POLY_ACRES", 'DOUBLE', 12, 8) arcpy.CalculateField_management(lyr, "POLY_ACRES", "!shape.area@ACRES!", "PYTHON_9.3", "") Desc = arcpy.Describe(lyr) polyAcres = ([ row[0] for row in arcpy.da.SearchCursor(lyr, ["POLY_ACRES"]) ][0]) arcpy.AddMessage("Analysis area = " + str(polyAcres) + " acres") if polyAcres > 50000: arcpy.AddMessage("Target layer overlap will not be calculated") #Clip Sites siteField = params[3].valueAsText siteValue = params[4].valueAsText outPoints = outFinal + "_Data_Points.shp" outSites = outRaw + "_Sites" if siteValue == "ALL SITES": arcpy.MakeFeatureLayer_management(Sites, outSites) else: siteQuery = '"' + siteField + '"' + " = " + "'" + siteValue + "'" arcpy.MakeFeatureLayer_management(Sites, outSites, siteQuery) arcpy.SelectLayerByLocation_management(outSites, "INTERSECT", lyr) siteResult = int(arcpy.GetCount_management(outSites).getOutput(0)) arcpy.AddMessage(siteValue + " Site Count = " + str(siteResult)) if siteResult < 10: arcpy.AddMessage( "There are insufficient site data for analysis") deleteInMemory() SystemExit(0) siteDensity = str(siteResult / polyAcres) arcpy.AddMessage("Site density = " + siteDensity[0:5] + " sites/acre") if siteResult / polyAcres < 0.01: arcpy.AddMessage( "Site density is too low for reliable analysis (0.010 sites/acre minimum), use discretion when interpreting results" ) arcpy.FeatureToPoint_management(outSites, outPoints, "CENTROID") #Clip DEM, Calculate Slope and Aspect, Reclassify outDEM = outRaw + "_Dem" outSlope = outRaw + "_Slp" outAspect = outRaw + "_Asp" arcpy.AddMessage("Clipping DEM") arcpy.Clip_management(DEM, "#", "in_memory\\DEMClip", lyr, "#", "ClippingGeometry") arcpy.Reclassify_3d( "in_memory\\DEMClip", "VALUE", "0 100 100;100 200 200;200 300 300;300 400 400;400 500 500;500 600 600;600 700 700;700 800 800;800 900 900;900 1000 1000;1000 1100 1100;1100 1200 1200;1200 1300 1300;1300 1400 1400;1400 1500 1500;1500 1600 1600;1600 1700 1700;1700 1800 1800;1800 1900 1900;1900 2000 2000;2000 2100 2100;2100 2200 2200;2200 2300 2300;2300 2400 2400;2400 2500 2500;2500 2600 2600;2600 2700 2700;2700 2800 2800;2800 2900 2900;2900 3000 3000;3000 3100 3100;3100 3200 3200;3200 3300 3300;3300 3400 3400;3400 3500 3500;3500 3600 3600;3600 3700 3700;3700 3800 3800;3800 3900 3900;3900 4000 4000;4000 4100 4100;4100 4200 4200;4200 4300 4300;4300 4400 4400;4400 4500 4500;4500 4600 4600;4600 4700 4700;4700 4800 4800;4800 4900 4900;4900 5000 5000;5000 5100 5100;5100 5200 5200;5200 5300 5300;5300 5400 5400;5400 5500 5500;5500 5600 5600;5600 5700 5700;5700 5800 5800;5800 5900 5900;5900 6000 6000;6000 6100 6100;6100 6200 6200;6200 6300 6300;6300 6400 6400;6400 6500 6500;6500 6600 6600;6600 6700 6700;6700 6800 6800;6800 6900 6900;6900 7000 7000;7000 7100 7100;7100 7200 7200;7200 7300 7300;7300 7400 7400;7400 7500 7500;7500 7600 7600;7600 7700 7700;7700 7800 7800;7800 7900 7900;7900 8000 8000;8000 8100 8100;8100 8200 8200;8200 8300 8300;8300 8400 8400;8400 8500 8500;8500 8600 8600;8600 8700 8700;8700 8800 8800;8800 8900 8900;8900 9000 9000;9000 9100 9100;9100 9200 9200;9200 9300 9300;9300 9400 9400;9400 9500 9500;9500 9600 9600;9600 9700 9700;9700 9800 9800;9800 9900 9900;9900 10000 10000;10000 10100 10100;10100 10200 10200;10200 10300 10300;10300 10400 10400;10400 10500 10500;10500 10600 10600;10600 10700 10700;10700 10800 10800;10800 10900 10900;10900 11000 11000;11000 11100 11100;11100 11200 11200;11200 11300 11300;11300 11400 11400;11400 11500 11500;11500 11600 11600;11600 11700 11700;11700 11800 11800;11800 11900 11900;11900 12000 12000;12000 12100 12100;12100 12200 12200;12200 12300 12300;12300 12400 12400;12400 12500 12500;12500 12600 12600;12600 12700 12700;12700 12800 12800;12800 12900 12900;12900 13000 13000;13000 13100 13100;13100 13200 13200;13200 13300 13300;13300 13400 13400;13400 13500 13500;13500 13600 13600;13600 13700 13700;13700 13800 13800;13800 13900 13900;13900 14000 14000;14000 14100 14100;14100 14200 14200;14200 14300 14300;14300 14400 14400;14400 14500 14500;14500 14600 14600;14600 14700 14700;14700 14800 14800;14800 14900 14900;14900 15000 15000", outDEM) arcpy.AddMessage("Calculating Slope") arcpy.Slope_3d("in_memory\\DEMClip", "in_memory\\outSlope", "DEGREE", zFactor) arcpy.Reclassify_3d( "in_memory\\outSlope", "VALUE", "0 5 5;5 10 10;10 15 15;15 20 20;20 25 25;25 30 30;30 35 35;35 40 40;40 45 45;45 90 90", outSlope) arcpy.AddMessage("Calculating Aspect") arcpy.Aspect_3d("in_memory\\DEMClip", "in_memory\\outAspect") arcpy.Reclassify_3d( "in_memory\\outAspect", "VALUE", "-1 22.5 0;22.5 67.5 1;67.5 112.5 2;112.5 157.5 3;157.5 202.5 4;202.5 247.5 5;247.5 292.5 6;292.5 337.5 7;337.5 360 0", outAspect) #Clip Geology arcpy.AddMessage("Clipping Geology") outGeo = outRaw + "_Geo.shp" arcpy.Clip_analysis(Geology, lyr, "in_memory\\outGeo") arcpy.Dissolve_management("in_memory\\outGeo", outGeo, geoField) #Clip Soils arcpy.AddMessage("Clipping Soils") outSoils = outRaw + "_Soil.shp" arcpy.Clip_analysis(Soils, lyr, "in_memory\\outSoil") arcpy.Dissolve_management("in_memory\\outSoil", outSoils, soilField) #Clip Vegetation arcpy.AddMessage("Clipping Vegetation") outVeg = outRaw + "_Veg.shp" arcpy.Clip_analysis(Vegetation, lyr, "in_memory\\outVeg") arcpy.Dissolve_management("in_memory\\outVeg", outVeg, vegField) #Clip Streams arcpy.AddMessage("Clipping and Buffering Streams") outStr = outRaw + "_Str.shp" strLayer = arcpy.MakeFeatureLayer_management( Streams, "in_memory\\streams") arcpy.SelectLayerByLocation_management("in_memory\\streams", "INTERSECT", lyr, "", "NEW_SELECTION") streamResult = int( arcpy.GetCount_management("in_memory\\streams").getOutput(0)) if streamResult == 0: arcpy.AddMessage("There Are No Streams Within This Polygon") else: outStreams = outRaw + "_Str.shp" arcpy.Clip_analysis(Streams, lyr, "in_memory\\outStreams") arcpy.MultipleRingBuffer_analysis("in_memory\\outStreams", outStr, [200, 400, 600, 800, 1000], "meters") deleteInMemory() #DEM demTarget = outFinal + "_Elevation_Target.shp" demFinal = outRaw + "_DEM.shp" arcpy.AddMessage("Processing DEM") ExtractValuesToPoints(outPoints, outDEM, "in_memory\\pointDEM") arcpy.Frequency_analysis("in_memory\\pointDEM", "in_memory\\DEM_Table", "RASTERVALU") arcpy.Sort_management("in_memory\\DEM_Table", "in_memory\\DEM_Sort", [["FREQUENCY", "DESCENDING"]]) Vdem = 0 Xdem = 0 demList = [] with arcpy.da.SearchCursor("in_memory\\DEM_Sort", ["RASTERVALU", "FREQUENCY"]) as cursor: for row in cursor: if Xdem == 0: Vdem = row[1] demList.append(row[0]) else: Vdem = Vdem + row[1] demList.append(row[0]) if float(Vdem) / float(siteResult) < Limit: Xdem = Xdem + 1 else: break arcpy.RasterToPolygon_conversion(outDEM, demFinal, "SIMPLIFY", "VALUE") DEMdesc = arcpy.Describe(demFinal) fields = DEMdesc.fields for field in fields: if field.name == "GRIDCODE": arcpy.AddField_management(demFinal, "ELEV", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor(demFinal, ["GRIDCODE", "ELEV"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.DeleteField_management(demFinal, "GRIDCODE") qryList = [str(dem) for dem in demList] expr = "ELEV IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(demFinal, "in_memory\\demTarget", expr) arcpy.Dissolve_management("in_memory\\demTarget", demTarget, "ELEV") #arcpy.Delete_management(outDEM) #SLOPE slopeTarget = outFinal + "_Slope_Target.shp" slopeFinal = outRaw + "_Slope.shp" arcpy.AddMessage("Processing Slope") ExtractValuesToPoints(outPoints, outSlope, "in_memory\\pointSlope") arcpy.Frequency_analysis("in_memory\\pointSlope", "in_memory\\Slope_Table", "RASTERVALU") arcpy.Sort_management("in_memory\\Slope_Table", "in_memory\\Slope_Sort", [["FREQUENCY", "DESCENDING"]]) Vslp = 0 Xslp = 0 slpList = [] with arcpy.da.SearchCursor("in_memory\\Slope_Sort", ["RASTERVALU", "FREQUENCY"]) as cursor: for row in cursor: if Xslp == 0: Vslp = row[1] slpList.append(row[0]) else: Vslp = Vslp + row[1] slpList.append(row[0]) if float(Vslp) / float(siteResult) < Limit: Xslp = Xslp + 1 else: break arcpy.RasterToPolygon_conversion(outSlope, slopeFinal, "SIMPLIFY", "VALUE") Slpdesc = arcpy.Describe(slopeFinal) fields = Slpdesc.fields for field in fields: if field.name == "GRIDCODE": arcpy.AddField_management(slopeFinal, "SLOPE", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( slopeFinal, ["GRIDCODE", "SLOPE"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.DeleteField_management(slopeFinal, "GRIDCODE") qryList = [str(slp) for slp in slpList] expr = "SLOPE IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(slopeFinal, "in_memory\\slopeTarget", expr) arcpy.Dissolve_management("in_memory\\slopeTarget", slopeTarget, "SLOPE") #arcpy.Delete_management(outSlope) #ASPECT aspectTarget = outFinal + "_Aspect_Target.shp" aspectFinal = outRaw + "_Aspect.shp" arcpy.AddMessage("Processing Aspect") ExtractValuesToPoints(outPoints, outAspect, "in_memory\\pointAspect") arcpy.Frequency_analysis("in_memory\\pointAspect", "in_memory\\aspect_Table", "RASTERVALU") arcpy.Sort_management("in_memory\\aspect_Table", "in_memory\\aspect_Sort", [["FREQUENCY", "DESCENDING"]]) Vasp = 0 Xasp = 0 aspList = [] with arcpy.da.SearchCursor("in_memory\\aspect_Sort", ["RASTERVALU", "FREQUENCY"]) as cursor: for row in cursor: if Xasp == 0: Vasp = row[1] aspList.append(row[0]) else: Vasp = Vasp + row[1] aspList.append(row[0]) if float(Vasp) / float(siteResult) < Limit: Xasp = Xasp + 1 else: break arcpy.RasterToPolygon_conversion(outAspect, aspectFinal, "SIMPLIFY", "VALUE") Aspdesc = arcpy.Describe(aspectFinal) fields = Aspdesc.fields for field in fields: if field.name == "GRIDCODE": arcpy.AddField_management(aspectFinal, "ASPECT", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( aspectFinal, ["GRIDCODE", "ASPECT"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.DeleteField_management(aspectFinal, "GRIDCODE") qryList = [str(asp) for asp in aspList] expr = "ASPECT IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(aspectFinal, "in_memory\\aspectTarget", expr) arcpy.Dissolve_management("in_memory\\aspectTarget", aspectTarget, "ASPECT") #arcpy.Delete_management(outAspect) #GEOLOGY GeoTarget = outFinal + "_Geology_Target.shp" arcpy.AddMessage("Processing Geology") arcpy.SpatialJoin_analysis(outPoints, outGeo, "in_memory\\pointGeo") arcpy.Frequency_analysis("in_memory\\pointGeo", "in_memory\\geo_Table", geoField) arcpy.Sort_management("in_memory\\geo_Table", "in_memory\\geo_Sort", [["FREQUENCY", "DESCENDING"]]) Vgeo = 0 Xgeo = 0 geoList = [] with arcpy.da.SearchCursor("in_memory\\geo_Sort", [geoField, "FREQUENCY"]) as cursor: for row in cursor: if Xgeo == 0: Vgeo = row[1] geoList.append(row[0]) else: Vgeo = Vgeo + row[1] geoList.append(row[0]) if float(Vgeo) / float(siteResult) < Limit: Xgeo = Xgeo + 1 else: break qryList = ["'" + geo + "'" for geo in geoList] expr = '"' + geoField + '"' + " IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(outGeo, "in_memory\\geoTarget", expr) GEOdesc = arcpy.Describe("in_memory\\geoTarget") fields = GEOdesc.fields for field in fields: if field.name == geoField: arcpy.AddField_management("in_memory\\geoTarget", "GEO_TYPE", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( "in_memory\\geoTarget", [geoField, "GEO_TYPE"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.Dissolve_management("in_memory\\geoTarget", GeoTarget, "GEO_TYPE") #SOILS SoilTarget = outFinal + "_Soil_Target.shp" arcpy.AddMessage("Processing Soils") arcpy.SpatialJoin_analysis(outPoints, outSoils, "in_memory\\pointSoil") arcpy.Frequency_analysis("in_memory\\pointSoil", "in_memory\\soil_Table", soilField) arcpy.Sort_management("in_memory\\soil_Table", "in_memory\\soil_Sort", [["FREQUENCY", "DESCENDING"]]) Vsoil = 0 Xsoil = 0 soilList = [] with arcpy.da.SearchCursor("in_memory\\soil_Sort", [soilField, "FREQUENCY"]) as cursor: for row in cursor: if Xsoil == 0: Vsoil = row[1] soilList.append(row[0]) else: Vsoil = Vsoil + row[1] soilList.append(row[0]) if float(Vsoil) / float(siteResult) < Limit: Xsoil = Xsoil + 1 else: break qryList = ["'" + soil + "'" for soil in soilList] expr = '"' + soilField + '"' + " IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(outSoils, "in_memory\\soilTarget", expr) SOILdesc = arcpy.Describe("in_memory\\soilTarget") fields = SOILdesc.fields for field in fields: if field.name == soilField: arcpy.AddField_management("in_memory\\soilTarget", "SOIL_TYPE", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( "in_memory\\soilTarget", [soilField, "SOIL_TYPE"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.Dissolve_management("in_memory\\soilTarget", SoilTarget, "SOIL_TYPE") #VEGETATION VegTarget = outFinal + "_Veg_Target.shp" arcpy.AddMessage("Processing Vegetation") arcpy.SpatialJoin_analysis(outPoints, outVeg, "in_memory\\pointVeg") arcpy.Frequency_analysis("in_memory\\pointVeg", "in_memory\\veg_Table", vegField) arcpy.Sort_management("in_memory\\veg_Table", "in_memory\\veg_Sort", [["FREQUENCY", "DESCENDING"]]) Vveg = 0 Xveg = 0 vegList = [] with arcpy.da.SearchCursor("in_memory\\veg_Sort", [vegField, "FREQUENCY"]) as cursor: for row in cursor: if Xveg == 0: Vveg = row[1] vegList.append(row[0]) else: Vveg = Vveg + row[1] vegList.append(row[0]) if float(Vveg) / float(siteResult) < Limit: Xveg = Xveg + 1 else: break qryList = ["'" + veg + "'" for veg in vegList] expr = '"' + vegField + '"' + " IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(outVeg, "in_memory\\vegTarget", expr) VEGdesc = arcpy.Describe("in_memory\\vegTarget") fields = VEGdesc.fields for field in fields: if field.name == vegField: arcpy.AddField_management("in_memory\\vegTarget", "VEG_TYPE", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( "in_memory\\vegTarget", [vegField, "VEG_TYPE"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.Dissolve_management("in_memory\\vegTarget", VegTarget, "VEG_TYPE") #WATER StreamTarget = outFinal + "_Water_Dist_Target.shp" arcpy.AddMessage("Processing Streams") if not streamResult == 0: arcpy.SpatialJoin_analysis(outPoints, outStreams, "in_memory\\pointStream") arcpy.Frequency_analysis("in_memory\\pointStream", "in_memory\\stream_Table", "distance") arcpy.Sort_management("in_memory\\stream_Table", "in_memory\\stream_Sort", [["FREQUENCY", "DESCENDING"]]) Vstr = 0 Xstr = 0 streamList = [] with arcpy.da.SearchCursor( "in_memory\\stream_Sort", ["distance", "FREQUENCY"]) as cursor: for row in cursor: if Xstr == 0: Vstr = row[1] streamList.append(row[0]) else: Vstr = Vstr + row[1] streamList.append(row[0]) if float(Vstr) / float(siteResult) < Limit: Xstr = Xstr + 1 else: break qryList = [str(stream) for stream in streamList] expr = "distance IN (" + ",".join(qryList) + ")" arcpy.MakeFeatureLayer_management(outStreams, "in_memory\\streamTarget", expr) strDesc = arcpy.Describe("in_memory\\streamTarget") fields = strDesc.fields for field in fields: if field.name == "distance": arcpy.AddField_management("in_memory\\streamTarget", "WAT_DIST", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( "in_memory\\streamTarget", ["distance", "WAT_DIST"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.Dissolve_management("in_memory\\streamTarget", StreamTarget, "WAT_DIST") #Overlay and count overlaps if params[15].value == 1 and polyAcres < 50000: arcpy.AddMessage("Calculating target layer overlap") layerList = [ demTarget, slopeTarget, aspectTarget, GeoTarget, SoilTarget, VegTarget, StreamTarget ] existsList = [] for layer in layerList: if arcpy.Exists(layer): existsList.append(layer) outMerge = outFinal + "_Merge.shp" outFtoLine = outFinal + "_FtoLine.shp" outFtoPoly = outFinal + "_FtoPoly.shp" outFtoPoint = outFinal + "_FtoPoint.shp" outJoin1 = outFinal + "_Join1.shp" outDiss1 = outFinal + "_Diss1.shp" outJoin2 = outFinal + "_Join2.shp" outDiss2 = outFinal + "_Diss2.shp" rankPoly = outFinal + "_Rank_Poly.shp" arcpy.Merge_management(existsList, outMerge) arcpy.FeatureToLine_management(outMerge, outFtoLine) arcpy.FeatureToPolygon_management(outFtoLine, outFtoPoly, "#", "NO_ATTRIBUTES", "#") arcpy.FeatureToPoint_management(outFtoPoly, outFtoPoint, "INSIDE") arcpy.SpatialJoin_analysis(outFtoPoint, outMerge, outJoin1, "JOIN_ONE_TO_MANY", "KEEP_ALL", "#", "INTERSECT", "#", "#") arcpy.Dissolve_management(outJoin1, outDiss1, "TARGET_FID", "Join_Count SUM", "MULTI_PART", "DISSOLVE_LINES") arcpy.SpatialJoin_analysis(outFtoPoly, outDiss1, outJoin2, "JOIN_ONE_TO_ONE", "KEEP_ALL", "#", "INTERSECT", "#", "#") rankDesc = arcpy.Describe(outJoin2) fields = rankDesc.fields for field in fields: if field.name == "SUM_Join_C": arcpy.AddField_management(outJoin2, "OVERLAP", field.type, field.precision, field.scale, field.length, "", "", "", "") with arcpy.da.UpdateCursor( outJoin2, ["SUM_Join_C", "OVERLAP"]) as cursor: for row in cursor: row[1] = row[0] cursor.updateRow(row) arcpy.Dissolve_management(outJoin2, outDiss2, "OVERLAP", "#", "MULTI_PART", "DISSOLVE_LINES") arcpy.Clip_analysis(outDiss2, lyr, rankPoly) delList = [ outMerge, outFtoLine, outFtoPoly, outFtoPoint, outJoin1, outDiss1, outJoin2, outDiss2 ] for item in delList: arcpy.Delete_management(item) finally: delList2 = [] for item in delList2: arcpy.Delete_management(item) deleteInMemory() return