28.2.1. DBマネージャプラグイン

DBマネージャプラグインは、QGISでサポートされている空間データベース形式(PostGIS、SpatiaLite、GeoPackage、Oracle Spatial、Virtual layers)を一つのユーザーインターフェースで統合し管理するメインツールとなることを意図しています。dbManager DBマネージャプラグイン はいくつかの機能を提供します。QGISブラウザからDBマネージャにレイヤをドラッグすると、レイヤを空間データベースにインポートすることができます。空間データベース間でテーブルをドラッグ&ドロップすることができ、それらはインポートされます。


図 28.4 [DBマネージャ]ダイアログ

データベース メニューでは、既存のデータベースへの接続、SQLウィンドウの起動、DBマネージャプラグインの終了を行うことができます。既存のデータベースに接続すると、 スキーマ (PostGIS / PostgreSQL などの DBMS に関連) と テーブル というメニューが表示されます。

The Schema menu includes tools to create and delete (only if empty) schemas and, if topology is available (e.g. with PostGIS topology), to start a TopoViewer.

The Table menu allows you to create and edit tables and to delete tables and views. It is also possible to empty tables and to move tables between schemas. You can Run Vacuum Analyze for the selected table. Vacuum reclaims space and makes it available for reuse, and analyze updates statistics that is used to determine the most efficient way to execute a query. Change Logging... allows you to add change logging support to a table. Finally, you can Import Layer/File... and Export to File....


Using the DB Manager it is possible to add comments for tables and columns of a PostgreSQL Database.

The Providers window lists all existing databases supported by QGIS. With a double-click, you can connect to the database. With the right mouse button, you can rename and delete existing schemas and tables. Tables can also be added to the QGIS canvas with the context menu.

If connected to a database, the main window of the DB Manager offers four tabs. The Info tab provides information about the table and its geometry, as well as about existing fields, constraints and indexes. It allows you to create a spatial index on a the selected table. The Table tab shows the table, and the Preview tab renders the geometries as preview. When you open an SQL Window, it will be placed in a new tab. Working with the SQL Window

You can use the DB Manager to execute SQL queries against your spatial database. Queries can be saved and loaded, and there the SQL Query Builder will help you formulate your queries. You can even view spatial output by checking Load as new layer and specifying Column(s) with unique values (IDs), Geometry column and Layer name (prefix). It is possible to highlight a portion of the SQL to only execute that portion when pressing Ctrl+R or clicking the Execute button.

The Query History button stores the last 20 queries of each database and provider.

Double clicking on an entry will add the string to the SQL window.


図 28.5 Executing SQL queries in the DB Manager SQL window


The SQL Window can also be used to create Virtual Layers. In that case, instead of selecting a database, select QGIS Layers under Virtual Layers before opening the SQL Window. See 仮想レイヤを作成する for instructions on the SQL syntax to use.