Beispiel #1
0
    def test_project_image_distances(self):
            prov = get_providers()
            trange = TargetSectionDescription(-math.pi * 2, math.pi * 2, 4000, -math.pi, math.pi, 2000)
            #frankfurt_a_m = LatLng(50.115822, 8.702537)
            angle = 30
            hamburg = LatLng(53.559988,9.982358)
            hamburg_elbbruecken = LatLng(53.535251,10.020135)
            lueneburg = LatLng(53.245280,10.408478)
            hannover = LatLng(52.370487,9.724743)
            fulda = LatLng(50.527068,9.684608)
            stockach = LatLng(47.847596,9.007671)
            for i,to in enumerate([ hamburg_elbbruecken,lueneburg,hannover,fulda,stockach]):

                projection = ComplexLogProjection(hamburg, to, math.radians(angle),
                                                  smoothing_function_type=DualCosSmoothingFunction)
                projector_transparent = RasterProjector(projection, prov['transparent'])
                projector_mapbox = RasterProjector(projection, prov['mapbox'])

                d_trans =  Image.fromarray(projector_transparent.project(trange))
                d_mapbox = Image.fromarray(projector_mapbox.project(trange))

                im = Image.alpha_composite(d_mapbox,d_trans)
                dist = int(hamburg.distanceTo(to))
                filename = get_destination("sample-distance-" + str(dist)+".jpeg")
                im.convert('RGB').save(filename,optimize=True)

                print("Finished " + filename + " with distance " + str(dist))
Beispiel #2
0
    def test_project_dist_video(self):
        prov = get_providers()
        w = 2000
        h = 1000

        trange = TargetSectionDescription(-math.pi * 2, math.pi * 2, w, -math.pi,math.pi, h)
        # frankfurt_a_m = LatLng(50.115822, 8.702537)
        start = LatLng(48.783810, 9.180071)
        angle = 30
        t = 5
        fps = 25
        end = LatLng(47.652839, 9.472735)  #


        numsteps = 400
        steps = list(reversed(list(map(lambda a:LatLng(a[0],a[1]),zip(np.linspace(end.lat,start.lat,numsteps,endpoint=False),np.linspace(end.lng,start.lng,numsteps,endpoint=False))))))
        print("FPS:", fps)
        with tempfile.TemporaryDirectory() as tdir:
            files = []

            for i,step in enumerate(steps):

                distance = start.distanceTo(step)
                projection = ComplexLogProjection(start, step, math.radians(angle),
                                                  smoothing_function_type=DualCosSmoothingFunction)
                projector_transparent = RasterProjector(projection, prov['transparent'])
                projector_mapbox = RasterProjector(projection, prov['mapbox'])

                d_trans = Image.fromarray(projector_transparent.project(trange))
                d_mapbox = Image.fromarray(projector_mapbox.project(trange))

                im = Image.alpha_composite(d_mapbox, d_trans)
                filename = "sample-ch-distance-{:012.6f}.jpeg".format(distance)
                filepath = os.path.join(tdir, filename)
                files.append((filepath, distance))
                im.convert('RGB').save(filepath, optimize=True)
                print(filepath)

            import cv2
            out = cv2.VideoWriter(get_destination('distances.avi'), cv2.VideoWriter_fourcc(*'MJPG'), fps, (w, h))
            for filepath, distance in files + list(reversed(files)):
                d = 0.01

                im = cv2.imread(filepath)
                text = "{:05.2f}km".format(distance)
                fontscale = h / 200
                linethickness = int(h / 100)
                cv2.putText(im,
                            text,
                            (int(w * d), int(h * (1 - d))),
                            cv2.FONT_HERSHEY_SIMPLEX,
                            fontscale,
                            (255, 10, 1),
                            linethickness,
                            cv2.LINE_AA)
                out.write(im)
            out.release()
Beispiel #3
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
Beispiel #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