[#955] locode: Use the nearest polygon when continent can't be found

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-11-01 22:35:18 +03:00 committed by Alex Vanin
parent 1462824ab8
commit 45f244eb77

View file

@ -31,7 +31,10 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error)
planarPoint := orb.Point{point.Longitude(), point.Latitude()} planarPoint := orb.Point{point.Longitude(), point.Latitude()}
var continent string var (
continent string
minDst float64
)
for _, feature := range db.features { for _, feature := range db.features {
if multiPolygon, ok := feature.Geometry.(orb.MultiPolygon); ok { if multiPolygon, ok := feature.Geometry.(orb.MultiPolygon); ok {
@ -45,6 +48,11 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error)
break break
} }
} }
distance := planar.DistanceFrom(feature.Geometry, planarPoint)
if minDst == 0 || minDst > distance {
minDst = distance
continent = feature.Properties.MustString(continentProperty)
}
} }
c := continentFromString(continent) c := continentFromString(continent)