Ejemplo n.º 1
0
    def __init__(self, lat, lng, size, precision, **kwargs):
        '''
        Args:
            lat (float): Latitude of the center of the 'x'.
            lng (float): Longitude of the center of the 'x'.
            size (int): Size of the 'x', in meters.
            precision (int): Number of digits after the decimal to round to for lat/lng values.

        Optional:

        Args:
            color (str): Color of the 'x'. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
            alpha (float): Opacity of the 'x', ranging from 0 to 1.
            width (int): Width of the 'x''s edge, in pixels.
        '''
        # TODO: The following generates a 'x' in Cartesian frame rather than in lat/lng; avoid this.
        delta_lat = (size / 1000.0 / _EARTH_RADIUS_IN_KM /
                     math.sqrt(2)) * (180.0 / math.pi)
        delta_lng = delta_lat / math.cos(math.pi * lat / 180.0)

        self._down_right_stroke = _Polyline([lat - delta_lat, lat + delta_lat],
                                            [lng + delta_lng, lng - delta_lng],
                                            precision, **kwargs)
        self._up_right_stroke = _Polyline([lat - delta_lat, lat + delta_lat],
                                          [lng - delta_lng, lng + delta_lng],
                                          precision, **kwargs)
Ejemplo n.º 2
0
    def __init__(self, lat, lng, size, **kwargs):
        '''
        Args:
            lat (float): Latitude of the center of the '+'.
            lng (float): Longitude of the center of the '+'.
            size (int): Size of the '+', in meters.

        Optional:

        Args:
            color/c/edge_color/ec (str): Color of the '+''s edge.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/edge_alpha/ea (float): Opacity of the '+''s edge, ranging from 0 to 1. Defaults to 1.0.
            edge_width/ew (int): Width of the '+''s edge, in pixels. Defaults to 1.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.
        '''
        kwargs.setdefault('edge_color', _get_hex_color(_get_value(kwargs, ['color', 'c', 'edge_color', 'ec'], 'black')))
        kwargs.setdefault('edge_alpha', _get_value(kwargs, ['alpha', 'edge_alpha', 'ea'], 1.0))
        kwargs.setdefault('edge_width', _get_value(kwargs, ['edge_width', 'ew'], 1))
        kwargs.setdefault('precision', _get_value(kwargs, ['precision'], 6))

        # TODO: The following generates a '+' in Cartesian frame rather than in lat/lng; avoid this.
        delta_lat = (size / 1000.0 / _EARTH_RADIUS_IN_KM) * (180.0 / math.pi)
        delta_lng = delta_lat / math.cos(math.pi * lat / 180.0)

        self._horizontal_stroke = _Polyline([lat, lat], [lng - delta_lng, lng + delta_lng], **kwargs)
        self._vertical_stroke = _Polyline([lat - delta_lat, lat + delta_lat], [lng, lng], **kwargs)
Ejemplo n.º 3
0
    def __init__(self, bounds, lat_increment, lng_increment, precision,
                 **kwargs):
        '''
        Args:
            bounds (dict): Grid bounds, as a dict of the form
                ``{'north': float, 'south': float, 'east': float, 'west': float}``.
            lat_increment (float): Distance between latitudinal divisions.
            lng_increment (float): Distance between longitudinal divisions.
            precision (int): Number of digits after the decimal to round to for lat/lng values.

        Optional:

        Args:
            color (str): Grid color. Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c').
            alpha (float): Opacity of the grid, ranging from 0 to 1.
            width (int): Width of the grid lines, in pixels.
        '''
        # Set up the bounding box:
        self._bounding_box = _Polyline(
            *zip(*[(bounds['south'],
                    bounds['west']), (bounds['north'], bounds['west']),
                   (bounds['north'],
                    bounds['east']), (
                        bounds['south'],
                        bounds['east']), (bounds['south'], bounds['west'])]),
            precision=precision,
            **kwargs)

        get_num_divisions = lambda start, end, increment: int(
            math.ceil((end - start) / increment))

        # Set up the latitudinal divisions:
        self._lat_divisions = []
        for lat_index in range(
                1,
                get_num_divisions(bounds['south'], bounds['north'],
                                  lat_increment)):
            lat = bounds['south'] + float(lat_index) * lat_increment
            self._lat_divisions.append(
                _Polyline(*zip(*[(lat, bounds['west']), (lat,
                                                         bounds['east'])]),
                          precision=precision,
                          **kwargs))

        # Set up the longitudinal divisions:
        self._lng_divisions = []
        for lng_index in range(
                1,
                get_num_divisions(bounds['west'], bounds['east'],
                                  lng_increment)):
            lng = bounds['west'] + float(lng_index) * lng_increment
            self._lng_divisions.append(
                _Polyline(*zip(*[(bounds['south'], lng), (bounds['north'],
                                                          lng)]),
                          precision=precision,
                          **kwargs))
Ejemplo n.º 4
0
    def plot(self, lats, lngs, **kwargs):
        '''
        Plot a polyline.

        Args:
            lats ([float]): Latitudes.
            lngs ([float]): Longitudes.

        Optional:

        Args:
            color/c/edge_color/ec (str): Color of the polyline.
                Can be hex ('#00FFFF'), named ('cyan'), or matplotlib-like ('c'). Defaults to black.
            alpha/edge_alpha/ea (float): Opacity of the polyline, ranging from 0 to 1. Defaults to 1.0.
            edge_width/ew (int): Width of the polyline, in pixels. Defaults to 1.
            precision (int): Number of digits after the decimal to round to for lat/lng values. Defaults to 6.

        Usage::
            
            import gmplot
            apikey = '' # (your API key here)
            gmap = gmplot.GoogleMapPlotter(37.766956, -122.438481, 13, apikey=apikey)

            path = zip(*[
                (37.773097, -122.471789),
                (37.785920, -122.472693),
                (37.787815, -122.472178),
                (37.791430, -122.469763),
                (37.792547, -122.469624),
                (37.800724, -122.469460)
            ])

            gmap.plot(*path, edge_width=7, color='red')
            gmap.draw('map.html')

        .. image:: GoogleMapPlotter.plot.png
        '''
        _validate_lat_lng_length(lats, lngs)

        self._drawables.append(
            _Polyline(
                lats,
                lngs,
                _get(kwargs, 'precision', 6),
                color=_get(kwargs, ['color', 'c', 'edge_color', 'ec'],
                           'black'),
                alpha=_get(kwargs, ['alpha', 'edge_alpha', 'ea'], 1.0),
                width=_get(kwargs, ['edge_width', 'ew'], 1),
            ))