def format_gps(dms_list, nsew_ref): """ Convert a [degrees, minutes, seconds] list of Fractions and a direction reference into a string for display. """ try: degs, mins, secs = dms_list except (TypeError, ValueError): return _('Invalid format') if not isinstance(degs, Fraction): # Old API uses pyexiv2.Rational degs = Fraction(str(degs)) mins = Fraction(str(mins)) secs = Fraction(str(secs)) value = float(degs) + float(mins) / 60 + float(secs) / 3600 if nsew_ref == 'N': result = conv_lat_lon(str(value), '0', 'DEG')[0] elif nsew_ref == 'S': result = conv_lat_lon('-' + str(value), '0', 'DEG')[0] elif nsew_ref == 'E': result = conv_lat_lon('0', str(value), 'DEG')[1] elif nsew_ref == 'W': result = conv_lat_lon('0', '-' + str(value), 'DEG')[1] else: result = None return result if result is not None else _('Invalid format')
def _validate_coordinate(self, widget, text, typedeg): if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"): return ValidationError(_(u"Invalid latitude (syntax: 18\u00b09'") + _('48.21"S, -18.2412 or -18:9:48.21)')) elif (typedeg == 'lon') and not conv_lat_lon("0", text, "ISO-D"): return ValidationError(_(u"Invalid longitude (syntax: 18\u00b09'") + _('48.21"E, -18.2412 or -18:9:48.21)'))
def _create_one_place(self, place): """ Create one entry for one place with a lat/lon. """ if place is None: return descr = place.get_title() longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8") # place.get_longitude and place.get_latitude return # one string. We have coordinates when the two values # contains non null string. if (longitude and latitude): self._append_to_places_list( descr, None, "", latitude, longitude, None, None, gen.lib.EventType.UNKNOWN, None, # person.gramps_id place.gramps_id, None, # event.gramps_id None # family.gramps_id ) else: self._append_to_places_without_coord(place.gramps_id, descr)
def sort_latitude(self, data): if not data[4]: return u' ' value = conv_lat_lon(data[4], '0', format='ISO-DMS') if data[4] else u'' if not value: return _("Error in format") return value
def column_latitude(self, data): if not data[4]: return u' ' value = conv_lat_lon(data[4], '0', format='DEG')[0] if not value: return _("Error in format") return value
def column_longitude(self, data): if not data[3]: return u' ' value = conv_lat_lon('0', data[3], format='DEG')[1] if not value: return _("Error in format") return value
def display_place(self, place): """ Display details of the active place. """ self.load_place_image(place) self.title.set_text(place.get_title()) self.clear_table() self.display_location(place.get_main_location()) self.display_separator() lat, lon = conv_lat_lon(place.get_latitude(), place.get_longitude(), format='DEG') if lat: self.add_row(_('Latitude'), lat) if lon: self.add_row(_('Longitude'), lon)
def _createpersonmarkers(self, dbstate, person, comment, fam_id): """ Create all markers for the specified person. """ self.cal = config.get('preferences.calendar-format-report') latitude = longitude = "" if person: # For each event, if we have a place, set a marker. for event_ref in person.get_event_ref_list(): if not event_ref: continue role = event_ref.get_role() event = dbstate.db.get_event_from_handle(event_ref.ref) eyear = event.get_date_object().to_calendar( self.cal).get_year() place_handle = event.get_place_handle() if place_handle: place = dbstate.db.get_place_from_handle(place_handle) if place: longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon( latitude, longitude, "D.D8") descr = place.get_title() evt = gen.lib.EventType(event.get_type()) descr1 = _("%(eventtype)s : %(name)s") % { 'eventtype': evt, 'name': _nd.display(person) } # place.get_longitude and place.get_latitude return # one string. We have coordinates when the two values # contains non null string. if (longitude and latitude): if not self._present_in_places_list( 2, str(descr1 + descr + str(evt))): self._append_to_places_list( descr, str(descr1 + descr + str(evt)), _nd.display(person), latitude, longitude, role, eyear, event.get_type(), person.gramps_id, place.gramps_id, event.gramps_id, fam_id) else: self._append_to_places_without_coord( place.gramps_id, descr) family_list = person.get_family_handle_list() for family_hdl in family_list: family = self.dbstate.db.get_family_from_handle(family_hdl) if family is not None: for event_ref in family.get_event_ref_list(): if event_ref: event = dbstate.db.get_event_from_handle( event_ref.ref) role = event_ref.get_role() if event.get_place_handle(): place_handle = event.get_place_handle() if place_handle: place = dbstate.db.get_place_from_handle( place_handle) if place: longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon( latitude, longitude, "D.D8") descr = place.get_title() evt = gen.lib.EventType( event.get_type()) (father_name, mother_name ) = self._get_father_and_mother_name( event) descr1 = "%s : %s - " % (evt, father_name) descr1 = "%s%s" % (descr1, mother_name) eyear = event.get_date_object( ).to_calendar(self.cal).get_year() if (longitude and latitude): if not self._present_in_places_list( 2, str(descr1 + descr + str(evt))): self._append_to_places_list( descr, str(descr1 + descr + str(evt)), _nd.display(person), latitude, longitude, role, eyear, event.get_type(), person.gramps_id, place.gramps_id, event.gramps_id, family.gramps_id) else: self._append_to_places_without_coord( place.gramps_id, descr)
def _createmap_for_one_event(self, event): """ Create all markers for each people's event in the database which has a lat/lon. """ dbstate = self.dbstate descr = descr2 = "" if event: place_handle = event.get_place_handle() eventyear = event.get_date_object().to_calendar( self.cal).get_year() else: place_handle = None if place_handle: place = dbstate.db.get_place_from_handle(place_handle) if place: descr1 = place.get_title() longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8") # place.get_longitude and place.get_latitude return # one string. We have coordinates when the two values # contains non null string. if (longitude and latitude): person_list = [ dbstate.db.get_person_from_handle(ref_handle) for (ref_type, ref_handle) in dbstate.db.find_backlink_handles(event.handle) if ref_type == 'Person' ] if person_list: for person in person_list: if descr2 == "": descr2 = ("%s") % _nd.display(person) else: descr2 = ("%s - %s") % (descr2, _nd.display(person)) else: # family list ? family_list = [ dbstate.db.get_family_from_handle(ref_handle) for (ref_type, ref_handle) in dbstate.db.find_backlink_handles(event.handle) if ref_type == 'Family' ] if family_list: for family in family_list: hdle = family.get_father_handle() father = dbstate.db.get_person_from_handle( hdle) hdle = family.get_mother_handle() mother = dbstate.db.get_person_from_handle( hdle) descr2 = ("%(father)s - %(mother)s") % { 'father': _nd.display(father) if father is not None else "?", 'mother': _nd.display(mother) if mother is not None else "?" } else: descr2 = _("incomplete or unreferenced event ?") self._append_to_places_list( descr1, None, None, latitude, longitude, descr2, eventyear, event.get_type(), None, # person.gramps_id place.gramps_id, event.gramps_id, None) else: descr = place.get_title() self._append_to_places_without_coord( place.gramps_id, descr)
def _createmap(self, obj): """ Create all markers for each people's event in the database which has a lat/lon. """ dbstate = self.dbstate self.cal = config.get('preferences.calendar-format-report') self.place_list = [] self.place_without_coordinates = [] self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0 self.minyear = 9999 self.maxyear = 0 latitude = "" longitude = "" person_handle = self.uistate.get_active('Person') person = dbstate.db.get_person_from_handle(person_handle) if person is not None: # For each event, if we have a place, set a marker. for event_ref in person.get_event_ref_list(): if not event_ref: continue event = dbstate.db.get_event_from_handle(event_ref.ref) role = event_ref.get_role() eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) place_handle = event.get_place_handle() if place_handle: place = dbstate.db.get_place_from_handle(place_handle) if place: longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon( latitude, longitude, "D.D8") descr = place.get_title() evt = gen.lib.EventType(event.get_type()) descr1 = _("%(eventtype)s : %(name)s") % { 'eventtype': evt, 'name': _nd.display(person) } # place.get_longitude and place.get_latitude return # one string. We have coordinates when the two values # contains non null string. if (longitude and latitude): self._append_to_places_list( descr, evt, _nd.display(person), latitude, longitude, descr1, eyear, event.get_type(), person.gramps_id, place.gramps_id, event.gramps_id, role) else: self._append_to_places_without_coord( place.gramps_id, descr) family_list = person.get_family_handle_list() for family_hdl in family_list: family = self.dbstate.db.get_family_from_handle(family_hdl) if family is not None: fhandle = family_list[0] # first is primary fam = dbstate.db.get_family_from_handle(fhandle) handle = fam.get_father_handle() father = dbstate.db.get_person_from_handle(handle) descr1 = " - " if father: descr1 = "%s - " % _nd.display(father) handle = fam.get_mother_handle() mother = dbstate.db.get_person_from_handle(handle) if mother: descr1 = "%s%s" % (descr1, _nd.display(mother)) for event_ref in family.get_event_ref_list(): if event_ref: event = dbstate.db.get_event_from_handle( event_ref.ref) role = event_ref.get_role() if event.get_place_handle(): place_handle = event.get_place_handle() if place_handle: place = dbstate.db.get_place_from_handle( place_handle) if place: longitude = place.get_longitude() latitude = place.get_latitude() latitude, longitude = conv_lat_lon( latitude, longitude, "D.D8") descr = place.get_title() evt = gen.lib.EventType( event.get_type()) eyear = str("%04d" % event.get_date_object().to_calendar(self.cal).get_year()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_month()) + \ str("%02d" % event.get_date_object().to_calendar(self.cal).get_day()) if (longitude and latitude): self._append_to_places_list( descr, evt, _nd.display(person), latitude, longitude, descr1, eyear, event.get_type(), person.gramps_id, place.gramps_id, event.gramps_id, role) else: self._append_to_places_without_coord( place.gramps_id, descr) self.sort = sorted(self.place_list, key=operator.itemgetter(6)) self._create_markers()
def _lat_lon(self, place, format="D.D8"): """return the lat, lon value of place in the requested format None, None if invalid """ return conv_lat_lon(place.get_latitude(), place.get_longitude(), format)