[#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:
parent
1462824ab8
commit
45f244eb77
1 changed files with 9 additions and 1 deletions
|
@ -31,7 +31,10 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error)
|
|||
|
||||
planarPoint := orb.Point{point.Longitude(), point.Latitude()}
|
||||
|
||||
var continent string
|
||||
var (
|
||||
continent string
|
||||
minDst float64
|
||||
)
|
||||
|
||||
for _, feature := range db.features {
|
||||
if multiPolygon, ok := feature.Geometry.(orb.MultiPolygon); ok {
|
||||
|
@ -45,6 +48,11 @@ func (db *DB) PointContinent(point *locodedb.Point) (*locodedb.Continent, error)
|
|||
break
|
||||
}
|
||||
}
|
||||
distance := planar.DistanceFrom(feature.Geometry, planarPoint)
|
||||
if minDst == 0 || minDst > distance {
|
||||
minDst = distance
|
||||
continent = feature.Properties.MustString(continentProperty)
|
||||
}
|
||||
}
|
||||
|
||||
c := continentFromString(continent)
|
||||
|
|
Loading…
Reference in a new issue