Re: calculate distance offshore (from a coast)

From: Dave Allured - NOAA Affiliate <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu Jul 25 2013 - 15:11:27 MDT


Are you asking for the CLOSEST distance from a point to the coastline?
 If so, then please consider the attached working NCL program that I
wrote a while ago. This could be simplified and adapted to your
question. The program is somewhat complicated and messy because I
made it for a specific batch application, multiple points and multiple
polygons. However, in the middle of nested loops there is a
functional algorithm to compute closest distance.

The method is about the same as what you and Dennis suggested, so this
is merely a working example. Traverse a list of lat/lon coordinates
of border line vertices, and use gc_latlon and a min function to find
the smallest point to point distance.

This method works well with high resolution polylines, where the point
to polyline distance is much larger than the point to point spacing
along the polyline. However, there is a potential error if there is a
long single line segment, and the closest approach of the test point
is actually along this line segment. This simple method will miss the
closest mid-line approach, and overestimate the final result for
closest distance.

If necessary, the missing step could be added. One would need to
first test whether the point lies "next to" each line segment, or off
one or the other end of the segment. Then, only for "next to"
segments, compute the minimum point-to-line distance. On the sphere,
the algorithms for both parts of this are rather complicated, so I
skipped this completely in my program.

Another caveat is exactly what you mean by "coastline". You may have
a shapefile or other coastline source that includes multiple
coastlines, including islands and so on. You would need to select a
specific polyline element if there is a risk of getting the closest
distance to the wrong feature.

Please excuse this rambling message. I had to think through this
earlier, and some of this might be helpful for your problem.


On Wed, Jul 24, 2013 at 11:05 AM, Sam McClatchie (NOAA Federal)
<> wrote:
> Colleagues
> I there a convenient way to calculate the distance of a point from the coast
> in NCL, given a projection? I know the function gc_latlon will give me the
> great circle distance between two points, or two arrays. So I expect the
> answer is to extract the coordinates from the coastline, convert to a an
> array variable, and then use gc_latlon to calculate the distance between
> the specified locations array and the coastline array. Is this the way to
> proceed, or is there a distance from coast function, please?
> Best fishes
> Sam
> --
> Sam McClatchie,
> Supervisory oceanographer, Fisheries oceanography
> Southwest Fisheries Science Center, NOAA,
> 8901 La Jolla Shores Dr.
> La Jolla, CA 92037-1509, U.S.A.
> email <>
> Office: 858 546 7083, Cellular: 858 752 8495
> Research home page <>
> /\
> ...>><xX(>
> //// \\\\
> <)Xx><<
> ///// \\\\\\
> ><(((>
> >><(((> ...>><xX(>O<)Xx><<
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:

ncl-talk mailing list
List instructions, subscriber options, unsubscribe:

Received on Thu Jul 25 15:11:39 2013

This archive was generated by hypermail 2.1.8 : Thu Aug 01 2013 - 15:55:04 MDT