# Populating attribute table from interpolation (grid)?

I am a novice ArcGIS Desktop 10 user, with a question on how to add data from a grid file to a shapefile based on an attribute and position. I have a shapefile with fish positions (x,y) and their temperature. I have created a grid from temperature observations collected from the surface of the lake to the bottom. I need to add the depth from the interpolated surface to the fish position based on the fishes temperature.

So for each fish (circle) I know its position along the x axis and I also know its temperature.

How do I retrieve depth from the grid based on the fish temperature and its position along the x axis?

Quick and dirty way would be to translate the XY points into a distance from river mouth, use that for river distance, and then graph the temperature as the Y value..If all you're doing is trying to get it to plot properly for that graphic.

If you're trying to do something 3D, look into z values.

If all you need to do is join grid to shapefile, convert the grid into a fishnet first.

``````# add this script to custom toolbox and run it from ArcMap v 10.1
#
# ---------------------------------------------------------------------------
import arcpy, os, traceback, sys
try:
def showPyMessage():
arcpy.AddMessage(str(time.ctime()) + " - " + message)

mxd = arcpy.mapping.MapDocument("CURRENT")
layers=arcpy.mapping.ListLayers(mxd)
##    ASSUME THAT  1st LAYER IN TABLE OF CONTENT IS POINT LAYER - FISH
fishLayer=layers[0]
##    ASSUME THAT  2nd LAYER IS TEMPERATURE RASTER. GET RASTER INFO
tempRaster=layers[1]
g=arcpy.Raster(tempRaster.name)
cSize=g.meanCellHeight
yMax=g.extent.YMax; yMin=g.extent.YMin; nRows=g.height
##    ASSUME THAT  TEMPERATURE TO FIND STORED IN FIELD 'Fish_Degr'
##    CORRESPONDING OUTPUT DEPTH STORED IN FIELD 'DEPTH'. BOTH NUMERIC
p=arcpy.Point()
with arcpy.da.UpdateCursor(fishLayer, ("SHAPE@","Fish_Degr","DEPTH")) as rows:
for row in rows:
x=row[0].firstPoint.X
fishTemp=row[1]
yCur=yMax
p.X=x;p.Y=yMin
##     GET ENTIRE COLUMN FROM RASTER AND ITERATE THROUGH TO FIND BEST MATCH
myAr=arcpy.RasterToNumPyArray(g,p,1,nRows)
difMin=1000000
for nr in range(nRows):
cellValue=myAr[nr,0]
difCur=abs(cellValue-fishTemp)
if difCur<difMin:
yBest=yCur; difMin=difCur
yCur+=-cSize
row[2]=yMax-yBest
rows.updateRow(row)

except:
message = "\n*** PYTHON ERRORS *** "; showPyMessage()
message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
message = "Python Error Info: " +  str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyMessage()
``````

so from this

you can get this (if this is what you realy want):

• Thanks for taking the time to write a script to solve the OP's problem. It would be useful if you could add a few lines before the script explaining the overall approach that you've taken – Stephen Lead Dec 23 '14 at 5:13
• @Stephen Lead. I thought comments in the body are suffucient.. Anyway the bone of above script is very useful function RasterToNumpy. Steps: take x-coord of fish 'on the surface'; create point (x-coord, ymin of the raster); use this point as lower left point in THE function to load entire column of raster cells into the array. Note that nRows is number of rows in raster.; iterate through array in order to find the cell with value closest to fish temperature, stored in points' table. Actually I've tried to solve it using field calculator. Dead end. THE function is not working in FC – FelixIP Dec 23 '14 at 6:51