CE 697V, Project 41 Project 4: Geoprocessing Script November 10, 2006 Kwangbae Kim
CE 697V, Project 42 Descriptions of this project ArcGIS geoprocessing to select suitable locations by tool development with geoprocessing script The object of this project: to make a tool with geoprocessing script to find the best site selection for his family at the city of West Lafayette of a new Purdue student
CE 697V, Project 43 Procedure 1. Create a personal geodatabase to save or load all the involved data 2. Load all vector and raster data in geodatabase 3. Project all vector data and raster data (DEM in Lafayette) 4. Perform spatial analysis tools by selection criteria to find the best location
CE 697V, Project 44 Contents of Geoprocessing Scripts Script Project 4a: Create a personal geodatabase to save or load all the involved data Script Project 4b: Load all vector and raster data in geodatabase and project all vector data and raster data (DEM in Lafayette) Script Project 4c: Perform spatial analysis tools by selection criteria to find the best location
CE 697V, Project 45 Selection criteria Input all feature data (all streets, restaurants, CE building, schoolmap, and houses shape files) into geodatabase Project all feature data on UTM zone 16N, NAD83 Project the elevation_lafayette raster data on UTM zone 16N, NAD83 Select US Highway 52 from all streets Buffer US Highway 52 within 1 mile from selected US Highway 52 Buffer restaurants within 2 miles from restaurants Buffer 6 driving distance miles to the Civil Engineering building Buffer 3 driving distance miles to school Select houses with 3 bedrooms and a price less than $150,000 from geocoding house addresses
CE 697V, Project 46 Selection criteria (features) Clip all_streets_buffer and restaurants_buffer → clip1_out Intersect civil_engineering_buffer and school_buffer → intersect_out Clip clip1_out and intersect_out → clip2_out Intersect clip2_out and houses_select → final_out
CE 697V, Project 47 Final Map
CE 697V, Project 48 Geoprocessing Scrpit # # Created on: Kwangbae Kim # CE697V, Project 4: Geoprocessing Script # # Import system modules import sys, os, win32com.client, string # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Load required toolboxes... gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") # Create workspace and geodatabase gp.workspace = gp.GetParameterAsText(0) Script project4a
CE 697V, Project 49 Geoprocessing Scrpit p4_mdb = gp.GetParameterAsText(1) geodb=gp.CreatePersonalGDB_management("H:/project4", p4_mdb) # Load the features, raster data, and table # Load features: all streets, restaurants, Civil Engineering, school, and houses features = gp.GetParameterAsText(2) gp.FeatureClassToGeodatabase_Conversion(features,geodb) rasters = gp.GetParameterAsText(3) gp.RasterToGeodatabase(rasters,geodb)
CE 697V, Project 410 Geoprocessing Scrpit # # Created on: Kwangbae Kim # CE697V, Project 4_b: Geoprocessing Script # # Import system modules import sys, os, win32com.client, string # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Load required toolboxes... gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") # Create workspace and geodatabase gp.workspace = gp.GetParameterAsText(0) Script project4b
CE 697V, Project 411 Geoprocessing Scrpit (cont ’ d) # Load the features, raster data, and table # Load features: all streets, restaurants, Civil Engineering, school, and houses all_streets = gp.GetParameterAsText(1) restaurants = gp.GetParameterAsText(2) civil_engineering = gp.GetParameterAsText(3) school = gp.GetParameterAsText(4) houses = gp.GetParameterAsText(5) # Load raster data: elevation data elevation_west_lafayette = gp.GetParameterAsText(6) elevation_east_lafayette = gp.GetParameterAsText(7) # Read the parameter value for projection projection = gp.GetParameterAsText(8)
CE 697V, Project 412 Geoprocessing Scrpit (cont ’ d) # Project the features class on UTM Zone 16N gp.BatchProject_management(all_streets, gp.workspace, projection) gp.BatchProject_management(restaurants, gp.workspace, projection) gp.BatchProject_management(civil_engineering, gp.workspace, projection) gp.BatchProject_management(school, gp.workspace, projection) gp.BatchProject_management(houses, gp.workspace, projection) # Project raster data on UTM Zone 16N gp.ProjectRaster_management(elevation_west_lafayette, "elevation_west_lafayette_project", projection, "BILINEAR", "", "","" ) gp.ProjectRaster_management(elevation_east_lafayette, "elevation_east_lafayette_project", projection, "BILINEAR", "", "","" ) Project all features and rasters on UTM Zone 16N
CE 697V, Project 413 Geoprocessing Scrpit (cont ’ d) # create new geodatabase gdb=gp.GetParameterAsText(9) geodb=gp.CreatePersonalGDB("H:/project4", gdb) # Input all features and raster data into geodatabase gp.FeatureClassToGeodatabase_Conversion(all_streets+"_1", geodb) gp.FeatureClassToGeodatabase_Conversion(restaurants+"_1", geodb) gp.FeatureClassToGeodatabase_Conversion(civil_engineering+"_1", geodb) gp.FeatureClassToGeodatabase_Conversion(school+"_1", geodb) gp.FeatureClassToGeodatabase_Conversion(houses+"_1", geodb) gp.RasterToGeodatabase_Conversion(elevation_west_lafayette+"_project", geodb) gp.RasterToGeodatabase_Conversion(elevation_east_lafayette+"_project", geodb)
CE 697V, Project 414 Geoprocessing Scrpit (cont ’ d) # # Created on: Kwangbae Kim # CE697V, Project 4_c: Geoprocessing Script # # Import system modules import sys, os, win32com.client, string # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Load required toolboxes... gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx") gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx") gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx") Script project4c
CE 697V, Project 415 Geoprocessing Scrpit (cont ’ d) # Create workspace and geodatabase gp.workspace = gp.GetParameterAsText(0) # Load the projected features: all streets, restaurants, Civil Engineering, school, and houses all_streets = gp.GetParameterAsText(1) restaurants = gp.GetParameterAsText(2) civil_engineering = gp.GetParameterAsText(3) school = gp.GetParameterAsText(4) houses = gp.GetParameterAsText(2) # Read the parameter values distance_US52 = gp.GetParameterAsText(3) distance_restaurants = gp.GetParameterAsText(7) distance_civil_engineering = gp.GetParameterAsText(8) distance_school = gp.GetParameterAsText(9)
CE 697V, Project 416 Geoprocessing Scrpit (cont ’ d) # Select US Highway 52 from all streets and distance buffer (1 mile) s1 = all_streets+'_select' gp.Select_analysis(all_streets, s1, "( [NAME] = 'SAGAMORE') OR( [NAME] = 'US HIGHWAY 52') OR( [NAME] = 'US HWY 52' )") # Buffer 2 miles distance to restaurants b2 = restaurants+'_buffer' gp.Buffer_analysis(restaurants, b2, distance_restaurants, "FULL", "ROUND", "ALL", "") # Buffer 6 miles driving distance to Civil Engineering building b3 = civil_engineering+'_buffer' gp.Buffer_analysis(civil_engineering, b3, distance_civil_engineering, "FULL", "ROUND", "ALL", "")
CE 697V, Project 417 Geoprocessing Scrpit (cont ’ d) # Buffer 3 miles driving distance to all schools b4 = school+'_buffer' gp.Buffer_analysis(school, b4, distance_school, "FULL", "ROUND", "ALL", "") # Select houses with 3 bedrooms and a price less than $ s2 = houses+'_select' gp.Select_analysis(houses, s2, "( [BED] = 3 ) AND ( [PRICE] <= )" # Clip US52_buffer and restaurants_buffer -> clip1_out feature gp.Clip_analysis(US52_buffer, restaurants_buffer, clip1_out) # Intersect civil_engineering_buffer and school_buffer -> intersect_out gp.Intersect_analysis(civil_engineering_buffer, school_buffer, intersect_out) # Clip clip1_out and intersect_out -> clip2_out gp.Clip_analysis(clip1_out, intersect_out, clip2_out)
CE 697V, Project 418 Geoprocessing Scrpit # Intersect clip2_out and houses_select -> final_out feature gp.Intersect_analysis(clip2_out, houses_select, final_out) # create new geodatabase gdb=gp.GetParameterAsText(3) geodb=gp.CreatePersonalGDB("H:/project4", gdb) # Input all features and raster data into geodatabase gp.FeatureClassToGeodatabase_Conversion(s1, geodb) gp.FeatureClassToGeodatabase_Conversion(b2, geodb) gp.FeatureClassToGeodatabase_Conversion(b3, geodb) gp.FeatureClassToGeodatabase_Conversion(b4, geodb) gp.FeatureClassToGeodatabase_Conversion(s2, geodb) gp.FeatureClassToGeodatabase_Conversion(clip1_out, geodb) gp.FeatureClassToGeodatabase_Conversion(intersect_out, geodb) gp.FeatureClassToGeodatabase_Conversion(clip2_out, geodb) gp.FeatureClassToGeodatabase_Conversion(final_out, geodb)