import arcgisscripting gp = arcgisscripting.create(9.3) gp.SelectLayerByLocation_management("county features/parks", "WITHIN", "AnotherLayer", "", "NEW_SELECTION") #Change "AnotherLayer" to a layer in the Map Document to use in the selection
# ----------------------------------------------------------------------------------------------------------- # # This script does a "select by location" query on layers in the TOC and exports the results as shapefiles. # # Note: when building a tool for this script, this tool requires a shapefile input # # ----------------------------------------------------------------------------------------------------------- # Import system modules import sys, string, os, arcgisscripting from os.path import basename, splitext # Create the Geoprocessor object gp = arcgisscripting.create(9.3) # Load required toolboxes... gp.AddToolbox("E:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") gp.AddToolbox("E:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") multinputs = sys.argv[1] inputlist = multinputs.split(";") units = ["unit_388", "unit_434"] # Local variables... unitnames = [ splitext(basename(i))[0] for i in inputlist ] cop_dictionary = {"local housing":"house","local streets":"streets","county features//parks":"cparks"} #The cop_dictionary variable houses the layer's names: the first name as the one appearing in TOC, second name as name of output shp #notice the third one is a parks layer in a group layer (county features) part_path = "X:\\Exported_shps\\" f = open( part_path + "logfile.txt ", 'a') f.write(" The script is: " + str(sys.argv[0])) for iter in cop_dictionary: for curr in unitnames: fc_output_subdir = part_path + str(curr) + "\\" try: os.makedirs(fc_output_subdir) except OSError: pass exportkav = fc_output_subdir + cop_dictionary[iter] imp = iter inter = iter using = "X:\\units_poly_bank\\" + curr + ".shp" gp.AddMessage( cop_dictionary[iter] +" "+ curr) f.write( " " + str(cop_dictionary[iter])+ " \n") f.write(" " + str(curr)+ " \n") desc = gp.Describe(imp) typest = str(desc.ShapeType) if "Point" in typest: gp.SelectLayerByLocation_management(imp, "WITHIN", using, "", "NEW_SELECTION") f.write("POINT LAYER DETECTED!! performing -WITHIN- select ONLY" + str(imp)+ " \n") gp.AddMessage("POINT LAYER DETECTED!! performing -WITHIN- select ONLY") else: gp.SelectLayerByLocation_management(imp, "WITHIN", using, "", "NEW_SELECTION") f.write("Finished -WITHIN- select"+ " \n") gp.AddMessage("Finished -WITHIN- select") gp.SelectLayerByLocation_management(imp, "CROSSED_BY_THE_OUTLINE_OF", using, "", "ADD_TO_SELECTION") f.write("Finished -CROSSED_BY_THE_OUTLINE- select"+ " \n") gp.AddMessage("Finished -CROSSED_BY_THE_OUTLINE- select") # Process: Select... gp.Select_analysis(inter, exportkav, "") gp.AddMessage(exportkav + " has been exported \n") f.write( str(cop_dictionary[iter]) + "_" + curr + " has been exported \n" ) # Use these commands when f i n i s h e d f.write( "Total export has ended \n" ) f.flush() f.close() del inputlist, using, exportkav, imp, inter
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.