Calculate distance to shore or coastline for a vessel

后端 未结 3 653
闹比i
闹比i 2021-01-05 08:42

For a dataset of 200M GPS (lon, lat) coordinates of vessels I want to calculate an approximate distance to the nearest land or coastline, as a function called distance_to_sh

3条回答
  •  無奈伤痛
    2021-01-05 09:25

    You need a Great Circle distance calculation formula. These are sometimes called Spherical Cosine Law, Haversine, or Vincenty, formulas.

    You can then compute the distance from each vessel to the nearest point in your coastline corpus. It's often helpful to use a bounding box computation to rule out irrelevant points before running the whole Great Circle formula on them.

    When you construct your coastline corpus, you may need to use interpolation to add extra coastline points if your raw coastline data has long segments in it. That's because you're computing distance to the nearest point not the nearest segment. Look up Great Circle interpolation.

    If your vessels are near either pole (well, near the North pole, seeing as how the South pole is on land) things are going to get funky with the standard Great Circle formulas and bounding rectangles. You probably should use the Vincenty formulation in that case.

    Here's a writeup on using a DBMS with indexing for this kind of purpose. https://www.plumislandmedia.net/mysql/haversine-mysql-nearest-loc/

    If you need NOAA-chart level accuracy, you probably need to learn about Universal Transverse Mercator projections. That's beyond the scope of a Stack Overflow answer.

提交回复
热议问题