Exemplo n.º 1
0
    def get_pixels_size(self, zoom, gk1, gk2):
        pixels1 = Transform.gk_to_pixel(gk1[0], gk1[1], self.map, zoom)
        pixels2 = Transform.gk_to_pixel(gk2[0], gk2[1], self.map, zoom)

        x_tiles = (pixels2[0] - pixels1[0]) + 1
        y_tiles = (pixels1[1] - pixels2[1]) + 1

        width = (x_tiles * self.map.tile_size_x) - pixels1[2] - (
            self.map.tile_size_x - pixels2[2])
        height = (y_tiles * self.map.tile_size_y) - pixels2[3] - (
            self.map.tile_size_y - pixels1[3])

        return width, height
Exemplo n.º 2
0
    def test_gk_to_pixel(self):
        dof = Map(345000, 215000, 256)
        dof.add_level(MapLevel([0, 0], [0, 0], 5000000, 1322.9193125052918))
        dof.add_level(MapLevel([0, 0], [1, 1], 2500000, 661.4596562526459))
        dof.add_level(MapLevel([0, 0], [1, 2], 1500000, 396.87579375158754))
        dof.add_level(MapLevel([0, 0], [2, 4], 1000000, 264.5838625010584))
        dof.add_level(MapLevel([0, 0], [3, 5], 750000, 198.43789687579377))
        dof.add_level(MapLevel([0, 0], [5, 8], 500000, 132.2919312505292))
        dof.add_level(MapLevel([1, 1], [10, 16], 250000, 66.1459656252646))
        dof.add_level(MapLevel([1, 2], [18, 27], 150000, 39.687579375158755))
        dof.add_level(MapLevel([2, 4], [27, 41], 100000, 26.458386250105836))
        dof.add_level(MapLevel([3, 5], [36, 55], 75000, 19.843789687579378))
        dof.add_level(MapLevel([5, 8], [54, 83], 50000, 13.229193125052918))
        dof.add_level(MapLevel([11, 17], [108, 166], 25000, 6.614596562526459))
        dof.add_level(MapLevel([19, 28], [181, 276], 15000,
                               3.9687579375158752))
        dof.add_level(MapLevel([28, 43], [272, 415], 10000,
                               2.6458386250105836))
        dof.add_level(MapLevel([57, 86], [544, 830], 5000, 1.3229193125052918))
        dof.add_level(
            MapLevel([115, 173], [1089, 1661], 2500, 0.6614596562526459))

        # Sv. Marija, Bled
        self.assertEqual(Transform.gk_to_pixel(5100921, 5462169, dof, 15),
                         [691, 673, 241, 178])
Exemplo n.º 3
0
    def export_image(self,
                     out_path,
                     out_format='PNG',
                     image_width=2000,
                     image_height=2000):
        if self.map is None:
            return None

        if self.bbox.coor_system.lower() == 'gps':
            # transform to Gauss-Krueger
            gk1 = Transform.wgs84_to_gk(self.bbox.min_lat, self.bbox.min_lon,
                                        0)  # left bottom
            gk2 = Transform.wgs84_to_gk(self.bbox.max_lat, self.bbox.max_lon,
                                        0)  # right top
        else:
            gk1 = [self.bbox.min_lat, self.bbox.min_lon]
            gk2 = [self.bbox.max_lat, self.bbox.max_lon]

        zoom = len(self.map.levels) - 1
        for z in range(0, len(self.map.levels)):
            width, height = self.get_pixels_size(z, gk1, gk2)
            # print(width, height)
            if width >= image_width or height >= image_height:
                zoom = z
                break

        pixels1 = Transform.gk_to_pixel(gk1[0], gk1[1], self.map, zoom)
        pixels2 = Transform.gk_to_pixel(gk2[0], gk2[1], self.map, zoom)

        # tile range
        start_x = pixels1[0]
        start_y = pixels2[1]
        end_x = pixels2[0]
        end_y = pixels1[1]

        # padding: left, top, right, bottom
        padding = (pixels1[2], pixels2[3], self.map.tile_size_x - pixels2[2],
                   self.map.tile_size_y - pixels1[3])

        if self.verbose:
            if self.bbox.coor_system.lower() == 'gps':
                print('Bounding box (WGS84): %f, %f, %f, %f' %
                      (self.bbox.min_lat, self.bbox.min_lon, self.bbox.max_lat,
                       self.bbox.max_lon))

            print('Bounding box (GK): %d, %d, %d, %d' %  # as integer !!
                  (gk1[0], gk1[1], gk2[0], gk2[1]))

            print('Output image: %s (%s)' % (out_path, out_format))
            print('Max image size: %dx%d' % (image_width, image_height))
            print('Tiles directory: %s' % self.map.map_dir)
            print('Tiles range: %d, %d, %d, %d (zoom: %d)' %
                  (start_x, start_y, end_x, end_y, zoom))
            print('Padding: %d, %d, %d, %d' % padding)

        start_time = time.time()
        self.export_map_tiles(start_x, start_y, end_x, end_y, zoom, padding,
                              out_path, out_format, image_width, image_height)
        elapsed_time = time.time() - start_time

        if self.verbose:
            print('Done, image exported in %0.3f seconds\n' % elapsed_time)