overlappping squares become points
This commit is contained in:
41
cmd/run.go
41
cmd/run.go
@@ -35,6 +35,7 @@ func Run(ctx context.Context) error {
|
||||
} `json:"geometry"`
|
||||
}
|
||||
type Area [1][5][2]float64
|
||||
type Point [2]float64
|
||||
geoJsons := []geoJson{}
|
||||
for _, town := range towns {
|
||||
for search, area := range searches {
|
||||
@@ -55,8 +56,11 @@ func Run(ctx context.Context) error {
|
||||
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 = []any{results[i].Lng, results[i].Lat}
|
||||
a.Geometry.Coordinates = Point{results[i].Lng, results[i].Lat}
|
||||
if *doArea {
|
||||
a.Geometry.Type = "Polygon"
|
||||
x, y := results[i].Lng, results[i].Lat
|
||||
@@ -80,20 +84,27 @@ func Run(ctx context.Context) error {
|
||||
return fmt.Sprint(a.Geometry.Coordinates) == fmt.Sprint(b.Geometry.Coordinates)
|
||||
})
|
||||
if *doArea {
|
||||
for i := 0; i < len(geoJsons); i++ {
|
||||
areaI := geoJsons[i].Geometry.Coordinates.(Area)[0]
|
||||
j := i + 1
|
||||
for j < len(geoJsons) {
|
||||
areaJ := geoJsons[j].Geometry.Coordinates.(Area)[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 = append(geoJsons[:j], geoJsons[j+1:]...)
|
||||
} else {
|
||||
j += 1
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,8 @@ run = "mise run search -- {olympia,lacey,tumwater}', wa'"
|
||||
[tasks.bend]
|
||||
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]
|
||||
run = "mise run search -- {burlington,sedro-wooley,'mt vernon',bellingham,ferndale}', wa'"
|
||||
|
||||
Reference in New Issue
Block a user