13.2. レイヤーを作成する

Layers can be created in many ways, including:

  • empty layers from scratch

  • layers from existing layers

  • layers from the clipboard

  • layers as a result of an SQL-like query based on one or many layers (virtual layers)

QGIS also provides tools to import/export from/to different formats.

13.2.1. Creating new vector layers

QGIS allows you to create new layers in different formats. It provides tools for creating GeoPackage, Shapefile, SpatiaLite, GPX format and Temporary Scratch layers (aka memory layers). Creation of a new GRASS layer is supported within the GRASS plugin.

13.2.1.1. Creating a new GeoPackage layer

To create a new GeoPackage layer, press the newGeoPackageLayer New GeoPackage Layer... button in the Layer ‣ Create Layer ‣ menu or from the Data Source Manager toolbar. The New GeoPackage Layer dialog will be displayed as shown in figure_create_geopackage.

../../../_images/editNewGeoPackage.png

図 13.13 Creating a New GeoPackage layer dialog

  1. The first step is to indicate the database file location. This can be done by pressing the ... button to the right of the Database field and select an existing GeoPackage file or create a new one. QGIS will automatically add the right extension to the name you provide.

  2. Give the new layer / table a name (Table name)

  3. Define the Geometry type. If not a geometryless layer, you can specify whether it should Include Z dimension and/or Include M values.

  4. Specify the coordinate reference system using the setProjection button

To add fields to the layer you are creating:

  1. Enter the Name of the field

  2. Select the data Type. Supported types are Text data, Whole number (both integer and integer64), Decimal number, Date and Date and time, Binary (BLOB) and Boolean.

  3. Depending on the selected data format, enter the Maximum length of values.

  4. Click on the newAttribute Add to Fields List button

  5. Reproduce the steps above for each field you need to add

  6. Once you are happy with the attributes, click OK. QGIS will add the new layer to the legend, and you can edit it as described in section 既存レイヤーのデジタイズ.

By default, when creating a GeoPackage layer, QGIS generates a Feature id column called fid which acts as the primary key of the layer. The name can be changed. The geometry field, if availabe, is named geometry, and you can choose to Create a spatial index on it. These options can be found under the Advanced Options together with the Layer identifier (short human readable name of the layer) and the Layer description.

Further management of GeoPackage layers can be done with the DB Manager.

13.2.1.2. 新しいシェープファイルレイヤーを作成する

To create a new ESRI Shapefile format layer, press the newVectorLayer New Shapefile Layer... button in the Layer ‣ Create Layer ‣ menu or from the Data Source Manager toolbar. The New Shapefile Layer dialog will be displayed as shown in figure_create_shapefile.

  1. Provide a path and file name using the ... button next to File name. QGIS will automatically add the right extension to the name you provide.

  2. Next, indicate the File encoding of the data

  3. Choose the Geometry type of the layer (point, multipoint, line or polygon)

  4. Specify whether the geometry should have Z (+ M values) or M values

  5. Specify the coordinate reference system using the setProjection button

../../../_images/editNewVector.png

図 13.14 新しいシェープファイルレイヤーを作成するダイアログ

To add fields to the layer you are creating:

  1. Enter the Name of the field

  2. Select the data Type. Only Decimal number, Whole number, Text data and Date attributes are supported.

  3. Depending on the selected data format, enter the Length and Precision.

  4. Click on the newAttribute Add to Fields List button

  5. Reproduce the steps above for each field you need to add

  6. Once you are happy with the attributes, click OK. QGIS will add the new layer to the legend, and you can edit it as described in section 既存レイヤーのデジタイズ.

By default, a first integer id column is added but can be removed.

13.2.1.3. 新しいSpatiaLiteレイヤーを作成する

To create a new SpatiaLite layer, press the newSpatiaLiteLayer New SpatiaLite Layer... button in the Layer ‣ Create Layer ‣ menu or from the Data Source Manager toolbar. The New SpatiaLite Layer dialog will be displayed as shown in Figure_create_spatialite.

../../../_images/editNewSpatialite.png

図 13.15 新SpatiaLiteレイヤーダイアログを作成する

  1. The first step is to indicate the database file location. This can be done by pressing the ... button to the right of the Database field and select an existing SpatiaLite file or create a new one. QGIS will automatically add the right extension to the name you provide.

  2. Provide a name (Layer name) for the new layer

  3. Define the Geometry type. If not a geometryless layer, you can specify whether it should Include Z dimension and/or Include M values.

  4. Specify the coordinate reference system using the setProjection button.

To add fields to the layer you are creating:

  1. Enter the Name of the field

  2. Select the data Type. Supported types are Text data, Whole number and Decimal number.

  3. Click on the newAttribute Add to Fields List button

  4. Reproduce the steps above for each field you need to add

  5. Once you are happy with the attributes, click OK. QGIS will add the new layer to the legend, and you can edit it as described in section 既存レイヤーのデジタイズ.

If desired, you can select checkbox Create an autoincrementing primary key under the guilabel:Advanced Options section. You can also rename the Geometry column (geometry by default).

Further management of SpatiaLite layers can be done with DB Manager.

13.2.1.4. 新しいGPXレイヤーを作成する

To create a new GPX file, you first need to load the GPS plugin. Plugins ‣ showPluginManager Plugin Manager... opens the Plugin Manager Dialog. Activate the checkbox GPS Tools checkbox.

When this plugin is loaded, choose Create Layer ‣ createGPX Create new GPX Layer... from the Layer menu. In the dialog, choose where to save the new file and press Save. Three new layers are added to the Layers Panel: waypoints, routes and tracks.

13.2.1.5. 新しい一時的な落書きレイヤーを作成する

Temporary Scratch Layers are in-memory layers, meaning that they are not saved on disk and will be discarded when QGIS is closed. They can be handy for storing features you temporarily need or as intermediate layers during geoprocessing operations.

To create a new Temporary Scratch layer, choose the createMemory New Temporary Scratch Layer... entry in the Layer ‣ Create Layer ‣ menu or in the Data Source Manager toolbar. The New Temporary Scratch Layer dialog will be displayed as shown in figure_create_temporary. Then:

  1. Provide the Layer name

  2. Select the Geometry type. Here you can create a:

    • No geometry type layer, served as simple table,

    • Point or MultiPoint layer,

    • LineString/CompoundCurve or MultiLineString/MultiCurve layer,

    • Polygon/CurvePolygon or MultiPolygon/MultiSurface layer.

  3. Specify the coordinate reference system using the setProjection button.

../../../_images/editNewTemporaryLayer.png

図 13.16 Creating a new Temporary Scratch layer dialog

By default, a new temporary scratch layer is created without any attributes. You can later add them using the newAttribute New Field button in the layer's attribute table dialog or the Fields tab of its properties dialog. You can also create prepopulated temporary scratch layers using e.g. the clipboard (see Creating new layers from the clipboard) or as a result of a Processing algorithm.

ちなみに

Permanently store a memory layer on disk

To avoid data loss when closing a project with temporary scratch layers, you can save these layers to any vector format supported by QGIS:

  • clicking the indicatorMemory indicator icon next to the layer;

  • selecting the Make permanent entry in the layer contextual menu;

  • using the Export ‣ entry from the contextual menu or the Layer ‣ Save As... menu.

Each of these commands opens the Save Vector Layer as dialog described in the Creating new layers from an existing layer section and the saved file replaces the temporary one in the Layers panel.

13.2.2. Creating new layers from an existing layer

Both raster and vector layers can be saved in a different format and/or reprojected to a different coordinate reference system (CRS) using the Layer ‣ Save As... menu or right-clicking on the layer in the Layers panel and selecting:

  • Export ‣ Save As... for raster layers

  • Export ‣ Save Features As... or Export ‣ Save Selected Features As... for vector layers.

  • Drag and drop the layer from the layer tree to the PostGIS entry in the Browser Panel. Note that you must have a PostGIS connection in the Browser Panel.

13.2.2.1. 一般的なパラメーター

The Save Layer as... dialog shows several parameters to change the behavior when saving the layer. Among the common parameters for raster and vector are:

  • File name: the location of the file on the disk. It can refer to the output layer or to a container that stores the layer (for example database-like formats such as GeoPackage, SpatiaLite or Open Document Spreadsheets).

  • CRS: can be changed to reproject the data

  • 範囲 (可能な値は レイヤー地図ビュー または ユーザー定義 範囲)

  • Add saved file to map: to add the new layer to the canvas

しかし、ラスター形式とベクター形式に固有のパラメーターもあります:

13.2.2.2. ラスター特定のパラメーター

Depending on the format of export, some of these options may not be available:

  • 出力モード (それができる 生データ または レンダリングされた画像

  • Format: exports to any raster format GDAL can write to, such as GeoTiff, GeoPackage, MBTiles, Geospatial PDF, SAGA GIS Binary Grid, Intergraph Raster, ESRI .hdr Labelled...

  • 解像度

  • Create Options: use advanced options (file compression, block sizes, colorimetry...) when generating files, either from the predefined create profiles related to the output format or by setting each parameter.

  • ピラミッド 作成

  • VRT Tiles in case you opted to checkbox Create VRT

  • データ値なし

../../../_images/saveasraster.png

図 13.17 新しいラスターレイヤーとして保存する

13.2.2.3. ベクター固有のパラメーター

Depending on the format of export, some of these options may be available:

  • Format: exports to any vector format GDAL can write to, such as GeoPackage, GML, ESRI Shapefile, AutoCAD DXF, ESRI FileGDB, Mapinfo TAB or MIF, SpatiaLite, CSV, KML, ODS, ...

  • Layer name: available when the File name refers to a container-like format, this entry represents the output layer.

  • エンコード

  • 選択地物のみ保存

  • エクスポートするフィールドとそのエクスポートオプションを選択編集ウィジェット ケースでは、いくつかのフィールドの動作を設定します、例えば 値マップ 、チェックすることにより、レイヤー中に表示される値を保つことができます checkbox 値を表示 によって選択されたすべての生のフィールドの値を交換してください。

  • シンボルをエクスポート :主にDXFのエクスポートのためと、DXF、KML、タブのファイル形式としてOGR地物のスタイル(下記の注を参照)を管理するすべてのファイル形式のために使用できます:

    • シンボルなし :データを読み込み、アプリケーションのデフォルトのスタイル

    • 地物シンボル :OGR地物スタイルによるスタイルの保存(下記を参照)

    • シンボルレイヤーシンボル :OGR地物スタイルで保存(下記の注を参照)が、使用される複数のシンボルのシンボルレイヤーが存在する場合、同じジオメトリを複数回エクスポート

    • A Scale value can be applied to the latest options

注釈

OGR Feature Styles are a way to store style directly in the data as a hidden attribute. Only some formats can handle this kind of information. KML, DXF and TAB file formats are such formats. For advanced details, you can read the OGR Feature Styles specification document.

  • ジオメトリ :出力レイヤーの幾何学的機能を設定できます

    • geometry type: keeps the original geometry of the features when set to Automatic, otherwise removes or overrides it with any type. You can add an empty geometry column to an attribute table and remove the geometry column of a spatial layer.

    • Force multi-type: forces creation of multi-geometry features in the layer.

    • ジオメトリに Z次元を含める

ちなみに

Overriding layer geometry type makes it possible to do things like save a geometryless table (e.g. .csv file) into a shapefile WITH any type of geometry (point, line, polygon), so that geometries can then be manually added to rows with the addPart Add Part tool.

  • Datasource Options, Layer Options or Custom Options which allow you to configure advanced parameters depending on the output format. Some are described in データフォーマットとフィールドを書き出す but for full details, see the GDAL driver documentation. Each file format has its own custom parameters, e.g. for the GeoJSON format have a look at the GDAL GeoJSON documentation.

../../../_images/saveasvector.png

図 13.18 新しいベクターレイヤーとして保存する

出力形式の能力(Geopackage、SpatiaLite、FileGDB ...)に応じて、既存のファイルへのベクターレイヤーを保存するとき、ユーザーは以下にするかどうかを決めることができます:

  • 全体のファイルを上書き

  • ターゲットレイヤーだけを上書き(レイヤー名は設定可能です)

  • 既存のターゲットレイヤーに地物を追加

  • 地物を追加し、いずれかが存在する場合、新しいフィールドを追加します。

ESRIシェープファイル、のMapInfo .TABのような形式の場合、地物追記も可能です。

13.2.3. Creating new DXF files

Besides the Save As... dialog which provides options to export a single layer to another format, including *.DXF, QGIS provides another tool to export multiple layers as a single DXF layer. It's accessible in the Project ‣ Import/Export ‣ Export Project to DXF... menu.

In the DXF Export dialog:

  1. Provide the destination file.

  2. Choose the symbology mode and scale (see the OGR Feature Styles note), if applicable.

  3. Select the data Encoding.

  4. Select the CRS to apply: the selected layers will be reprojected to the given CRS.

  5. Select the layers to include in the DXF files either by checking them in the table widget or automatically picking them from an existing map theme. The Select All and Deselect All buttons can help to quickly set the data to export.

    For each layer, you can choose whether to export all the features in a single DXF layer or rely on a field whose values are used to split the features into layers in the DXF output.

Optionally, you can also choose to:

  • checkbox Use the layer title as name if set instead of the layer name itself;

  • checkbox Export features intersecting the current map extent;

  • unchecked Force 2d output (eg. to support polyline width);

  • checkbox Export label as MTEXT elements or TEXT elements.

../../../_images/export_dxf.png

図 13.19 Exporting a project to DXF dialog

13.2.4. Creating new layers from the clipboard

クリップボードにある地物は、新しいレイヤーに貼り付けできます。これを行うには、いくつかの地物を選択し、クリップボードにコピーし、 編集 ‣ 形式を選択して地物を貼り付け ‣ を使用して新しいレイヤーに貼り付け、以下を選択します:

A new layer, filled with selected features and their attributes is created (and added to map canvas).

注釈

Creating layers from the clipboard is possible with features selected and copied within QGIS as well as features from another application, as long as their geometries are defined using well-known text (WKT).

13.2.5. Creating virtual layers

A virtual layer is a special kind of vector layer. It allows you to define a layer as the result of an SQL query involving any number of other vector layers that QGIS is able to open. Virtual layers do not carry data by themselves and can be seen as views.

To create a virtual layer, open the virtual layer creation dialog by:

  • choosing the addVirtualLayer Add/Edit Virtual Layer entry in the Layer ‣ Add Layer ‣ menu;

  • enabling the addVirtualLayer Add Virtual Layer tab in the Data Source Manager dialog;

  • or using the DB Manager dialog tree.

The dialog allows you to specify a Layer name and an SQL Query. The query can use the name (or id) of loaded vector layers as tables, as well as their field names as columns.

airports と呼ばれるレイヤーを持っている場合たとえば、次のようなSQLクエリで public_airports と呼ばれる新しい仮想レイヤーを作成できます。

SELECT *
FROM airports
WHERE USE = "Civilian/Public"

The SQL query will be executed, regardless of the underlying provider of the airports layer, even if this provider does not directly support SQL queries.

../../../_images/create_virtual_layers.png

図 13.20 仮想レイヤーダイアログを作成します。

Joins and complex queries can also be created, for example, to join airports and country information:

SELECT airports.*, country.population
FROM airports
JOIN country
ON airports.country = country.name

注釈

DB Manager Plugin のSQLウィンドウを使用して仮想レイヤーを作成することも可能です。

13.2.5.1. Embedding layers for use in queries

Besides the vector layers available in the map canvas, the user can add layers to the Embedded layers list, which can be used in queries without the need to have them showing in the map canvas or Layers panel.

レイヤーを埋め込むには、 追加 をクリックし ローカル名プロバイダーエンコード および ソース へのパスを提供してください。

The Import button allows adding layers in the map canvas into the Embedded layers list. Those layers can then be removed from the Layers panel without breaking existent queries.

13.2.5.2. Supported query language

基本となるエンジンは動作するSQLiteのとSpatiaLiteを使用しています。

それはSQLiteのローカルインストールが理解SQLのすべてを使用できることを意味します。

SQLiteのとSpatiaLiteから空間関数から関数も仮想レイヤーのクエリで使用できます。例えば、属性のみのレイヤーのうちポイントレイヤーを作成することに類似したクエリを実行できます。

SELECT id, MakePoint(x, y, 4326) as geometry
FROM coordinates

QGIS式の関数 も仮想レイヤーのクエリ中で使用できます。

レイヤーのジオメトリ列を参照するため、名前 geometry を使用します。

Contrary to a pure SQL query, all the fields of a virtual layer query must be named. Don't forget to use the as keyword to name your columns if they are the result of a computation or a function call.

13.2.5.3. パフォーマンスの問題

With default parameters, the virtual layer engine will try its best to detect the type of the different columns of the query, including the type of the geometry column if one is present.

This is done by introspecting the query when possible or by fetching the first row of the query (LIMIT 1) as a last resort. Fetching the first row of the result just to create the layer may be undesirable for performance reasons.

The creation dialog parameters:

  • Unique identifier column: specifies a field of the query that represents unique integer values that QGIS can use as row identifiers. By default, an autoincrementing integer value is used. Defining a unique identifier column speeds up the selection of rows by id.

  • No geometry: forces the virtual layer to ignore any geometry field. The resulting layer is an attribute-only layer.

  • Geometry Column: specifies the name of the geometry column.

  • Geometry Type: specifies the type of the geometry.

  • Geometry CRS: specifies the coordinate reference system of the virtual layer.

13.2.5.4. 特別のコメント

仮想レイヤーエンジンは、クエリの各列のタイプを決定しようとします。それが失敗した場合、クエリの最初の行は、列の型を決定するためにフェッチされます。

特定の列の種類はいくつかの特別なコメントを使用することでクエリ中で直接指定できます。

構文は次のようです: /*:type*/ 。それはちょうど列の名前の後に配置する必要があります。 type は、整数の int 、浮動小数点数または text ための real のいずれかであり得ます。

例えば:

SELECT id+1 as nid /*:int*/
FROM table

ジオメトリ列の種類と座標参照系はまた、次の構文 /*:gtype:srid*/ を持つ特殊コメントのおかげで設定できます。ここで gtype はジオメトリタイプ( pointlinestringpolygonmultipointmultilinestring または multipolygon )であり srid は座標参照系のEPSGコードを表す整数です。

13.2.5.5. 索引の使用

When requesting a layer through a virtual layer, the source layer indices will be used in the following ways:

  • = 述語は、レイヤーの主キー列で使用される場合、基礎となるデータプロバイダーは、特定のID(FilterFid)を要求します

  • 他の述語( ><=!= など)または主キーのない列に対しては、式から構築された要求が基礎となるベクターデータプロバイダーを要求するために使用されます。それは、索引が存在する場合にそれらをデータベース・プロバイダーで使用できることを意味します。

具体的な構文が、リクエストで空間述語を処理し、空間索引の使用をトリガするために存在します: _search_frame_ という名前の非表示の列が各仮想レイヤーに対して存在します。この列はバウンディングボックスに等しいかどうかを比較できます。例:

SELECT *
FROM vtab
WHERE _search_frame_=BuildMbr(-2.10,49.38,-1.3,49.99,4326)

Spatial binary predicates like ST_Intersects are sped up significantly when used in conjunction with this spatial index syntax.