From 2d53b0639be864c536bc297164bc50eba783b82e Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:39:55 -0600 Subject: [PATCH] dedupe points across searches but not across towns --- cmd/run.go | 63 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index b9de86d..3fa3ab9 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -37,43 +37,52 @@ func Run(ctx context.Context) error { type Area [1][5][2]float64 type Point [2]float64 geoJsons := []geoJson{} - for _, town := range towns { - for search, area := range searches { - radius := area / convertToMiles - radiusX := 2 * radius / 2 - radiusY := 2 * radius / 3 + for search, area := range searches { + results := []Location{} + for _, town := range towns { m, err := NewMapsOf(ctx, town) if err != nil { return err } - results, err := m.Search(ctx, search, *searchRadius) + more, err := m.Search(ctx, search, *searchRadius) if err != nil { return err } + results = append(results, more...) + } - for i := range results { - var a geoJson - a.Type = "Feature" - a.Properties.Name = path.Join(search, results[i].Name) - if strings.Contains(search, "school") { - a.Properties.Name = " " - } - a.Geometry.Type = "Point" - a.Geometry.Coordinates = Point{results[i].Lng, results[i].Lat} - if *doArea { - a.Geometry.Type = "Polygon" - x, y := results[i].Lng, results[i].Lat - a.Geometry.Coordinates = Area{{ - [2]float64{x, y + radiusY}, // top - [2]float64{x + radiusX, y}, // right - [2]float64{x, y - radiusY}, // bot - [2]float64{x - radiusX, y}, // left - [2]float64{x, y + radiusY}, // top - }} - } - geoJsons = append(geoJsons, a) + slices.SortFunc(results, func(a, b Location) int { + return strings.Compare(a.Name, b.Name) + }) + slices.CompactFunc(results, func(a, b Location) bool { + return a.Name == b.Name + }) + radius := area / convertToMiles + radiusX := 2 * radius / 2 + radiusY := 2 * radius / 3 + + for i := range results { + var a geoJson + a.Type = "Feature" + a.Properties.Name = path.Join(search, results[i].Name) + if strings.Contains(search, "school") { + a.Properties.Name = " " } + a.Geometry.Type = "Point" + a.Geometry.Coordinates = Point{results[i].Lng, results[i].Lat} + if *doArea { + a.Geometry.Type = "Polygon" + x, y := results[i].Lng, results[i].Lat + a.Geometry.Coordinates = Area{{ + [2]float64{x, y + radiusY}, // top + [2]float64{x + radiusX, y}, // right + [2]float64{x, y - radiusY}, // bot + [2]float64{x - radiusX, y}, // left + [2]float64{x, y + radiusY}, // top + }} + } + geoJsons = append(geoJsons, a) } } log.Println(len(geoJsons))