예제 #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))
예제 #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()
예제 #3
0
    def test_project_ch_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)
        stuttgart = LatLng(48.783810,9.180071)

        num_steps = 200
        fn = LatLng(47.652839, 9.472735)  #
        angles  = np.linspace(0,44.9,num_steps).tolist()
        fps = 25
        print("FPS:",fps)

        with tempfile.TemporaryDirectory() as tdir:
            files = []

            for angle in angles:

                projection = ComplexLogProjection(stuttgart, fn, 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-angle-{:05.2f}.jpeg".format(angle)
                filepath = os.path.join(tdir,filename)
                files.append((filepath,angle))
                im.convert('RGB').save(filepath,optimize=True)
                print(filepath)

            import cv2
            out = cv2.VideoWriter(get_destination('angles-{}.avi'.format('mapbox-osm')), cv2.VideoWriter_fourcc(*'MJPG'), fps, (w,h))
            for filepath,angle in files + list(reversed(files)):
                d = 0.01
                print("Loading ", filepath)

                im = cv2.imread(filepath)
                text = "{:05.2f}".format(angle)
                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,10),
                            linethickness,
                            cv2.LINE_AA)
                out.write(im)
            out.release()
예제 #4
0
def fetch_providers():
    p = get_providers()
    out_dict = {}
    for prov_name, prov_data in p.items():
        if isinstance(prov_data, RemoteRasterDataProvider):
            prov_data_r: RemoteRasterDataProvider = prov_data
            res: TileURLResolver = prov_data_r.resolver

            out_dict[prov_name] = res.normalized()

    response = jsonify(out_dict)
    return add_cors_headers(response)
예제 #5
0
    def test_project_image_osm_wide(self):
        prov = get_providers()
        konstanz = LatLng(47.711801, 9.084545)
        leipzig = LatLng(51.348419, 12.370946)  #
        projection = ComplexLogProjection(
            konstanz,
            leipzig,
            math.pi / 6,
            smoothing_function_type=CosCutoffSmoothingFunction)
        projector = RasterProjector(projection, prov['transparent'])
        trange = TargetSectionDescription(-math.pi * 4, math.pi * 4, 2000,
                                          -math.pi, math.pi, 500)
        d = projector.project(trange)

        import matplotlib.pyplot as plt
        plt.imshow(d)
        plt.savefig("sample.png", dpi=2000)
        plt.clf()
예제 #6
0
    def test_project_ch(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)
        stuttgart = LatLng(48.783810,9.180071)

        fn = LatLng(47.652839, 9.472735)  #
        for angle in [0,15,30,45]:

            projection = ComplexLogProjection(stuttgart, fn, math.radians(angle),
                                              smoothing_function_type=DualCosSmoothingFunction)
            projector_transparent = RasterProjector(projection, prov['ch'])
            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 = get_destination("sample-ch-angle-" + str(angle)+".jpeg")
            im.convert('RGB').save(filename,optimize=True)
            print(filename)
예제 #7
0
    def test_project_image_angles(self):
        prov = get_providers()
        trange = TargetSectionDescription(-math.pi * 2, math.pi * 2, 4000, -math.pi/2, math.pi/2, 1000)
        #frankfurt_a_m = LatLng(50.115822, 8.702537)
        halle = LatLng(51.506136,11.964422)

        leipzig = LatLng(51.348419, 12.370946)  #
        for angle in [0,15,30,45]:

            projection = ComplexLogProjection(halle, leipzig, 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 = get_destination("sample-angle-" + str(angle)+".jpeg")
            im.convert('RGB').save(filename,optimize=True)
            print(filename)
예제 #8
0
from source.raster_data.tile_resolver import TileURLResolver
from PIL import Image
from source.flat_tiling import FlatTiling
from server_timing import Timing
import numpy as np

app = Flask(__name__)
logging.basicConfig(level=logging.INFO)
app.config.from_mapping(build_cache_config())
cache = Cache(app)
CORS(app)
t = Timing(app, force_debug=True)

from source.hard_coded_providers import get_providers

providers = get_providers()


def do_projection(lat1,
                  lng1,
                  lat2,
                  lng2,
                  data_source: AbstractRasterDataProvider,
                  pixel_width=256,
                  pixel_height=256,
                  xmin=-1,
                  xmax=1,
                  ymin=-1,
                  ymax=1,
                  cutoff=math.pi / 6,
                  smoothing=CosCutoffSmoothingFunction,