<p>It should be noted that NetCDF data just describes the format that the data is in. One dataset that I know of (<a href="https://www.ncdc.noaa.gov/ibtracs/index.php?name=ib-v4-access" rel="nofollow noreferrer">IBTrACS</a>) contains data that is not gridded data, and also contains a landmask. But this is besides your question.</p>
<p>To rephrase your question: How can I determine the orientation of the coastline in a gridded dataset?</p>
<p>Well, one way is using mathematics. Let's call the boolean landmask variable <span class="math-container">$L$</span>, where <span class="math-container">$L=\{^{0 \text{ if land}}_{1\text{ if water}}$</span> Then the gradient is <span class="math-container">$$\nabla L =\{^{&lt;\frac{\delta L}{\delta x},\frac{\delta L}{\delta y}&gt; \text{ at the coastline}}_{\vec{0} \text{ not at the coastline}}$$</span> Let's look at just the coastline. The angle is <span class="math-container">$\arctan2(\frac{\delta L}{\delta x},\frac{\delta L}{\delta y})$</span>.</p>
<p>Now if you want to find out the angle difference between the coast and the wind, then you can use the <a href="https://en.wikipedia.org/wiki/Dot_product" rel="nofollow noreferrer">properties of the dot product</a> to find the angle difference. That is <span class="math-container">$$\delta \phi=\arccos\left(\frac{\nabla L \cdot \vec{v}}{|\nabla L||\vec{v}|}\right)=\arccos\left(\frac{u\frac{\delta L}{\delta x}+v\frac{\delta L}{\delta y}}{\sqrt{u^2+v^2}\sqrt{\left(\frac{\delta L}{\delta x}\right)^2+\left(\frac{\delta L}{\delta y}\right)^2}}\right)$$</span></p>

CC BY-SA 4.0
2021-06-09T06:43:20.353Z
Thank you for your answer. I really like your idea of doing the gradient of L. I must say though, that I find it awkward the part of your answer that reads "Well, one way is using mathematics." -- was this really necessary? It reads to me a bit like "Well, use your brain". As if "using mathematics" had not occurred to me. This is not encouraging for people to ask further questions. But thank you for the good answer again.
ouranos
CC BY-SA 4.0
2021-06-09T15:50:01.610Z
Thanks @gansub. Yes, I initially was going to say 'vector calculus', but at some point changed it to just 'mathematics' since there isn't actual calculus (the use of infinitesimals) involved. I'm fairly certain there are other ways to do it, not using strict mathematics. GIS may have one solution, for example.
BarocliniCplusplus
CC BY-SA 4.0
2021-06-08T18:36:50.417Z
2021-06-08T18:36:50.417Z
BarocliniCplusplus
<p>I have a NetCDF file (gridded data) with a landsea mask. I would like to determine, for the coastal grid-cells, what the orientation of the coastline is. I need to do this in order to calculate the angle between incident wind direction and the coastline at each coastal grid cell. </p>

<p>For example, if at a certain location the coastline is zonal (east to west) and the land is to the south, and the sea to the north, the orientation would be 0°:</p>

<p><a href="https://i.sstatic.net/crQnr.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/crQnr.png" alt="enter image description here"></a></p>

<p>If the coast is zonal but the position of land and ocean are inverted, the orientation of the coast would be 180°.</p>

<p><a href="https://i.sstatic.net/6EnOs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6EnOs.png" alt="enter image description here"></a></p>

<p>If the coast is 45° with the land to the south, the angle is 45°. With the land to the north, the orientation is 135°... you get the idea.</p>

<p><a href="https://i.sstatic.net/CeYHM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CeYHM.png" alt="enter image description here"></a>
<a href="https://i.sstatic.net/dIRec.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dIRec.png" alt="enter image description here"></a></p>

<p>Any suggestions on how to get this information from the landsea mask grid?</p>

<p>Thank you in advance. </p>

CC BY-SA 4.0
2019-07-12T07:35:55.600Z
Gridded data is orthogonal by definition, so you either have 0/180° or 90/270°.
Erik
CC BY-SA 4.0
2020-05-14T07:13:51.030Z
There are sometimes curvilinear grids, like those with 3 poles or 2 poles and one over Greenland.
ouranos
CC BY-SA 4.0
2021-06-09T04:08:51.100Z
Perhaps it may be best to take like a regional linear average of the coast and then calculate as Baroclinic suggested?  Perhaps use a running mean over a handful of data points.  But of course that means transferring to something "vector" instead of "raster"?  I don't know, thinking out loud, I was considering this challenge a bit years ago for hurricanes, but never got to it.
JeopardyTempest
<geomorphology><numerical-modelling><coastal><netcdf>
How to determine the orientation of coastline from NetCDF file
ouranos
# How to determine the orientation of coastline from NetCDF file

(Asked by: username_0 on 2019-07-11)

I have a NetCDF file (gridded data) with a landsea mask. I would like to determine, for the coastal grid-cells, what the orientation of the coastline is. I need to do this in order to calculate the angle between incident wind direction and the coastline at each coastal grid cell.

For example, if at a certain location the coastline is zonal (east to west) and the land is to the south, and the sea to the north, the orientation would be 0°:

[![enter image description here](https://i.sstatic.net/crQnr.png)](https://i.sstatic.net/crQnr.png)

If the coast is zonal but the position of land and ocean are inverted, the orientation of the coast would be 180°.

[![enter image description here](https://i.sstatic.net/6EnOs.png)](https://i.sstatic.net/6EnOs.png)

If the coast is 45° with the land to the south, the angle is 45°. With the land to the north, the orientation is 135°... you get the idea.

[![enter image description here](https://i.sstatic.net/CeYHM.png)](https://i.sstatic.net/CeYHM.png)
[![enter image description here](https://i.sstatic.net/dIRec.png)](https://i.sstatic.net/dIRec.png)

Any suggestions on how to get this information from the landsea mask grid?

Thank you in advance.

**Tags:** geomorphology, numerical-modelling, coastal, netcdf

> **Comments:**
> **username_1**: Gridded data is orthogonal by definition, so you either have 0/180° or 90/270°.  
> **username_0**: There are sometimes curvilinear grids, like those with 3 poles or 2 poles and one over Greenland.  
> **username_2**: Perhaps it may be best to take like a regional linear average of the coast and then calculate as Baroclinic suggested?  Perhaps use a running mean over a handful of data points.  But of course that means transferring to something "vector" instead of "raster"?  I don't know, thinking out loud, I was considering this challenge a bit years ago for hurricanes, but never got to it.  

---

## 1 answers

### Answer by username_3 on 2021-06-08. Score: 3

It should be noted that NetCDF data just describes the format that the data is in. One dataset that I know of ([IBTrACS](https://www.ncdc.noaa.gov/ibtracs/index.php?name=ib-v4-access)) contains data that is not gridded data, and also contains a landmask. But this is besides your question.

To rephrase your question: How can I determine the orientation of the coastline in a gridded dataset?

Well, one way is using mathematics. Let's call the boolean landmask variable $L$, where $L=\{^{0 \text{ if land}}\_{1\text{ if water}}$ Then the gradient is $$\nabla L =\{^{<\frac{\delta L}{\delta x},\frac{\delta L}{\delta y}> \text{ at the coastline}}\_{\vec{0} \text{ not at the coastline}}$$ Let's look at just the coastline. The angle is $\arctan2(\frac{\delta L}{\delta x},\frac{\delta L}{\delta y})$.

Now if you want to find out the angle difference between the coast and the wind, then you can use the [properties of the dot product](https://en.wikipedia.org/wiki/Dot_product) to find the angle difference. That is $$\delta \phi=\arccos\left(\frac{\nabla L \cdot \vec{v}}{|\nabla L||\vec{v}|}\right)=\arccos\left(\frac{u\frac{\delta L}{\delta x}+v\frac{\delta L}{\delta y}}{\sqrt{u^2+v^2}\sqrt{\left(\frac{\delta L}{\delta x}\right)^2+\left(\frac{\delta L}{\delta y}\right)^2}}\right)$$

> **Comments:**
> **username_0**: Thank you for your answer. I really like your idea of doing the gradient of L. I must say though, that I find it awkward the part of your answer that reads "Well, one way is using mathematics." -- was this really necessary? It reads to me a bit like "Well, use your brain". As if "using mathematics" had not occurred to me. This is not encouraging for people to ask further questions. But thank you for the good answer again.  
> **username_3**: Thanks @gansub. Yes, I initially was going to say 'vector calculus', but at some point changed it to just 'mathematics' since there isn't actual calculus (the use of infinitesimals) involved. I'm fairly certain there are other ways to do it, not using strict mathematics. GIS may have one solution, for example.  

---

