🚒Downloading Metadata

This tutorial provides two examples for downloading metadata using MMSI and SQLite database.

There are many scenarios where metadata related to vessels is not found in the AIS messages. To leverage the publicly available web sources, this tutorial provides you built-in function to extract information related to a specific MMSI.

from aisdb.webdata._scraper import search_metadata_vesselfinder, search_metadata_marinetraffic

MMSI = 240927000

dict_ = search_metadata_vesselfinder(MMSI)

dict_2 = search_metadata_marinetraffic(MMSI)

If you already have a database containing AIS track data, then vessel metadata can be downloaded and stored in a separate database.

from datetime import datetime 
from aisdb import track_gen, decode_msgs, DBQuery, sqlfcn_callbacks, Domain

dbpath = "/home/database.db"
start = datetime(2021, 11, 1)
end = datetime(2021, 11, 2)

with DBConn(dbpath="/home/data_sample_dynamic.csv.db") as dbconn:
        qry = aisdb.DBQuery(dbconn=dbconn, callback=in_timerange,
                      start = datetime(2020, 1, 1, hour=0),
                      end=datetime(2020, 12, 3, hour=2)
                      )
        # a new database will be created if not exist to save the downloaded info from MarineTraffic
        traffic_database_path = "/home/traffic_info.db"
       
        # user can select custom boundary for query using aisdb.Domain
        qry.check_marinetraffic(trafficDBpath=, boundary={"xmin":-180, "xmax":180, "ymin":-180,  "ymax":180} )
        
        # boundary = aisdb.Domain(name='example', zones=[
        # {'name': 'zone1',
        # 'geometry': shapely.geometry.Polygon([(-40,60), (-40, 61), (-41, 61), (-41, 60), (-40, 60)])}, 
        # ])
        
        rowgen = qry.gen_qry(verbose=True)
        trackgen = track_gen.TrackGen(rowgen, decimate=True)

Last updated