-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
72 lines (62 loc) · 2.32 KB
/
main.go
File metadata and controls
72 lines (62 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"log/slog"
"time"
"github.com/paulmach/orb"
"github.com/paulmach/orb/encoding/wkt"
"github.com/tilebox/tilebox-go/datasets/v1"
examplesv1 "github.com/tilebox/tilebox-go/protogen/examples/v1"
"github.com/tilebox/tilebox-go/query"
)
func main() {
ctx := context.Background()
// Create a Tilebox Datasets client
client := datasets.NewClient()
// Select a dataset
dataset, err := client.Datasets.Get(ctx, "open_data.copernicus.sentinel2_msi")
if err != nil {
slog.ErrorContext(ctx, "Failed to get dataset", slog.Any("error", err))
return
}
// Select a collection
collection, err := client.Collections.Get(ctx, dataset.ID, "S2A_S2MSI1C")
if err != nil {
slog.ErrorContext(ctx, "Failed to get collection", slog.Any("error", err))
return
}
// Select a temporal extent
startDate := time.Date(2025, 4, 2, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2025, 4, 3, 0, 0, 0, 0, time.UTC)
// Select a spatial extent
area := orb.Polygon{ // area roughly covering the state of Colorado
{{-109.05, 41.00}, {-102.05, 41.00}, {-102.05, 37.0}, {-109.045, 37.0}, {-109.05, 41.00}},
}
// Perform a spatial-temporal query
// Sentinel2Msi type is generated using tilebox-generate
var foundDatapoints []*examplesv1.Sentinel2Msi
err = client.Datapoints.QueryInto(ctx,
dataset.ID,
&foundDatapoints,
datasets.WithCollections(collection),
datasets.WithTemporalExtent(query.NewTimeInterval(startDate, endDate)),
datasets.WithSpatialExtent(area),
)
if err != nil {
slog.ErrorContext(ctx, "Failed to query datapoints", slog.Any("error", err))
return
}
slog.InfoContext(ctx, "Found datapoints over Colorado in March 2025", slog.Int("count", len(foundDatapoints)))
if len(foundDatapoints) > 0 {
slog.InfoContext(ctx, "First datapoint over Colorado",
slog.String("id", foundDatapoints[0].GetId().AsUUID().String()),
slog.Time("event time", foundDatapoints[0].GetTime().AsTime()),
slog.Time("ingestion time", foundDatapoints[0].GetIngestionTime().AsTime()),
slog.String("geometry", wkt.MarshalString(foundDatapoints[0].GetGeometry().AsGeometry())),
slog.String("granule name", foundDatapoints[0].GetGranuleName()),
slog.String("processing level", foundDatapoints[0].GetProcessingLevel().String()),
slog.String("product type", foundDatapoints[0].GetProductType()),
// and so on...
)
}
}