Select to view content in your preferred language

automate kriging of multiple (120) layers

3730
4
Jump to solution
10-06-2014 10:00 PM
LaurenSahagun
New Contributor

Hello,

I am trying to find geographic patterns within pavement distresses at 70+ airfields across the continental United States.  I have many layers that I have already completed spatial analysis on (manually).  I had to change the values used to Krig from and would like to find a faster way to perform the Krig analysis using Python.

Bottom line:

I need to Krig 120 layers

I would like to use the first layer as a template for the remaining 119 layers because I need to change the parameters of lag size, # of classes, break values, and have it use the maximum of any coincidental points

Once created I would like to rename the Krig layer the same of the inputLayer + "Krig"

 

Any help would be great!! Thank you very much.  

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

2017-01-13 Updated script formatting

Alright...an example...just read it carefully

"""
krigingTest.py
Dan_Patterson.carleton.ca
requires:  read carefully
see http://resources.arcgis.com/en/help/main/10.2/index.html#//009z0000006n000000
 as well
"""

import arcpy
arcpy.CheckOutExtension("Spatial")                   #get the extension
from arcpy.sa import *                               #import all the frigging stuff
arcpy.env.overwriteOutput = True                     #make sure that you overwrite your feable attempts
input_shp = "C:/Temp/krige/pnts.shp"                 #input the shapefile name
arcpy.MakeFeatureLayer_management(input_shp,"temp")  #create a temporary layer
for i in range(1,6):                                 #run it in a range, make sure it isn't 0 for the start
    cellsize = i                                     #vary the cell size is being modelled *********
    outname ="C:/Temp/Krige/test" + str(cellsize)
    print ( "output grid: {0} cellsize {1}".format(outname,cellsize) )
    #arcpy.gp.Kriging_sa("pnts","Z","C:/Temp/Krige/output","Spherical 4.110560","2","VARIABLE 12","#") #another example
    #arcpy.gp.Idw_sa("pnts","Z","C:/Temp/Krige/IDW","2","2","VARIABLE 12","#")
    # Do the work *****
    arcpy.gp.Kriging_sa(input_shp,"Z",outname,"Spherical 4.110560",cellsize,"VARIABLE 12","#") 
    outRaster = Raster(outname)
    outRaster.save()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

To get you started...do one manually until you get everything right, then go to the Geoprocessing Results window, right-click on the last process you did and copy it as a python snippet as shown in the figure.  From there it is a matter of putting that within a loop fixing your output names as you go along.

# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script

# The following inputs are layers or table views: "pnts"

arcpy.gp.Kriging_sa("pnts","Z","C:/Temp/Krige/output","Spherical 4.110560","2","VARIABLE 12","#")

is the output from a simple default run with nothing else selected.

KrigingExample.png

0 Kudos
DanPatterson_Retired
MVP Emeritus

2017-01-13 Updated script formatting

Alright...an example...just read it carefully

"""
krigingTest.py
Dan_Patterson.carleton.ca
requires:  read carefully
see http://resources.arcgis.com/en/help/main/10.2/index.html#//009z0000006n000000
 as well
"""

import arcpy
arcpy.CheckOutExtension("Spatial")                   #get the extension
from arcpy.sa import *                               #import all the frigging stuff
arcpy.env.overwriteOutput = True                     #make sure that you overwrite your feable attempts
input_shp = "C:/Temp/krige/pnts.shp"                 #input the shapefile name
arcpy.MakeFeatureLayer_management(input_shp,"temp")  #create a temporary layer
for i in range(1,6):                                 #run it in a range, make sure it isn't 0 for the start
    cellsize = i                                     #vary the cell size is being modelled *********
    outname ="C:/Temp/Krige/test" + str(cellsize)
    print ( "output grid: {0} cellsize {1}".format(outname,cellsize) )
    #arcpy.gp.Kriging_sa("pnts","Z","C:/Temp/Krige/output","Spherical 4.110560","2","VARIABLE 12","#") #another example
    #arcpy.gp.Idw_sa("pnts","Z","C:/Temp/Krige/IDW","2","2","VARIABLE 12","#")
    # Do the work *****
    arcpy.gp.Kriging_sa(input_shp,"Z",outname,"Spherical 4.110560",cellsize,"VARIABLE 12","#") 
    outRaster = Raster(outname)
    outRaster.save()‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
LaurenSahagun
New Contributor

Dan- Thank you very much for your help.  I really appreciate you taking the time to consider my question.

0 Kudos
DanPatterson_Retired
MVP Emeritus

No problem, good luck with your example

0 Kudos