def worker(tile):
                tick = time.monotonic()

                x, y, z = map(str, [tile.x, tile.y, tile.z])

                os.makedirs(os.path.join(args.out, z, x), exist_ok=True)
                path = os.path.join(args.out, z, x, '{}.{}'.format(y, args.ext))

                if os.path.isfile(path):
                    return tile, True

                url = args.url.format(x=tile.x, y=tile.y, z=tile.z)

                res = fetch_image(session, url)

                if not res:
                    return tile, False

                try:
                    image = Image.open(res)
                    image.save(path, optimize=True)
                except OSError:
                    return tile, False

                tock = time.monotonic()

                time_for_req = tock - tick
                time_per_worker = num_workers / args.rate

                if time_for_req < time_per_worker:
                    time.sleep(time_per_worker - time_for_req)

                progress.update()

                return tile, True
Ejemplo n.º 2
0
def tile(z, x, y):

    # Todo: predictor should take care of zoom levels
    if z != 18:
        abort(404)

    tile = mercantile.Tile(x, y, z)

    url = tiles.format(x=tile.x, y=tile.y, z=tile.z)
    res = fetch_image(session, url)

    if not res:
        abort(500)

    image = Image.open(res)

    mask = predictor.segment(image)

    return send_png(mask)
def tile(z, x, y):

    # Todo: predictor should take care of zoom levels
    if z != 18:
        abort(404)

    tile = mercantile.Tile(x, y, z)

    url = tiles.format(x=tile.x, y=tile.y, z=tile.z)
    res = fetch_image(session, url)

    if not res:
        abort(500)

    image = Image.open(res)

    mask = predictor.segment(image)

    return send_png(mask)
Ejemplo n.º 4
0
def tile(z, x, y):

    # Todo: predictor should take care of zoom levels
    if z != 18:
        abort(404)

    tile = mercantile.Tile(x, y, z)

    url = tiles.format(x=tile.x, y=tile.y, z=tile.z)
    res = fetch_image(session, url)

    if not res:
        abort(500)

    image = cv2.imdecode(np.asarray(bytearray(res.read()), dtype=np.uint8),
                         cv2.COLOR_BGR2RGB)

    mask = predictor.segment(image)

    return send_png(mask)
Ejemplo n.º 5
0
            def worker(tile):
                tick = time.monotonic()

                x, y, z = map(str, [tile.x, tile.y, tile.z])

                os.makedirs(os.path.join(args.out, z, x), exist_ok=True)
                path = os.path.join(args.out, z, x, "{}.{}".format(y, args.ext))

                if os.path.isfile(path):
                    return tile, None, True

                if args.type == "XYZ":
                    url = args.url.format(x=tile.x, y=tile.y, z=tile.z)
                elif args.type == "TMS":
                    tile.y = (2 ** tile.z) - tile.y - 1
                    url = args.url.format(x=tile.x, y=tile.y, z=tile.z)
                elif args.type == "WMS":
                    xmin, ymin, xmax, ymax = xy_bounds(tile)
                    url = args.url.format(xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax)

                res = fetch_image(session, url, args.timeout)
                if not res:
                    return tile, url, False

                try:
                    image = Image.open(res)
                    image.save(path, optimize=True)
                except OSError:
                    return tile, url, False

                tock = time.monotonic()

                time_for_req = tock - tick
                time_per_worker = num_workers / args.rate

                if time_for_req < time_per_worker:
                    time.sleep(time_per_worker - time_for_req)

                progress.update()

                return tile, url, True