dedupe points across searches but not across towns

This commit is contained in:
Bel LaPointe
2026-03-17 12:39:55 -06:00
parent c8066d7b17
commit 2d53b0639b

View File

@@ -37,43 +37,52 @@ func Run(ctx context.Context) error {
type Area [1][5][2]float64 type Area [1][5][2]float64
type Point [2]float64 type Point [2]float64
geoJsons := []geoJson{} geoJsons := []geoJson{}
for _, town := range towns { for search, area := range searches {
for search, area := range searches { results := []Location{}
radius := area / convertToMiles for _, town := range towns {
radiusX := 2 * radius / 2
radiusY := 2 * radius / 3
m, err := NewMapsOf(ctx, town) m, err := NewMapsOf(ctx, town)
if err != nil { if err != nil {
return err return err
} }
results, err := m.Search(ctx, search, *searchRadius) more, err := m.Search(ctx, search, *searchRadius)
if err != nil { if err != nil {
return err return err
} }
results = append(results, more...)
}
for i := range results { slices.SortFunc(results, func(a, b Location) int {
var a geoJson return strings.Compare(a.Name, b.Name)
a.Type = "Feature" })
a.Properties.Name = path.Join(search, results[i].Name) slices.CompactFunc(results, func(a, b Location) bool {
if strings.Contains(search, "school") { return a.Name == b.Name
a.Properties.Name = " " })
} radius := area / convertToMiles
a.Geometry.Type = "Point" radiusX := 2 * radius / 2
a.Geometry.Coordinates = Point{results[i].Lng, results[i].Lat} radiusY := 2 * radius / 3
if *doArea {
a.Geometry.Type = "Polygon" for i := range results {
x, y := results[i].Lng, results[i].Lat var a geoJson
a.Geometry.Coordinates = Area{{ a.Type = "Feature"
[2]float64{x, y + radiusY}, // top a.Properties.Name = path.Join(search, results[i].Name)
[2]float64{x + radiusX, y}, // right if strings.Contains(search, "school") {
[2]float64{x, y - radiusY}, // bot a.Properties.Name = " "
[2]float64{x - radiusX, y}, // left
[2]float64{x, y + radiusY}, // top
}}
}
geoJsons = append(geoJsons, a)
} }
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)) log.Println(len(geoJsons))