예제 #1
0
    def testZoomLevel(self):
        projection_small = ComplexLogProjection(LatLng(0, 0), LatLng(10, 10),
                                                math.pi / 4)

        projection_large = ComplexLogProjection(LatLng(-10, -10),
                                                LatLng(10, 10), math.pi / 4)
        data = np.array([[-1, -2, 1, 2], [1, 1, 1, 1]])
        # expected = np.array([np.exp(1), np.exp(2), np.exp(1), np.exp(2)])
        r1 = projection_small.getZoomLevel(data, 100)
        r2 = projection_large.getZoomLevel(data, 100)
        r3 = projection_small.getZoomLevel(data, 200)
        diff = r1 - r2
        np.testing.assert_almost_equal(diff, np.array([1, 1, 1, 1]))
        assert r1[0] < r1[1]
        np.testing.assert_almost_equal(r3[0] - r1[0], 1)
        pass
예제 #2
0
def to_leaflet(lat1, lng1, lat2, lng2, cutoff, smoothing):

    if request.method != "POST":
        return ""

    json_i = request.get_json(force=True)
    if json_i is None:
        return "Could not parse JSON", 500

    precision = int(request.args.get("precision", 5))  # number of digits
    c1latlng = LatLng(lat1, lng1)
    c2latlng = LatLng(lat2, lng2)

    proj = ComplexLogProjection(
        c1latlng,
        c2latlng,
        math.radians(cutoff),
        smoothing_function_type=parse_smoothing(smoothing))

    center_distance = c1latlng.distanceTo(c2latlng)
    pixel_per_m = 256.0 / (156412.0)
    elements = json_i['data']
    ret_v = []
    for e in elements:
        xy = np.array([[e[0]], [e[0]]])
        xy, clipping = proj(xy, calculate_clipping=True)
        z = proj.getZoomLevel(xy, pixel_per_m)
        latlng = tiling.to_leaflet_LatLng(xy[0, 0], xy[1, 0])

        clipping = bool(clipping[0])

        ret_element = [
            round(latlng.lat, precision),
            round(latlng.lng, precision),
            round(z[0], precision), clipping
        ]
        ret_v.append(ret_element)

    z_values = list(map(lambda x: x[2], ret_v))
    min_z = min(*z_values)
    max_z = max(*z_values)
    response = app.response_class(response=json.dumps(
        {
            "data": ret_v,
            "min_z": min_z,
            "max_z": max_z
        },
        check_circular=False,
        indent=None),
                                  status=200,
                                  mimetype='application/json')

    return response
예제 #3
0
    def test_vis_zoomLevel(self):

        projection1 = ComplexLogProjection(LatLng(0, 0), LatLng(10, 10),
                                           math.pi / 4)
        projection2 = ComplexLogProjection(LatLng(-10, -10), LatLng(10, 10),
                                           math.pi / 4)
        projector = RasterProjector(projection1,
                                    OSMRasterDataProvider(dummy_resolver))
        grid = projector.build_grid(
            TargetSectionDescription(-4, 4, 400, -2, 2, 200))
        zoom = projection1.getZoomLevel(grid, 100)
        import matplotlib.pyplot as plt
        plt.imshow(zoom.reshape(200, 400))
        plt.colorbar()
        plt.show()
        plt.scatter(range(400), zoom.reshape(200, 400)[10, :])
        plt.show()
예제 #4
0
def cities_projected(lat1, lng1, lat2, lng2, cutoff, smoothing):

    with t.time("loading_cities_lat_lng"):
        cities_lat_lng = np.array(
            list(map(lambda e: [e['lat'], e['lon']],
                     get_cities()['elements']))).transpose()
    with t.time("parsing_params"):
        precision = int(request.args.get("precision", 5))  # number of digits
        c1latlng = LatLng(lat1, lng1)
        c2latlng = LatLng(lat2, lng2)

        proj = ComplexLogProjection(
            c1latlng,
            c2latlng,
            math.radians(cutoff),
            smoothing_function_type=parse_smoothing(smoothing))

        center_distance = c1latlng.distanceTo(c2latlng)
        pixel_per_m = 256.0 / (156412.0)
        num_cities = cities_lat_lng.shape[1]

    with t.time("projection"):
        xy, clipping = proj(cities_lat_lng, calculate_clipping=True)
    with t.time("zoomlevel"):
        z = proj.getZoomLevel(xy, pixel_per_m)
    with t.time("tiling"):
        latlngs = [None] * num_cities
        for i in range(num_cities):

            latlng = tiling.to_leaflet_LatLng(xy[0, i], xy[1, i])
            latlngs[i] = latlng
    with t.time("packaging"):
        ret_v = [None] * num_cities
        p_x_int = 10**precision
        p_x_float = 10.**precision
        my_round = lambda x: int(x * (p_x_int)) / (p_x_float)
        for i in range(num_cities):
            clipping_v = bool(clipping[i])
            latlng = latlngs[i]
            ret_element = [
                my_round(latlng.lat),
                my_round(latlng.lng),
                my_round(z[i]), clipping_v
            ]
            ret_v[i] = ret_element

    with t.time("assembly"):
        z_values = list(map(lambda x: x[2], ret_v))
        min_z = min(*z_values)
        max_z = max(*z_values)
        response = app.response_class(response=json.dumps(
            {
                "data": ret_v,
                "min_z": min_z,
                "max_z": max_z
            },
            check_circular=False,
            indent=None),
                                      status=200,
                                      mimetype='application/json')
    return response