Ejemplo n.º 1
0
    def handle(self, *args, **options):
        # drop all old data
        if options["clear_mapnik_db"]:
            clear_mapnik_tables()

        ohdm2mapnik: Ohdm2Mapnik = Ohdm2Mapnik(chunk_size=options["cache"])
        ohdm2mapnik.run()
Ejemplo n.º 2
0
def test_render_tile_with_data(tile_generator: TileGenerator,
                               tile_test_cases: Dict[str, dict]):
    """
    test render tiles for tile_test_cases with using ohdm test data
    
    Arguments:
        tile_generator {TileGenerator} -- default TileGenerator
    """
    # cleanup data
    clear_mapnik_tables()

    # fill database
    run_import(
        file_path="/map.osm",
        db_cache_size=10000,
        cache2file=False,
    )

    tile_generator.request_date = timezone.now()

    for test_case in tile_test_cases:
        # contine if test case has not test data
        if not tile_test_cases[test_case]["has_date_data"]:
            continue

        print("test: {}".format(test_case))
        tile_generator.zoom = tile_test_cases[test_case]["zoom"]
        tile_generator.x_pixel = tile_test_cases[test_case]["x"]
        tile_generator.y_pixel = tile_test_cases[test_case]["y"]

        # generate new tile into a tmp file
        new_tile: SpooledTemporaryFile = SpooledTemporaryFile()
        new_tile.write(tile_generator.render_tile())
        new_tile.seek(0)

        # open new tile as image
        new_tile_image: Image = Image.open(new_tile)

        new_tile_image.save("/app/bremen.png")

        # check if the tile is a PNG file
        assert new_tile_image.format == "PNG"

        # monochrome & resize images to better compare them
        reference_tile = Image.open(
            "/app/compose/local/django/test_tile/{}".format(
                tile_test_cases[test_case]["tile_png"]))

        diff: bool = ImageChops.difference(reference_tile,
                                           new_tile_image).getbbox() is None
        assert diff is False

    # cleanup data
    clear_mapnik_tables()
Ejemplo n.º 3
0
def test_prerender():
    clear_mapnik_tables()

    PlanetOsmPoint.objects.create(
        valid_since=date(2020, 1, 3), valid_until=date(2020, 1, 1),
    )

    PlanetOsmLine.objects.create(
        valid_since=date(2020, 1, 2), valid_until=date(2020, 1, 2),
    )

    PlanetOsmPolygon.objects.create(
        valid_since=date(2020, 1, 1), valid_until=date(2020, 1, 3),
    )

    prerender(zoom_level=0, test_mode=True)
Ejemplo n.º 4
0
    def handle(self, *args, **options):

        # drop all old data
        if options["clear_mapnik_db"]:
            clear_mapnik_tables()

        if options["planet"]:
            if not Path(options["planet"]).is_file():
                print("Planet file does not exists!")
                exit(1)
            print("Start planet import!")
            run_import(
                file_path=options["planet"],
                db_cache_size=options["cache"],
                cache2file=options["cache2file"],
            )
        else:
            print("No Planet was selected, please add --planet path")
Ejemplo n.º 5
0
    def handle(self, *args, **options):

        # drop all old data
        if options["clear_rel_db"]:
            clear_rel_tables()
        if options["clear_mapnik_db"]:
            clear_mapnik_tables()

        if options["planet"]:
            if not Path(options["planet"]).is_file():
                print("Planet file does not exists!")
                exit(1)
            print("Start planet import!")
            run_import(
                file_path=options["planet"],
                db_cache_size=options["cache"],
                cache2file=options["cache2file"],
            )

        if options["rel2pgsql"]:
            print("Start convert rel 2 osm2pgsql!")
            rel2pgsql: Rel2pgsql = Rel2pgsql(chunk_size=options["cache"])
            rel2pgsql.run_import()