# --------------------------------------------------------------------------- # soil_clipping.py # Created on: Fri Mar 24 2006 02:40:26 PM # (generated by ArcGIS/ModelBuilder) # Usage: soil_select_test # --------------------------------------------------------------------------- # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Load required toolboxes... gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Statistics Tools.tbx") gp.OverwriteOutput = 1 # no separate Boolean type in Python 2.1, must use 0 and 1 soil_name = {} max_cases = {} county_cases = {} musym = {} comma = {} county = {} county_select_string = {} musym_by_county_name = "C:\\GISResources\\ssurgo\\musym_by_county.csv" musym_file = open(musym_by_county_name,"r") for counties in range(6): # change to range(6) header_line = musym_file.readline() comma[1] = header_line.find(",") comma[2] = header_line.find(",", comma[1] + 1) comma[3] = header_line.find(",", comma[2] + 1) comma[4] = header_line.find(",", comma[3] + 1) county[counties] = header_line[comma[3] + 1:comma[4]] county_select_string[counties] = "\"areasymbol\" = 'OR"+county[counties][:3]+"' AND ( " #print header_line #print county[counties] #print county_select_string for soil_num in range(340): # need to set to range(340) process_line = musym_file.readline() comma[1] = process_line.find(",") comma[2] = process_line.find(",", comma[1] + 1) comma[3] = process_line.find(",", comma[2] + 1) comma[4] = process_line.find(",", comma[3] + 1) comma[5] = process_line.find(",", comma[4] + 1) comma[6] = process_line.find(",", comma[5] + 1) comma[7] = process_line.find(",", comma[6] + 1) comma[8] = process_line.find(",", comma[7] + 1) comma[9] = process_line.find(",", comma[8] + 1) comma[10] = process_line.find(",", comma[9] + 1) comma[11] = process_line.find(",", comma[10] + 1) soil_name[soil_num] = process_line[:comma[1]] max_cases[soil_num] = int(process_line[comma[1] + 1:comma[2]]) county_cases[soil_num] = int(process_line[comma[2] + 1:comma[3]]) for multi_musym in range(8): index = county[counties]+", "+str(soil_num)+", "+str(multi_musym) skip_space = process_line[comma[3+multi_musym] + 1:comma[4+multi_musym]] if skip_space != " " and skip_space != "": musym[index] = skip_space #print ".", ignore_line = musym_file.readline() # final line at end of each county's data is a summary line #print #print "done reading in County "+county[counties] values_here = musym.values() indexes_here = musym.keys() a=values_here.sort() b=indexes_here.sort() #print values_here #print indexes_here musym_file.close() print "file closed" print soil_name[141] print soil_name[142] print soil_name[235] print soil_name[282] print #stop = 1/0 # now ready to actually run the selections by musym and create files for each specific soil name #western_oregon_soils = "C:\\GISResources\\ssurgo\\" cert_fields = "C:\\DataFiles\\OSUSeedCert\\SpatialStats\\LinnBoundaries_OID_only_wArea.shp" for soil_num in range(141,142): # full run is 0 to 340 soils this_soil = soil_name[soil_num] soil_file_name = "C:\\GISResources\\ssurgo\\"+this_soil+"_dissolve.shp" #clipped_output = "C:\\DataFiles\\clip_"+this_soil+".shp" clipped_output = "C:\\DataFiles\\OSUSeedCert\\SpatialStats\\Soils\\clip_"+this_soil+".shp" try: gp.Clip_analysis(cert_fields, soil_file_name, clipped_output, "") except: print "problems even clipping with this soil = "+this_soil+" soil num "+str(soil_num) clipped_wArea = clipped_output[:-4]+"_wArea.shp" print try: gp.CalculateAreas_stats(clipped_output, clipped_wArea) print "done with "+this_soil+" soil num "+str(soil_num) except: print "no data left after clipping "+this_soil+" soil num "+str(soil_num)