27.1.2. 数据库
27.1.2.1. 导出到PostgreSQL
将矢量图层导出到PostgreSQL数据库,从而创建新关系。如果存在同名关系,则可以在创建新关系之前将其删除。在此之前,必须在QGIS和PostgreSQL数据库之间创建连接(请参阅 创建存储的连接 )。
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Layer to import |
|
[vector: any] |
要添加到数据库的矢量图层 |
Database (connection name) |
|
[string] |
数据库连接的名称(不是数据库名称)。现有连接将显示在组合框中。 |
Schema (schema name) 任选 |
|
[string] 默认值:‘PUBLIC’ |
存储数据的架构的名称。它可以是新的,也可以已经存在。 |
Table to import to (leave blank to use layer name) 任选 |
|
[string] 默认:‘’ |
定义导入的矢量文件的表名。如果未添加任何内容,则将使用层名称。 |
Primary key field 任选 |
|
[tablefield: any] |
从矢量层中的现有字段设置主键字段。一列带有 unique 值可以用作数据库的主键。 |
Geometry column |
|
[string] 默认:‘Geom’ |
定义新的PostGIS表中几何图形列的名称。要素的几何图形信息存储在此列中。 |
Encoding 任选 |
|
[string] 默认:‘UTF-8’ |
定义输出图层的编码 |
Overwrite |
|
[boolean] 默认值:True |
如果指定的表存在,则将此选项设置为 |
Create spatial index |
|
[boolean] 默认值:True |
指定是否创建空间索引 |
Convert field names to lowercase |
|
[boolean] 默认值:True |
将输入矢量图层的字段名称转换为小写 |
Drop length constraint on character fields |
|
[boolean] 默认:FALSE |
是否应取消对字符字段的长度限制 |
Create single-part geometries instead of multi-part |
|
[boolean] 默认:FALSE |
输出层的特征是否应该是单部分而不是多部分。默认情况下,保留现有的几何信息。 |
产出
该算法没有输出。
Python代码
Algorithm ID : qgis:importintopostgis
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。
27.1.2.2. 导出到SpatiaLite
将矢量图层导出到SpatiaLite数据库。在此之前,必须在QGIS和SpatiaLite数据库之间创建连接(请参见 SpatiaLite层 )。
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Layer to import |
|
[vector: any] |
要添加到数据库的矢量图层 |
File database |
|
[vector: any] |
要连接到的SQLite/SpatiaLite数据库文件 |
Table to import to (leave blank to use layer name) 任选 |
|
[string] 默认:‘’ |
定义导入的矢量文件的表名。如果未指定任何内容,则将使用层名称。 |
Primary key field 任选 |
|
[tablefield: any] |
使用输入矢量图层中的字段作为主键 |
Geometry column |
|
[string] 默认:‘Geom’ |
定义新SpatiaLite表中几何图形列的名称。要素的几何图形信息存储在此列中。 |
Encoding 任选 |
|
[string] 默认:‘UTF-8’ |
定义输出图层的编码 |
Overwrite |
|
[boolean] 默认值:True |
如果指定的表存在,则将此选项设置为 |
Create spatial index |
|
[boolean] 默认值:True |
指定是否创建空间索引 |
Convert field names to lowercase |
|
[boolean] 默认值:True |
将输入矢量图层的字段名称转换为小写 |
Drop length constraint on character fields |
|
[boolean] 默认:FALSE |
是否应取消对字符字段的长度限制 |
Create single-part geometries instead of multi-part |
|
[boolean] 默认:FALSE |
输出层的特征是否应该是单部分而不是多部分。默认情况下,保留现有的几何信息。 |
产出
该算法没有输出。
Python代码
Algorithm ID : qgis:importintospatialite
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。
27.1.2.3. 包层
将图层添加到GeoPackage。
如果GeoPackage存在并且 Overwrite existing GeoPackage
选中后,它将被覆盖(删除并重新创建)。如果GeoPackage存在并且 Overwrite existing GeoPackage
未选中,则将附加层。
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Input layers |
|
[vector: any] [list] |
要导入到GeoPackage中的(矢量)层。不支持栅格层。如果添加了栅格层,则 |
Overwrite existing GeoPackage |
|
[boolean] 默认:FALSE |
如果指定的GeoPackage存在,则将此选项设置为 |
Save layer styles into GeoPackage |
|
[boolean] 默认值:True |
保存层样式 |
Save only selected features |
|
[boolean] 默认:FALSE |
如果某个层具有选定内容,则将此选项设置为 |
Export related layers following relations defined in the project |
|
[boolean] 默认:FALSE |
如果输入层具有 relations 在项目中设置,并将此选项设置为 |
Destination GeoPackage |
|
[file] 默认: |
指定存储GeoPackage文件的位置。其中之一
|
产出
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Layers within new package |
|
[string] [list] |
添加到GeoPackage的图层列表。 |
Python代码
Algorithm ID : native:package
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。
27.1.2.4. PostgreSQL执行和加载SQL
允许在连接到QGIS的PostgreSQL数据库上执行SQL数据库查询并加载结果。该算法 won't 创建一个新层:它旨在对层本身运行查询。
Example
将现有字段的所有值设置为固定值。SQL查询字符串将为:
UPDATE your_table SET field_to_update=20;
在上例中,该字段的值
field_to_update
餐桌上的your_table
将全部设置为20
。创建新的
area
列,并使用ST_AREA
邮政地理信息系统功能。-- Create the new column "area" on the table your_table" ALTER TABLE your_table ADD COLUMN area double precision; -- Update the "area" column and calculate the area of each feature: UPDATE your_table SET area=ST_AREA(geom);
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Database (connection name) |
|
[string] |
数据库连接(不是数据库名称)。现有连接将显示在组合框中。 |
SQL query |
|
[string] |
定义SQL查询,例如 |
Unique ID field name |
|
[string] 默认:ID |
设置主键字段(结果表中的一列) |
Geometry field name 任选 |
|
[string] 默认:‘Geom’ |
几何图形列的名称(结果表中的列) |
产出
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
SQL layer |
|
[vector: any] |
生成的要加载到QGIS中的矢量图层。 |
Python代码
Algorithm ID : qgis:postgisexecuteandloadsql
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。
27.1.2.5. PostgreSQL执行SQL
允许在连接到QGIS的PostgreSQL数据库上执行SQL数据库查询。该算法 won't 创建一个新层:它旨在对层本身运行查询。
Example
将现有字段的所有值设置为固定值。SQL查询字符串将为:
UPDATE your_table SET field_to_update=20;
在上例中,该字段的值
field_to_update
餐桌上的your_table
将全部设置为20
。创建新的
area
列,并使用ST_AREA
邮政地理信息系统功能。-- Create the new column "area" on the table your_table" ALTER TABLE your_table ADD COLUMN area double precision; -- Update the "area" column and calculate the area of each feature: UPDATE your_table SET area=ST_AREA(geom);
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Database (connection name) |
|
[string] |
数据库连接(不是数据库名称)。现有连接将显示在组合框中。 |
SQL query |
|
[string] |
定义SQL查询,例如 |
产出
不会创建任何输出。SQL查询就地执行。
Python代码
Algorithm ID : native:postgisexecutesql
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。
27.1.2.6. SpatiaLite执行SQL
允许在SpatiaLite数据库上执行SQL数据库查询。该算法 won't 创建一个新层:它旨在对层本身运行查询。
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
File Database |
|
[vector] |
要连接到的SQLite/SpatiaLite数据库文件 |
SQL query |
|
[string] 默认:‘’ |
定义SQL查询,例如 |
产出
不会创建任何输出。SQL查询就地执行。
Python代码
Algorithm ID : native:spatialiteexecutesql
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。
27.1.2.7. SpatiaLite执行SQL(注册数据库)
允许在连接到QGIS的SpatiaLite数据库上执行SQL数据库查询。该算法 won't 创建一个新层:它旨在对层本身运行查询。
参数
标签 |
名字 |
类型 |
描述 |
---|---|---|---|
Database |
|
[enumeration] 默认:未设置 |
选择连接到当前会话的SQLite/SpatiaLite数据库 |
SQL query |
|
[string] 默认:‘’ |
定义SQL查询,例如 |
产出
不会创建任何输出。SQL查询就地执行。
Python代码
Algorithm ID : native:spatialiteexecutesqlregistered
import processing
processing.run("algorithm_id", {parameter_dictionary})
这个 algorithm id 当您将鼠标悬停在处理工具箱中的算法上时,将显示。这个 parameter dictionary 提供参数名称和值。看见 从控制台使用处理算法 有关如何从Python控制台运行处理算法的详细信息。