0

C# Xaml で Windows ストア (8.1) アプリを実行して、mbtiles ファイルを含む C# 拡張機能の Bing Maps を使用してマップを生成しています。すでにプロジェクト Portable Basemap Server を使用して作業を行っていますが、今はアクセスしようとしていますmbtiles ファイルのデータを自分で SQLite を使用して作成しました。

私は WPF でその種のファイルからタイルを取得することができましたが、Windows ストア プロジェクトでそれを行う方法がわかりません。

WPF の私のコード:

        SQLiteConnection _sqlcon;
        using (_sqlcon = new SQLiteConnection(String.Format("Data Source={0};Version=3;", "PATH_TO_MBTILES")))
        {
            _sqlcon.Open();
            SQLiteCommand cmd = new SQLiteCommand(string.Format("SELECT tile_data FROM tiles WHERE tile_column={0} AND tile_row={1} AND zoom_level={2}", 2, 5, 3), _sqlcon);
            object o = cmd.ExecuteScalar();

            if (o != null)
            {
                byte[] c = (byte[])o;
                using (MemoryStream stream = new MemoryStream(c))
                {
                    BitmapImage bmp = new BitmapImage();
                    bmp.BeginInit();
                    bmp.CacheOption = BitmapCacheOption.OnLoad;
                    bmp.StreamSource = stream;
                    bmp.EndInit();
                    img.Source = bmp;
                }
            }
        }

そのコードで、列 2、行 5、ズーム レベル 3 のタイルを取得します。

しかし、Windowsストアアプリでは、同じファイルを作成しようとすると、「データベースファイルを開けませんでした」というSQLiteExceptionが発生しSQLiteConnectionます(NuGet sqlite-netとSqLite for Windows Runtime 8.1拡張機能を使用しています)

Windowsストアアプリの私のコード:

        SQLiteConnection _sqlcon;
        using (_sqlcon = new SQLiteConnection(String.Format("Data Source={0};Version=3;", "PATH_TO_MBTILES"))) //SQLiteExeption here
        {
            SQLiteCommand cmd = new SQLiteCommand(string.Format("SELECT tile_data FROM tiles WHERE tile_column={0} AND tile_row={1} AND zoom_level={2}", 2, 5, 3), _sqlcon);
            byte[] o = cmd.ExecuteScalar<byte[]>();
            //etc...
        }

Visual Studio のデバッガーから、 sqlite-net NuGet の SQLite.cs ファイルが表示されます。

    public SQLiteConnection (string databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = false)
    {
        if (string.IsNullOrEmpty (databasePath))
            throw new ArgumentException ("Must be specified", "databasePath");

        DatabasePath = databasePath;

#if NETFX_CORE
        SQLite3.SetDirectory(/*temp directory type*/2, Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);
#endif

        Sqlite3DatabaseHandle handle;

#if SILVERLIGHT || USE_CSHARP_SQLITE
        var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);
#else
        // open using the byte[]
        // in the case where the path may include Unicode
        // force open to using UTF-8 using sqlite3_open_v2
        var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
        var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);
#endif

        Handle = handle;
        if (r != SQLite3.Result.OK) {
            throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
        }
        _open = true; // Debugger Stops here !

        StoreDateTimeAsTicks = storeDateTimeAsTicks;

        BusyTimeout = TimeSpan.FromSeconds (0.1);
    }

WPF で使用される mbtiles ファイルの例は多数見つかりましたが、Windows ストア アプリでは見つかりませんでした。

Windows ストア開発用の SQLite 拡張機能は、データベースとして MBTiles ファイルをサポートしていますか? はいの場合、私は何を間違っていますか?

4

1 に答える 1

0

Windows ストア アプリは、独自のディレクトリにのみアクセスできますが、管理者ユーザーのプライベート ファイルにはアクセスできません。

ドキュメントを読んでください。ただし、アプリの一部としてデータをインストールすることをお勧めします。

于 2015-04-10T13:22:23.907 に答える