**** Ascii to ArcRaster & Project Pyramids (Python Script)**** # --------------------------------------------------------------------------- # ascii_to_arcraster_project_pyramids_stand_alone.py # Created on: Tuesday Oct 04 2006 # Nadine Golden # --------------------------------------------------------------------------- # Import system modules import glob, sys, string, os, win32com.client # 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/Conversion Tools.tbx") files = glob.glob("F:/test/grids/*asc") for file in files: (basename, ext) = os.path.splitext(file) ingrid = file outgrid = basename + "tmp" os.system("scii_to_arcraster_project_pyramids_stand_alone.py %s %s" % (ingrid, outgrid)) # Process: ASCII to Raster... gp.ASCIIToRaster_conversion(ingrid, outgrid, "INTEGER") ## # Process: Define Projection... ## gp.DefineProjection_management(outgrid, "PROJCS['NAD_1983_UTM_Zone_11N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983', SPHEROID['GRS_1980',6378137.0,298.257222101]], PRIMEM['Greenwich',0.0], UNIT['Degree',0.0174532925199433]], PROJECTION['Transverse_Mercator'], PARAMETER['False_Easting',500000.0], PARAMETER['False_Northing',0.0], PARAMETER['Central_Meridian',-117.0], PARAMETER['Scale_Factor',0.9996], PARAMETER['Latitude_Of_Origin',0.0], UNIT['Meter',1.0]]") # Process: Project Raster... finalgrid = basename gp.ProjectRaster_management(outgrid, finalgrid, "PROJCS['WGS_1984_UTM_Zone_11N',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984', SPHEROID['WGS_1984',6378137.0,298.257223563]], PRIMEM['Greenwich',0.0], UNIT['Degree',0.0174532925199433]], PROJECTION['Transverse_Mercator'], PARAMETER['False_Easting',500000.0], PARAMETER['False_Northing',0.0], PARAMETER['Central_Meridian',-117.0], PARAMETER['Scale_Factor',0.9996], PARAMETER['Latitude_Of_Origin',0.0], UNIT['Meter',1.0]]; -10000 -10000 100000;0 100000;0 100000", "NEAREST", "1") # Process: Build Pyramids... gp.BuildPyramids_management(finalgrid) # Clean up the mess gp.Delete(outgrid)
**** Rasters Statistics for Normalizing Data (Python Script)**** # --------------------------------------------------------------------------- # RasterStats.py # To Calculate the mean value of a raster # Created on: Thursday Oct 20, 2006 # Nadine Golden # --------------------------------------------------------------------------- # Import system modules import sys, string, os, win32com.client # Create the Geoprocessor object gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") # Check out any necessary licenses gp.CheckOutExtension("spatial") # Load required toolboxes... gp.AddToolbox("E:/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx") gp.AddToolbox("E:/ArcGIS/RasterStatsTool/RasterStatistics.tbx") #Directory of grids gp.Workspace = "F:\\test" rasterlist = gp.ListRasters() name = rasterlist.Next() while name: print name # Process: RasterBand Statistics... mean = gp.RasterBandStatistics(name, "MEAN") print mean # Process: Minus... (indir,basename) = os.path.split(name) outgrid = os.path.join("F:\\test\\Normalized", basename) gp.Minus_sa(name, mean, outgrid) print outgrid name = rasterlist.Next()