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 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))