# How to find the data in the nearest grid point?

**URL:** <https://discourse.julialang.org/t/how-to-find-the-data-in-the-nearest-grid-point/77213>\
**Category:** General Usage\
**Tags:** question, gmt\
**Created:** [March 1, 2022, 12:45am UTC](https://discourse.julialang.org/t/how-to-find-the-data-in-the-nearest-grid-point/77213 "2022-03-01T00:45:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [March 1, 2022, 12:45am UTC](https://discourse.julialang.org/t/how-to-find-the-data-in-the-nearest-grid-point/77213/1 "2022-03-01T00:45:57Z")

</div>

I have some ship track based data missing one of the variables (Var1) that I want to extract from a gridded database (1 x 1 degree).

At one location of my ship track, there will be 4 grid points (Left up, left down, right up and right down). Sometimes, 1 to 3 of them can be NaNs when they are close to land near the coastline. Is there a way I can quickly find the order of the distance between my data point and these 4 points? That way, I can use the one with the shortest distance that is non-NaN.

Many thanks!

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [March 1, 2022, 2:12am UTC](https://discourse.julialang.org/t/how-to-find-the-data-in-the-nearest-grid-point/77213/2 "2022-03-01T02:12:16Z")

</div>

_man of no faith_  
See `grdtrack T` option

> To be used with normal grid sampling, and limited to a single, non-IMG grid. If the nearest node to the input point is NaN, search outwards until we find the nearest non-NaN node and report that value instead. Optionally specify a search radius which limits the consideration to points within this distance from the input point. To report the location of the nearest node and its distance from the input point, append **+e**.
