Exemplo n.º 1
0
def from_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

    proj = ComplexLogProjection(
        LatLng(lat1, lng1),
        LatLng(lat2, lng2),
        math.radians(cutoff),
        smoothing_function_type=parse_smoothing(smoothing))

    elements = json_i['data']
    ret_v = []
    for e in elements:
        x, y = tiling.from_leaflet_LatLng(LatLng(e['lat'], e['lng']))
        xy = np.array([[x], [y]])
        latlng_data = proj.invert(xy)
        assert latlng_data.shape == (2, 1)
        ret_element = {"lat": latlng_data[0, 0], "lng": latlng_data[1, 0]}
        ret_v.append(ret_element)
    response = app.response_class(response=json.dumps({"data": ret_v}),
                                  status=200,
                                  mimetype='application/json')

    return response
Exemplo n.º 2
0
 def test_loop(self):
     projection = ComplexLogProjection(LatLng(0, 0), LatLng(10, 10),
                                       math.pi / 4)
     # only small slice where no stitching was used
     data = np.array([[1, 9], [1, 9]])
     res = projection(data.copy())
     returned = projection.invert(res.copy())
     np.testing.assert_almost_equal(returned, data)
     pass
Exemplo n.º 3
0
def resolve(lat1, lng1, lat2, lng2, cutoff, smoothing, clickLat, clickLng):
    proj = ComplexLogProjection(
        LatLng(lat1, lng1),
        LatLng(lat2, lng2),
        math.radians(cutoff),
        smoothing_function_type=parse_smoothing(smoothing))

    x, y = tiling.from_leaflet_LatLng(LatLng(clickLat, clickLng))

    xy = np.array([[x], [y]])
    latlng_data = proj.invert(xy)

    assert latlng_data.shape == (2, 1)
    ret_data = {"lat": latlng_data[0, 0], "lng": latlng_data[1, 0]}
    response = app.response_class(response=json.dumps(ret_data),
                                  status=200,
                                  mimetype='application/json')
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers',
                         'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods',
                         'GET,PUT,POST,DELETE,OPTIONS')
    return response