Example #1
0
 def __init__(self, subdivide, tilegrid=None, queue=None, seeds=()):
     self.subdivide = subdivide
     self.tilegrid = tilegrid
     if self.tilegrid is None:
         self.tilegrid = QuadTileGrid()
     self.queue = queue
     if self.queue is None:
         self.queue = deque()
     for seed in seeds:
         self.queue.append(seed)
Example #2
0
 def __init__(self, subdivide, tilegrid=None, queue=None, seeds=()):
     super(RenderingTheWorldTileStore, self).__init__()
     self.subdivide = subdivide
     self.tilegrid = tilegrid
     if self.tilegrid is None:
         self.tilegrid = QuadTileGrid()
     self.queue = queue
     if self.queue is None:
         self.queue = deque()
     for seed in seeds:
         self.queue.append(seed)
Example #3
0
 def __init__(
         self,
         subdivide: Callable[[Tile], Iterable[Tile]],
         tilegrid: Optional[TileGrid] = None,
         queue: Optional[Deque[Tile]] = None,
         seeds: Tuple[Tile, ...] = (),
 ):
     super().__init__()
     self.subdivide = subdivide
     self.tilegrid = tilegrid
     if self.tilegrid is None:
         self.tilegrid = QuadTileGrid()
     if queue is None:
         queue = deque()
     self.queue = queue
     for seed in seeds:
         self.queue.append(seed)
Example #4
0
 def setUp(self):
     self.qtsn = QuadTileGrid()
     self.qtsf = QuadTileGrid(flip_y=True)
Example #5
0
 def setUp(self):
     self.qtg = QuadTileGrid(max_extent=(0.0, 1.0, 2.0, 3.0))
Example #6
0
 def setUp(self):
     self.ftg = FreeTileGrid([8, 4, 2, 1], tile_size=0.125)
     self.qtg = QuadTileGrid(max_zoom=3)
Example #7
0
def main():
    parser = ArgumentParser(
        description=
        "Used to import the osm2pgsql expire-tiles file to Postgres",
        prog=sys.argv[0])
    parser.add_argument(
        "--buffer",
        type=float,
        default=0.0,
        help="Extent buffer to the tiles [m], default is 0",
    )
    parser.add_argument(
        "--simplify",
        type=float,
        default=0.0,
        help="Simplify the result geometry [m], default is 0",
    )
    parser.add_argument(
        "--create",
        default=False,
        action="store_true",
        help="create the table if not exists",
    )
    parser.add_argument(
        "--delete",
        default=False,
        action="store_true",
        help="empty the table",
    )
    parser.add_argument(
        "file",
        metavar="FILE",
        help="The osm2pgsql expire-tiles file",
    )
    parser.add_argument(
        "connection",
        metavar="CONNECTION",
        help=("The PostgreSQL connection string e.g. "
              '"user=www-data password=www-data dbname=sig host=localhost"'),
    )
    parser.add_argument(
        "table",
        metavar="TABLE",
        help="The PostgreSQL table to fill",
    )
    parser.add_argument(
        "--schema",
        default="public",
        help=
        "The PostgreSQL schema to use (should already exists), default is public",
    )
    parser.add_argument(
        "column",
        metavar="COLUMN",
        default="geom",
        nargs="?",
        help='The PostgreSQL column, default is "geom"',
    )
    parser.add_argument(
        "--srid",
        type=int,
        default=3857,
        nargs="?",
        help="The stored geometry SRID, no conversion by default (3857)",
    )
    options = parser.parse_args()

    connection = psycopg2.connect(options.connection)
    cursor = connection.cursor()

    if options.create:
        cursor.execute(
            "SELECT count(*) FROM pg_tables WHERE schemaname='{}' AND tablename='{}'"
            .format(options.schema, options.table))
        if cursor.fetchone()[0] == 0:
            cursor.execute(
                'CREATE TABLE IF NOT EXISTS "{}"."{}" (id serial)'.format(
                    options.schema, options.table))
            cursor.execute(
                "SELECT AddGeometryColumn('{}', '{}', '{}', {}, 'MULTIPOLYGON', 2)"
                .format(options.schema, options.table, options.column,
                        options.srid))

    if options.delete:
        cursor.execute('DELETE FROM "{}"'.format((options.table)))

    geoms = []
    grid = QuadTileGrid(max_extent=(-20037508.34, -20037508.34, 20037508.34,
                                    20037508.34), )
    with open(options.file, "r") as f:
        for coord in f:
            extent = grid.extent(parse_tilecoord(coord), options.buffer)
            geoms.append(
                Polygon((
                    (extent[0], extent[1]),
                    (extent[0], extent[3]),
                    (extent[2], extent[3]),
                    (extent[2], extent[1]),
                )))
    if len(geoms) == 0:
        print("No coords found")
        connection.commit()
        cursor.close()
        connection.close()
        sys.exit(0)
    geom = cascaded_union(geoms)
    if geom.geom_type == "Polygon":
        geom = MultiPolygon((geom, ))

    if options.simplify > 0:
        geom.simplify(options.simplify)

    sql_geom = "ST_GeomFromText('{}', 3857)".format(geom.wkt)
    if options.srid <= 0:
        sql_geom = "ST_GeomFromText('{}')".format(geom.wkt)  # pragma: no cover
    elif options.srid != 3857:
        sql_geom = "ST_Transform({}, {})".format(sql_geom, options.srid)

    cursor.execute('INSERT INTO "{}" ("{}") VALUES ({})'.format(
        options.table, options.column, sql_geom))
    connection.commit()
    cursor.close()
    connection.close()
    print("Import successful")
Example #8
0
def main():
    parser = ArgumentParser(
        description=
        'Used to import the osm2pgsql expire-tiles file to Postgres',
        prog='./buildout/bin/import_expire_tiles',
    )
    parser.add_argument(
        '--buffer',
        type=float,
        default=0.0,
        help='Extent buffer to the tiles [m], default is 0',
    )
    parser.add_argument(
        '--simplify',
        type=float,
        default=0.0,
        help='Simplify the result geometry [m], default is 0',
    )
    parser.add_argument(
        '--create',
        default=False,
        action="store_true",
        help='create the table if not exists',
    )
    parser.add_argument(
        '--delete',
        default=False,
        action="store_true",
        help='empty the table',
    )
    parser.add_argument(
        'file',
        metavar='FILE',
        help='The osm2pgsql expire-tiles file',
    )
    parser.add_argument(
        'connection',
        metavar='CONNECTION',
        help=
        'The PostgreSQL connection string e.g. "user=www-data password=www-data dbname=sig host=localhost"',
    )
    parser.add_argument(
        'table',
        metavar='TABLE',
        help='The PostgreSQL table to fill',
    )
    parser.add_argument(
        '--schema',
        default='public',
        help=
        'The PostgreSQL schema to use (should already exists), default is public',
    )
    parser.add_argument(
        'column',
        metavar='COLUMN',
        default='geom',
        nargs='?',
        help='The PostgreSQL column, default is "geom"',
    )
    parser.add_argument(
        '--srid',
        type=int,
        default=3857,
        nargs='?',
        help='The stored geometry SRID, no conversion by default (3857)',
    )
    options = parser.parse_args()

    connection = psycopg2.connect(options.connection)
    cursor = connection.cursor()

    if options.create:
        cursor.execute(
            "SELECT count(*) FROM pg_tables WHERE schemaname='%s' AND tablename='%s'"
            % (
                options.schema,
                options.table,
            ))
        if cursor.fetchone()[0] == 0:
            cursor.execute('CREATE TABLE IF NOT EXISTS "%s"."%s" (id serial)' %
                           (
                               options.schema,
                               options.table,
                           ))
            cursor.execute(
                "SELECT AddGeometryColumn('%s', '%s', '%s', %s, 'MULTIPOLYGON', 2)"
                % (
                    options.schema,
                    options.table,
                    options.column,
                    options.srid,
                ))

    if options.delete:
        cursor.execute('DELETE FROM "%s"' % (options.table))

    geoms = []
    f = file(options.file, 'r')
    grid = QuadTileGrid(max_extent=(-20037508.34, -20037508.34, 20037508.34,
                                    20037508.34), )
    for coord in f:
        extent = grid.extent(parse_tilecoord(coord), options.buffer)
        geoms.append(
            Polygon(((extent[0], extent[1]), (extent[0], extent[3]),
                     (extent[2], extent[3]), (extent[2], extent[1]))))
    f.close()
    if len(geoms) == 0:
        print "No coords found"
        connection.commit()
        cursor.close()
        connection.close()
        exit(0)
    geom = cascaded_union(geoms)
    if geom.geom_type == 'Polygon':
        geom = MultiPolygon((geom, ))

    if options.simplify > 0:
        geom.simplify(options.simplify)

    sql_geom = "ST_GeomFromText('%s', 3857)" % geom.wkt
    if options.srid <= 0:
        sql_geom = "ST_GeomFromText('%s')" % geom.wkt  # pragma: no cover
    elif options.srid != 3857:
        sql_geom = 'ST_Transform(%s, %i)' % (sql_geom, options.srid)

    cursor.execute('INSERT INTO "%s" ("%s") VALUES (%s)' %
                   (options.table, options.column, sql_geom))
    connection.commit()
    cursor.close()
    connection.close()
    print 'Import successful'
Example #9
0
def main() -> None:
    """Import the osm2pgsql expire-tiles file to Postgres."""
    try:
        parser = ArgumentParser(
            description=
            "Used to import the osm2pgsql expire-tiles file to Postgres",
            prog=sys.argv[0])
        parser.add_argument(
            "--buffer",
            type=float,
            default=0.0,
            help="Extent buffer to the tiles [m], default is 0",
        )
        parser.add_argument(
            "--simplify",
            type=float,
            default=0.0,
            help="Simplify the result geometry [m], default is 0",
        )
        parser.add_argument(
            "--create",
            default=False,
            action="store_true",
            help="create the table if not exists",
        )
        parser.add_argument(
            "--delete",
            default=False,
            action="store_true",
            help="empty the table",
        )
        parser.add_argument(
            "file",
            metavar="FILE",
            help="The osm2pgsql expire-tiles file",
        )
        parser.add_argument(
            "connection",
            metavar="CONNECTION",
            help=(
                "The PostgreSQL connection string e.g. "
                '"user=www-data password=www-data dbname=sig host=localhost"'),
        )
        parser.add_argument(
            "table",
            metavar="TABLE",
            help="The PostgreSQL table to fill",
        )
        parser.add_argument(
            "--schema",
            default="public",
            help=
            "The PostgreSQL schema to use (should already exists), default is public",
        )
        parser.add_argument(
            "column",
            metavar="COLUMN",
            default="geom",
            nargs="?",
            help='The PostgreSQL column, default is "geom"',
        )
        parser.add_argument(
            "--srid",
            type=int,
            default=3857,
            nargs="?",
            help="The stored geometry SRID, no conversion by default (3857)",
        )
        options = parser.parse_args()

        connection = psycopg2.connect(options.connection)
        cursor = connection.cursor()

        if options.create:
            cursor.execute(
                "SELECT count(*) FROM pg_tables WHERE schemaname=%(schema)s AND tablename=%(table)s",
                {
                    "schema": options.schema,
                    "table": options.table
                },
            )
            if cursor.fetchone()[0] == 0:
                cursor.execute(
                    f'CREATE TABLE IF NOT EXISTS "{options.schema}"."{options.table}" (id serial)'
                )
                cursor.execute(
                    "SELECT AddGeometryColumn(%(schema)s, %(table)s, %(column)s, %(srid)s, 'MULTIPOLYGON', 2)",
                    {
                        "schema": options.schema,
                        "table": options.table,
                        "column": options.column,
                        "srid": options.srid,
                    },
                )

        if options.delete:
            cursor.execute(
                psycopg2.sql.SQL("DELETE FROM {}").format(
                    psycopg2.sql.Identifier(options.table)))

        geoms = []
        grid = QuadTileGrid(max_extent=(-20037508.34, -20037508.34,
                                        20037508.34, 20037508.34), )
        with open(options.file, encoding="utf-8") as f:
            for coord in f:
                extent = grid.extent(parse_tilecoord(coord), options.buffer)
                geoms.append(
                    Polygon((
                        (extent[0], extent[1]),
                        (extent[0], extent[3]),
                        (extent[2], extent[3]),
                        (extent[2], extent[1]),
                    )))
        if len(geoms) == 0:
            print("No coords found")
            connection.commit()
            cursor.close()
            connection.close()
            sys.exit(0)
        geom = unary_union(geoms)
        if geom.geom_type == "Polygon":
            geom = MultiPolygon((geom, ))

        if options.simplify > 0:
            geom.simplify(options.simplify)

        sql_geom = f"ST_GeomFromText('{geom.wkt}', 3857)"
        if options.srid <= 0:
            sql_geom = f"ST_GeomFromText('{geom.wkt}')"
        elif options.srid != 3857:
            sql_geom = f"ST_Transform({sql_geom}, {options.srid})"

        cursor.execute(
            f'INSERT INTO "{options.table}" ("{options.column}") VALUES ({sql_geom})'
        )
        connection.commit()
        cursor.close()
        connection.close()
        print("Import successful")
    except SystemExit:
        raise
    except:  # pylint: disable=bare-except
        logger.exception("Exit with exception")
        sys.exit(1)
Example #10
0
from tilecloud.grid.quad import QuadTileGrid

GoogleTileGrid = QuadTileGrid(max_extent=(-20037508.34, -20037508.34,
                                          20037508.34, 20037508.34),
                              tile_size=256)