Select to view content in your preferred language

IDW interpolatation using ArcPy

1952
5
08-03-2020 06:29 AM
PedroMoreira
Emerging Contributor

I have multiple point feature class (las_1.shp, las_2.shp....._711) into one folder. I am trying to write a python script to perform IDW interpolation which will loop all the point feature class and outraster will save as it name of input raster. 

Each Point feature class hold  one Z filed only (Altit).

The problem is that after interpolation some of the generated raster are saved, however, with an error (all black). I think that the problem is in the part of save the raster (os.path.join) because a execute the script without this part and the interpolation works perfectly. I'm using Python 2.7.

Below is my script, what i have so far

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

# settings
env.workspace = r"C:\Users\pedro\Documents\Mestrado\GEO\Pontos_Laser\TESTE"
out_folder = r"C:\Users\pedro\Documents\Mestrado\GEO\Pontos_Laser\RASTER"
zField = "Altit" # has to be string, not list

points = arcpy.ListFeatureClasses("las_*.shp", "POINT")
print points

cellSize = 5
power = 2
searchRadius = RadiusVariable(12, 5)

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

# Execute IDW
for fc in points:
    print fc
    outIDW = Idw(fc, zField, cellSize, power, searchRadius)
    #Save output raster to output workspace
    tifname = fc[:7]
    
    # Save output
    IDW_OUT= os.path.join(out_folder, '{}.tif'.format(tifname))
    print IDW_OUT
    outIDW.save(IDW_OUT)

print 'done'‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

From your print statements, this must be in arcmap/python 2.7?

Also, your indentation is off and line numbers would be a help

/blogs/dan_patterson/2016/08/14/script-formatting 


... sort of retired...
0 Kudos
PedroMoreira
Emerging Contributor

Thank you Dan Patterson. I edited my question according to the instructions that you posted. And yes I'm using python 2.7.

0 Kudos
DanPatterson
MVP Esteemed Contributor

I edited your indentation and changed a line to print.  Can you give an example of the print statements


... sort of retired...
0 Kudos
PedroMoreira
Emerging Contributor

Dan Patterson, I just ran the script again to try it out. There is no error message, however, some rasters have negative values. All files have the same coordinate system and have the same field in relation to the "Z" attribute. I can't find why some files generate the raster correctly and others don't.

0 Kudos
DanPatterson
MVP Esteemed Contributor

I don't know, That would depend on your inputs, their values, their location in space and a load of other things.  IDW only works with what it has, so you might want to examine your data to make sure that input points don't have negative values which represent nodata values


... sort of retired...
0 Kudos