Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Python script iterator to interpolate accross multiple fields of attribute table

$
0
0

I interpolated precipitation data in ArcMap (ver. 10.2) using a surface-fitting tool [e.g. Global Polynomial Interpolation (GPI)]. I built a GPI model using model builder in ArcGIS 10.2, but the model only interpolates precipitation for one field. I needed to iterate the model over 2,000 fields. So, I added python script to my GPI model in order to loop the GPI model across the rest of the fields (long integer format) in my attribute table.

Please see script below.
Problem solved. The script below works

# Import arcpy module
import arcpy

#allow for overwrites
arcpy.env.overwriteOutput = True

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")
arcpy.CheckOutExtension("GeoStats")

# Local variables:
GPI__3_ = "D:\ArcGIS\MAP_models\MAP_daily.gdb\GPI"
HCW_subbasins = "D:\ArcGIS\MAP_models\MAP_daily.gdb\HCW_subbasins"
PPT_day = "D:\ArcGIS\MAP_models\MAP_daily.gdb\PPT_day"
GPI_0 = "D:\ArcGIS\MAP_models\MAP_daily.gdb\GPI_0"
Clip_0 = "D:\ArcGIS\MAP_models\MAP_daily.gdb\Clip_0"
zonal_0 = "D:\ArcGIS\MAP_models\MAP_daily.gdb\zonal_0"
Output_geostatistical_layer = ""

# Field iterator:
fieldList = arcpy.ListFields("d:ArcGISMAP_modelsMAP_daily.gdbPPT_day","p*")
for fl in fieldList:
    # Define fl_name:
    fl_name = fl.name        
    #Process: GPI model 
    tempEnvironment0 = arcpy.env.extent
    arcpy.env.extent = "D:\ArcGIS\MAP_models\MAP_daily.gdb\HCW_subbasins"
    arcpy.GlobalPolynomialInterpolation_ga(PPT_day, fl_name,Output_geostatistical_layer, GPI_0, "88.4831469726562", "2", "")
    arcpy.env.extent = tempEnvironment0
    arcpy.Clip_management(GPI_0, "550467.825991242 4303888.26928986 572588.612734406 4332191.57190217", Clip_0, HCW_subbasins, "-3.402823e+038", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
    arcpy.gp.ZonalStatisticsAsTable_sa(HCW_subbasins, "gridcode", Clip_0, zonal_0, "DATA", "MEAN")
    arcpy.Append_management("D:\ArcGIS\MAP_models\MAP_daily.gdb\zonal_0", GPI__3_, "TEST", "", "")

The GPI model functioned. It even looped, and appended all of the results into a table. But, it used the same z value field for the GPI tool every time (i.e. “p08280″) found in line 33 of the code above.

What do I change the z value field name “p08280″ to in order to get the GPI model to loop across the rest of the fields in my attribute table?


Viewing all articles
Browse latest Browse all 767

Trending Articles