コード例 #1
0
        internal static void Create(string connectionString,
                                    string name, MbTilesType type, double version, string description,
                                    MbTilesFormat format, Extent extent, params string[] kvp)
        {
            var dict = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(name))
            {
                dict.Add("name", name);
            }
            dict.Add("type", type.ToString().ToLowerInvariant());
            dict.Add("version", version.ToString(CultureInfo.InvariantCulture));
            if (!string.IsNullOrEmpty(description))
            {
                dict.Add("description", description);
            }
            dict.Add("format", format.ToString().ToLower());
            dict.Add("bounds", string.Format(NumberFormatInfo.InvariantInfo,
                                             "{0},{1},{2},{3}", extent.MinX, extent.MinY, extent.MaxX, extent.MaxY));

            for (var i = 0; i < kvp.Length - 1; i++)
            {
                dict.Add(kvp[i++], kvp[i]);
            }
        }
コード例 #2
0
        public MbTilesCache(SQLiteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
            : base(connection, (parent, child) => $"\"{child}\"", string.Empty, "tiles",
                   null, null, FindTileCommand)
        {
            var wasOpen = true;

            if (Connection.State != ConnectionState.Open)
            {
                Connection.Open();
                wasOpen = false;
            }

            if (type == MbTilesType.None)
            {
                // Type (if defined)
                _type = ReadType(connection);
            }
            else
            {
                _type = type;
            }

            if (schema == null)
            {
                // Format (if defined)
                _format = ReadFormat(connection);

                // Extent
                _extent = ReadExtent(connection);


                if (HasMapTable(connection))
                {
                    // it is possible to override the schema by definining it in a 'map' table.
                    // This method depends on reading tiles from an 'images' table, which
                    // is not part of the MBTiles spec

                    // Declared zoom levels
                    var declaredZoomLevels = ReadZoomLevels(connection, out _tileRange);

                    // Create schema
                    _schema = new GlobalMercator(Format.ToString(), declaredZoomLevels);
                }
                else
                {
                    // this is actually the most regular case:
                    _schema = new GlobalSphericalMercator();
                }
            }
            else
            {
                _schema = schema;
            }

            if (!wasOpen)
            {
                Connection.Close();
            }
        }
コード例 #3
0
ファイル: MbTilesTileSource.cs プロジェクト: yjsh824/BruTile
        public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
        {
            _connectionString = connectionString;
            var connection = new SQLiteConnectionWithLock(connectionString, SQLiteOpenFlags.ReadOnly);

            using (connection.Lock())
            {
                Type = type == MbTilesType.None ? ReadType(connection) : type;
                var schemaFromDatabase = ReadSchemaFromDatabase(connection);
                Schema = schema ?? schemaFromDatabase;

                // the tile range should be based on the tiles actually present.
                var zoomLevelsFromDatabase = schemaFromDatabase.Resolutions.Select(r => r.Key);
                _tileRange = ReadZoomLevelsFromTilesTable(connection, zoomLevelsFromDatabase);
            }
        }
コード例 #4
0
ファイル: MbTilesCache.cs プロジェクト: zhousuhua/BruTile
        internal MbTilesCache(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
        {
            if (_connectionPool == null)
            {
                throw new InvalidOperationException("You must assign a platform prior to using MbTilesCache by calling MbTilesTileSource.SetPlatform()");
            }

            _connectionString = connectionString;
            var connection = _connectionPool.GetConnection(connectionString);

            using (connection.Lock())
            {
                _type = type == MbTilesType.None ? ReadType(connection) : type;

                if (schema == null)
                {
                    // Format (if defined)
                    _format = ReadFormat(connection);

                    // Extent
                    _extent = ReadExtent(connection);


                    if (HasMapTable(connection))
                    {
                        // it is possible to override the schema by definining it in a 'map' table.
                        // This method depends on reading tiles from an 'images' table, which
                        // is not part of the MBTiles spec

                        // Declared zoom levels
                        var declaredZoomLevels = ReadZoomLevels(connection, out _tileRange);

                        // Create schema
                        _schema = new GlobalMercator(_format.ToString(), declaredZoomLevels);
                    }
                    else
                    {
                        // this is actually the most regular case:
                        _schema = new GlobalSphericalMercator();
                    }
                }
                else
                {
                    _schema = schema;
                }
            }
        }
コード例 #5
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="connectionString">The MapBox tiles file</param>
 /// <param name="name">The name of the TileSource</param>
 /// <param name="schema">The tile schema</param>
 /// <param name="type">The type of the MapBox tiles file</param>
 public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null,
                          MbTilesType type = MbTilesType.None, string name = DefaultName)
     : this(new MbTilesProvider(connectionString, schema, type), name)
 {
 }
コード例 #6
0
ファイル: MbTilesTileSource.cs プロジェクト: galchen/brutile
 internal MbTilesTileSource(SqliteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _tileSource = new MbTilesProvider(connection, schema, type);
 }
コード例 #7
0
ファイル: MbTilesTileSource.cs プロジェクト: galchen/brutile
 public MbTilesTileSource(string file, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
     : this(new SqliteConnection(string.Format("Data Source={0}", new Uri(file))), schema, type)
 {
 }
コード例 #8
0
ファイル: MbTilesTileSource.cs プロジェクト: galchen/brutile
 internal MbTilesTileSource(SqliteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _tileSource = new MbTilesProvider(connection, schema, type);
 }
コード例 #9
0
ファイル: MbTilesTileSource.cs プロジェクト: galchen/brutile
 public MbTilesTileSource(string file, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
     : this(new SqliteConnection(string.Format("Data Source={0}", new Uri(file))), schema, type)
 {
 }
コード例 #10
0
ファイル: MbTilesProvider.cs プロジェクト: bertt/BruTile
 internal MbTilesProvider(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _cache = new MbTilesCache(connectionString, schema, type);
 }
コード例 #11
0
ファイル: MbTilesTileSource.cs プロジェクト: bertt/BruTile
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="connectionString">The MapBox tiles file</param>
 /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param>
 /// <param name="type">The type of the MapBox tiles file</param>
 public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
     : this(new MbTilesProvider(connectionString, schema, type))
 {
 }
コード例 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionString">The connection string to the mbtiles file</param>
        /// <param name="schema">The TileSchema of the mbtiles file. If this parameter is set the schema information
        /// within the mbtiles file will be ignored. </param>
        /// <param name="type">BaseLayer or Overlay</param>
        /// <param name="determineZoomLevelsFromTilesTable">When 'determineZoomLevelsFromTilesTable' is true the zoom levels
        /// will be determined from the available tiles in the 'tiles' table. This operation can take long if there are many tiles in
        /// the 'tiles' table. When 'determineZoomLevelsFromTilesTable' is false the zoom levels will be read from the metadata table
        ///(by reading 'zoommin' and 'zoommax'). If there are no zoom levels specificied in the metadata table the GlobalSphericalMercator
        ///default levels are assumed. This parameter will have no effect if the schema is passed in as argument. The default is false.</param>
        /// <param name="determineTileRangeFromTilesTable">In some cases not all tiles specified by the schema are present in each
        /// level. When 'determineTileRangeFromTilesTable' is 'true' the range of tiles available for each level is determined
        /// by the tiles present for each level in the 'tiles' table. The advantage is that requests can be faster because they do not have to
        /// go to the database if they are outside the TileRange. The downside is that for large files it can take long to read the TileRange
        /// from the tiles table. The default is false.</param>
        public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type  = MbTilesType.None,
                                 bool determineZoomLevelsFromTilesTable = false, bool determineTileRangeFromTilesTable = false)
        {
            _connectionString = connectionString;

            using (var connection = new SQLiteConnectionWithLock(connectionString))
                using (connection.Lock())
                {
                    Schema      = schema ?? ReadSchemaFromDatabase(connection, determineZoomLevelsFromTilesTable);
                    Type        = type == MbTilesType.None ? ReadType(connection) : type;
                    Version     = ReadString(connection, "version");
                    Attribution = new Attribution(ReadString(connection, "attribution"));
                    Description = ReadString(connection, "description");
                    Name        = ReadString(connection, "name");
                    Json        = ReadString(connection, "json");
                    Compression = ReadString(connection, "compression");

                    if (determineTileRangeFromTilesTable)
                    {
                        // the tile range should be based on the tiles actually present.
                        var zoomLevelsFromDatabase = Schema.Resolutions.Select(r => r.Key);
                        _tileRange = ReadTileRangeForEachLevelFromTilesTable(connection, zoomLevelsFromDatabase);
                    }
                }
        }
コード例 #13
0
ファイル: MbTilesTileSource.cs プロジェクト: huhen/BruTile
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="connection">The connection to the MapBox tiles file</param>
 /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param>
 /// <param name="type">The type of the MapBox tiles file</param>
 public MbTilesTileSource(SQLiteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
     : this(new MbTilesProvider(connection, schema, type))
 {
 }
コード例 #14
0
ファイル: MbTilesTileSource.cs プロジェクト: huhen/BruTile
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="file">The MapBox tiles file</param>
 /// <param name="schema">The tile schema (should be of <see cref="GlobalMercator"/></param>
 /// <param name="type">The type of the MapBox tiles file</param>
 public MbTilesTileSource(string file, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
     : this(new SQLiteConnection($"Data Source={file}"), schema, type)
 {
 }
コード例 #15
0
 internal MbTilesProvider(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _cache = new MbTilesCache(connectionString, schema, type);
 }
コード例 #16
0
ファイル: MbTilesProvider.cs プロジェクト: galchen/brutile
 public MbTilesProvider(SqliteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _cache = new MbTilesCache(connection, schema, type);
 }
コード例 #17
0
 public MbTilesProvider(SQLiteConnection connection, ITileSchema schema = null, MbTilesType type = MbTilesType.None)
 {
     _cache = new MbTilesCache(connection, schema, type);
 }
コード例 #18
0
        public MbTilesTileSource(SQLiteConnectionString connectionString, ITileSchema schema = null, MbTilesType type = MbTilesType.None, bool tileRangeOptimization = true)
        {
            _connectionString = connectionString;
            if (tileRangeOptimization || schema == null)
            {
                using (var connection = new SQLiteConnectionWithLock(connectionString))
                    using (connection.Lock())
                    {
                        Type = type == MbTilesType.None ? ReadType(connection) : type;
                        var schemaFromDatabase = ReadSchemaFromDatabase(connection);
                        Schema = schema ?? schemaFromDatabase;

                        // Read other stuff
                        Version     = ReadString(connection, "version");
                        Attribution = new Attribution(ReadString(connection, "attribution"));
                        Description = ReadString(connection, "description");
                        Name        = ReadString(connection, "name");
                        Json        = ReadString(connection, "json");
                        Compression = ReadString(connection, "compression");

                        var zoomMin = ReadInt(connection, "minzoom");
                        ZoomMin = zoomMin < 0 ? 0 : zoomMin;

                        var zoomMax = ReadInt(connection, "maxzoom");
                        ZoomMax = zoomMax < 0 ? int.MaxValue : zoomMax;

                        // the tile range should be based on the tiles actually present.
                        var zoomLevelsFromDatabase = schemaFromDatabase.Resolutions.Select(r => r.Key);
                        _tileRange = ReadZoomLevelsFromTilesTable(connection, zoomLevelsFromDatabase);
                    }
            }
            else
            {
                Schema     = schema;
                _tileRange = null;
            }
        }