Compare commits
3 Commits
1b4d33b7ce
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d53b0639b | ||
|
|
c8066d7b17 | ||
|
|
582e890dc4 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/turbomaps-er
|
||||||
58
cmd/run.go
58
cmd/run.go
@@ -31,35 +31,50 @@ func Run(ctx context.Context) error {
|
|||||||
} `json:"properties"`
|
} `json:"properties"`
|
||||||
Geometry struct {
|
Geometry struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Coordinates []any `json:"coordinates"`
|
Coordinates any `json:"coordinates"`
|
||||||
} `json:"geometry"`
|
} `json:"geometry"`
|
||||||
}
|
}
|
||||||
|
type Area [1][5][2]float64
|
||||||
|
type Point [2]float64
|
||||||
geoJsons := []geoJson{}
|
geoJsons := []geoJson{}
|
||||||
for _, town := range towns {
|
|
||||||
for search, area := range searches {
|
for search, area := range searches {
|
||||||
radius := area / convertToMiles
|
results := []Location{}
|
||||||
radiusX := 2 * radius / 2
|
for _, town := range towns {
|
||||||
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...)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
for i := range results {
|
||||||
var a geoJson
|
var a geoJson
|
||||||
a.Type = "Feature"
|
a.Type = "Feature"
|
||||||
a.Properties.Name = path.Join(search, results[i].Name)
|
a.Properties.Name = path.Join(search, results[i].Name)
|
||||||
|
if strings.Contains(search, "school") {
|
||||||
|
a.Properties.Name = " "
|
||||||
|
}
|
||||||
a.Geometry.Type = "Point"
|
a.Geometry.Type = "Point"
|
||||||
a.Geometry.Coordinates = []any{results[i].Lng, results[i].Lat}
|
a.Geometry.Coordinates = Point{results[i].Lng, results[i].Lat}
|
||||||
if *doArea {
|
if *doArea {
|
||||||
a.Geometry.Type = "Polygon"
|
a.Geometry.Type = "Polygon"
|
||||||
x, y := results[i].Lng, results[i].Lat
|
x, y := results[i].Lng, results[i].Lat
|
||||||
a.Geometry.Coordinates = []any{[]any{
|
a.Geometry.Coordinates = Area{{
|
||||||
[2]float64{x, y + radiusY}, // top
|
[2]float64{x, y + radiusY}, // top
|
||||||
[2]float64{x + radiusX, y}, // right
|
[2]float64{x + radiusX, y}, // right
|
||||||
[2]float64{x, y - radiusY}, // bot
|
[2]float64{x, y - radiusY}, // bot
|
||||||
@@ -70,7 +85,6 @@ func Run(ctx context.Context) error {
|
|||||||
geoJsons = append(geoJsons, a)
|
geoJsons = append(geoJsons, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
log.Println(len(geoJsons))
|
log.Println(len(geoJsons))
|
||||||
slices.SortFunc(geoJsons, func(a, b geoJson) int {
|
slices.SortFunc(geoJsons, func(a, b geoJson) int {
|
||||||
return strings.Compare(fmt.Sprint(a.Geometry.Coordinates), fmt.Sprint(b.Geometry.Coordinates))
|
return strings.Compare(fmt.Sprint(a.Geometry.Coordinates), fmt.Sprint(b.Geometry.Coordinates))
|
||||||
@@ -78,6 +92,32 @@ func Run(ctx context.Context) error {
|
|||||||
geoJsons = slices.CompactFunc(geoJsons, func(a, b geoJson) bool {
|
geoJsons = slices.CompactFunc(geoJsons, func(a, b geoJson) bool {
|
||||||
return fmt.Sprint(a.Geometry.Coordinates) == fmt.Sprint(b.Geometry.Coordinates)
|
return fmt.Sprint(a.Geometry.Coordinates) == fmt.Sprint(b.Geometry.Coordinates)
|
||||||
})
|
})
|
||||||
|
if *doArea {
|
||||||
|
for i := range geoJsons {
|
||||||
|
areaI, ok := geoJsons[i].Geometry.Coordinates.(Area)
|
||||||
|
if ok {
|
||||||
|
areaI := areaI[0]
|
||||||
|
for j := i + 1; j < len(geoJsons); j++ {
|
||||||
|
areaJ, ok := geoJsons[j].Geometry.Coordinates.(Area)
|
||||||
|
if ok {
|
||||||
|
areaJ := areaJ[0]
|
||||||
|
// if diamond i contains j, then drop j
|
||||||
|
iAbove := areaI[0][1] > areaJ[0][1]
|
||||||
|
iRight := areaI[1][0] > areaJ[1][0]
|
||||||
|
iBelow := areaI[2][1] < areaJ[2][1]
|
||||||
|
iLeft := areaI[3][0] < areaJ[3][0]
|
||||||
|
if iAbove && iRight && iBelow && iLeft {
|
||||||
|
geoJsons[j].Geometry.Type = "Point"
|
||||||
|
geoJsons[j].Geometry.Coordinates = Point{
|
||||||
|
(areaJ[1][0] + areaJ[3][0]) / 2.0,
|
||||||
|
(areaJ[0][1] + areaJ[2][1]) / 2.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Println("COMPACTED", len(geoJsons))
|
log.Println("COMPACTED", len(geoJsons))
|
||||||
b, _ := json.Marshal(map[string]any{
|
b, _ := json.Marshal(map[string]any{
|
||||||
"features": geoJsons,
|
"features": geoJsons,
|
||||||
|
|||||||
@@ -11,5 +11,8 @@ run = "mise run search -- {olympia,lacey,tumwater}', wa'"
|
|||||||
[tasks.bend]
|
[tasks.bend]
|
||||||
run = "mise run search -- 'bend, or'"
|
run = "mise run search -- 'bend, or'"
|
||||||
|
|
||||||
|
[tasks.ridgefield]
|
||||||
|
run = "mise run search -- {ridgefield,vancouver,'mt vista','hazel dell',felida,'brush prarie','battle ground'}', or'"
|
||||||
|
|
||||||
[tasks.bellingham]
|
[tasks.bellingham]
|
||||||
run = "mise run search -- {burlington,sedro-wooley,'mt vernon',bellingham,ferndale}', wa'"
|
run = "mise run search -- {burlington,sedro-wooley,'mt vernon',bellingham,ferndale}', wa'"
|
||||||
|
|||||||
Reference in New Issue
Block a user