def OLS(): arcpy.env.overwriteOutput = True path = 'F:/Test/Paper180829/Process/' for y in range(15, 18): for m in range(1, 13): name = str(((2000 + y) * 100) + m) shpFile = path + '10kmData/' + 'd' + name + '.shp' shpOut = path + '10kmData_OLSResult/' + '10kmDataOLS' + name + '.shp' coefOut = path + '10kmData_OLSResult/' + 'coef10kmDataOLS' + name + '.dbf' diagOut = path + '10kmData_OLSResult/' + 'diag10kmDataOLS' + name + '.dbf' arcpy.OrdinaryLeastSquares_stats(shpFile, "ORIG_FID", shpOut, "IMERG", "DEM;LTD;X;Y", coefOut, diagOut) print 'finish ', name
def runOLS(hexBins, projectFolder, projectGDBPath): # print( "\nRunning Ordinary Least Squares (OLS) linear regression on hexagon polygons using cancer rate as DV and nitrate levels as IV..." ) # Set environment settings arcpy.env.workspace = projectFolder olsResults = os.path.join(projectGDBPath, "OLS_Results") olsCoefficients = os.path.join(projectGDBPath, "OLS_Coefficients") olsDiagnostics = os.path.join(projectGDBPath, "OLS_Diagnostics") olsReport = os.path.join(projectFolder, "OLS_Report.pdf") # arcpy.OrdinaryLeastSquares_stats(hexBins, "UID", olsResults, "can_MEAN", "nit_MEAN", olsCoefficients, olsDiagnostics, olsReport) # print( "\n\nWisconsin nitrate level and cancer rate Ordinary Least Squares (OLS) linear regression analysis completed." )
def runOLS(hexBins_lyr, projectFolder, projectGDBPath): # arcpy.AddMessage( "\nRunning Ordinary Least Squares (OLS) linear regression on hexagon polygons using cancer rate as DV and nitrate levels as IV..." ) olsResults = os.path.join(projectGDBPath, "OLS_Results") olsCoefficients = os.path.join(projectGDBPath, "OLS_Coefficients") olsDiagnostics = os.path.join(projectGDBPath, "OLS_Diagnostics") olsReport = os.path.join(projectFolder, "OLS_Report.pdf") # arcpy.OrdinaryLeastSquares_stats(hexBins_lyr, "UID", olsResults, "can_MEAN", "nit_MEAN", olsCoefficients, olsDiagnostics, olsReport) # arcpy.AddMessage("\n" + arcpy.GetMessages()) # Add the output to the MXD arcpy.SetParameterAsText(10, olsResults) arcpy.SetParameterAsText(11, olsCoefficients) arcpy.SetParameterAsText(12, olsDiagnostics) arcpy.SetParameterAsText(13, olsReport) # arcpy.AddMessage("\nOLS Results generated:\n" + olsResults) # arcpy.AddMessage("\nOLS Coefficients generated:\n" + olsCoefficients) # arcpy.AddMessage("\nOLS Diagnostics generated:\n" + olsDiagnostics) # arcpy.AddMessage("\nOLS Report generated:\n" + olsReport) # Delete local variables del hexBins_lyr, olsResults, olsCoefficients, olsDiagnostics, olsReport, projectFolder, projectGDBPath # arcpy.AddMessage( "\n\nWisconsin nitrate level and cancer rate Ordinary Least Squares (OLS) linear regression analysis completed." )
if row.getValue("RASTERVALU") < 0 or row.getValue("RASTERVALU") == "None": cursor.deleteRow(row) del cursor del row #Add unique ID field to stations_wElevation for use in OLS function arcpy.AddField_management(fcStations_wElevation, "Unique_ID", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(fcStations_wElevation, "Unique_ID", "!OBJECTID!", "PYTHON_9.3", "") #Run ordinary least squares on stats1 arcpy.AddMessage("Running ordinary least squares") arcpy.CreateTable_management(scratchGDB, "coef_table") ols = arcpy.OrdinaryLeastSquares_stats(fcStations_wElevation, "Unique_ID", "in_memory/fcResid", "MEAN_vapor_pressure", "RASTERVALU", scratchGDB + "/coef_table", "", "") #arcpy.TableToTable_conversion(scratchGDB + "/coef_table", "in_memory", "coef_table") #arcpy.Delete_management(scratchGDB + "/coef_table") intercept = list( (row.getValue("Coef") for row in arcpy.SearchCursor(scratchGDB + "/coef_table", fields="Coef")))[0] slope = list( (row.getValue("Coef") for row in arcpy.SearchCursor(scratchGDB + "/coef_table", fields="Coef")))[1] #Estimate air temperature at all stations using elevation, and slope and intercept from above arcpy.AddMessage("Estimating vapor pressure at all stations") cursor = arcpy.UpdateCursor(fcStations_wElevation)
# Run Regression on the new joined censusjoin shapefile # Set property to overwrite existing outputs arcpy.env.overwriteOutput = True # Local variables... workspace = "C:\\MyUW\\SummerProject1" try: # Set the current workspace (to avoid having to specify the full path to the feature classes each time) arcpy.env.workspace = workspace # Growth as a function of {log of starting income, dummy for South # counties, interaction term for South counties, population density} # Process: Ordinary Least Squares... ols = arcpy.OrdinaryLeastSquares_stats( "C:\\MyUW\\SummerProject1\\censusjoin.shp", "OID_", "C:\\MyUW\\SummerProject1\\olsResults.shp", "canrate", "MEAN") # Create Spatial Weights Matrix (Can be based off input or output FC) # Process: Generate Spatial Weights Matrix... swm = arcpy.GenerateSpatialWeightsMatrix_stats( "C:\\MyUW\\SummerProject1\\censusjoin.shp", "OID_", "C:\\MyUW\\SummerProject1\\euclidean6Neighs.swm", "K_NEAREST_NEIGHBORS", "#", "#", "#", 6) # Calculate Moran's Index of Spatial Autocorrelation for # OLS Residuals using a SWM File. # Process: Spatial Autocorrelation (Morans I)... moransI = arcpy.SpatialAutocorrelation_stats( "C:\\MyUW\\SummerProject1\\olsResults.shp", "Residual", "NO_REPORT", "GET_SPATIAL_WEIGHTS_FROM_FILE", "EUCLIDEAN_DISTANCE",
tempEnvironment42 = arcpy.env.mask arcpy.env.mask = "" tempEnvironment43 = arcpy.env.spatialGrid3 arcpy.env.spatialGrid3 = "0" tempEnvironment44 = arcpy.env.maintainSpatialIndex arcpy.env.maintainSpatialIndex = "false" tempEnvironment45 = arcpy.env.workspace arcpy.env.workspace = "C:\\Users\\sfrazier\\Documents\\ArcGIS\\Default.gdb" tempEnvironment46 = arcpy.env.MResolution arcpy.env.MResolution = "" tempEnvironment47 = arcpy.env.derivedPrecision arcpy.env.derivedPrecision = "HIGHEST" tempEnvironment48 = arcpy.env.ZTolerance arcpy.env.ZTolerance = "" arcpy.OrdinaryLeastSquares_stats(CancerTractsCalc_shp, "zonal_trac", OLSResults_shp, "cancer_t_2", "zonal_tr_5", Coefficient_Output_Table, Diagnostic_Output_Table, olsTable_pdf) arcpy.env.newPrecision = tempEnvironment0 arcpy.env.autoCommit = tempEnvironment1 arcpy.env.XYResolution = tempEnvironment2 arcpy.env.processingServerUser = tempEnvironment3 arcpy.env.XYDomain = tempEnvironment4 arcpy.env.processingServerPassword = tempEnvironment5 arcpy.env.scratchWorkspace = tempEnvironment6 arcpy.env.cartographicPartitions = tempEnvironment7 arcpy.env.terrainMemoryUsage = tempEnvironment8 arcpy.env.MTolerance = tempEnvironment9 arcpy.env.compression = tempEnvironment10 arcpy.env.coincidentPoints = tempEnvironment11 arcpy.env.randomGenerator = tempEnvironment12 arcpy.env.outputCoordinateSystem = tempEnvironment13
def run(*args): try: #setup workspace env.workspace = r"C:\Users\sfrazier\Desktop\GEOG777\Project1" env.overwriteOutput = True #Set arcGIS Pro project location - will be used throughout script. aprx = arcpy.mp.ArcGISProject( r"C:\Users\sfrazier\Desktop\GEOG777\Project1\Project1\Project1.aprx" ) # Set local variables for the IDW tool inPointFeatures = r"\well_nitrate\well_nitrate_WTM.shp" zField = "nitr_ran" ##cellSize = 2000.0 power = float(powerEntry.get()) searchRadius = RadiusVariable(10, ) powerText = str(power) messagebox.showinfo("Running", "The analysis has begun using "+powerText+" for the power\n lease"\ " wait for the IDW process to complete.") # Execute IDW outIDW = Idw(inPointFeatures, zField, '', power, searchRadius) ## Save the output IDW as a Tiff outIDW.save( r"C:\Users\sfrazier\Desktop\GEOG777\Project1\outputFiles\idwout.tif" ) #Set variables for building the IDW jpeg map idwTif = r"C:\Users\sfrazier\Desktop\GEOG777\Project1\outputFiles\idwout.tif" # Locating the first map in the project map1 = aprx.listMaps('IDWMap')[0] map1.addDataFromPath( r"C:\Users\sfrazier\Desktop\GEOG777\Project1\outputFiles\idwout.tif" ) #define the Layers refLay = map1.listLayers()[0] #print("no name: " +refLay.name) moveLay = map1.listLayers()[1] #print(moveLay.name) #Apply symbology to the IDW raster sybLyr = r"C:\Users\sfrazier\Desktop\Geog777\Project1\outputFiles\idwout.lyrx" #apply symbology for the output raster arcpy.ApplySymbologyFromLayer_management(refLay, sybLyr) #rearrange the layers in the map to move the tracts above the raster. map1.moveLayer(refLay, moveLay, 'BEFORE') #locate correct layout to export the map lyt = aprx.listLayouts()[1] lyt.exportToJPEG( r"C:\Users\sfrazier\Desktop\Geog777\Project1\Images\Idw.jpg") #message box to let user know process has completed the IDW messagebox.showinfo( "Completed IDW", "Completed IDW Interpolation.\n OLS process is now running.") #activate display IDW map button idwDisplay.config(state=NORMAL) # Set local variables for zonal join idwTif = r"C:\Users\sfrazier\Desktop\GEOG777\Project1\outputFiles\idwout.tif" inZoneData = r"cancer_tracts\cancer_tracts_WTM.shp" zoneField = "GEOID10" inValueRaster = idwTif outTable = "zonalstat" # Execute ZonalStatisticsAsTable outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "DATA", "MEAN") #set the environment setting arcpy.env.qualifiedFieldNames = False # Set local variables for the zonal table to census tracts shapefile inFeatures = r"\cancer_tracts\cancer_tracts_WTM.shp" joinTable = "zonalstat" joinField = "GEOID10" outFeature = r"outputFiles\Tract_IDW" # Join the feature layer to a table canTract_joined_table = arcpy.AddJoin_management( inFeatures, joinField, joinTable, joinField, "KEEP_COMMON") # Copy the layer to a new permanent feature class arcpy.CopyFeatures_management(canTract_joined_table, outFeature) print("join") #Location of the Tract IDW.shp feature = r"C:\Users\sfrazier\Desktop\Geog777\Project1\outputFiles\Tract_IDW.shp" #run the OLS tool ols = arcpy.OrdinaryLeastSquares_stats(feature, "Rowid_", r"outputFiles\olsResults.shp", "canrate", "MEAN", '', '', r"outputFiles\olsTable.pdf") print("we got to the OLS") #Load data into OLS Map olsRes = r"C:\Users\sfrazier\Desktop\Geog777\Project1\outputFiles\olsResults.shp" map2 = aprx.listMaps("OLS")[0] map2.addDataFromPath(olsRes) #call the ols layout and export the map lyt1 = aprx.listLayouts("olsMap")[0] lyt1.exportToJPEG( r"C:\Users\sfrazier\Desktop\Geog777\Project1\Images\olsMap.jpg") #activate the olsDisplay button and show a feedback that OLS is completed olsDisplay.config(state=NORMAL) messagebox.showinfo( "Completed OLS", "Completed OLS. \nPlease wait for process to complete") # run morans I moransI = arcpy.SpatialAutocorrelation_stats( r"C:\Users\sfrazier\Desktop\Geog777\Project1\outputFiles\olsResults.shp", "Residual", "GENERATE_REPORT", "INVERSE_DISTANCE", "EUCLIDEAN_DISTANCE", "NONE", "", "") #print("completed spatial Process") # activate ols button olsDisplay.config(state=NORMAL) #let user know that process is complete. messagebox.showinfo("Process Completed", "Process Completed") except: #an error check to let user know to enter a number. messagebox.showwarning( "Power Error", "Enter a number greater then 1\n for the power") print("please enter a number value")
##OrdinaryLeastSquares_stats (Input_Feature_Class, Unique_ID_Field, Output_Feature_Class, ## Dependent_Variable, Explanatory_Variables, {Coefficient_Output_Table}, ## {Diagnostic_Output_Table}, {Output_Report_File}) #try: # Set the current workspace (to avoid having to specify the full path to the feature classes each time) #arcpy.env.workspace = workspace # Growth as a function of {log of starting income, dummy for South # counties, interaction term for South counties, population density} # Process: Ordinary Least Squares... env.overwriteOutput = True feature = r"C:\Users\sfrazier\Desktop\Geog777\Project1\Tract_IDW.shp" ols = arcpy.OrdinaryLeastSquares_stats(feature, "Rowid_", "olsResults1.shp","canrate", "MEAN", "olsTable") print ("OLS completed") olsRes = r"C:\Users\sfrazier\Desktop\Geog777\Project1\olsResults1.shp" map2 = aprx.listMaps()[2] map2.addDataFromPath(olsRes) lyt = aprx.listLayouts()[2] lyt.exportToJPEG(r"C:\Users\sfrazier\Desktop\Geog777\Project1\Images\olsMap.jpg") # Create Spatial Weights Matrix (Can be based off input or output FC) # Process: Generate Spatial Weights Matrix... ## swm = arcpy.GenerateSpatialWeightsMatrix_stats("USCounties.shp", "MYID", ## "euclidean6Neighs.swm", ## "K_NEAREST_NEIGHBORS",
if row.getValue("MEAN_elevation") < 0 or row.getValue( "MEAN_elevation") == "None": cursor.deleteRow(row) del cursor del row #Add unique ID field to stations_wElevation for use in OLS function arcpy.AddField_management(scratchGDB + "/temp_stations3", "Unique_ID", "SHORT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") arcpy.CalculateField_management(scratchGDB + "/temp_stations3", "Unique_ID", "!OBJECTID!", "PYTHON_9.3", "") #Run ordinary least squares on stats1 arcpy.AddMessage("Running ordinary least squares") arcpy.CreateTable_management(scratchGDB, "coef_table") ols = arcpy.OrdinaryLeastSquares_stats(scratchGDB + "/temp_stations3", "Unique_ID", "in_memory/fcResid", "MEAN_st005", "MEAN_elevation", scratchGDB + "/coef_table", "", "") intercept = list( (row.getValue("Coef") for row in arcpy.SearchCursor(scratchGDB + "/coef_table", fields="Coef")))[0] slope = list( (row.getValue("Coef") for row in arcpy.SearchCursor(scratchGDB + "/coef_table", fields="Coef")))[1] #Create final raster output_raster = (Raster(elevation_raster) * slope + intercept) output_raster.save(outRaster)
# tables that will store statistical information #out_coefficients_table = arcpy.CreateUniqueName('result_coefficients.dbf', arcpy.env.scratchWorkspace) #out_diagnostics_table = arcpy.CreateUniqueName('result_diagnostics.dbf', arcpy.env.scratchWorkspace) out_coefficients_table = 'result_coefficients.dbf' out_diagnostics_table = 'result_diagnostics.dbf' #out_coefficients_table = os.path.join('result_coefficients') #out_diagnostics_table = os.path.join('result_diagnostics') # Do OLS out_features = arcpy.CreateUniqueName('results', arcpy.env.scratchWorkspace) #out_features = os.path.join('in_memory','results') arcpy.AddMessage('Output: ' + out_features) arcpy.OrdinaryLeastSquares_stats(Input_Feature_Class=feature_layer, Unique_ID_Field='UNIQUE_ID', Output_Feature_Class=out_features, Dependent_Variable='Y', Explanatory_Variables=';'.join(ex_variables), Coefficient_Output_Table=out_coefficients_table, Diagnostic_Output_Table=out_diagnostics_table) arcpy.AddMessage('OLS complete') # Write raster as result arcpy.SetParameter(2, out_features) arcpy.SetParameter(3, out_coefficients_table) arcpy.SetParameter(4, out_diagnostics_table) except Exception as e: arcpy.AddError(str(e)) finally:
## --------------------------------------------------------------------------------------------## ## Perform Oridanry Least Squares Regression olsCoefTab = 'olsCoefTab' olsDiagTab = 'olsDiagTab' ols = "OLS" try: if arcpy.Exists(ols): arcpy.Delete_management(ols) if arcpy.Exists(olsCoefTab): arcpy.Delete_management(olsCoefTab) if arcpy.Exists(olsDiagTab): arcpy.Delete_management(olsDiagTab) arcpy.OrdinaryLeastSquares_stats("hexbin", "ID", ols, "CancerRate", "NitrateRate", olsCoefTab, olsDiagTab) # transfer attributes to hexbins fieldJoinCalc('hexbin', ['ID', 'Residual'], 'OLS', ['ID', 'Residual']) print("The 'Residual' field in the hexbin data has been updated") fieldJoinCalc('hexbin', ['ID', 'Estimated'], 'OLS', ['ID', 'Estimated']) print("The 'Estimated' field in the hexbin data has been updated") fieldJoinCalc('hexbin', ['ID', 'StdResidual'], 'OLS', ['ID', 'StdResid']) print( "The 'Standard Deviation of Residuals' field in the hexbin data has been updated" ) except: # If an error occurred when running the tool, print out the error message. print(arcpy.GetMessages())
def idw(): #Determine which spatial unit the user chose selection = unitVar.get() #Setting up the workspace arcpy.env.workspace = "C:\\MAMP\\htdocs\\cancerAnalysis\\files" arcpy.env.overwriteOutput = True arcpy.CheckOutExtension("Spatial") #Setting up the variables for the IDW tool inPoint = "well_nitrate.shp" zField = "nitr_ran" power = float(powerEntry.get()) print power searchRadius = RadiusVariable(10, 150000) #Run IDW idwOutPut = Idw(inPoint, zField, "", power, searchRadius) #Save the output raster idwOutPut.save("C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\idw.tif") #Update the mxd to include the IDW raster mxd = arcpy.mapping.MapDocument(r"C:\\MAMP\\htdocs\\cancerAnalysis\\idwMap.mxd") dataFrame = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] #Change the symbology of the IDW raster idwTiff = arcpy.mapping.Layer(r"C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\idw.tif") idwSymbology = r"C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\idwSymbology.lyr" arcpy.ApplySymbologyFromLayer_management(idwTiff, idwSymbology) #Add newly changed IDW raster to the map arcpy.mapping.AddLayer(dataFrame, idwTiff, "BOTTOM") #Export the map arcpy.mapping.ExportToPNG(mxd, "C:\\MAMP\\htdocs\\cancerAnalysis\\idwResults.png") del mxd #Update the county mxd to include the IDW raster mxd2 = arcpy.mapping.MapDocument(r"C:\\MAMP\\htdocs\\cancerAnalysis\\countyIDWMap.mxd") dataFrame2 = arcpy.mapping.ListDataFrames(mxd2, "Layers")[0] arcpy.mapping.AddLayer(dataFrame2, idwTiff, "BOTTOM") arcpy.mapping.ExportToPNG(mxd2, "C:\\MAMP\\htdocs\\cancerAnalysis\\countyIDWResults.png") idwDisplay.config(state=NORMAL) tkMessageBox.showinfo("Completed IDW", "Completed IDW interpolation...") #Setting up the process for the two different spatial units if selection == 1: #Allow overwriting arcpy.env.overwriteOutput = True #Setting up the variables for the Zonal Statistics tool inZone = "cancer_tracts.shp" zone = "GEOID10" rasterValue = idwTiff table = "zonalStatistics.dbf" #Run the Zonal Statistics tool outZoneStat = ZonalStatisticsAsTable(inZone, zone, rasterValue, table, "NODATA", "MEAN") #Join the Zonal Statistics table with the census tracts try: #Setting up the variables inFeatures = "cancer_tracts.shp" layerName = "cancer_tracts" joinTable = "zonalStatistics.dbf" joinField = "GEOID10" outputFeature = r"C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\joinedCensus" #Make a feature layer from the cancer tracts arcpy.MakeFeatureLayer_management(inFeatures, layerName) #Join the feature to the table arcpy.AddJoin_management(layerName, joinField, joinTable, joinField, "KEEP_COMMON") #Create a copy of the joined layer arcpy.CopyFeatures_management(layerName, outputFeature) tkMessageBox.showinfo("Completed Zonal Statistics", "Completed Zonal Statistics...") except Exception, e: import traceback, sys tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print e.message #Run linear regression on the results try: #Set the environment to allow to overwrite existing data arcpy.env.overwriteOutput = True #Create the tool to run Ordinary Least Squares ordLeastSq = arcpy.OrdinaryLeastSquares_stats("C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\joinedCensus", "cancer_tracts_ID", "C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\olsResults", "cancer_tracts_canrate", "zonalStatistics_MEAN", "", "C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\olsTable.pdf") except: print (arcpy.GetMessages()) moransI = arcpy.SpatialAutocorrelation_stats("C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\olsResults", "Residual", "NO_REPORT", "INVERSE_DISTANCE", "EUCLIDEAN_DISTANCE", "NONE", "", "") #Get the mxd olsMXD = arcpy.mapping.MapDocument("C:\\MAMP\\htdocs\\cancerAnalysis\\OLSmap.mxd") olsDF = arcpy.mapping.ListDataFrames(olsMXD, "Layers")[0] #Add the OLS output to an mxd and apply symbology olsResults = arcpy.mapping.Layer(r"C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\olsResults") olsSymbology = r"C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\olsSymbology.lyr" arcpy.ApplySymbologyFromLayer_management(olsResults, olsSymbology) arcpy.mapping.AddLayer(olsDF, olsResults, "AUTO_ARRANGE") #Add the legend to the map olsLegend = arcpy.mapping.ListLayoutElements(olsMXD, "LEGEND_ELEMENT", "Legend")[0] olsLegend.autoAdd = True #Export the mxd arcpy.mapping.ExportToPNG(olsMXD, "C:\\MAMP\\htdocs\\cancerAnalysis\\olsResults.png") tkMessageBox.showinfo("Completed OLS", "Completed Ordinary Least Squares..." + "\n\nYou can now view and download the maps") olsDisplay.config(state=NORMAL) downloadButton.config(state=NORMAL) image3 = ImageTk.PhotoImage(file="C:\\MAMP\\htdocs\\cancerAnalysis\\olsResults.png") mapDisplay.configure(image=image3) mapDisplay.image = image3 Image.ANTIALIAS
arcpy.CopyFeatures_management(layerName, outputFeature) tkMessageBox.showinfo("Completed Zonal Statistics", "Completed Zonal Statistics...") except Exception, e: import traceback, sys tb = sys.exc_info()[2] print "Line %i" % tb.tb_lineno print e.message #Run linear regression on the results try: #Set the environment to allow to overwrite existing data arcpy.env.overwriteOutput = True #Create the tool to run Ordinary Least Squares ordLeastSq = arcpy.OrdinaryLeastSquares_stats("C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\joinedCounty", "zonalStatistics_ZONE_CODE", "C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\countyOLSResults", "cancer_county_canrate", "zonalStatistics_MEAN", "", "C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\countyOLSTable.pdf") except: print (arcpy.GetMessages()) moransII = arcpy.SpatialAutocorrelation_stats("C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\countyOLSResults", "Residual", "NO_REPORT", "INVERSE_DISTANCE", "EUCLIDEAN_DISTANCE", "NONE", "", "") #Get the mxd olsMXD = arcpy.mapping.MapDocument("C:\\MAMP\\htdocs\\cancerAnalysis\\OLSmap.mxd") olsDF = arcpy.mapping.ListDataFrames(olsMXD, "Layers")[0] #Add the OLS output to an mxd and apply symbology olsResults = arcpy.mapping.Layer(r"C:\\MAMP\\htdocs\\cancerAnalysis\\files\\Result_Testing.gdb\\countyOLSResults") olsSymbology = r"C:\\MAMP\\htdocs\\cancerAnalysis\\project1\\olsSymbology.lyr" arcpy.ApplySymbologyFromLayer_management(olsResults, olsSymbology)