overlappping squares become points
This commit is contained in:
29
cmd/run.go
29
cmd/run.go
@@ -35,6 +35,7 @@ func Run(ctx context.Context) error {
|
|||||||
} `json:"geometry"`
|
} `json:"geometry"`
|
||||||
}
|
}
|
||||||
type Area [1][5][2]float64
|
type Area [1][5][2]float64
|
||||||
|
type Point [2]float64
|
||||||
geoJsons := []geoJson{}
|
geoJsons := []geoJson{}
|
||||||
for _, town := range towns {
|
for _, town := range towns {
|
||||||
for search, area := range searches {
|
for search, area := range searches {
|
||||||
@@ -55,8 +56,11 @@ func Run(ctx context.Context) error {
|
|||||||
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
|
||||||
@@ -80,20 +84,27 @@ func Run(ctx context.Context) error {
|
|||||||
return fmt.Sprint(a.Geometry.Coordinates) == fmt.Sprint(b.Geometry.Coordinates)
|
return fmt.Sprint(a.Geometry.Coordinates) == fmt.Sprint(b.Geometry.Coordinates)
|
||||||
})
|
})
|
||||||
if *doArea {
|
if *doArea {
|
||||||
for i := 0; i < len(geoJsons); i++ {
|
for i := range geoJsons {
|
||||||
areaI := geoJsons[i].Geometry.Coordinates.(Area)[0]
|
areaI, ok := geoJsons[i].Geometry.Coordinates.(Area)
|
||||||
j := i + 1
|
if ok {
|
||||||
for j < len(geoJsons) {
|
areaI := areaI[0]
|
||||||
areaJ := geoJsons[j].Geometry.Coordinates.(Area)[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
|
// if diamond i contains j, then drop j
|
||||||
iAbove := areaI[0][1] > areaJ[0][1]
|
iAbove := areaI[0][1] > areaJ[0][1]
|
||||||
iRight := areaI[1][0] > areaJ[1][0]
|
iRight := areaI[1][0] > areaJ[1][0]
|
||||||
iBelow := areaI[2][1] < areaJ[2][1]
|
iBelow := areaI[2][1] < areaJ[2][1]
|
||||||
iLeft := areaI[3][0] < areaJ[3][0]
|
iLeft := areaI[3][0] < areaJ[3][0]
|
||||||
if iAbove && iRight && iBelow && iLeft {
|
if iAbove && iRight && iBelow && iLeft {
|
||||||
geoJsons = append(geoJsons[:j], geoJsons[j+1:]...)
|
geoJsons[j].Geometry.Type = "Point"
|
||||||
} else {
|
geoJsons[j].Geometry.Coordinates = Point{
|
||||||
j += 1
|
(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]
|
[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