def test_add_folder(self):
     kml = KMLGenerator()
     self.assertFalse(kml.folders)
     kml.add_folder('first')
     self.assertFalse(kml.folders['first'], [])
     kml.add_folder('second')
     self.assertEqual(kml.folders.keys(), ['first', 'second'])
Exemple #2
0
 def test_add_folder(self):
     kml = KMLGenerator()
     self.assertFalse(kml.folders)
     kml.add_folder('first')
     self.assertFalse(kml.folders['first'], [])
     kml.add_folder('second')
     self.assertEqual(list(kml.folders.keys()), ['first', 'second'])
def test_add_sigmets(sigmets_json):
    kml = KMLGenerator()
    kml.add_folder('sigmets', pin=PIN_ORANGE)
    add_sigmets(kml, 'sigmets', sigmets_json)
    out = kml.render_folder('sigmets')
    assert out
    assert '#placemark-orange' in out
    assert '#sigmets' in out
def test_add_sigmets(sigmets_json):
    kml = KMLGenerator()
    kml.add_folder('sigmets', pin=PIN_ORANGE)
    add_sigmets(kml, 'sigmets', sigmets_json)
    out = kml.render_folder('sigmets')
    assert out
    assert '#placemark-orange' in out
    assert '#sigmets' in out
 def test_add_points(self):
     kml = KMLGenerator(point_template="{name}{color}")
     kml.add_folder('aFolder')
     from editolido.route import Route
     from editolido.geopoint import GeoPoint
     route = Route([GeoPoint((0, 0)), GeoPoint((0, 90))], name="route")
     kml.add_points('aFolder', route, color="blouge")
     self.assertEqual(''.join(kml.folders['aFolder']), 'blouge' * 2)
Exemple #6
0
 def test_add_line(self):
     kml = KMLGenerator(line_template="{name} {color}")
     kml.add_folder('aFolder')
     from editolido.route import Route
     from editolido.geopoint import GeoPoint
     route = Route([GeoPoint((0, 0)), GeoPoint((0, 90))], name="route")
     kml.add_line('aFolder', route, color="blouge")
     self.assertEqual(kml.folders['aFolder'][0], 'route blouge')
 def test_add_line(self):
     kml = KMLGenerator(line_template="{name} {color}")
     kml.add_folder('aFolder')
     from editolido.route import Route
     from editolido.geopoint import GeoPoint
     route = Route([GeoPoint((0, 0)), GeoPoint((0, 90))], name="route")
     kml.add_line('aFolder', route, color="blouge")
     self.assertEqual(kml.folders['aFolder'][0], 'route blouge')
 def test_render_folder(self):
     kml = KMLGenerator(folder_template="{name} {open} {content}",
                        point_template="{name} {color} {style}")
     kml.add_folder('aFolder')
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style='#mystyle')
     self.assertEqual(kml.render_folder('aFolder'),
                      'aFolder 1 P1 blouge #mystyle')
Exemple #9
0
 def test_add_point_no_pin_set_in_folder(self):
     kml = KMLGenerator(point_template="{name} {color}")
     kml.add_folder('aFolder')
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"))
     self.assertFalse(kml.folders['aFolder'])
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style='#style')
     self.assertEqual(kml.folders['aFolder'][0], 'P1 blouge')
Exemple #10
0
 def test_add_points(self):
     kml = KMLGenerator(point_template="{name}{color}")
     kml.add_folder('aFolder')
     from editolido.route import Route
     from editolido.geopoint import GeoPoint
     route = Route([GeoPoint((0, 0)), GeoPoint((0, 90))], name="route")
     kml.add_points('aFolder', route, color="blouge")
     self.assertEqual(''.join(kml.folders['aFolder']),
                      'N0000.0W00000.0blougeN0000.0E09000.0blouge')
 def test_add_point_no_pin_set_in_folder(self):
     kml = KMLGenerator(point_template="{name} {color}")
     kml.add_folder('aFolder')
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"))
     self.assertFalse(kml.folders['aFolder'])
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style='#style')
     self.assertEqual(kml.folders['aFolder'][0], 'P1 blouge')
Exemple #12
0
 def test_render_folder(self):
     kml = KMLGenerator(folder_template="{name} {open} {content}",
                        point_template="{name} {color} {style}")
     kml.add_folder('aFolder')
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style='#mystyle')
     self.assertEqual(kml.render_folder('aFolder'),
                      'aFolder 1 P1 blouge #mystyle')
 def test_add_point_pin_set_in_folder(self):
     kml = KMLGenerator(point_template="{name} {color} {style}")
     kml.add_folder('aFolder', pin=PIN_ORANGE)
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"), color="blouge")
     self.assertEqual(kml.folders['aFolder'][0],
                      'P1 blouge #placemark-orange')
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style=PIN_RED)
     self.assertEqual(kml.folders['aFolder'][1],
                      'P1 blouge #placemark-red')
Exemple #14
0
 def test_add_point_pin_set_in_folder(self):
     kml = KMLGenerator(point_template="{name} {color} {style}")
     kml.add_folder('aFolder', pin=PIN_ORANGE)
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"), color="blouge")
     self.assertEqual(kml.folders['aFolder'][0],
                      'P1 blouge #placemark-orange')
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style=PIN_RED)
     self.assertEqual(kml.folders['aFolder'][1],
                      'P1 blouge #placemark-red')
Exemple #15
0
 def test_add_segments(self):
     kml = KMLGenerator(point_template="{name}{color}")
     kml.add_folder('aFolder')
     from editolido.route import Route
     from editolido.geopoint import GeoPoint
     route = Route([GeoPoint((0, 0), name='p1'),
                    GeoPoint((45, 90), name='p2'),
                    GeoPoint((0, 90), name='p3')], name="route")
     kml.add_points('aFolder', route, color="blouge")
     self.assertEqual(''.join(kml.folders['aFolder']),
                      'p1blougep2blougep3blouge')
 def test_render(self):
     kml = KMLGenerator(folder_template="{name} {open} {content}",
                        point_template="{name} {color} {style}",
                        template="{folders} {name} {extra}")
     kml.add_folder('aFolder')
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style="#mystyle")
     self.assertEqual(kml.render(extra="what else ?",
                                 name='no name',
                                 aFolder_color="white"),
                      'aFolder 1 P1 blouge #mystyle no name what else ?')
Exemple #17
0
 def test_render(self):
     kml = KMLGenerator(folder_template="{name} {open} {content}",
                        point_template="{name} {color} {style}",
                        template="{folders} {name} {extra}")
     kml.add_folder('aFolder')
     from editolido.geopoint import GeoPoint
     kml.add_point('aFolder', GeoPoint((0, 0), name="P1"),
                   color="blouge", style="#mystyle")
     self.assertEqual(kml.render(extra="what else ?",
                                 name='no name',
                                 aFolder_color="white"),
                      'aFolder 1 P1 blouge #mystyle no name what else ?')
Exemple #18
0
    def test_kml_segments_ofp6752_05Feb2017(self):
        """
        Ensure all waypoints and in the good order
        """
        from editolido.ofp import OFP
        with open(DATADIR + '/AF6752_FMEE-FMMI_05Feb2017_11:50z_OFP_5_0_1.txt',
                  'r') as f:
            ofp = OFP(f.read())

        kml = KMLGenerator()
        kml.add_folder('rmain')
        kml.add_segments('rmain', ofp.route)
        self.assertEqual(6, len(kml.folders['rmain']))
Exemple #19
0
    def test_kml_ofp374_22Jul2016(self):
        """
        Ensure all waypoints and in the good order
        """
        from editolido.ofp import OFP
        with open(DATADIR + '/AF374_LFPG-CYVR_22Jul2016_08:45z_OFP_8_0_1.txt',
                  'r') as f:
            ofp = OFP(f.read())

        kml = KMLGenerator(point_template="{coordinates}")
        kml.add_folder('rmain')
        kml.add_points('rmain', ofp.route)
        coords = ["{1:.6f},{0:.6f}".format(p.latitude, p.longitude)
                  for p in ofp.route]
        self.assertEqual(coords, kml.folders['rmain'])
 def test_as_kml_line(self):
     kml = KMLGenerator(
         line_template='{name}/{style}/{description}/{coordinates}',)
     from editolido.geopoint import GeoPoint
     from editolido.route import Route
     start = GeoPoint((0, 0))
     end = GeoPoint((0, 90))
     route = Route(
         [start, end], name="route_name", description="route_description")
     kml.add_folder('aFolder')
     kml.add_line('aFolder', route, style='route_style')
     self.assertEqual(
         ''.join(kml.folders['aFolder']),
         'route_name/route_style/route_description/'
         '0.000000,0.000000 90.000000,0.000000'
     )
Exemple #21
0
 def test_as_kml_line(self):
     kml = KMLGenerator(
         line_template='{name}/{style}/{description}/{coordinates}',)
     from editolido.geopoint import GeoPoint
     from editolido.route import Route
     start = GeoPoint((0, 0))
     end = GeoPoint((0, 90))
     route = Route(
         [start, end], name="route_name", description="route_description")
     kml.add_folder('aFolder')
     kml.add_line('aFolder', route, style='route_style')
     self.assertEqual(
         ''.join(kml.folders['aFolder']),
         'route_name/route_style/route_description/'
         '0.000000,0.000000 90.000000,0.000000'
     )
Exemple #22
0
 def test_as_kml_points(self):
     kml = KMLGenerator(
         point_template='{name}/{style}/{description}/{coordinates}',)
     from editolido.geopoint import GeoPoint
     from editolido.route import Route
     start = GeoPoint((0, 0), name="P1")
     end = GeoPoint((0, 90), name="P2", description="D2")
     route = Route(
         [start, end], name="route_name", description="route_description")
     kml.add_folder('aFolder')
     kml.add_points('aFolder', route, style='point_style')
     self.assertEqual(
         '\n'.join(kml.folders['aFolder']),
         'P1/point_style//0.000000,0.000000\n'
         'P2/point_style/D2/90.000000,0.000000'
     )
 def test_as_kml_points(self):
     kml = KMLGenerator(
         point_template='{name}/{style}/{description}/{coordinates}',)
     from editolido.geopoint import GeoPoint
     from editolido.route import Route
     start = GeoPoint((0, 0), name="P1")
     end = GeoPoint((0, 90), name="P2", description="D2")
     route = Route(
         [start, end], name="route_name", description="route_description")
     kml.add_folder('aFolder')
     kml.add_points('aFolder', route, style='point_style')
     self.assertEqual(
         '\n'.join(kml.folders['aFolder']),
         'P1/point_style//0.000000,0.000000\n'
         'P2/point_style/D2/90.000000,0.000000'
     )
Exemple #24
0
def lido2gramet(action_in, params=None, debug=False):
    """
     Puts the Ogimet/Gramet route in the clipboard
     Output kml route if params['Afficher Ogimet'] is True
    :param action_in: the OFP text
    :param params: workflow action parameters
    :param debug: bool switch to output debug info
    :return: unicode kml or None

    Usage from Editorial is:

    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals
    import workflow
    from editolido.workflows.lido2gramet import lido2gramet


    params = workflow.get_parameters()
    action_in = workflow.get_input()
    workflow.set_output(lido2gramet(action_in, params=params))
    """
    import datetime
    from editolido.ofp import OFP, utc
    from editolido.kml import KMLGenerator
    from editolido.ogimet import \
        ogimet_url_and_route_and_tref,\
        get_gramet_image_url
    from editolido.constants import PIN_ORANGE
    params = params or {}
    ofp = OFP(action_in)
    kml = KMLGenerator()
    taxitime = (ofp.infos['taxitime'] or
                int(params.get('Temps de roulage', '') or '15'))
    ogimet_url, route, tref = ogimet_url_and_route_and_tref(
        ofp, taxitime=taxitime, debug=debug)
    url, ogimet_serverid = get_gramet_image_url(ogimet_url)
    url = url or ogimet_url
    # noinspection PyUnresolvedReferences
    import clipboard  # EDITORIAL module
    clipboard.set(url)

    if debug:
        print(url)

    switch_sigmets = params.get('Afficher SIGMETs', True)
    switch_ogimet = params.get('Afficher Ogimet', True)

    switch_kml = params.get('Générer KML', None)  # 1.0.x compatibility
    if switch_kml is not None:
        switch_ogimet = switch_sigmets = switch_kml

    if switch_ogimet:
        kml.add_folder('ogimet')
        kml.add_line('ogimet', route)

    if switch_sigmets:
        pin_sigmets = params.get('Label SIGMET', PIN_ORANGE)
        kml.add_folder('SIGMETs', pin=pin_sigmets)
        try:
            jsondata = get_sigmets_json() or {}
        except requests.exceptions.RequestException:
            pass
        else:
            try:
                add_sigmets(kml, 'SIGMETs', jsondata)
            except ValueError:
                pass

    name = ("Route Gramet/SIGMETs {flight} {departure}-{destination} "
            "{tref_dt:%d%b%Y %H:%M}z OFP {ofp}".format(
                tref_dt=datetime.datetime.fromtimestamp(tref, tz=utc),
                **ofp.infos))
    if switch_ogimet or switch_sigmets:
        kml = kml.render(
            name=name,
            ogimet_color=params.get('Couleur Ogimet', '') or '40FF0000',
            SIGMETs_color=params.get('Couleur SIGMET', '') or '50143CFA')
        try:
            # noinspection PyUnresolvedReferences
            import clipboard  # EDITORIAL Module
            json_results = {
                'type': '__editolido__.extended_clipboard',
                'gramet_url': url,
                'ogimet_url': ogimet_url,
                'ogimet_serverid': ogimet_serverid,
                'kml': kml,
            }
            clipboard.set(json.dumps(json_results))
        except ImportError:
            pass
        return kml
    try:
        # noinspection PyUnresolvedReferences
        import clipboard  # EDITORIAL Module
        json_results = {
            'type': '__editolido__.extended_clipboard',
            'gramet_url': url,
            'ogimet_url': ogimet_url,
            'ogimet_serverid': ogimet_serverid,
            'kml': '',
        }
        clipboard.set(json.dumps(json_results))
    except ImportError:
        pass
    return ''
Exemple #25
0
def lido2gramet(action_in, params=None):
    """
     Puts the Ogimet/Gramet route in the clipboard
     Output kml route if params['Afficher Ogimet'] is True
    :param action_in: the OFP text
    :param params: workflow action parameters
    :return: unicode kml or None

    Usage from Editorial is:

    # -*- coding: utf-8 -*-
    from __future__ import unicode_literals
    import workflow
    from editolido.workflows.lido2gramet import lido2gramet


    params = workflow.get_parameters()
    action_in = workflow.get_input()
    workflow.set_output(lido2gramet(action_in, params=params))
    """
    import datetime
    from editolido.ofp import OFP
    from editolido.ofp_infos import utc
    from editolido.kml import KMLGenerator
    from editolido.ogimet import \
        ogimet_url_and_route_and_tref,\
        get_gramet_image_url
    from editolido.constants import PIN_ORANGE
    params = params or {}
    ofp = OFP(action_in)
    kml = KMLGenerator()
    taxitime = (ofp.infos['taxitime'] or
                int(params.get('Temps de roulage', '') or '15'))
    ogimet_url, route, tref = ogimet_url_and_route_and_tref(ofp,
                                                            taxitime=taxitime)
    url, ogimet_serverid = get_gramet_image_url(ogimet_url)
    url = url or ogimet_url
    # noinspection PyUnresolvedReferences,PyPackageRequirements
    import clipboard  # EDITORIAL module
    clipboard.set(url)

    switch_sigmets = params.get('Afficher SIGMETs', True)
    switch_ogimet = params.get('Afficher Ogimet', True)

    switch_kml = params.get('Générer KML', None)  # 1.0.x compatibility
    if switch_kml is not None:
        switch_ogimet = switch_sigmets = switch_kml

    if switch_ogimet:
        kml.add_folder('ogimet')
        kml.add_line('ogimet', route)

    if switch_sigmets:
        pin_sigmets = params.get('Label SIGMET', PIN_ORANGE)
        kml.add_folder('SIGMETs', pin=pin_sigmets)
        try:
            jsondata = get_sigmets_json() or {}
        except requests.exceptions.RequestException:
            pass
        else:
            try:
                add_sigmets(kml, 'SIGMETs', jsondata)
            except ValueError:
                pass

    name = ("Route Gramet/SIGMETs {flight} {departure}-{destination} "
            "{tref_dt:%d%b%Y %H:%M}z OFP {ofp}".format(
                tref_dt=datetime.datetime.fromtimestamp(tref, tz=utc),
                **ofp.infos))
    if switch_ogimet or switch_sigmets:
        kml = kml.render(
            name=name,
            ogimet_color=params.get('Couleur Ogimet', '') or '40FF0000',
            SIGMETs_color=params.get('Couleur SIGMET', '') or '50143CFA')
        try:
            # noinspection PyUnresolvedReferences,PyPackageRequirements
            import clipboard  # EDITORIAL Module
            json_results = {
                'type': '__editolido__.extended_clipboard',
                'gramet_url': url,
                'ogimet_url': ogimet_url,
                'ogimet_serverid': ogimet_serverid,
                'kml': kml,
            }
            clipboard.set(json.dumps(json_results))
        except ImportError:
            pass
        return kml
    try:
        # noinspection PyUnresolvedReferences,PyPackageRequirements
        import clipboard  # EDITORIAL Module
        json_results = {
            'type': '__editolido__.extended_clipboard',
            'gramet_url': url,
            'ogimet_url': ogimet_url,
            'ogimet_serverid': ogimet_serverid,
            'kml': '',
        }
        clipboard.set(json.dumps(json_results))
    except ImportError:
        pass
    return ''