Files
turbomaps-er/cmd/run.go
2026-03-08 23:55:40 -06:00

47 lines
959 B
Go

package cmd
import (
"context"
"encoding/json"
"fmt"
"os"
"path"
)
func Run(ctx context.Context) error {
m, err := NewMapsOf(ctx, os.Args[1])
if err != nil {
return err
}
results, err := m.Search(ctx, os.Args[2])
if err != nil {
return err
}
type geoJson struct {
Type string `json:"type"`
Properties struct {
Name string `json:"name"`
} `json:"properties"`
Geometry struct {
Type string `json:"type"`
Coordinates []float64 `json:"coordinates"`
} `json:"geometry"`
}
geoJsons := make([]geoJson, len(results))
for i := range results {
geoJsons[i].Type = "Feature"
geoJsons[i].Properties.Name = path.Join(os.Args[2], results[i].Name)
geoJsons[i].Geometry.Type = "Point"
geoJsons[i].Geometry.Coordinates = []float64{results[i].Lng, results[i].Lat}
}
b, _ := json.Marshal(map[string]any{
"features": geoJsons,
"type": "FeatureCollection",
})
fmt.Printf("%s\n", b)
return ctx.Err()
}