dedupe points across searches but not across towns
This commit is contained in:
63
cmd/run.go
63
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))
|
||||
|
||||
Reference in New Issue
Block a user