Extracting distance features from and to points-of-interest using raster files.
The distances of a vessel from the nearest shore, coast, and port are essential to perform particular tasks such as vessel behavior analysis, environmental monitoring, and maritime safety assessments. AISdb offers functions to acquire these distances for specific vessel positions. In this tutorial, we provide examples of calculating the distance in kilometers from shore and from the nearest port for a given point.
from aisdb.webdata.shore_dist import ShoreDist
with ShoreDist(data_dir="./testdata/") as sdist:
# Getting distance from shore for each point in the track
for track in sdist.get_distance(tracks_short):
assert 'km_from_shore' in track['dynamic']
assert 'km_from_shore' in track.keys()
print(track['km_from_shore'])
[ 1 3 2 9 14]
Distance from coast
Similar to acquiring the distance from shore, CoastDist is implemented to obtain the distance between the given track positions and the coastline.
from aisdb.webdata.shore_dist import CoastDist
with CoastDist(data_dir="./testdata/") as cdist:
# Getting distance from the coast for each point in the track
for track in cdist.get_distance(tracks_short):
assert 'km_from_coast' in track['dynamic']
assert 'km_from_coast' in track.keys()
print(track['km_from_coast'])
[ 1 3 2 8 13]
Distance from port
from aisdb.webdata.shore_dist import PortDist
with PortDist(data_dir="./testdata/") as pdist:
# Getting distance from the port for each point in the track
for track in pdist.get_distance(tracks_short):
assert 'km_from_port' in track['dynamic']
assert 'km_from_port' in track.keys()
print(track['km_from_port'])
The class is used to calculate the nearest distance to shore, along with a raster file containing shore distance data. Currently, calling the get_distance function in ShoreDist will automatically download the shore distance raster file from our server. The function then merges the tracks in the provided track list, creates a new key, "km_from_shore", and stores the shore distance as the value for this key.
Like the distances from the coast and shore, the class determines the distance between the track positions and the nearest ports.