locode: Use quadtree to find continent #830
1 changed files with 12 additions and 11 deletions
|
@ -92,7 +92,14 @@ func (db *DB) buildQuadtree() error {
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, feature := range db.features {
|
for _, feature := range db.features {
|
||||||
|
|||||||
if multiPolygon, ok := feature.Geometry.(orb.MultiPolygon); ok {
|
multiPolygon := make(orb.MultiPolygon, 0)
|
||||||
fyrchik marked this conversation as resolved
fyrchik
commented
What about What about `var multiPolygon orb.MultiPolygon`? `make(_, 0)` is usually never needed: `nil` acts good enough as the default value.
Nesterfifa
commented
Fixed Fixed
|
|||||||
|
|
||||||
|
if polygon, ok := feature.Geometry.(orb.Polygon); ok {
|
||||||
|
multiPolygon = append(multiPolygon, polygon)
|
||||||
|
} else {
|
||||||
|
multiPolygon = feature.Geometry.(orb.MultiPolygon)
|
||||||
|
}
|
||||||
|
|
||||||
for _, polygon := range multiPolygon {
|
for _, polygon := range multiPolygon {
|
||||||
newFeature := geojson.NewFeature(polygon)
|
newFeature := geojson.NewFeature(polygon)
|
||||||
newFeature.Properties = feature.Properties.Clone()
|
newFeature.Properties = feature.Properties.Clone()
|
||||||
|
@ -101,12 +108,6 @@ func (db *DB) buildQuadtree() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if _, ok := feature.Geometry.(orb.Polygon); ok {
|
|
||||||
err := db.tree.Add(feature)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue
Is there a way to simplify this code?
cff78d77c2/pkg/util/locode/db/continents/geojson/calls.go (L94-L110)
Reduced the nesting depth to 2