0

I have 12 point feature datasets for different month. I want to perform IDW interpolation.

I have created the python code but its taking only one "Z" field for different month feature datasets from the attribute. Below I have mentioned the code. How to assign here multiple Z field from each month folder (JANUARY, FEBRUARY......DECEMBER).

Point feature class from different month folder (e.g. For January Merged_001, for FEBRUARY Merged_002.......for DECEMBER Merged_012 ) and want to perform IDW interpolation and save it as on same month folder as it Z field name (Max_Temper, Min_Temper, Precipitatat, Wind, Relative_H, Solar) with month (e.g for January 001_Max_Temper, 001_Min_Temper, 001_Precipitatat, 001_Wind, 001_Relative_H, 001_Solar).

After Whatever Solar raster for different month (for January 001_Solar....for DECEMBER 012_Solar) we will get, I want to do some calculation (001_Solar * 30) *0.5 and save it 001_sr ........012_sr in Month wise folder.

Here is my code.

import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.env.parallelProcessingFactor = "100%"
arcpy.env.overwriteOutput = True

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

env.workspace = "D:\SWAT-WEATHER-DATA2\APRIL"

# Set local variables
inPointFeatures = "D:\SWAT-WEATHER-DATA2\APRIL\Merged_004.shp"

zField = "Min_Temper" #Z_Filed Name= Max_Temper, Min_Temper, Precipitatat, Wind, Relative_H, Solar

cellSize = 0.002298707671
power = 2
searchRadius = RadiusVariable(10, 150000)

#Mask region of interest
mask="D:\Gujarta Shape file\GUJARATSTATE.shp"

# Execute IDW
outIDW = Idw(inPointFeatures, zField, cellSize, power, searchRadius)

# Execute Mask
IDWMASk = ExtractByMask(outIDW, mask)

# Save output, except Solar Radiation raster
IDWMASk.save("004_Min_Temp.tif")

# 004_Max_Temp.tif, 004_Min_Temp.tif....Solar

#Only for Solar Radiation raster
#PAR = (IDWMASk * 30) * 0.5

#Save output, Only for Solar Radiation raster
#PAR.save("003_sr.tif")

#print done
1

Take a list of your Z Fields and loop through them

zFields = ["Min_Temper", "Max_Temper", "Min_Temper", "Precipitatat", "Wind", "Relative_H", "Solar"]

cellSize = 0.002298707671
power = 2
searchRadius = RadiusVariable(10, 150000)
#Mask region of interest
mask="D:\Gujarta Shape file\GUJARATSTATE.shp"

# Execute IDW
for zField in zFields:
    outIDW = Idw(inPointFeatures, zField, cellSize, power, searchRadius)
    # Execute Mask
    IDWMASk = ExtractByMask(outIDW, mask)

    if not zField == "Solar":
        # Save output, except Solar Radiation raster
        IDWMASk.save("004_{}.tif".format(zField))
    else:
        #Only for Solar Radiation raster
        PAR = (IDWMASk * 30) * 0.5
        #Save output, Only for Solar Radiation raster
        PAR.save("004_{}.tif".format(zField))

The line IDWMASK.save("004_{}.tif".format(zField)) will save each output file with the name of the relevant field, e.g. 004_Min_Temper.tif

  • thank you. Code is working perfectly. But how i execute this function into solar raster (001_Solar * 30) *0.5 and save it (e.g for JANAUARY 001_Solar). – Shouvik Jha Aug 21 '16 at 18:13
  • @ShouvikJha see my updated code - added an if and else to check if processing the Solar field, and if so to include the extra calculation. – Midavalo Aug 21 '16 at 18:23
  • Thank you very much. All functions are working perfectly. Once again thank you for your kind Cooperation. – Shouvik Jha Aug 21 '16 at 18:34
  • I am modifying above code, instead of giving path of every month's point feature class (JANUARY:Merged_001, FEBRUARY:002, ...DECEMBER:Merged_012), i want to make a loop function that can take each month point feature class from different month folder and save it as same month folder with z field name. Same as above program, just run a loop function on each month folder. i have made a code but its not running. i added my code above . – Shouvik Jha Sep 2 '16 at 6:47
  • Don't add the code here, that's a new question – Midavalo Sep 2 '16 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.