Beispiel #1
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 ?')
Beispiel #2
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 ?')
Beispiel #3
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 ''
Beispiel #4
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 ''
Beispiel #5
0
def lido2mapsme(action_in,
                params,
                use_segments=False,
                kmlargs=None,
                debug=False,
                fishfile=None):
    """
    Lido2Mapsme KML rendering action
    :param fishfile: absolute path to a fishfile or None
    :param action_in: unicode action input
    :param params: dict action's parameters
    :param use_segments: plot route as LineString segments instead of
                         a single LineString (Avenza fix)
    :param kmlargs: optional dictionnary for KML Generator
    :param debug: bool determines wether or not to print ogimet debug messages
    :return:
    """
    from editolido.constants import NAT_POSITION_ENTRY, PIN_NONE
    from editolido.fishpoint import find_fishfile
    from editolido.geopoint import GeoPoint
    from editolido.kml import KMLGenerator
    from editolido.ofp import OFP
    from editolido.route import Route

    ofp = OFP(action_in)
    if kmlargs:
        kml = KMLGenerator(**kmlargs)
    else:
        kml = KMLGenerator()
    pin_rnat = params.get('Repère NAT', PIN_NONE)
    pin_rmain = params.get('Point Route', PIN_NONE)
    pin_ralt = params.get('Point Dégagement', PIN_NONE)
    kml.add_folders('greatcircle', ('rnat', pin_rnat),
                    ('rnat_incomplete', pin_rnat), ('ralt', pin_ralt),
                    ('rmain', pin_rmain))
    route_name = "{departure}-{destination}".format(**ofp.infos)
    route = ofp.route
    route.name = route_name
    route.description = ofp.description

    # set route/line plot method
    add_kml_route = kml.add_segments if use_segments else kml.add_line

    natmarks = []
    if params.get('Afficher NAT', False):
        pin_pos = 0 if params['Position repère'] == NAT_POSITION_ENTRY else -1
        fishfile = fishfile if fishfile else find_fishfile()
        if debug:
            print("using fish points file %s\n" % fishfile)
        for track in ofp.tracks(fishfile=fishfile):
            if track:
                folder = 'rnat_incomplete' if not track.is_complete else 'rnat'
                add_kml_route(folder, track)
                if pin_rnat != PIN_NONE:
                    if track.is_mine:
                        p = GeoPoint(track[0],
                                     name=track.name,
                                     description=track.description)
                        natmarks.append(p)
                        kml.add_point(folder, p, style=pin_rnat)
                        p = GeoPoint(track[-1],
                                     name=track.name,
                                     description=track.description)
                        natmarks.append(p)
                        kml.add_point(folder, p, style=pin_rnat)
                    else:
                        p = GeoPoint(track[pin_pos],
                                     name=track.name,
                                     description=track.description)
                        natmarks.append(p)
                        kml.add_point(folder, p, style=pin_rnat)
            else:
                print("empty track found %s" % track.name)

    if params.get('Afficher Ortho', False):
        greatcircle = Route(
            (route[0], route[-1])).split(300, name="Ortho %s" % route_name)
        add_kml_route('greatcircle', greatcircle)

    add_kml_route('rmain', route)
    if pin_rmain != PIN_NONE:
        kml.add_points('rmain', route, excluded=natmarks, style=pin_rmain)

    if params.get('Afficher Dégagement', False):
        alt_route = Route(ofp.wpt_coordinates_alternate(),
                          name="Route Dégagement")
        add_kml_route('ralt', alt_route)
        if pin_ralt != PIN_NONE:
            kml.add_points('ralt', alt_route[1:], style=pin_ralt)

    kml = kml.render(
        name=ofp.description,
        rnat_color=params.get('Couleur NAT', '') or '60DA25A8',
        ogimet_color=params.get('Couleur Ogimet', '') or '40FF0000',
        greatcircle_color=params.get('Couleur Ortho', '') or '5F1478FF',
        rmain_color=params.get('Couleur Route', '') or 'FFDA25A8',
        ralt_color=params.get('Couleur Dégagement', '') or 'FFFF00FF',
        rnat_incomplete_color=params.get('Couleur NAT incomplet', '')
        or 'FF0000FF',
    )
    try:
        # noinspection PyUnresolvedReferences
        import clipboard  # EDITORIAL Module
        json_results = {
            'type': '__editolido__.extended_clipboard',
            'lido_route': ' '.join(ofp.lido_route),
            'kml': kml,
        }
        clipboard.set(json.dumps(json_results))
    except ImportError:
        pass
    return kml
Beispiel #6
0
def lido2mapsme(action_in, params, debug=False):
    """
    Lido2Mapsme KML rendering action
    :param action_in: unicode action input
    :param params: dict action's parameters
    :param debug: bool determines wether or not to print ogimet debug messages
    :return:
    """
    from editolido.constants import NAT_POSITION_ENTRY, PIN_NONE
    from editolido.geopoint import GeoPoint
    from editolido.kml import KMLGenerator
    from editolido.ofp import OFP
    from editolido.route import Route
    from editolido.ogimet import ogimet_route
    ofp = OFP(action_in)
    kml = KMLGenerator()
    pin_rnat = params.get('Repère NAT', PIN_NONE)
    pin_rmain = params.get('Point Route', PIN_NONE)
    pin_ralt = params.get('Point Dégagement', PIN_NONE)
    kml.add_folders(
        'greatcircle', 'ogimet',
        ('rnat', pin_rnat),
        ('ralt', pin_ralt),
        ('rmain', pin_rmain))
    route_name = "{departure}-{destination}".format(**ofp.infos)
    route = ofp.route
    route.name = route_name
    route.description = ofp.description

    natmarks = []
    if params.get('Afficher NAT', False):
        pin_pos = 0 if params['Position repère'] == NAT_POSITION_ENTRY else -1
        for track in ofp.tracks:
            if track:
                kml.add_line('rnat', track)
                if pin_rnat != PIN_NONE:
                    if track.is_mine:
                        p = GeoPoint(track[0], name=track.name,
                                     description=track.description)
                        natmarks.append(p)
                        kml.add_point('rnat', p, style=pin_rnat)
                        p = GeoPoint(track[-1], name=track.name,
                                     description=track.description)
                        natmarks.append(p)
                        kml.add_point('rnat', p, style=pin_rnat)
                    else:
                        p = GeoPoint(track[pin_pos], name=track.name,
                                     description=track.description)
                        natmarks.append(p)
                        kml.add_point('rnat', p, style=pin_rnat)
            else:
                print("empty track found %s" % track.name)

    if params.get('Afficher Ortho', False):
        greatcircle = Route((route[0], route[-1])).split(
            300, name="Ortho %s" % route_name)
        kml.add_line('greatcircle', greatcircle)

    kml.add_line('rmain', route)
    if pin_rmain != PIN_NONE:
        kml.add_points('rmain', route,
                       excluded=natmarks, style=pin_rmain)

    if params.get('Afficher Dégagement', False):
        alt_route = Route(ofp.wpt_coordinates_alternate,
                          name="Route Dégagement")
        kml.add_line('ralt', alt_route)
        if pin_ralt != PIN_NONE:
            kml.add_points(
                'ralt', alt_route[1:],
                style=pin_ralt)

    if params.get('Afficher Ogimet', False):  # 1.0.x compatible
        kml.add_line('ogimet',
                     ogimet_route(route, debug=debug, name="Ogimet Route"))

    return kml.render(
        name=ofp.description,
        rnat_color=params.get('Couleur NAT', '') or '60DA25A8',
        ogimet_color=params.get('Couleur Ogimet', '')  or '40FF0000',
        greatcircle_color=params.get('Couleur Ortho', '')  or '5F1478FF',
        rmain_color=params.get('Couleur Route', '')  or 'FFDA25A8',
        ralt_color=params.get('Couleur Dégagement', '') or 'FFFF00FF'
    )