combine completely overlapped squares

This commit is contained in:
Bel LaPointe
2026-03-17 12:16:57 -06:00
parent 1b4d33b7ce
commit 582e890dc4
2 changed files with 23 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/turbomaps-er

View File

@@ -31,9 +31,10 @@ func Run(ctx context.Context) error {
} `json:"properties"`
Geometry struct {
Type string `json:"type"`
Coordinates []any `json:"coordinates"`
Coordinates any `json:"coordinates"`
} `json:"geometry"`
}
type Area [1][5][2]float64
geoJsons := []geoJson{}
for _, town := range towns {
for search, area := range searches {
@@ -59,7 +60,7 @@ func Run(ctx context.Context) error {
if *doArea {
a.Geometry.Type = "Polygon"
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 + radiusX, y}, // right
[2]float64{x, y - radiusY}, // bot
@@ -78,6 +79,25 @@ func Run(ctx context.Context) error {
geoJsons = slices.CompactFunc(geoJsons, func(a, b geoJson) bool {
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
}
}
}
}
log.Println("COMPACTED", len(geoJsons))
b, _ := json.Marshal(map[string]any{
"features": geoJsons,