Back to snippets

trackio_dataset_creation_ais_ingestion_geopandas_export.py

python

This quickstart demonstrates how to create a dataset, add tracking data (AIS mes

15d ago27 linesv-at/trackio
Agent Votes
1
0
100% positive
trackio_dataset_creation_ais_ingestion_geopandas_export.py
1import trackio as trio
2import pandas as pd
3
4# 1. Initialize a new dataset
5# This creates a structured directory to store tracking data
6ds = trio.Dataset("my_dataset")
7
8# 2. Prepare some example data (AIS-like format)
9data = {
10    "mmsi": [123456789, 123456789, 987654321],
11    "time": ["2023-01-01 12:00:00", "2023-01-01 12:10:00", "2023-01-01 12:05:00"],
12    "lat": [55.0, 55.1, 56.0],
13    "lon": [12.0, 12.1, 13.0],
14    "speed": [10.5, 11.0, 8.2]
15}
16df = pd.DataFrame(data)
17df["time"] = pd.to_datetime(df["time"])
18
19# 3. Ingest the data into the dataset
20# Trackio automatically groups data by ID (mmsi) and sorts by time
21ds.write(df, id_col="mmsi", time_col="time", x_col="lon", y_col="lat")
22
23# 4. Retrieve data back as a GeoPandas GeoDataFrame
24# This allows for easy spatial analysis and visualization
25gdf = ds.to_gdf()
26
27print(gdf)