# Calculating average raster grid values perpendicular to a barrier and transferring values to adjacent cells? [closed]

I was hoping I could get a little help for 2 questions dealing with raster datasets. I have access to ArcMap 10.2 and ArcView 3 to do this. Here is what I am trying to do:

1) I need to calculate an average value for a subset of cells in a line for every cell along a coastline. More specifically, I have a raster grid that lies over the water along a coastline. I need to get the average value of the three cells that lead offshore perpendicular to the coast, this needs to be done for each cell that touches the coast.

2) I then need to move the values calculated above from over water to adjacent cells over land. The over water layer with the values does not extend over the land where I need to transfer the values so I cannot do a simple overlay.

• You have some basic problems to resolve before you can get started. A coastline in raster format is a collection of cells: these are jagged and won't typically indicate a unique perpendicular direction. For instance, many directions radiating away from a cell at the point of a peninsula will all be perpendicular to the coast. Which of those directions will you choose? A cell at the end of an inlet has the opposite problem: often no direction will be measurably perpendicular to the coast. Even when it does, there might not be three cells over the water in that direction. What will you do? – whuber Feb 10 '15 at 22:06
• Thanks! Yes, these are all issues we are considering. We are using a resolution of 4km and looking for general trends along a large expanse of coastline (i.e. all of North America). The coastline data is vector data, so we will not have the jagged issue for that portion, but we will have it for the ocean grid. What we are interested in is the variables an animal will encounter as it travels away from the coast (delineated by the grid). So the exact number of grid cells used in the average isn't as important. We will have to accept some compromises on the resolution and scale. – FSUTurtleLab Feb 11 '15 at 16:29
• We also were planning on doing the analysis several times using different selection factors for placing lines on features such as peninsulas and inlets. A sensitivity analysis would then be used to determine the differences arising from these factors. For the most part, our study animals are located on sandy beaches so the values near these features are more important than those around complex coastal features. – FSUTurtleLab Feb 11 '15 at 16:32
• Why not consider a focal mean with a circular neighborhood? By setting land values to NoData you will pick up the average values over water within the desired distance of every point that is on or near water. Intersecting that result with the coastline will give you values all along the coastline--not just at the specified points. If you wish, you can then extract values at particular points. This will be a little crude within tortuous inlets or along narrow spits of land, and will vary in precision according to the amount of data in each neighborhood, but might be quite acceptable. – whuber Feb 11 '15 at 17:41
• @whuber That may be the way we go with this analysis, I'm playing around with the different settings and distances to see if I get ecologically relevant results. Obviously we'll have to sacrifice some precision and resolution around complex land features and islands though. Thanks again. – FSUTurtleLab Feb 12 '15 at 15:05

## 2 Answers

This is one of multiple solutions, depending on the inputs (100% agree with @whuber)

1. Create perpendiculars to coast line, there are many ways to do it. I used @whuber Avenue script found in ArcScripts. Make sure the direction is correct, i.e. water=>land
2. Create points along line at fixed step=cell size (shown on above picture). Select ones with Chainage (distance from start <= 2*cell size).
3. Sample water grid using this points and find average per line. This can be easily transferred to points with chainage=3*cell size, presumably 1st 'cell' on land (shown in red)

The trouble starts here. Grey area shows 'water' grid expanded by one cell and cell centers as yellow points: If you'll decide to keep all yellow points, spatial join them to red points and convert to grid. I've used real data here and as one can see the definition of coast line is overly important.

• This looks great! What ArcScript is this? @whuber has a number of scripts posted. Thanks for the help. – FSUTurtleLab Feb 11 '15 at 16:43
• +1 Excellent illustrations--they point out the salient difficulties. Thanks for doing this work. Because the transects can intersect, a zonal mean solution will not work. However, I suspect in the OP's case the transects generally will not intersect. Thus, they can be rasterized into zones. Those zones can be limited by distance to the land so that each zone incorporates the desired number of off-land cells plus at least one land cell. Intersecting the zonal mean grid with the coastline grid finishes the job. – whuber Feb 11 '15 at 17:25
• @FSU I cannot find this solution on arcscripts (but you're welcome to look: all my contributions can be found by searching for "QD"). By Googling "whuber site:forums.esri.com transect script" I was able to find a script posted in an answer at forums.esri.com/Thread.asp?c=3&f=38&t=201703. An example of its output is shown at forums.esri.com/Attachments/21443.png. BTW, it estimates the perpendicular direction by means of a finite difference along the polyline. – whuber Feb 11 '15 at 17:35
• I think converting water grid to integer raster con(~isnull(water),1) and turning it into polygon with simplification will serve best as coastline for 4km cells. Nice idea with zones – FelixIP Feb 11 '15 at 19:20

I'm sure this can be done in several ways but the tough problem is how are you going to define what is perpendicular to the coast? Your sketch is not reality and you may even have islands in the way. What is the cell size of your off-shore raster, 1m - 10Km? If it is large but you have a shoreline that was captured at a different scale then you will have to accept some compromise in averaging the values.

As a first you should be looking at DSAS I think this will create the perpendiculars?

• Thanks. The sketches are just a dumbed down version of what I'm trying t achieve. What I'm defining as perpendicular to the coast is the position on the coast every 4km from a set start point. So the angle will change depending on where the point falls on the coastline. The offshore grid is composed of 4km grid cells which extend 12km offshore (so 3 cells wide). As for the island/barrier issue, this will be regarded as no data and not averaged into the value. What we are concerned with is the wave fetch values along the shore. – FSUTurtleLab Feb 10 '15 at 20:18
• Finding perpendiculars can be done in several ways. A crude (but effective) method uses finite differences along the coastline to estimate the tangent direction and rotates it 90 degrees. A slightly more accurate method fits a spline to the vertices and computes its derivative. See gis.stackexchange.com/a/37078 for a working, illustrated example of the latter approach (which uses the splines to compute both first and second derivatives in order to map the curvature of a polyline). – whuber Feb 11 '15 at 17:44