Could not convert string to float
by using withinarea filter rule + difference between sidebar filter and filter rule + some pylint improvements
This commit is contained in:
parent
d096d269c7
commit
7617891faf
@ -1,3 +1,6 @@
|
|||||||
|
"""
|
||||||
|
WithinArea : used to verify if a place is contained in a specific area
|
||||||
|
"""
|
||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
@ -25,17 +28,19 @@
|
|||||||
# Standard Python modules
|
# Standard Python modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
from math import pi, cos, hypot
|
from math import pi, cos, hypot
|
||||||
from ....const import GRAMPS_LOCALE as glocale
|
|
||||||
_ = glocale.translation.sgettext
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Gramps modules
|
# Gramps modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from ....const import GRAMPS_LOCALE as glocale
|
||||||
from .. import Rule
|
from .. import Rule
|
||||||
from ....utils.location import located_in
|
from ....utils.place import conv_lat_lon
|
||||||
|
|
||||||
|
_ = glocale.translation.sgettext
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -51,6 +56,10 @@ class WithinArea(Rule):
|
|||||||
name = _('Places within an area')
|
name = _('Places within an area')
|
||||||
description = _('Matches places within a given distance of another place')
|
description = _('Matches places within a given distance of another place')
|
||||||
category = _('Position filters')
|
category = _('Position filters')
|
||||||
|
handle = None
|
||||||
|
radius = None
|
||||||
|
latitude = None
|
||||||
|
longitude = None
|
||||||
|
|
||||||
def prepare(self, db, user):
|
def prepare(self, db, user):
|
||||||
ref_place = db.get_place_from_gramps_id(self.list[0])
|
ref_place = db.get_place_from_gramps_id(self.list[0])
|
||||||
@ -60,13 +69,16 @@ class WithinArea(Rule):
|
|||||||
self.longitude = None
|
self.longitude = None
|
||||||
if ref_place:
|
if ref_place:
|
||||||
self.handle = ref_place.handle
|
self.handle = ref_place.handle
|
||||||
self.latitude = ref_place.get_latitude()
|
latitude = ref_place.get_latitude()
|
||||||
if self.latitude == "":
|
if latitude == "":
|
||||||
self.latitude = None
|
latitude = None
|
||||||
return
|
return
|
||||||
self.longitude = ref_place.get_longitude()
|
longitude = ref_place.get_longitude()
|
||||||
value = self.list[1]
|
self.latitude, self.longitude = conv_lat_lon(latitude,
|
||||||
unit = self.list[2]
|
longitude,
|
||||||
|
"D.D8")
|
||||||
|
value = int(self.list[1])
|
||||||
|
unit = int(self.list[2])
|
||||||
# earth perimeter in kilometers for latitude
|
# earth perimeter in kilometers for latitude
|
||||||
# 2 * pi * (6371 * cos(latitude/180*pi))
|
# 2 * pi * (6371 * cos(latitude/180*pi))
|
||||||
# so 1 degree correspond to the result above / 360
|
# so 1 degree correspond to the result above / 360
|
||||||
@ -79,7 +91,7 @@ class WithinArea(Rule):
|
|||||||
self.radius = float(value)
|
self.radius = float(value)
|
||||||
self.radius = self.radius/2
|
self.radius = self.radius/2
|
||||||
|
|
||||||
def apply(self, db, place):
|
def apply(self, dummy_db, place):
|
||||||
if self.handle is None:
|
if self.handle is None:
|
||||||
return False
|
return False
|
||||||
if self.latitude is None:
|
if self.latitude is None:
|
||||||
@ -90,7 +102,9 @@ class WithinArea(Rule):
|
|||||||
lat = place.get_latitude()
|
lat = place.get_latitude()
|
||||||
lon = place.get_longitude()
|
lon = place.get_longitude()
|
||||||
if lat and lon:
|
if lat and lon:
|
||||||
if (hypot(float(self.latitude)-float(lat),
|
latit, longit = conv_lat_lon(lat, lon, "D.D8")
|
||||||
float(self.longitude)-float(lon)) <= self.radius) == True:
|
if (hypot(float(self.latitude)-float(latit),
|
||||||
|
float(self.longitude)-float(longit))
|
||||||
|
<= self.radius):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user