Avoid bad coordinates in the ref place

This commit is contained in:
SNoiraud 2019-09-01 10:30:44 +02:00 committed by Nick Hall
parent d397b83dc8
commit 5767b9c3c8

View File

@ -40,6 +40,7 @@ import re
from ....const import GRAMPS_LOCALE as glocale
from .. import Rule
from ....utils.place import conv_lat_lon
from gramps.gen.errors import FilterError
_ = glocale.translation.sgettext
@ -78,6 +79,12 @@ class WithinArea(Rule):
self.latitude, self.longitude = conv_lat_lon(latitude,
longitude,
"D.D8")
if self.latitude is None or self.longitude is None:
raise FilterError(_("Cannot use the filter 'within area'"),
_("The place you selected contains bad coordinates. "
"Please, run the tool 'clean input data'"))
return
val = self.list[1]
if isinstance(val, str):
val = re.sub("\D", "", val) # suppress all alpha characters
@ -107,6 +114,8 @@ class WithinArea(Rule):
lon = place.get_longitude()
if lat and lon:
latit, longit = conv_lat_lon(lat, lon, "D.D8")
if latit is None or longit is None:
return False
if (hypot(float(self.latitude)-float(latit),
float(self.longitude)-float(longit))
<= self.radius):