Interpolating with IDW(geostatistical analyst): Python for Loop

4230
4
Jump to solution
02-14-2015 05:42 PM
KevinAchieng
New Contributor

Hi All,

I'm trying to interpolate point feature classes with Python.  I would like the output to maintain the name of the input feature class.

However, my code seem not to be running.

Please assist me troubleshoot the code:

Thanks in advance.

Kevin

Please see below

# Import system modules

import arcpy

from arcpy import env

# Set environment settings

arcpy.env.workspace = r"\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\Monthly"

fclist=arcpy.ListFeatureClasses()

arcpy.env.overwriteOutput="True"

# Set local variables

inPointFeatures = "fc"

zField = "ETommd"

outLayer = "outIDW"

outRaster = r"\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\MonthlyET.gdb\fc"

cellSize = 2000.0

power = 2

# Set variables for search neighborhood

majSemiaxis = 300000

minSemiaxis = 300000

angle = 0

maxNeighbors = 15

minNeighbors = 10

sectorType = "ONE_SECTOR"

searchNeighbourhood = arcpy.SearchNeighborhoodStandard(majSemiaxis, minSemiaxis,

                                                       angle, maxNeighbors,

                                                       minNeighbors, sectorType)

# Check out the ArcGIS Geostatistical Analyst extension license

arcpy.CheckOutExtension("GeoStats")

# Execute IDW

for fc in fclist:

    outRaster = r"\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\MonthlyET.gdb\fc[:-4]"

    arcpy.IDW_ga(fc, zField, "", outRaster, cellSize, power, searchNeighbourhood)

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

Also, your path to outRaster will not work as you expect. By leaving the variable fc[:-4] inside the quotes, it literally becomes part of the string (e.g. "...\Product\MonthlyET.gdb\fc[:-4]").

Instead, use the os module's path.join method to join your base path to the variable:

>>> fc = "someraster2014"
>>> import os
>>> outRaster = os.path.join(r"\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\MonthlyET.gdb",fc[:-4])
>>> print outRaster
\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\MonthlyET.gdb\someraster

View solution in original post

4 Replies
DanPatterson_Retired
MVP Emeritus

Which Place or Space is this to be directed?

You provide no error messages or what the problem is.  Since that is missing it is impossible to assist without going through the analysis ourselves.  What environment settings did you stipulate when performing the IDW other than those provided in the script?  Is the file paths some network location?  Have you tried source and destinations on a local drive etc.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Off the top, it should be arcpy.env.overwriteOutput = True (no quotes) and setting inPointFeatures = "fc" literally sets the variable to the string "fc" and is never used.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Also, your path to outRaster will not work as you expect. By leaving the variable fc[:-4] inside the quotes, it literally becomes part of the string (e.g. "...\Product\MonthlyET.gdb\fc[:-4]").

Instead, use the os module's path.join method to join your base path to the variable:

>>> fc = "someraster2014"
>>> import os
>>> outRaster = os.path.join(r"\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\MonthlyET.gdb",fc[:-4])
>>> print outRaster
\\bsedom5\users\kachieng2\Desktop\ET_2002-2014\Product\MonthlyET.gdb\someraster
KevinAchieng
New Contributor

Hi Darren,

I imported os, and used the join method. It worked!

Thanks

Kevin

0 Kudos