Esempio n. 1
0
    def test_gbif_mapbox_comp(self, taxon_id, tile_ids):
        mpta = TileArray.from_dict({x: Tile(x) for x in tile_ids})
        gbta = TileArray.from_dict({x: Tile(x) for x in tile_ids})

        mapbox_tiles = self.mapbox.get_tiles(mpta)
        gbif_tiles = self.gbif.get_tiles(taxon_id, gbta)
        c_tiles = mapbox_tiles._composite_layer(gbif_tiles)
        c_tiles.name = "gbif+mapbox"
        final_image = c_tiles._composite_all()
        final_image.save(f"gbif+mapbox-{taxon_id}-final.png")
Esempio n. 2
0
 def test_change_zoom_empty(self, tile_ids, images, zoom, exc):
     print("zoom", zoom)
     print("exc", exc)
     tile_array = TileArray()
     for z in zoom:
         if exc:
             with pytest.raises(exc):
                 tile_array.zoom = z
         else:
             tile_array.zoom = z
Esempio n. 3
0
 def test_creation_constructor(self, tile_ids, images):
     tile_array = TileArray.from_dict(
         {TileID(k): Tile(TileID(k), v)
          for k, v in zip(tile_ids, images)})
     for tid in tile_ids:
         assert tid in tile_array
     pprint(tile_array)
Esempio n. 4
0
 def test_get_tilearray(self, taxon_id, tile_ids_expected_image, map_type):
     tile_ids = tile_ids_expected_image.keys()
     ta = TileArray.from_dict({x: Tile(x) for x in tile_ids})
     ta = self.gbif.get_tiles(taxon_id, ta, mode=map_type)
     print(ta)
     for k, t in ta.items():
         t.save()
         print("IE", k, tile_ids_expected_image[k])
         print("timg", t.img)
Esempio n. 5
0
    def test_set_name(self, tile_ids, images):
        ta = TileArray(name="testname")
        assert ta.name == "testname"

        ta.name = "newtestname"
        assert ta.name == "newtestname"

        ts2 = TileArray()
        ts2.name = "anothertestname"
        assert ts2.name == "anothertestname"
Esempio n. 6
0
    def get_tiles(self,
                  taxon_key: int,
                  tile_array: TileArray,
                  mode: str = "hex",
                  **params) -> TileArray:
        print("gt ta:", tile_array)
        params["taxonKey"] = params.get("taxon_key", taxon_key)
        if "mode" in params:
            mode = params.pop("mode")
        funcmap = {"hex": self.get_hex_tile, "square": self.get_square_tile}
        func = funcmap.get(mode, self.get_hex_tile)

        new_tilearray = TileArray()
        for tid in tile_array:
            # TODO: this call can return None on HTTP errors. Handle that.
            tile = func(tile_id=tid, **params)
            new_tilearray[tid] = tile
        return new_tilearray
Esempio n. 7
0
    def get_tiles(self, species_code: str, zoom: int = 0, map_size: int = 512):
        bbox = self.get_bbox(species_code)
        if not bbox:
            return []
        tiles = self.get_bbox_tiles(bbox, zoom, map_size)
        # eBird doesn't handle crossing the antimeridian well, so we need to "improvise" one.
        rsid = ""
        if not tiles:
            rsid = self.get_rsid(species_code, 0)
            proxy_tile = self.download_tile(TileID(0, 0, 0), rsid)
            _, _, proxy_bbox = self.find_image_bbox(proxy_tile.img, 0)
            print("proxy bbox:", proxy_bbox)
            tiles = self.get_bbox_tiles(proxy_bbox, zoom, map_size, True)
            print("ebgt2")
            pprint(tiles)
        if tiles[0].zoom >= 6 or not rsid:
            rsid = self.get_rsid(species_code, tiles[0].zoom)

        filled_tiles = [
            TileArray.from_dict(
                {tid: self.download_tile(tid, rsid)
                 for tid in a}) for a in tiles
        ]
        return filled_tiles
Esempio n. 8
0
 def create_tilearray(self, tids, imgs):
     tile_array = TileArray()
     for tid, img in zip(tids, imgs):
         tile = Tile(tid=tid, img=img)
         tile_array[tid] = tile
     return tile_array
Esempio n. 9
0
 def get_tiles(self, tile_ids: List[TileID], **kwargs) -> TileArray:
     tile_array = TileArray(name="Mapbox")
     for tid in tile_ids:
         tile_array[tid] = self.get_tile(tid, **kwargs)
     return tile_array