Exemplo n.º 1
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(_("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(_("Invalid longitude (syntax: 18\u00b09'") +
                                _('48.21"E, -18.2412 or -18:9:48.21)'))
Exemplo n.º 2
0
def format_gps(raw_dms, nsew):
    """
    Convert raw degrees, minutes, seconds and a direction
    reference into a string for display.
    """
    value = 0.0
    divisor = 1.0
    for val in raw_dms.split(' '):
        try:
            num = float(val.split('/')[0]) / float(val.split('/')[1])
        except (ValueError, IndexError):
            value = None
            break
        value += num / divisor
        divisor *= 60

    if nsew == 'N':
        result = conv_lat_lon(str(value), '0', 'DEG')[0]
    elif nsew == 'S':
        result = conv_lat_lon('-' + str(value), '0', 'DEG')[0]
    elif nsew == 'E':
        result = conv_lat_lon('0', str(value), 'DEG')[1]
    elif nsew == 'W':
        result = conv_lat_lon('0', '-' + str(value), 'DEG')[1]
    else:
        result = None

    return result if result is not None else _('Invalid format')
Exemplo n.º 3
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(_("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(_("Invalid longitude (syntax: 18\u00b09'") +
                                _('48.21"E, -18.2412 or -18:9:48.21)'))
 def person_count(self, person):
     """
     Count the number of events associated to a place with coordinates
     """
     dbstate = self.dbstate
     for event_ref in person.get_event_ref_list():
         if not event_ref:
             continue
         event = dbstate.db.get_event_from_handle(event_ref.ref)
         place_handle = event.get_place_handle()
         if place_handle and event_ref.ref not in self.event_list:
             self.event_list.append(event_ref.ref)
             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")
                 if longitude and latitude:
                     self.nb_evts += 1
     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)
             father = mother = None
             handle = fam.get_father_handle()
             if handle:
                 father = dbstate.db.get_person_from_handle(handle)
             if father:
                 self.already_done.append(handle)
             handle = fam.get_mother_handle()
             if handle:
                 self.already_done.append(handle)
                 mother = dbstate.db.get_person_from_handle(handle)
             for event_ref in family.get_event_ref_list():
                 if event_ref:
                     event = dbstate.db.get_event_from_handle(event_ref.ref)
                     if event.get_place_handle():
                         place_handle = event.get_place_handle()
                         if (place_handle
                                 and event_ref.ref not in self.event_list):
                             self.event_list.append(event_ref.ref)
                             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")
                                 if longitude and latitude:
                                     self.nb_evts += 1
     for pers in [
             self._get_parent(person, True),
             self._get_parent(person, False)
     ]:
         if pers:
             self.person_count(pers)
Exemplo n.º 5
0
    def _test_formats_success(self, lat, lon):
        for format_ in ["D.D4", "D.D8", "DEG", "DEG-:", "RT90", "GEDCOM"]:
            res1, res2 = conv_lat_lon(lat, lon, format_)
            self.assertIsNotNone(res1, 'Failed for %s %s' % (lat, lon))
            self.assertIsNotNone(res2, 'Failed for %s %s' % (lat, lon))

        for format_ in ["ISO-D", "ISO-DM", "ISO-DMS"]:
            res = conv_lat_lon(lat, lon, format_)
            self.assertIsNotNone(res, 'Failed for %s %s' % (lat, lon))
Exemplo n.º 6
0
    def _test_formats_success(self, lat, lon):
        for format_ in ["D.D4", "D.D8", "DEG", "DEG-:", "RT90", "GEDCOM"]:
            res1, res2 = conv_lat_lon(lat, lon, format_)
            self.assertIsNotNone(res1, 'Failed for %s %s' % (lat, lon))
            self.assertIsNotNone(res2, 'Failed for %s %s' % (lat, lon))

        for format_ in ["ISO-D", "ISO-DM", "ISO-DMS"]:
            res = conv_lat_lon(lat, lon, format_)
            self.assertIsNotNone(res, 'Failed for %s %s' % (lat, lon))
Exemplo n.º 7
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(
             # translators: translate the "S" too (and the "or" of course)
             _('Invalid latitude\n(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(
             # translators: translate the "E" too (and the "or" of course)
             _('Invalid longitude\n(syntax: '
               '18\u00b09\'48.21"E, -18.2412 or -18:9:48.21)'))
Exemplo n.º 8
0
 def _validate_coordinate(self, widget, text, typedeg):
     if (typedeg == 'lat') and not conv_lat_lon(text, "0", "ISO-D"):
         return ValidationError(
             # translators: translate the "S" too (and the "or" of course)
             _('Invalid latitude\n(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(
             # translators: translate the "E" too (and the "or" of course)
             _('Invalid longitude\n(syntax: '
               '18\u00b09\'48.21"E, -18.2412 or -18:9:48.21)'))
Exemplo n.º 9
0
    def match(self, lat, lon):
        """
        coordinates matching.
        """
        rds = float(self.radius)
        self.places = []

        # place
        for entry in self.place_list:
            if (math.hypot(lat-float(entry[3]),
                           lon-float(entry[4])) <= rds) == True:
                # Do we already have this place ? avoid duplicates
                (country, state, county,
                 place, other) = self.get_location(entry[9])
                if not [country, state, county, place, other] in self.places:
                    self.places.append([country, state, county, place, other])
        self.warning = False
        for place in self.dbstate.db.iter_places():
            latn = place.get_latitude()
            lonn = place.get_longitude()
            if latn and lonn:
                latn, ignore = conv_lat_lon(latn, "0", "D.D8")
                if not latn:
                    if not self.warning:
                        self.close()
                    warn1 = _("you have a wrong latitude for:")
                    warn2 = _pd.display(self.dbstate.db, place) + "\n\n<b>"
                    warn2 += _("Please, correct this before linking") + "</b>"
                    WarningDialog(warn1, warn2, parent=self.uistate.window)
                    self.warning = True
                    continue
                ignore, lonn = conv_lat_lon("0", lonn, "D.D8")
                if not lonn:
                    if not self.warning:
                        self.close()
                    warn1 = _("you have a wrong longitude for:") + "\n"
                    warn2 = _pd.display(self.dbstate.db, place) + "\n\n<b>"
                    warn2 += _("Please, correct this before linking") + "</b>"
                    WarningDialog(warn1, warn2, parent=self.uistate.window)
                    self.warning = True
                    continue
                if (math.hypot(lat-float(latn),
                               lon-float(lonn)) <= rds) == True:
                    (country, state, county,
                     place, other) = self.get_location(place.get_gramps_id())
                    if not [country, state, county,
                            place, other] in self.places:
                        self.places.append([country, state, county,
                                            place, other])
Exemplo n.º 10
0
 def _create_one_place(self,place):
     """
     Create one entry for one place with a lat/lon.
     """
     if place is None:
         return
     if self.nbplaces >= self._config.get("geography.max_places"):
         return
     descr = _pd.display(self.dbstate.db, place)
     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,
                                     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)
Exemplo n.º 11
0
 def _create_one_place(self, place):
     """
     Create one entry for one place with a lat/lon.
     """
     if place is None:
         return
     if self.nbplaces >= self._config.get("geography.max_places"):
         return
     descr = _pd.display(self.dbstate.db, place)
     longitude = place.get_longitude()
     latitude = place.get_latitude()
     latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8")
     self.load_kml_files(place)
     # 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:
         colour = self.plc_color[int(place.get_type())+1]
         if int(place.get_type()) == PlaceType.CUSTOM:
             try:
                 colour = (str(place.get_type()),
                           self.plc_custom_color[str(place.get_type())])
             except:
                 colour = self.plc_color[PlaceType.CUSTOM + 1]
         self._append_to_places_list(descr, None, "",
                                     latitude, longitude,
                                     None, None,
                                     EventType.UNKNOWN,
                                     None, # person.gramps_id
                                     place.gramps_id,
                                     None, # event.gramps_id
                                     None, # family.gramps_id
                                     color=colour
                                    )
Exemplo n.º 12
0
 def column_longitude(self, data):
     if not data[3]:
         return ''
     value = conv_lat_lon('0', data[3], format='DEG')[1]
     if not value:
         return _("Error in format")
     return value
Exemplo n.º 13
0
 def column_latitude(self, data):
     if not data[4]:
         return ''
     value = conv_lat_lon(data[4], '0', format='DEG')[0]
     if not value:
         return _("Error in format")
     return value
Exemplo n.º 14
0
 def sort_latitude(self, data):
     if not data[4]:
         return ''
     value = conv_lat_lon(data[4], '0', format='ISO-DMS') if data[4] else ''
     if not value:
         return _("Error in format")
     return value
Exemplo n.º 15
0
    def on_fromDBButton_clicked(self, widget):
        latitude = self.entry_lat_db.get_text()
        longitude = self.entry_long_db.get_text()
        if latitude != "" and longitude != "":
            self.entry_lat.set_text(self.entry_lat_db.get_text())
            self.entry_long.set_text(self.entry_long_db.get_text())
            try:
                latitude, longitude = conv_lat_lon(
                    latitude, longitude, format="D.D8")
                latitude = float(latitude)
                longitude = float(longitude)
            except:
                self.entry_foundName.set_text(
                    _("Failed to interpret the input format."))

            # self.osm.grab_focus()
            try:
                loc = GeocodeGlib.Location.new(latitude, longitude, 0)
                obj = GeocodeGlib.Reverse.new_for_location(loc)
                result = GeocodeGlib.Reverse.resolve(obj)

                location_information = dict((p.name, result.get_property(
                    p.name)) for p in result.list_properties()
                    if result.get_property(p.name))
                self.entry_foundName.set_text(
                    generate_address_string(location_information))
            except Exception as e:
                self.entry_foundName.set_text(_("The place was not identified.") + ' ' + str(e))
        else:
            self.entry_foundName.set_text(_("Coordinates were not given."))
Exemplo n.º 16
0
 def column_latitude(self, data):
     if not data[4]:
         return ''
     value = conv_lat_lon(data[4], '0', format='DEG')[0]
     if not value:
         return _("Error in format")
     return ("\u202d" + value + "\u202e") if glocale.rtl_locale else value
Exemplo n.º 17
0
 def _create_one_place(self,place):
     """
     Create one entry for one place with a lat/lon.
     """
     if place is None:
         return
     if self.nbplaces >= self._config.get("geography.max_places"):
         return
     descr = _pd.display(self.dbstate.db, place)
     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,
                                     EventType.UNKNOWN,
                                     None, # person.gramps_id
                                     place.gramps_id,
                                     None, # event.gramps_id
                                     None # family.gramps_id
                                    )
Exemplo n.º 18
0
    def add_event_ref(self, event_ref, spouse=None, name=""):
        """
        Add an event to the model.
        """
        self.callman.register_handles({'event': [event_ref.ref]})
        event = self.dbstate.db.get_event_from_handle(event_ref.ref)
        event_date = get_date(event)
        event_sort = '%012d' % event.get_date_object().get_sort_value()
        place_name = place_displayer.display_event(self.dbstate.db, event)
        place_handle = event.get_place_handle()
        place_id = latitude = longitude = ""
        if place_handle:
            plc = self.dbstate.db.get_place_from_handle(place_handle)
            if plc:
                place_id = plc.get_gramps_id()
                latitude = plc.get_latitude()
                longitude = plc.get_longitude()
                latitude, longitude = conv_lat_lon(latitude, longitude, "D.D8")

        description = event.get_description()
        if description == "":
            description = name

        self.model.add((event.get_handle(),
                        str(event.get_type()),
                        description,
                        event_date,
                        event_sort,
                        place_name,
                        place_id,
                        latitude,
                        longitude
                        ))
Exemplo n.º 19
0
 def sort_latitude(self, data):
     if not data[4]:
         return ''
     value = conv_lat_lon(data[4], '0', format='ISO-DMS') if data[4] else ''
     if not value:
         return _("Error in format")
     return value
Exemplo n.º 20
0
    def match(self, lat, lon):
        """
        coordinates matching.
        """
        rds = float(self.radius)
        self.places = []

        # place
        for entry in self.place_list:
            if (math.hypot(lat - float(entry[3]), lon - float(entry[4])) <=
                    rds) == True:
                # Do we already have this place ? avoid duplicates
                (country, state, county, place,
                 other) = self.get_location(entry[9])
                if not [country, state, county, place, other] in self.places:
                    self.places.append([country, state, county, place, other])
        for place in self.dbstate.db.iter_places():
            latn = place.get_latitude()
            lonn = place.get_longitude()
            if latn and lonn:
                latn, lonn = conv_lat_lon(latn, lonn, "D.D8")
                if (math.hypot(lat - float(latn), lon - float(lonn)) <=
                        rds) == True:
                    (country, state, county, place,
                     other) = self.get_location(place.get_gramps_id())
                    if not [country, state, county, place, other
                            ] in self.places:
                        self.places.append(
                            [country, state, county, place, other])
Exemplo n.º 21
0
 def column_latitude(self, data):
     if not data[4]:
         return ''
     value = conv_lat_lon(data[4], '0', format='DEG')[0]
     if not value:
         return _("Error in format")
     return value
Exemplo n.º 22
0
 def column_longitude(self, data):
     if not data[3]:
         return ''
     value = conv_lat_lon('0', data[3], format='DEG')[1]
     if not value:
         return _("Error in format")
     return value
Exemplo n.º 23
0
    def match(self, lat, lon):
        """
        coordinates matching.
        """
        rds = float(self.radius)
        self.places = []

        # place
        for entry in self.place_list:
            if (math.hypot(lat-float(entry[3]),
                           lon-float(entry[4])) <= rds) == True:
                # Do we already have this place ? avoid duplicates
                (country, state, county,
                 place, other) = self.get_location(entry[9])
                if not [country, state, county, place, other] in self.places:
                    self.places.append([country, state, county, place, other])
        for place in self.dbstate.db.iter_places():
            latn = place.get_latitude()
            lonn = place.get_longitude()
            if latn and lonn:
                latn, lonn = conv_lat_lon(latn, lonn, "D.D8")
                if (math.hypot(lat-float(latn),
                               lon-float(lonn)) <= rds) == True:
                    (country, state, county,
                     place, other) = self.get_location(place.get_gramps_id())
                    if not [country, state, county,
                            place, other] in self.places:
                        self.places.append([country, state, county,
                                            place, other])
Exemplo n.º 24
0
    def _place(self, place, dateobj, level):
        """
        PLACE_STRUCTURE:=
            n PLAC <PLACE_NAME> {1:1}
            +1 FORM <PLACE_HIERARCHY> {0:1}
            +1 FONE <PLACE_PHONETIC_VARIATION> {0:M}  # not used
            +2 TYPE <PHONETIC_TYPE> {1:1}
            +1 ROMN <PLACE_ROMANIZED_VARIATION> {0:M} # not used
            +2 TYPE <ROMANIZED_TYPE> {1:1}
            +1 MAP {0:1}
            +2 LATI <PLACE_LATITUDE> {1:1}
            +2 LONG <PLACE_LONGITUDE> {1:1}
            +1 <<NOTE_STRUCTURE>> {0:M}
        """
        if place is None:
            return
        place_name = _pd.display(self.dbase, place, dateobj)
        self._writeln(level, "PLAC", place_name.replace('\r', ' '), limit=120)
        longitude = place.get_longitude()
        latitude = place.get_latitude()
        if longitude and latitude:
            (latitude, longitude) = conv_lat_lon(latitude, longitude, "GEDCOM")
        if longitude and latitude:
            self._writeln(level + 1, "MAP")
            self._writeln(level + 2, 'LATI', latitude)
            self._writeln(level + 2, 'LONG', longitude)

        # The Gedcom standard shows that an optional address structure can
        # be written out in the event detail.
        # http://homepages.rootsweb.com/~pmcbride/gedcom/55gcch2.htm#EVENT_DETAIL
        location = get_main_location(self.dbase, place)
        street = location.get(PlaceType.STREET)
        locality = location.get(PlaceType.LOCALITY)
        city = location.get(PlaceType.CITY)
        state = location.get(PlaceType.STATE)
        country = location.get(PlaceType.COUNTRY)
        postal_code = place.get_code()

        if street or locality or city or state or postal_code or country:
            self._writeln(level, "ADDR", street)
            if street:
                self._writeln(level + 1, 'ADR1', street)
            if locality:
                self._writeln(level + 1, 'ADR2', locality)
            if city:
                self._writeln(level + 1, 'CITY', city)
            if state:
                self._writeln(level + 1, 'STAE', state)
            if postal_code:
                self._writeln(level + 1, 'POST', postal_code)
            if country:
                self._writeln(level + 1, 'CTRY', country)
        if self.placenote:
            LOG.debug("PLACENOTE")
            self._note_references(place.get_note_list(), level)
        else:
            LOG.debug(" PAS PLACENOTE")
            self._note_references(place.get_note_list(), level + 1)
Exemplo n.º 25
0
 def test_RT90_conversion(self):
     """A given lat/lon is converted to RT90 and back"""
     x, y = conv_lat_lon('59:40:9.09', '12:58:57.74', 'RT90')
     lat, lon = conv_SWED_RT90_WGS84(float(x), float(y))
     
     expetced_lat = 59.0 + 40.0/60. + 9.09/3600.0
     expetced_lon = 12.0 + 58.0/60.0 + 57.74/3600.0
     
     self.assertAlmostEqual(lat, expetced_lat, places=3)
     self.assertAlmostEqual(lon, expetced_lon, places=3)
Exemplo n.º 26
0
    def test_RT90_conversion(self):
        """A given lat/lon is converted to RT90 and back"""
        x, y = conv_lat_lon('59:40:9.09', '12:58:57.74', 'RT90')
        lat, lon = conv_SWED_RT90_WGS84(float(x), float(y))

        expetced_lat = 59.0 + 40.0 / 60. + 9.09 / 3600.0
        expetced_lon = 12.0 + 58.0 / 60.0 + 57.74 / 3600.0

        self.assertAlmostEqual(lat, expetced_lat, places=3)
        self.assertAlmostEqual(lon, expetced_lon, places=3)
Exemplo n.º 27
0
    def find_place_lat_lon(self, event):
        """
#        Use the most recent occupation residence.
#        """
        lat = " "
        lon = " "
        place_handle = event.get_place_handle()
        if place_handle:
            place =  self.__db.get_place_from_handle(place_handle)
            if place:
#                lat, lon = conv_lat_lon(place.get_latitude(), place.get_longitude(), format="D.D8")
                lat, lon = conv_lat_lon(place.get_latitude(), place.get_longitude(), format="DEG")
        return(lat, lon)
Exemplo n.º 28
0
 def __output_place(self, ldatec, tbody, first_place, pname, place_handle,
                    letter, bucket_link):
     place = self.r_db.get_place_from_handle(place_handle)
     if place:
         if place.get_change_time() > ldatec:
             ldatec = place.get_change_time()
         plc_title = pname
         main_location = get_main_location(self.r_db, place)
         if not plc_title or plc_title == " ":
             letter = "&nbsp;"
         trow = Html("tr")
         tbody += trow
         tcell = Html("td", class_="ColumnLetter", inline=True)
         trow += tcell
         if first_place:
             # or primary_difference(letter, prev_letter, self.rlocale):
             first_place = False
             # prev_letter = letter
             trow.attr = 'class = "BeginLetter"'
             ttle = self._("Places beginning " "with letter %s") % letter
             tcell += Html("a",
                           letter,
                           name=letter,
                           title=ttle,
                           id_=bucket_link)
         else:
             tcell += "&nbsp;"
         trow += Html("td",
                      self.place_link(place.get_handle(), plc_title,
                                      place.get_gramps_id()),
                      class_="ColumnName")
         trow.extend(
             Html("td", data or "&nbsp;", class_=colclass, inline=True)
             for (colclass, data) in [[
                 "ColumnState",
                 main_location.get(PlaceType.STATE, '')
             ], ["ColumnCountry",
                 main_location.get(PlaceType.COUNTRY, '')]])
         if self.display_coordinates:
             tcell1 = Html("td", class_="ColumnLatitude", inline=True)
             tcell2 = Html("td", class_="ColumnLongitude", inline=True)
             trow += tcell1, tcell2
             if place.lat and place.long:
                 latitude, longitude = conv_lat_lon(place.lat, place.long,
                                                    "DEG")
                 tcell1 += latitude
                 tcell2 += longitude
             else:
                 tcell1 += '&nbsp;'
                 tcell2 += '&nbsp;'
     return (ldatec, first_place)
Exemplo n.º 29
0
    def find_place_lat_lon(self, event):
        """
#        Use the most recent occupation residence.
#        """
        lat = " "
        lon = " "
        place_handle = event.get_place_handle()
        if place_handle:
            place = self.__db.get_place_from_handle(place_handle)
            if place:
                #                lat, lon = conv_lat_lon(place.get_latitude(), place.get_longitude(), format="D.D8")
                lat, lon = conv_lat_lon(place.get_latitude(),
                                        place.get_longitude(),
                                        format="DEG")
        return (lat, lon)
Exemplo n.º 30
0
 def places(self):
     """
     For all places in the database, if the name contains leading or
     trailing spaces.
     """
     for place_handle in self.db.get_place_handles():
         self.progress.step()
         place = self.db.get_place_from_handle(place_handle)
         place_name = place.get_name()
         pname = place_name.get_value()
         found = False
         self.tooltip = ""
         if pname != pname.strip():
             self.add_text_to_tip(0, _("leading and/or trailing spaces"))
             found = True
         plat = place.get_latitude()
         plon = place.get_longitude()
         lat, lon = conv_lat_lon(plat, plon, "D.D8")
         self.f_lat = self.f_lon = False
         if not lat:
             self.add_text_to_tip(1, _("invalid format"))
             found = True
         if plat != plat.strip():
             self.add_text_to_tip(1, _("leading and/or trailing spaces"))
             found = True
         if plat.find(',') != -1:
             self.add_text_to_tip(1, _("comma instead of dot"))
             found = True
         if validate_lat_lon(plat):
             self.add_text_to_tip(1, _("invalid char instead of '-'"))
             found = True
         if not lon:
             self.add_text_to_tip(2, _("invalid format"))
             found = True
         if plon != plon.strip():
             self.add_text_to_tip(2, _("leading and/or trailing spaces"))
             found = True
         if plon.find(',') != -1:
             self.add_text_to_tip(2, _("comma instead of dot"))
             found = True
         if validate_lat_lon(plat):
             self.add_text_to_tip(1, _("invalid char instead of '-'"))
             found = True
         if found:
             value = (place_handle, pname, plat, plon, self.tooltip)
             self.model_2.append(value)
     return True
Exemplo n.º 31
0
    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)
        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)
Exemplo n.º 32
0
def get_place_profile_for_object(
    db_handle: DbReadBase,
    place: Place,
    locale: GrampsLocale = glocale,
    parent_places: bool = True,
) -> Dict[str, Any]:
    """Get place profile given a Place."""
    latitude, longitude = conv_lat_lon(place.lat, place.long, format="D.D8")
    profile = {
        "gramps_id":
        place.gramps_id,
        "type":
        _format_place_type(place.get_type(), locale=locale),
        "name":
        place.get_name().value,
        "alternate_names":
        [place_name.value for place_name in place.get_alternative_names()],
        "lat":
        float(latitude) if (latitude and longitude) else None,
        "long":
        float(longitude) if (latitude and longitude) else None,
    }
    if parent_places:
        parent_places_handles = []
        _place = place
        handle = None
        while True:
            for placeref in _place.get_placeref_list():
                handle = placeref.ref
                break
            if handle is None or handle in parent_places_handles:
                break
            _place = db_handle.get_place_from_handle(handle)
            if _place is None:
                break
            parent_places_handles.append(handle)
        profile["parent_places"] = [
            get_place_profile_for_object(
                db_handle=db_handle,
                place=db_handle.get_place_from_handle(parent_place),
                locale=locale,
                parent_places=False,
            ) for parent_place in parent_places_handles
        ]
    return profile
Exemplo n.º 33
0
    def display_place(self, place):
        """
        Display details of the active place.
        """
        self.load_place_image(place)
        title = place_displayer.display(self.dbstate.db, place)
        self.title.set_text(title)

        self.clear_grid()
        self.add_row(_('Name'), place.get_name())
        self.add_row(_('Type'), place.get_type())
        self.display_separator()
        self.display_alt_names(place)
        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)
Exemplo n.º 34
0
    def display_place(self, place):
        """
        Display details of the active place.
        """
        self.load_place_image(place)
        title = place_displayer.display(self.dbstate.db, place)
        self.title.set_text(title)

        self.clear_grid()
        self.add_row(_('Name'), place.get_name().get_value())
        self.add_row(_('Type'), place.get_type())
        self.display_separator()
        self.display_alt_names(place)
        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)
Exemplo n.º 35
0
    def display_place(self, place):
        """
        Display details of the active place.
        """
        self.load_place_image(place)
        title = place_displayer.display(self.dbstate.db, place)
        self.title.set_markup("<span size='large' weight='bold'>%s</span>" %
                              markup_escape_text(title))

        self.clear_grid()
        self.add_row(_('Name'), place.get_name().get_value())
        self.add_row(_('Type'), place.get_type())
        self.display_separator()
        self.display_alt_names(place)
        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)
Exemplo n.º 36
0
    def display_place(self, place):
        """
        Display details of the active place.
        """
        self.load_place_image(place)
        title = place_displayer.display(self.dbstate.db, place)
        self.title.set_text(title)
        self.clear_table()

        #parser = FormatStringParser(self._place_keys)
        place_dict = self.generate_place_dictionary(place)
        parser = FormatStringParser(place_dict)

        addr1 = parser.parse(place_dict, self._address_format[0])
        addr2 = parser.parse(place_dict, self._address_format[1])
        city = parser.parse(place_dict, self._address_format[2])
        state = parser.parse(place_dict, self._address_format[3])
        country = parser.parse(place_dict, self._address_format[4])
        code = parser.parse(place_dict, self._address_format[5])

        self.add_row(_("Address 1"), addr1)
        self.add_row(_("Address 2"), addr2)
        self.add_row(_("City"), city)
        self.add_row(_("State"), state)
        self.add_row(_("Country"), country)
        self.add_row(_("Postal Code"), code)
        self.add_row(_("Version"), "0.1")

        #self.add_row(_('Name'), place.get_name())
        #self.add_row(_('Type'), place.get_type())
        #self.display_separator()
        #self.display_alt_names(place)
        #self.display_separator()
        lat, lon = conv_lat_lon(place.get_latitude(),
                                place.get_longitude(),
                                format='DEG')
Exemplo n.º 37
0
    def placelistpage(self, report, title, place_handles):
        """
        Create a place index

        @param: report        -- The instance of the main report class for
                                 this report
        @param: title         -- Is the title of the web page
        @param: place_handles -- The handle for the place to add
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("places")
        placelistpage, head, body = self.write_header(self._("Places"))
        ldatec = 0
        prev_letter = " "

        # begin places division
        with Html("div", class_="content", id="Places") as placelist:
            body += placelist

            # place list page message
            msg = self._("This page contains an index of all the places in the "
                         "database, sorted by their title. "
                         "Clicking on a place&#8217;s "
                         "title will take you to that place&#8217;s page.")
            placelist += Html("p", msg, id="description")

            # begin alphabet navigation
            index_list = get_first_letters(self.r_db, place_handles,
                                           _KEYPLACE, rlocale=self.rlocale)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav is not None:
                placelist += alpha_nav

            # begin places table and table head
            with Html("table",
                      class_="infolist primobjlist placelist") as table:
                placelist += table

                # begin table head
                thead = Html("thead")
                table += thead

                trow = Html("tr")
                thead += trow

                if self.display_coordinates:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass) in [
                            [self._("Letter"), "ColumnLetter"],
                            [self._("Place Name | Name"), "ColumnName"],
                            [self._("State/ Province"), "ColumnState"],
                            [self._("Country"), "ColumnCountry"],
                            [self._("Latitude"), "ColumnLatitude"],
                            [self._("Longitude"), "ColumnLongitude"]
                        ]
                    )
                else:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass) in [
                            [self._("Letter"), "ColumnLetter"],
                            [self._("Place Name | Name"), "ColumnName"],
                            [self._("State/ Province"), "ColumnState"],
                            [self._("Country"), "ColumnCountry"]
                        ]
                    )

                # bug 9495 : incomplete display of place hierarchy labels
                def sort_by_place_name(obj):
                    """ sort by lower case place name. """
                    name = self.report.obj_dict[Place][obj][1]
                    return name.lower()

                handle_list = sorted(place_handles,
                                     key=lambda x: sort_by_place_name(x))
                first = True

                # begin table body
                tbody = Html("tbody")
                table += tbody

                for place_handle in handle_list:
                    place = self.r_db.get_place_from_handle(place_handle)
                    if place:
                        if place.get_change_time() > ldatec:
                            ldatec = place.get_change_time()
                        plc_title = self.report.obj_dict[Place][place_handle][1]
                        main_location = get_main_location(self.r_db, place)

                        if plc_title and plc_title != " ":
                            letter = get_index_letter(first_letter(plc_title),
                                                      index_list,
                                                      self.rlocale)
                        else:
                            letter = '&nbsp;'

                        trow = Html("tr")
                        tbody += trow

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell
                        if first or primary_difference(letter, prev_letter,
                                                       self.rlocale):
                            first = False
                            prev_letter = letter
                            trow.attr = 'class = "BeginLetter"'

                            ttle = self._("Places beginning "
                                          "with letter %s") % letter
                            tcell += Html("a", letter, name=letter, title=ttle)
                        else:
                            tcell += "&nbsp;"

                        trow += Html("td",
                                     self.place_link(
                                         place.get_handle(),
                                         plc_title, place.get_gramps_id()),
                                     class_="ColumnName")

                        trow.extend(
                            Html("td", data or "&nbsp;", class_=colclass,
                                 inline=True)
                            for (colclass, data) in [
                                ["ColumnState",
                                 main_location.get(PlaceType.STATE, '')],
                                ["ColumnCountry",
                                 main_location.get(PlaceType.COUNTRY, '')]
                            ]
                        )

                        if self.display_coordinates:
                            tcell1 = Html("td", class_="ColumnLatitude",
                                          inline=True)
                            tcell2 = Html("td", class_="ColumnLongitude",
                                          inline=True)
                            trow += (tcell1, tcell2)

                            if place.lat and place.long:
                                latitude, longitude = conv_lat_lon(place.lat,
                                                                   place.long,
                                                                   "DEG")
                                tcell1 += latitude
                                tcell2 += longitude
                            else:
                                tcell1 += '&nbsp;'
                                tcell2 += '&nbsp;'

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        body += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placelistpage, output_file, sio, ldatec)
Exemplo n.º 38
0
    def placepage(self, report, title, place_handle):
        """
        Create a place page

        @param: report            -- The instance of the main report class for
                                     this report
        @param: title             -- Is the title of the web page
        @param: place_handle -- The handle for the place to add
        """
        place = report.database.get_place_from_handle(place_handle)
        if not place:
            return None
        BasePage.__init__(self, report, title, place.get_gramps_id())
        self.bibli = Bibliography()
        place_name = self.report.obj_dict[Place][place_handle][1]
        ldatec = place.get_change_time()

        output_file, sio = self.report.create_file(place_handle, "plc")
        self.uplink = True
        self.page_title = place_name
        placepage, head, body = self.write_header(_("Places"))

        self.placemappages = self.report.options['placemappages']
        self.mapservice = self.report.options['mapservice']
        self.googlemapkey = self.report.options['googlemapkey']

        # begin PlaceDetail Division
        with Html("div", class_="content", id="PlaceDetail") as placedetail:
            body += placedetail

            if self.create_media:
                media_list = place.get_media_list()
                thumbnail = self.disp_first_img_as_thumbnail(media_list,
                                                             place)
                if thumbnail is not None:
                    placedetail += thumbnail

            # add section title
            placedetail += Html("h3",
                                html_escape(place_name),
                                inline=True)

            # begin summaryarea division and places table
            with Html("div", id='summaryarea') as summaryarea:
                placedetail += summaryarea

                with Html("table", class_="infolist place") as table:
                    summaryarea += table

                    # list the place fields
                    self.dump_place(place, table)

            # place gallery
            if self.create_media:
                placegallery = self.disp_add_img_as_gallery(media_list, place)
                if placegallery is not None:
                    placedetail += placegallery

            # place notes
            notelist = self.display_note_list(place.get_note_list())
            if notelist is not None:
                placedetail += notelist

            # place urls
            urllinks = self.display_url_list(place.get_url_list())
            if urllinks is not None:
                placedetail += urllinks

            # add place map here
            # Link to Gramps marker
            fname = "/".join(['images', 'marker.png'])
            marker_path = self.report.build_url_image("marker.png",
                                                      "images", self.uplink)

            if self.placemappages:
                if place and (place.lat and place.long):
                    latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                       place.get_longitude(),
                                                       "D.D8")
                    placetitle = place_name

                    # add narrative-maps CSS...
                    fname = "/".join(["css", "narrative-maps.css"])
                    url = self.report.build_url_fname(fname, None, self.uplink)
                    head += Html("link", href=url, type="text/css",
                                 media="screen", rel="stylesheet")

                    # add MapService specific javascript code
                    src_js = GOOGLE_MAPS + "api/js?sensor=false"
                    if self.mapservice == "Google":
                        if self.googlemapkey:
                            src_js += "&key=" + self.googlemapkey
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)
                    else:
                        url = self.secure_mode
                        url += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/"
                                "css/bootstrap.min.css")
                        head += Html("link", href=url, type="text/javascript",
                                     rel="stylesheet")
                        src_js = self.secure_mode
                        src_js += ("ajax.googleapis.com/ajax/libs/jquery/1.9.1/"
                                   "jquery.min.js")
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)
                        src_js = self.secure_mode
                        src_js += "openlayers.org/en/v3.17.1/build/ol.js"
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)
                        url = self.secure_mode
                        url += "openlayers.org/en/v3.17.1/css/ol.css"
                        head += Html("link", href=url, type="text/javascript",
                                     rel="stylesheet")
                        src_js = self.secure_mode
                        src_js += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/"
                                   "js/bootstrap.min.js")
                        head += Html("script", type="text/javascript",
                                     src=src_js, inline=True)

                    # section title
                    placedetail += Html("h4", self._("Place Map"), inline=True)

                    # begin map_canvas division
                    with Html("div", id="map_canvas", inline=True) as canvas:
                        placedetail += canvas

                        # Begin inline javascript code because jsc is a
                        # docstring, it does NOT have to be properly indented
                        if self.mapservice == "Google":
                            with Html("script", type="text/javascript",
                                      indent=False) as jsc:
                                head += jsc

                                # Google adds Latitude/ Longitude to its maps...
                                plce = placetitle.replace("'", "\\'")
                                jsc += MARKER_PATH % marker_path
                                jsc += MARKERS % ([[plce,
                                                    latitude,
                                                    longitude,
                                                    1]],
                                                  latitude, longitude,
                                                  10)

                        else:
                            # OpenStreetMap (OSM) adds Longitude/ Latitude
                            # to its maps, and needs a country code in
                            # lowercase letters...
                            with Html("script", type="text/javascript") as jsc:
                                canvas += jsc
                                #param1 = xml_lang()[3:5].lower()
                                jsc += MARKER_PATH % marker_path
                                jsc += OSM_MARKERS % ([[float(longitude),
                                                        float(latitude),
                                                        placetitle]],
                                                      longitude, latitude, 10)

            # add javascript function call to body element
            body.attr += ' onload = "initialize();" '

            # add div for popups.
            with Html("div", id="popup", inline=True) as popup:
                placedetail += popup

            # source references
            srcrefs = self.display_ind_sources(place)
            if srcrefs is not None:
                placedetail += srcrefs

            # References list
            ref_list = self.display_bkref_list(Place, place_handle)
            if ref_list is not None:
                placedetail += ref_list

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        body += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placepage, output_file, sio, ldatec)
Exemplo n.º 39
0
 def _test_formats_fail(self, lat, lon):
     res1, res2 = conv_lat_lon(lat, lon)
     self.assertIsNone(res1, 'Expected failure for %s %s' % (lat, lon))
     self.assertIsNone(res2, 'Expected failure for %s %s' % (lat, lon))
Exemplo n.º 40
0
 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
     if self.nbplaces >= self._config.get("geography.max_places"):
         return
     descr1 = 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 = _pd.display(dbstate.db, place)
             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:
                             father = mother = None
                             hdle = family.get_father_handle()
                             if hdle:
                                 father = dbstate.db.get_person_from_handle(
                                                                        hdle)
                             hdle = family.get_mother_handle()
                             if hdle:
                                 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
                                             )
Exemplo n.º 41
0
    def _createmap(self, person, color, place_list, reference):
        """
        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 = place_list
        self.place_without_coordinates = []
        self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        latitude = ""
        longitude = ""
        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()
                try:
                    date = event.get_date_object().to_calendar(self.cal)
                except:
                    continue
                eyear = str("%04d" % date.get_year()) + \
                          str("%02d" % date.get_month()) + \
                          str("%02d" % date.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 = _pd.display(dbstate.db, place)
                        evt = 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()
            descr1 = " - "
            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)
                    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 = _pd.display(dbstate.db, place)
                                        evt = 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)

            sort1 = sorted(self.place_list, key=operator.itemgetter(6))
            self.draw(None, sort1, color, reference)
            # merge with the last results
            merge_list = []
            for the_list in self.sort, sort1 : merge_list += the_list
            self.sort = sorted(merge_list, key=operator.itemgetter(6))
Exemplo n.º 42
0
    def _createmap(self, place_x):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        """
        dbstate = self.dbstate
        self.place_list = []
        self.places_found = []
        self.place_without_coordinates = []
        self.minlat = 0.0
        self.maxlat = 0.0
        self.minlon = 0.0
        self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        self.without = 0
        latitude = ""
        longitude = ""
        self.nbmarkers = 0
        self.nbplaces = 0
        self.message_layer.clear_messages()
        self.message_layer.clear_font_attributes()
        self.no_show_places_in_status_bar = False
        # base "villes de france" : 38101 places :
        # createmap : 8'50"; create_markers : 1'23"
        # base "villes de france" : 38101 places :
        # createmap : 8'50"; create_markers : 0'07" with pixbuf optimization
        # base "villes de france" : 38101 places :
        # gramps 3.4 python 2.7 (draw_markers are estimated when moving the map)
        # 38101 places: createmap: 04'32";
        #               create_markers: 0'04"; draw markers: N/A :: 0'03"
        # 65598 places: createmap: 10'03";
        #               create_markers: 0'07"; draw markers: N/A :: 0'05"
        # gramps 3.5 python 2.7 new marker layer
        # 38101 places: createmap: 03'09";
        #               create_markers: 0'01"; draw markers: 0'04"
        # 65598 places: createmap: 08'48";
        #               create_markers: 0'01"; draw markers: 0'07"
        _LOG.debug("%s", time.strftime("start createmap : "
                   "%a %d %b %Y %H:%M:%S", time.gmtime()))
        if self.show_all:
            self.show_all = False
            try:
                places_handle = dbstate.db.get_place_handles()
            except:
                return
            progress = ProgressMeter(self.window_name, can_cancel=False,
                                     parent=self.uistate.window)
            length = len(places_handle)
            progress.set_pass(_('Selecting all places'), length)
            for place_hdl in places_handle:
                place = dbstate.db.get_place_from_handle(place_hdl)
                self._create_one_place(place)
                progress.step()
            progress.close()
        elif self.generic_filter:
            place_list = self.generic_filter.apply(dbstate.db)
            progress = ProgressMeter(self.window_name, can_cancel=False,
                                     parent=self.uistate.window)
            length = len(place_list)
            progress.set_pass(_('Selecting all places'), length)
            for place_handle in place_list:
                place = dbstate.db.get_place_from_handle(place_handle)
                self._create_one_place(place)
                progress.step()
            progress.close()
        elif place_x != None:
            place = dbstate.db.get_place_from_handle(place_x)
            self._create_one_place(place)
            self.message_layer.add_message(
                 _("Right click on the map and select 'show all places'"
                   " to show all known places with coordinates. "
                   "You can use filtering."))
            if place.get_latitude() != "" and place.get_longitude() != "":
                latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                   place.get_longitude(),
                                                   "D.D8")
                self.osm.set_center_and_zoom(float(latitude), float(longitude),
                                             int(config.get(
                                                 "geography.zoom_when_center")))
        else:
            self.message_layer.add_message(
                 _("Right click on the map and select 'show all places'"
                   " to show all known places with coordinates. "
                   " You can use the history to navigate on the map. "
                   "You can use filtering."))
        _LOG.debug(" stop createmap.")
        _LOG.debug("%s", time.strftime("begin sort : "
                   "%a %d %b %Y %H:%M:%S", time.gmtime()))
        self.sort = sorted(self.place_list,
                           key=operator.itemgetter(0)
                          )
        _LOG.debug("%s", time.strftime("  end sort : "
                   "%a %d %b %Y %H:%M:%S", time.gmtime()))
        if self.nbmarkers > 500: # performance issue. Is it the good value ?
            self.message_layer.add_message(
                 _("The place name in the status bar is disabled."))
            self.no_show_places_in_status_bar = True
        if self.nbplaces >= self._config.get("geography.max_places"):
            self.message_layer.set_font_attributes(None, None, "red")
            self.message_layer.add_message(
                 _("The maximum number of places is reached (%d).") %
                   self._config.get("geography.max_places"))
            self.message_layer.add_message(
                 _("Some information are missing."))
            self.message_layer.add_message(
                 _("Please, use filtering to reduce this number."))
            self.message_layer.add_message(
                 _("You can modify this value in the geography option."))
            self.message_layer.add_message(
                 _("In this case, it may take time to show all markers."))

        self._create_markers()
Exemplo n.º 43
0
    def placepage(self, report, title, place_handle):
        """
        Create a place page

        @param: report            -- The instance of the main report class for
                                     this report
        @param: title             -- Is the title of the web page
        @param: place_handle -- The handle for the place to add
        """
        place = report.database.get_place_from_handle(place_handle)
        if not place:
            return
        BasePage.__init__(self, report, title, place.get_gramps_id())
        self.bibli = Bibliography()
        place_name = self.report.obj_dict[Place][place_handle][1]
        ldatec = place.get_change_time()

        output_file, sio = self.report.create_file(place_handle, "plc")
        self.uplink = True
        self.page_title = place_name
        placepage, head, body, outerwrapper = self.write_header(_("Places"))

        self.placemappages = self.report.options['placemappages']
        self.mapservice = self.report.options['mapservice']
        self.googlemapkey = self.report.options['googlemapkey']

        # begin PlaceDetail Division
        with Html("div", class_="content", id="PlaceDetail") as placedetail:
            outerwrapper += placedetail

            if self.create_media:
                media_list = place.get_media_list()
                thumbnail = self.disp_first_img_as_thumbnail(media_list, place)
                if thumbnail is not None:
                    placedetail += thumbnail

            # add section title
            placedetail += Html("h3", html_escape(place_name), inline=True)

            # begin summaryarea division and places table
            with Html("div", id='summaryarea') as summaryarea:
                placedetail += summaryarea

                with Html("table", class_="infolist place") as table:
                    summaryarea += table

                    # list the place fields
                    self.dump_place(place, table)

            # place gallery
            if self.create_media:
                placegallery = self.disp_add_img_as_gallery(media_list, place)
                if placegallery is not None:
                    placedetail += placegallery

            # place notes
            notelist = self.display_note_list(place.get_note_list())
            if notelist is not None:
                placedetail += notelist

            # place urls
            urllinks = self.display_url_list(place.get_url_list())
            if urllinks is not None:
                placedetail += urllinks

            # add place map here
            # Link to Gramps marker
            fname = "/".join(['images', 'marker.png'])
            marker_path = self.report.build_url_image("marker.png", "images",
                                                      self.uplink)

            if self.placemappages:
                if place and (place.lat and place.long):
                    latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                       place.get_longitude(),
                                                       "D.D8")
                    placetitle = place_name

                    # add narrative-maps CSS...
                    fname = "/".join(["css", "narrative-maps.css"])
                    url = self.report.build_url_fname(fname, None, self.uplink)
                    head += Html("link",
                                 href=url,
                                 type="text/css",
                                 media="screen",
                                 rel="stylesheet")

                    # add MapService specific javascript code
                    src_js = GOOGLE_MAPS + "api/js?sensor=false"
                    if self.mapservice == "Google":
                        if self.googlemapkey:
                            src_js += "&key=" + self.googlemapkey
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)
                    else:
                        url = self.secure_mode
                        url += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/"
                                "css/bootstrap.min.css")
                        head += Html("link",
                                     href=url,
                                     type="text/javascript",
                                     rel="stylesheet")
                        src_js = self.secure_mode
                        src_js += (
                            "ajax.googleapis.com/ajax/libs/jquery/1.9.1/"
                            "jquery.min.js")
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)
                        src_js = self.secure_mode
                        src_js += "openlayers.org/en/latest/build/ol.js"
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)
                        url = self.secure_mode
                        url += "openlayers.org/en/latest/css/ol.css"
                        head += Html("link",
                                     href=url,
                                     type="text/javascript",
                                     rel="stylesheet")
                        src_js = self.secure_mode
                        src_js += ("maxcdn.bootstrapcdn.com/bootstrap/3.3.7/"
                                   "js/bootstrap.min.js")
                        head += Html("script",
                                     type="text/javascript",
                                     src=src_js,
                                     inline=True)

                    # section title
                    placedetail += Html("h4", self._("Place Map"), inline=True)

                    # begin map_canvas division
                    with Html("div", id="map_canvas", inline=True) as canvas:
                        placedetail += canvas

                        # Begin inline javascript code because jsc is a
                        # docstring, it does NOT have to be properly indented
                        if self.mapservice == "Google":
                            with Html("script",
                                      type="text/javascript",
                                      indent=False) as jsc:
                                head += jsc

                                # Google adds Latitude/ Longitude to its maps...
                                plce = placetitle.replace("'", "\\'")
                                jsc += MARKER_PATH % marker_path
                                jsc += MARKERS % ([[
                                    plce, latitude, longitude, 1
                                ]], latitude, longitude, 10)

                        else:
                            # OpenStreetMap (OSM) adds Longitude/ Latitude
                            # to its maps, and needs a country code in
                            # lowercase letters...
                            with Html("script", type="text/javascript") as jsc:
                                canvas += jsc
                                #param1 = xml_lang()[3:5].lower()
                                jsc += MARKER_PATH % marker_path
                                jsc += OSM_MARKERS % ([[
                                    float(longitude),
                                    float(latitude), placetitle
                                ]], longitude, latitude, 10)

            # add javascript function call to body element
            body.attr += ' onload = "initialize();" '

            # add div for popups.
            with Html("div", id="popup", inline=True) as popup:
                placedetail += popup

            # source references
            srcrefs = self.display_ind_sources(place)
            if srcrefs is not None:
                placedetail += srcrefs

            # References list
            ref_list = self.display_bkref_list(Place, place_handle)
            if ref_list is not None:
                placedetail += ref_list

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placepage, output_file, sio, ldatec)
Exemplo n.º 44
0
    def placelistpage(self, report, title, place_handles):
        """
        Create a place index

        @param: report        -- The instance of the main report class for
                                 this report
        @param: title         -- Is the title of the web page
        @param: place_handles -- The handle for the place to add
        """
        BasePage.__init__(self, report, title)

        output_file, sio = self.report.create_file("places")
        result = self.write_header(self._("Places"))
        placelistpage, dummy_head, dummy_body, outerwrapper = result
        ldatec = 0
        prev_letter = " "

        # begin places division
        with Html("div", class_="content", id="Places") as placelist:
            outerwrapper += placelist

            # place list page message
            msg = self._(
                "This page contains an index of all the places in the "
                "database, sorted by their title. "
                "Clicking on a place&#8217;s "
                "title will take you to that place&#8217;s page.")
            placelist += Html("p", msg, id="description")

            # begin alphabet navigation
            index_list = get_first_letters(self.r_db,
                                           place_handles,
                                           _KEYPLACE,
                                           rlocale=self.rlocale)
            alpha_nav = alphabet_navigation(index_list, self.rlocale)
            if alpha_nav is not None:
                placelist += alpha_nav

            # begin places table and table head
            with Html("table",
                      class_="infolist primobjlist placelist") as table:
                placelist += table

                # begin table head
                thead = Html("thead")
                table += thead

                trow = Html("tr")
                thead += trow

                if self.display_coordinates:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass
                             ) in [[self._("Letter"), "ColumnLetter"],
                                   [self._("Place Name | Name"), "ColumnName"],
                                   [self._("State/ Province"), "ColumnState"],
                                   [self._("Country"), "ColumnCountry"],
                                   [self._("Latitude"), "ColumnLatitude"],
                                   [self._("Longitude"), "ColumnLongitude"]])
                else:
                    trow.extend(
                        Html("th", label, class_=colclass, inline=True)
                        for (label, colclass
                             ) in [[self._("Letter"), "ColumnLetter"],
                                   [self._("Place Name | Name"), "ColumnName"],
                                   [self._("State/ Province"), "ColumnState"],
                                   [self._("Country"), "ColumnCountry"]])

                # bug 9495 : incomplete display of place hierarchy labels
                def sort_by_place_name(obj):
                    """ sort by lower case place name. """
                    name = self.report.obj_dict[Place][obj][1]
                    return name.lower()

                handle_list = sorted(place_handles,
                                     key=lambda x: sort_by_place_name(x))
                first = True

                # begin table body
                tbody = Html("tbody")
                table += tbody

                for place_handle in handle_list:
                    place = self.r_db.get_place_from_handle(place_handle)
                    if place:
                        if place.get_change_time() > ldatec:
                            ldatec = place.get_change_time()
                        plc_title = self.report.obj_dict[Place][place_handle][
                            1]
                        main_location = get_main_location(self.r_db, place)

                        if plc_title and plc_title != " ":
                            letter = get_index_letter(first_letter(plc_title),
                                                      index_list, self.rlocale)
                        else:
                            letter = '&nbsp;'

                        trow = Html("tr")
                        tbody += trow

                        tcell = Html("td", class_="ColumnLetter", inline=True)
                        trow += tcell
                        if first or primary_difference(letter, prev_letter,
                                                       self.rlocale):
                            first = False
                            prev_letter = letter
                            trow.attr = 'class = "BeginLetter"'

                            ttle = self._("Places beginning "
                                          "with letter %s") % letter
                            tcell += Html("a", letter, name=letter, title=ttle)
                        else:
                            tcell += "&nbsp;"

                        trow += Html("td",
                                     self.place_link(place.get_handle(),
                                                     plc_title,
                                                     place.get_gramps_id()),
                                     class_="ColumnName")

                        trow.extend(
                            Html("td",
                                 data or "&nbsp;",
                                 class_=colclass,
                                 inline=True) for (colclass, data) in
                            [[
                                "ColumnState",
                                main_location.get(PlaceType.STATE, '')
                            ],
                             [
                                 "ColumnCountry",
                                 main_location.get(PlaceType.COUNTRY, '')
                             ]])

                        if self.display_coordinates:
                            tcell1 = Html("td",
                                          class_="ColumnLatitude",
                                          inline=True)
                            tcell2 = Html("td",
                                          class_="ColumnLongitude",
                                          inline=True)
                            trow += (tcell1, tcell2)

                            if place.lat and place.long:
                                latitude, longitude = conv_lat_lon(
                                    place.lat, place.long, "DEG")
                                tcell1 += latitude
                                tcell2 += longitude
                            else:
                                tcell1 += '&nbsp;'
                                tcell2 += '&nbsp;'

        # add clearline for proper styling
        # add footer section
        footer = self.write_footer(ldatec)
        outerwrapper += (FULLCLEAR, footer)

        # send page out for processing
        # and close the file
        self.xhtml_writer(placelistpage, output_file, sio, ldatec)
Exemplo n.º 45
0
    def _createmap_for_one_person(self, person, color, place_list, reference):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        """
        self.place_list = []
        dbstate = self.dbstate
        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()
                try:
                    date = event.get_date_object().to_calendar(self.cal)
                except:
                    continue
                eyear = str("%04d" % date.get_year()) + \
                          str("%02d" % date.get_month()) + \
                          str("%02d" % date.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 = _pd.display(dbstate.db, place)
                        evt = 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()
            descr1 = " - "
            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)
                    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 = _pd.display(dbstate.db, place)
                                        evt = 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)

            sort1 = sorted(self.place_list, key=operator.itemgetter(6))
            self.draw(None, sort1, color, reference)
            # merge with the last results
            merge_list = []
            for the_list in self.sort, sort1 : merge_list += the_list
            self.sort = sorted(merge_list, key=operator.itemgetter(6))
Exemplo n.º 46
0
 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 = _pd.display(dbstate.db, place)
                     evt = 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 = _pd.display(dbstate.db, place)
                                     evt = 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)
Exemplo n.º 47
0
    def _createmap(self, active):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        @param: active is mandatory but unused in this view. Fix : 10088
        """
        dbstate = self.dbstate
        self.cal = config.get('preferences.calendar-format-report')
        self.place_list = []
        self.place_without_coordinates = []
        self.places_found = []
        self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        latitude = ""
        longitude = ""
        self.nbplaces = 0
        self.nbmarkers = 0
        self.message_layer.clear_messages()
        self.message_layer.set_font_attributes(None, None, None)
        self.kml_layer.clear()
        person_handle = self.uistate.get_active('Person')
        person = None
        if person_handle:
            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.
            self.load_kml_files(person)
            self.message_layer.add_message(
                _("Person places for %s") % _nd.display(person))
            for event_ref in person.get_event_ref_list():
                if not event_ref:
                    continue
                event = dbstate.db.get_event_from_handle(event_ref.ref)
                self.load_kml_files(event)
                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 = _pd.display(dbstate.db, place)
                        evt = EventType(event.get_type())
                        descr1 = _("%(eventtype)s : %(name)s") % {
                            'eventtype': evt,
                            'name': _nd.display(person)
                        }
                        self.load_kml_files(place)
                        # 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)
                    father = mother = None
                    handle = fam.get_father_handle()
                    if handle:
                        father = dbstate.db.get_person_from_handle(handle)
                    descr1 = " - "
                    if father:
                        descr1 = "%s - " % _nd.display(father)
                    handle = fam.get_mother_handle()
                    if 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)
                            self.load_kml_files(event)
                            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 = _pd.display(dbstate.db, place)
                                        evt = 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())
                                        self.load_kml_files(place)
                                        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()
Exemplo n.º 48
0
 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)
Exemplo n.º 49
0
    def _createmap(self, place_x):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        """
        dbstate = self.dbstate
        self.place_list = []
        self.places_found = []
        self.place_without_coordinates = []
        self.minlat = 0.0
        self.maxlat = 0.0
        self.minlon = 0.0
        self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        self.without = 0
        latitude = ""
        longitude = ""
        self.nbmarkers = 0
        self.nbplaces = 0
        self.remove_all_markers()
        self.message_layer.clear_messages()
        self.message_layer.clear_font_attributes()
        self.kml_layer.clear()
        self.no_show_places_in_status_bar = False
        _col = self._config.get
        self.plc_color = [
            (PlaceType.UNKNOWN, _col('geography.color.unknown')),
            (PlaceType.CUSTOM, _col('geography.color.custom')),
            (PlaceType.COUNTRY, _col('geography.color.country')),
            (PlaceType.STATE, _col('geography.color.state')),
            (PlaceType.COUNTY, _col('geography.color.county')),
            (PlaceType.CITY, _col('geography.color.city')),
            (PlaceType.PARISH, _col('geography.color.parish')),
            (PlaceType.LOCALITY, _col('geography.color.locality')),
            (PlaceType.STREET, _col('geography.color.street')),
            (PlaceType.PROVINCE, _col('geography.color.province')),
            (PlaceType.REGION, _col('geography.color.region')),
            (PlaceType.DEPARTMENT, _col('geography.color.department')),
            (PlaceType.NEIGHBORHOOD, _col('geography.color.neighborhood')),
            (PlaceType.DISTRICT, _col('geography.color.district')),
            (PlaceType.BOROUGH, _col('geography.color.borough')),
            (PlaceType.MUNICIPALITY, _col('geography.color.municipality')),
            (PlaceType.TOWN, _col('geography.color.town')),
            (PlaceType.VILLAGE, _col('geography.color.village')),
            (PlaceType.HAMLET, _col('geography.color.hamlet')),
            (PlaceType.FARM, _col('geography.color.farm')),
            (PlaceType.BUILDING, _col('geography.color.building')),
            (PlaceType.NUMBER, _col('geography.color.number'))
        ]
        # base "villes de france" : 38101 places :
        # createmap : 8'50"; create_markers : 1'23"
        # base "villes de france" : 38101 places :
        # createmap : 8'50"; create_markers : 0'07" with pixbuf optimization
        # base "villes de france" : 38101 places :
        # gramps 3.4 python 2.7 (draw_markers are estimated when moving the map)
        # 38101 places: createmap: 04'32";
        #               create_markers: 0'04"; draw markers: N/A :: 0'03"
        # 65598 places: createmap: 10'03";
        #               create_markers: 0'07"; draw markers: N/A :: 0'05"
        # gramps 3.5 python 2.7 new marker layer
        # 38101 places: createmap: 03'09";
        #               create_markers: 0'01"; draw markers: 0'04"
        # 65598 places: createmap: 08'48";
        #               create_markers: 0'01"; draw markers: 0'07"
        _LOG.debug(
            "%s",
            time.strftime("start createmap : "
                          "%a %d %b %Y %H:%M:%S", time.gmtime()))
        self.custom_places()
        if self.show_all:
            self.show_all = False
            try:
                places_handle = dbstate.db.get_place_handles()
            except:
                return
            progress = ProgressMeter(self.window_name,
                                     can_cancel=False,
                                     parent=self.uistate.window)
            length = len(places_handle)
            progress.set_pass(_('Selecting all places'), length)
            for place_hdl in places_handle:
                place = dbstate.db.get_place_from_handle(place_hdl)
                self._create_one_place(place)
                progress.step()
            progress.close()
        elif self.generic_filter:
            user = self.uistate.viewmanager.user
            place_list = self.generic_filter.apply(dbstate.db, user=user)
            progress = ProgressMeter(self.window_name,
                                     can_cancel=False,
                                     parent=self.uistate.window)
            length = len(place_list)
            progress.set_pass(_('Selecting all places'), length)
            for place_handle in place_list:
                place = dbstate.db.get_place_from_handle(place_handle)
                self._create_one_place(place)
                progress.step()
            progress.close()
            # reset completely the filter. It will be recreated next time.
            self.generic_filter = None
        elif place_x != None:
            place = dbstate.db.get_place_from_handle(place_x)
            self._create_one_place(place)
            self.message_layer.add_message(
                _("Right click on the map and select 'show all places'"
                  " to show all known places with coordinates. "
                  "You can change the markers color depending on place type. "
                  "You can use filtering."))
            if place.get_latitude() != "" and place.get_longitude() != "":
                latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                   place.get_longitude(),
                                                   "D.D8")
                if latitude and longitude:
                    self.osm.set_center_and_zoom(
                        float(latitude), float(longitude),
                        int(config.get("geography.zoom_when_center")))
        else:
            self.message_layer.add_message(
                _("Right click on the map and select 'show all places'"
                  " to show all known places with coordinates. "
                  "You can use the history to navigate on the map. "
                  "You can change the markers color depending on place type. "
                  "You can use filtering."))
        _LOG.debug(" stop createmap.")
        _LOG.debug(
            "%s",
            time.strftime("begin sort : "
                          "%a %d %b %Y %H:%M:%S", time.gmtime()))
        self.sort = sorted(self.place_list, key=operator.itemgetter(0))
        _LOG.debug(
            "%s",
            time.strftime("  end sort : "
                          "%a %d %b %Y %H:%M:%S", time.gmtime()))
        if self.nbmarkers > 500:  # performance issue. Is it the good value ?
            self.message_layer.add_message(
                _("The place name in the status bar is disabled."))
            self.no_show_places_in_status_bar = True
        if self.nbplaces >= self._config.get("geography.max_places"):
            self.message_layer.set_font_attributes(None, None, "red")
            self.message_layer.add_message(
                _("The maximum number of places is reached (%d).") %
                self._config.get("geography.max_places"))
            self.message_layer.add_message(_("Some information are missing."))
            self.message_layer.add_message(
                _("Please, use filtering to reduce this number."))
            self.message_layer.add_message(
                _("You can modify this value in the geography option."))
            self.message_layer.add_message(
                _("In this case, it may take time to show all markers."))

        self._create_markers()
Exemplo n.º 50
0
 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 = _pd.display(dbstate.db, place)
                     evt = 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 = _pd.display(dbstate.db, place)
                                     evt = 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)
Exemplo n.º 51
0
    def _createmap(self, active):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        @param: active is mandatory but unused in this view. Fix : 10088
        """
        dbstate = self.dbstate
        self.cal = config.get('preferences.calendar-format-report')
        self.place_list = []
        self.place_without_coordinates = []
        self.places_found = []
        self.minlat = self.maxlat = self.minlon = self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        latitude = ""
        longitude = ""
        self.nbplaces = 0
        self.nbmarkers = 0
        self.message_layer.clear_messages()
        self.kml_layer.clear()
        person_handle = self.uistate.get_active('Person')
        person = None
        if person_handle:
            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.
            self.load_kml_files(person)
            self.message_layer.add_message(
                                _("Person places for %s") % _nd.display(person))
            for event_ref in person.get_event_ref_list():
                if not event_ref:
                    continue
                event = dbstate.db.get_event_from_handle(event_ref.ref)
                self.load_kml_files(event)
                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 = _pd.display(dbstate.db, place)
                        evt = EventType(event.get_type())
                        descr1 = _("%(eventtype)s : %(name)s") % {
                                        'eventtype': evt,
                                        'name': _nd.display(person)}
                        self.load_kml_files(place)
                        # 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)
                    father = mother = None
                    handle = fam.get_father_handle()
                    if handle:
                        father = dbstate.db.get_person_from_handle(handle)
                    descr1 = " - "
                    if father:
                        descr1 = "%s - " % _nd.display(father)
                    handle = fam.get_mother_handle()
                    if 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)
                            self.load_kml_files(event)
                            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 = _pd.display(dbstate.db, place)
                                        evt = 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())
                                        self.load_kml_files(place)
                                        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()
Exemplo n.º 52
0
    def _createmap(self, place_x):
        """
        Create all markers for each people's event in the database which has
        a lat/lon.
        """
        dbstate = self.dbstate
        self.place_list = []
        self.places_found = []
        self.place_without_coordinates = []
        self.minlat = 0.0
        self.maxlat = 0.0
        self.minlon = 0.0
        self.maxlon = 0.0
        self.minyear = 9999
        self.maxyear = 0
        self.without = 0
        latitude = ""
        longitude = ""
        self.nbmarkers = 0
        self.nbplaces = 0
        self.remove_all_markers()
        self.message_layer.clear_messages()
        self.message_layer.clear_font_attributes()
        self.kml_layer.clear()
        self.no_show_places_in_status_bar = False
        _col = self._config.get
        self.plc_color  = [
            (PlaceType.UNKNOWN, _col('geography.color.unknown')),
            (PlaceType.CUSTOM, _col('geography.color.custom')),
            (PlaceType.COUNTRY, _col('geography.color.country')),
            (PlaceType.STATE, _col('geography.color.state')),
            (PlaceType.COUNTY, _col('geography.color.county')),
            (PlaceType.CITY, _col('geography.color.city')),
            (PlaceType.PARISH, _col('geography.color.parish')),
            (PlaceType.LOCALITY, _col('geography.color.locality')),
            (PlaceType.STREET, _col('geography.color.street')),
            (PlaceType.PROVINCE, _col('geography.color.province')),
            (PlaceType.REGION, _col('geography.color.region')),
            (PlaceType.DEPARTMENT, _col('geography.color.department')),
            (PlaceType.NEIGHBORHOOD, _col('geography.color.neighborhood')),
            (PlaceType.DISTRICT, _col('geography.color.district')),
            (PlaceType.BOROUGH, _col('geography.color.borough')),
            (PlaceType.MUNICIPALITY, _col('geography.color.municipality')),
            (PlaceType.TOWN, _col('geography.color.town')),
            (PlaceType.VILLAGE, _col('geography.color.village')),
            (PlaceType.HAMLET, _col('geography.color.hamlet')),
            (PlaceType.FARM, _col('geography.color.farm')),
            (PlaceType.BUILDING, _col('geography.color.building')),
            (PlaceType.NUMBER, _col('geography.color.number'))
            ]
        # base "villes de france" : 38101 places :
        # createmap : 8'50"; create_markers : 1'23"
        # base "villes de france" : 38101 places :
        # createmap : 8'50"; create_markers : 0'07" with pixbuf optimization
        # base "villes de france" : 38101 places :
        # gramps 3.4 python 2.7 (draw_markers are estimated when moving the map)
        # 38101 places: createmap: 04'32";
        #               create_markers: 0'04"; draw markers: N/A :: 0'03"
        # 65598 places: createmap: 10'03";
        #               create_markers: 0'07"; draw markers: N/A :: 0'05"
        # gramps 3.5 python 2.7 new marker layer
        # 38101 places: createmap: 03'09";
        #               create_markers: 0'01"; draw markers: 0'04"
        # 65598 places: createmap: 08'48";
        #               create_markers: 0'01"; draw markers: 0'07"
        _LOG.debug("%s", time.strftime("start createmap : "
                   "%a %d %b %Y %H:%M:%S", time.gmtime()))
        if self.show_all:
            self.show_all = False
            try:
                places_handle = dbstate.db.get_place_handles()
            except:
                return
            progress = ProgressMeter(self.window_name,
                                     can_cancel=False,
                                     parent=self.uistate.window)
            length = len(places_handle)
            progress.set_pass(_('Selecting all places'), length)
            for place_hdl in places_handle:
                place = dbstate.db.get_place_from_handle(place_hdl)
                self._create_one_place(place)
                progress.step()
            progress.close()
        elif self.generic_filter:
            user=self.uistate.viewmanager.user
            place_list = self.generic_filter.apply(dbstate.db, user=user)
            progress = ProgressMeter(self.window_name,
                                     can_cancel=False,
                                     parent=self.uistate.window)
            length = len(place_list)
            progress.set_pass(_('Selecting all places'), length)
            for place_handle in place_list:
                place = dbstate.db.get_place_from_handle(place_handle)
                self._create_one_place(place)
                progress.step()
            progress.close()
            # reset completely the filter. It will be recreated next time.
            self.generic_filter = None
        elif place_x != None:
            place = dbstate.db.get_place_from_handle(place_x)
            self._create_one_place(place)
            self.message_layer.add_message(
                 _("Right click on the map and select 'show all places'"
                   " to show all known places with coordinates. "
                   "You can change the markers color depending on place type. "
                   "You can use filtering."))
            if place.get_latitude() != "" and place.get_longitude() != "":
                latitude, longitude = conv_lat_lon(place.get_latitude(),
                                                   place.get_longitude(),
                                                   "D.D8")
                self.osm.set_center_and_zoom(float(latitude), float(longitude),
                                             int(config.get(
                                                 "geography.zoom_when_center")))
        else:
            self.message_layer.add_message(
                 _("Right click on the map and select 'show all places'"
                   " to show all known places with coordinates. "
                   "You can use the history to navigate on the map. "
                   "You can change the markers color depending on place type. "
                   "You can use filtering."))
        _LOG.debug(" stop createmap.")
        _LOG.debug("%s", time.strftime("begin sort : "
                   "%a %d %b %Y %H:%M:%S", time.gmtime()))
        self.sort = sorted(self.place_list,
                           key=operator.itemgetter(0)
                          )
        _LOG.debug("%s", time.strftime("  end sort : "
                   "%a %d %b %Y %H:%M:%S", time.gmtime()))
        if self.nbmarkers > 500: # performance issue. Is it the good value ?
            self.message_layer.add_message(
                 _("The place name in the status bar is disabled."))
            self.no_show_places_in_status_bar = True
        if self.nbplaces >= self._config.get("geography.max_places"):
            self.message_layer.set_font_attributes(None, None, "red")
            self.message_layer.add_message(
                 _("The maximum number of places is reached (%d).") %
                   self._config.get("geography.max_places"))
            self.message_layer.add_message(
                 _("Some information are missing."))
            self.message_layer.add_message(
                 _("Please, use filtering to reduce this number."))
            self.message_layer.add_message(
                 _("You can modify this value in the geography option."))
            self.message_layer.add_message(
                 _("In this case, it may take time to show all markers."))

        self._create_markers()