combine completely overlapped squares
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/turbomaps-er
|
||||
24
cmd/run.go
24
cmd/run.go
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user