예제 #1
0
    def create_map(self):
        _map = Map(tiles="cartodbpositron")
        geos = self.get_geos()
        max_lat, max_lon, min_lat, min_lon = get_min_max_ll(geos)

        geos = [(i, numpy.log(j + 1) / (self.tree.get_node_height(k) + 1), k)
                for i, j, k in geos]
        mx, mn = max([j for i, j, k in geos]), min([j for i, j, k in geos])
        geos = [(i, (j - mn) / (mx - mn), k) for i, j, k in geos]

        for points, count, h in sorted(geos, key=lambda x: x[1]):
            tooltip = f"hex: {h}"
            polygon = Polygon(locations=points,
                              tooltip=tooltip,
                              fill=True,
                              color=cm.linear.OrRd_03.rgb_hex_str(count),
                              fill_color=cm.linear.OrRd_03.rgb_hex_str(count),
                              fill_opacity=0.3,
                              weight=3,
                              opacity=0.4)
            polygon.add_to(_map)

        _map.fit_bounds([[min_lat, min_lon], [max_lat, max_lon]])

        return _map
예제 #2
0
    def create_map(self):

        try:
            from folium import Map
            from folium.vector_layers import Polygon
            import branca.colormap as cm
        except ImportError:  # pragma: no cover
            logger.error('Mapping requires folium==0.10.0 to be installed, geo mapping will not work.'
                         'Install it with: pip install scikit-hts[geo]')
            return

        _map = Map(tiles="cartodbpositron")
        geos = self.get_geos()
        max_lat, max_lon, min_lat, min_lon = get_min_max_ll(geos)

        geos = [(i, numpy.log(j + 1) / (self.tree.get_node_height(k) + 1), k) for i, j, k in geos]
        mx, mn = max([j for i, j, k in geos]), min([j for i, j, k in geos])
        geos = [(i, (j - mn) / (mx - mn), k) for i, j, k in geos]

        for points, count, h in sorted(geos, key=lambda x: x[1]):
            tooltip = f"hex: {h}"
            polygon = Polygon(locations=points,
                              tooltip=tooltip,
                              fill=True,
                              color=cm.linear.OrRd_03.rgb_hex_str(count),
                              fill_color=cm.linear.OrRd_03.rgb_hex_str(count),
                              fill_opacity=0.3,
                              weight=3,
                              opacity=0.4)
            polygon.add_to(_map)

        _map.fit_bounds([[min_lat, min_lon], [max_lat, max_lon]])

        return _map
예제 #3
0
def test_polygon_marker():
    m = Map()
    locations = [[35.6636, 139.7634], [35.6629, 139.7664], [35.6663, 139.7706],
                 [35.6725, 139.7632], [35.6728, 139.7627], [35.6720, 139.7606],
                 [35.6682, 139.7588], [35.6663, 139.7627]]
    polygon = Polygon(locations=locations, popup='I am a polygon')
    polygon.add_to(m)

    expected_options = {
        'bubblingMouseEvents': True,
        'color': '#3388ff',
        'dashArray': None,
        'dashOffset': None,
        'fill': False,
        'fillColor': '#3388ff',
        'fillOpacity': 0.2,
        'fillRule': 'evenodd',
        'lineCap': 'round',
        'lineJoin': 'round',
        'noClip': False,
        'opacity': 1.0,
        'smoothFactor': 1.0,
        'stroke': True,
        'weight': 3,
    }

    m._repr_html_()
    expected_rendered = """
    var {name} = L.polygon(
    {locations},
    {{
    "bubblingMouseEvents": true,
    "color": "#3388ff",
    "dashArray": null,
    "dashOffset": null,
    "fill": false,
    "fillColor": "#3388ff",
    "fillOpacity": 0.2,
    "fillRule": "evenodd",
    "lineCap": "round",
    "lineJoin": "round",
    "noClip": false,
    "opacity": 1.0,
    "smoothFactor": 1.0,
    "stroke": true,
    "weight": 3
    }}
    )
    .addTo({map});
    """.format(locations=locations, name=polygon.get_name(), map=m.get_name())

    rendered = polygon._template.module.script(polygon)
    assert _normalize(rendered) == _normalize(expected_rendered)
    assert polygon.get_bounds() == get_bounds(locations)
    assert json.dumps(polygon.to_dict()) == polygon.to_json()
    assert polygon.options == json.dumps(expected_options,
                                         sort_keys=True,
                                         indent=2)  # noqa
예제 #4
0
def test_polygon_marker():
    m = Map()
    locations = [[35.6636, 139.7634],
                 [35.6629, 139.7664],
                 [35.6663, 139.7706],
                 [35.6725, 139.7632],
                 [35.6728, 139.7627],
                 [35.6720, 139.7606],
                 [35.6682, 139.7588],
                 [35.6663, 139.7627]]
    polygon = Polygon(locations=locations, popup='I am a polygon')
    polygon.add_to(m)

    expected_options = {
        'bubblingMouseEvents': True,
        'color': '#3388ff',
        'dashArray': None,
        'dashOffset': None,
        'fill': False,
        'fillColor': '#3388ff',
        'fillOpacity': 0.2,
        'fillRule': 'evenodd',
        'lineCap': 'round',
        'lineJoin': 'round',
        'noClip': False,
        'opacity': 1.0,
        'smoothFactor': 1.0,
        'stroke': True,
        'weight': 3,
    }

    m._repr_html_()
    expected_rendered = """
    var {name} = L.polygon(
    {locations},
    {{
    "bubblingMouseEvents": true,
    "color": "#3388ff",
    "dashArray": null,
    "dashOffset": null,
    "fill": false,
    "fillColor": "#3388ff",
    "fillOpacity": 0.2,
    "fillRule": "evenodd",
    "lineCap": "round",
    "lineJoin": "round",
    "noClip": false,
    "opacity": 1.0,
    "smoothFactor": 1.0,
    "stroke": true,
    "weight": 3
    }}
    )
    .addTo({map});
    """.format(locations=locations, name=polygon.get_name(), map=m.get_name())

    rendered = polygon._template.module.script(polygon)
    assert normalize(rendered) == normalize(expected_rendered)
    assert polygon.get_bounds() == get_bounds(locations)
    assert json.dumps(polygon.to_dict()) == polygon.to_json()
    assert polygon.options == expected_options