def EBK_ga(inPointFeatures, outPath): try: arcpy.AddField_management(inPointFeatures, "PM102", "FLOAT", 9) except: traceback.print_exc() try: arcpy.CalculateField_management(inPointFeatures, 'PM102', "float(!PM10__μg_!)", "PYTHON_9.3") except: traceback.print_exc() name = os.path.split(inPointFeatures)[1][:-4] outRaster = os.path.join(outPath, name + '.tif') cellSize = 0.01 transformation = "NONE" maxLocalPoints = 50 overlapFactor = 0.5 numberSemivariograms = 100 # Set variables for search neighborhood radius = 1.0 smooth = 0.14 try: #lyr to shp searchNeighbourhood = arcpy.SearchNeighborhoodSmoothCircular( radius, smooth) except Exception as err: arcpy.AddMessage("SearchNeighborhoodSmoothCircular: " + " Failed") arcpy.AddMessage(err.message) outputType = "PREDICTION" Output_geostatistical_layer = '' quantileValue = "" thresholdType = "" probabilityThreshold = "" semivariogram = "POWER" tempEnvironment0 = arcpy.env.extent arcpy.env.extent = Extent # Execute EmpiricalBayesianKriging start = time.time() try: arcpy.EmpiricalBayesianKriging_ga( inPointFeatures, 'PM102', Output_geostatistical_layer, outRaster, cellSize, transformation, maxLocalPoints, overlapFactor, numberSemivariograms, searchNeighbourhood, outputType, quantileValue, thresholdType, probabilityThreshold) print('Converting {} to {}'.format(inPointFeatures, outRasNa)) arcpy.AddMessage(normaltime + ":" + "经验贝叶斯克里金插值完成") except Exception as err: arcpy.AddMessage("EmpiricalBayesianKriging_ga: " + " Failed") arcpy.AddMessage(err.message) end = time.time() print('Running time: %s Seconds' % (end - start)) arcpy.env.extent = tempEnvironment0
def EBK_ga(out_file, zField): normaltime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) arcpy.AddMessage(normaltime + ":" + out_file + "正在进行经验贝叶斯克里金插值...") outTableName = arcpy.ValidateTableName( os.path.basename(out_file.strip(".xls")), out_gdb) print(outTableName) outTable = os.path.join(out_gdb, outTableName) print('Converting sheet1 to {}'.format(outTable)) # Perform the conversion dbfTable = os.path.join(outdBASEPath, outTableName + '.dbf') try: arcpy.ExcelToTable_conversion(out_file, outTable, "Sheet1") # Excel to Table arcpy.TableToDBASE_conversion(outTable, outdBASEPath) #Table to dbf except Exception as err: print("{} is existing".format(dbfTable)) arcpy.AddMessage(err.message) # dbaseTableName = filename.strip(".xls") # print (dbaseTableName) # outTable = os.path.join(outgdb, dbaseTableName) # print (outTable) # arcpy.ExcelToTable_conversion(xlsTable, outTable, "Sheet1") x_coords = 'Long' #list(date[u'Long'].head()) y_coords = 'Lat' #list(date[u'Lat'].values) outLayerName = outTableName + '.lyr' outLayer = os.path.join(outLayerPath, outLayerName) spRef = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" try: arcpy.MakeXYEventLayer_management(dbfTable, x_coords, y_coords, outLayerName, spRef) except Exception as err: arcpy.AddMessage("MakeXYEventLayer_management: " + outLayerName + " created Failed") arcpy.AddMessage(err.message) try: arcpy.SaveToLayerFile_management(outLayerName, outLayer) except Exception as err: arcpy.AddMessage("SaveToLayerFile_management: " + outLayer + " created Failed") arcpy.AddMessage(err.message) try: #lyr to shp arcpy.FeatureClassToShapefile_conversion(outLayer, outShpPath) except Exception as err: arcpy.AddMessage("FeatureClassToShapefile_conversion: " + outShpPath + " created Failed") arcpy.AddMessage(err.message) # Set local variables inPointFeatures = os.path.join(outShpPath, outTableName + '_lyr.shp') Output_geostatistical_layer = "" outRasNa = outTableName + '.tif' nt = time.strftime('%Y%m%d', time.localtime(time.time())) dt = time.strftime('%m%d%H', time.localtime(time.time())) outFilePath = "F:\\xiaju\\" + nt + "\\" + houtime + "\\" + zField + "\\" + "tif" try: os.makedirs(outFilePath) except: print("") outRaster = os.path.join(outFilePath, outRasNa) cellSize = 0.001 transformation = "NONE" maxLocalPoints = 50 overlapFactor = 0.5 numberSemivariograms = 100 # Set variables for search neighborhood radius = 0.3 smooth = 0.1 try: #lyr to shp searchNeighbourhood = arcpy.SearchNeighborhoodSmoothCircular( radius, smooth) except Exception as err: arcpy.AddMessage("SearchNeighborhoodSmoothCircular: " + " Failed") arcpy.AddMessage(err.message) outputType = "PREDICTION" quantileValue = "" thresholdType = "" probabilityThreshold = "" semivariogram = "POWER" tempEnvironment0 = arcpy.env.extent arcpy.env.extent = Extent # Execute EmpiricalBayesianKriging try: arcpy.EmpiricalBayesianKriging_ga( inPointFeatures, zField, Output_geostatistical_layer, outRaster, cellSize, transformation, maxLocalPoints, overlapFactor, numberSemivariograms, searchNeighbourhood, outputType, quantileValue, thresholdType, probabilityThreshold) print('Converting {} to {}'.format(inPointFeatures, outRasNa)) arcpy.AddMessage(normaltime + ":" + "经验贝叶斯克里金插值完成") except Exception as err: arcpy.AddMessage("EmpiricalBayesianKriging_ga: " + " Failed") arcpy.AddMessage(err.message) arcpy.env.extent = tempEnvironment0
arcpy.env.workspace = "C:/gapyexamples/data" # Set local variables inPointFeatures = "ca_ozone_pts.shp" zField = "ozone" outLayer = "outEBK" outRaster = "C:/gapyexamples/output/ebkout" cellSize = 10000.0 transformation = "EMPIRICAL" maxLocalPoints = 50 overlapFactor = 0.5 numberSemivariograms = 100 # Set variables for search neighborhood radius = 300000 smooth = 0.6 searchNeighbourhood = arcpy.SearchNeighborhoodSmoothCircular(radius, smooth) outputType = "PREDICTION" quantileValue = "" thresholdType = "" probabilityThreshold = "" semivariogram = "K_BESSEL" # Check out the ArcGIS Geostatistical Analyst extension license arcpy.CheckOutExtension("GeoStats") # Execute EmpiricalBayesianKriging arcpy.EmpiricalBayesianKriging_ga(inPointFeatures, zField, outLayer, outRaster, cellSize, transformation, maxLocalPoints, overlapFactor, numberSemivariograms, searchNeighbourhood, outputType, quantileValue, thresholdType, probabilityThreshold, semivariogram)