GPKG—地质包矢量

司机简称

GPKG

生成依赖项

libsqlite3

这个驱动程序实现了对 OGC GeoPackage format standard GeoPackage标准使用SQLite数据库文件作为通用容器,标准定义:

  • 需要元数据表 (gpkg_contentsgpkg_spatial_ref_sysgpkg_geometry_columns

  • 空间表中几何图形的二进制格式编码(基本上是GPKG标准头对象,后跟ISO标准众所周知的二进制(WKB))

  • 扩展名(扩展功能类型)和索引的命名和约定(如何以可互操作的方式使用SQLite r-tree)

此驱动程序从文件系统读取和写入SQLite文件,因此必须由对其使用的文件具有读/写访问权限的用户运行。

The driver also supports reading and writing the following non-linear geometry types: CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON, MULTICURVE and MULTISURFACE

GeoPackage raster/tiles are supported. See the GeoPackage raster documentation page.

驱动程序功能

Supports Create()

This driver supports the GDALDriver::Create() operation

Supports Georeferencing

This driver supports georeferencing

Supports VirtualIO

This driver supports virtual I/O operations (/vsimem/, etc.)

规范版本

从GDAL 2.2开始,驱动程序能够按照1.0/1.0.1、1.1或1.2版本创建GeoPackage数据库。对于GDAL2.2,它将自动调整到所用地质包功能所需的最低版本。对于GDAL 2.3或更高版本,它将默认为1.2。可以通过指定版本数据集创建选项来完成显式版本选择。

局限性

  • GeoPackage每个表只支持一个几何列。

SQL

驱动程序支持OGR属性过滤器,用户需要提供SQLite方言的过滤器,因为它们将直接针对数据库执行。

传递给ExecuteSQL()的SQL SELECT语句也直接针对数据库执行。如果使用Spatialite,则需要最新版本(4.2.0),并且需要使用显式cast操作符AsGPB()将GeoPackage几何体转换为Spatialite几何体(由GPKG驱动程序自动完成Spatialite几何体的反向转换)。也可以与任何Spatialite版本一起使用,但速度较慢,方法是指定“INDIRECTu SQLITE”方言。在这种情况下,地理包几何图形在OGR转换后自动显示为空间几何图形。

从GDAL 2.2开始,可以使用“DROP TABLE layer_name”和“ALTER TABLE layer_name RENAME TO new_layer”语句。他们将更新GeoPackage系统表。

从GDAL 2.2开始,“has spatial index('table_name','geom_col_name')”语句可用于检查表在命名几何列上是否有空间索引。

当删除表或从表中删除记录时,它们占用的空间不会立即释放并保存在文件页池中,供SQLite以后重用。如果需要将文件缩小到最小大小,则需要发出显式的“真空”SQL请求。请注意,这将导致文件的完全重写。

SQL函数

The following SQL functions, from the GeoPackage specification, are available:

  • ST_MinX(geom Geometry): returns the minimum X coordinate of the geometry

  • ST_MinY(geom Geometry): returns the minimum Y coordinate of the geometry

  • ST_MaxX(geom Geometry): returns the maximum X coordinate of the geometry

  • ST_MaxY(geom Geometry): returns the maximum Y coordinate of the geometry

  • ST_IsEmpty(geom Geometry): returns 1 if the geometry is empty (but not null), e.g. a POINT EMPTY geometry

  • ST_GeometryType(geom Geometry): returns the geometry type: 'POINT', 'LINESTRING', 'POLYGON', 'MULTIPOLYGON', 'MULTILINESTRING', 'MULTIPOINT', 'GEOMETRYCOLLECTION'

  • ST_SRID(geom Geometry): returns the SRID of the geometry

  • GPKG_不可分割(预期的_geom_类型 ,实际几何类型 ):主要用于“几何类型触发器扩展”

以下函数的语法和语义与Spatialite中的相同:

  • CreateSpatialIndex(table_name String, geom_column_name String): creates a spatial index (RTree) on the specified table/geometry column

  • DisableSpatialIndex(table_name String, geom_column_name String): drops an existing spatial index (RTree) on the specified table/geometry column

  • STU变换(geom 几何图形 ,目标u srsu id 整数 ):将几何体重新投影到指定SRSid的SRS。如果在gpkgU spatialU refU sys中找不到具有给定SRSid的SRS,则从GDAL 3.2开始,它将被解释为EPSG代码。

交易支持

驱动程序在数据库级别实现事务,根据 RFC 54:数据集事务

数据集打开选项

以下打开选项可用:

  • LIST_ALL_TABLES =AUTO/YES/NO:(GDAL>=2.2)是否应列出所有表,包括gpkg目录中未列出的表。默认为自动。如果是AUTO,则将列出所有表,包括未在gpkg_contents中列出的表,除非找到aspatial扩展名或表在gpkg_contents中注册为“attributes”。如果是,在所有情况下,将列出所有表格,包括gpkg目录中未列出的表格。如果没有,则只列出注册为“features”、“attributes”或“aspatial”的表。

  • PRELUDE_STATEMENTS =字符串(GDAL>=3.2)。在SQLite3连接上发送的SQL语句先于任何其他语句。如果有多个语句,则必须用半列(;)符号分隔。此选项可能有助于 attach another database 并发出跨数据库请求。

    备注

    附加的数据库也必须是GeoPackage数据库,以便正确识别其几何体blob(因此通常不是Spatialite数据库)

  • NOLOCK= YES/NO (GDAL >= 3.4.2). Defaults is NO. Whether the database should be used without doing any file locking. Setting it to YES will only be honoured when opening in read-only mode and if the journal mode is not WAL. This corresponds to the nolock=1 query parameter described at https://www.sqlite.org/uri.html

Note: open options are typically specified with "-oo name=value" syntax in most OGR utilities, or with the GDALOpenEx() API call.

Note: configuration option OGR_SQLITE_JOURNAL can be used to set the journal mode of the GeoPackage (and thus SQLite) file, see also https://www.sqlite.org/pragma.html#pragma_journal_mode.

创建问题

创建新的GeoPackage文件时,驱动程序将尝试强制数据库进入UTF-8模式进行文本处理,以满足OGR严格的UTF-8功能。对于预先存在的文件,驱动程序将使用给定的任何文件。

The driver updates the GeoPackage last_change timestamp when the file is created or modified. If consistent binary output is required for reproducibility, the timestamp can be forced to a specific value by setting the OGR_CURRENT_DATE global configuration option. When setting the option, take care to meet the specific time format requirement of the GeoPackage standard, e.g. for version 1.2.

数据集创建选项

以下创建选项(特定于矢量或与栅格公用)可用:

  • VERSION=AUTO/1.0/1.1/1.2/1.3: (GDAL >= 2.2) Set GeoPackage version (for application_id and user_version fields). In AUTO mode, this will be equivalent to 1.2 starting with GDAL 2.3. 1.3 is available starting with GDAL 3.3

  • ADD_GPKG_OGR_CONTENTS =YES/NO:(GDAL>=2.2)定义是否添加gpkg_ogr_contents表以保持功能计数,以及相关的触发器。默认为“是”。

  • DATETIME_FORMAT =WITHu TZ/UTC:(GDAL>=3.2)定义是保留数据源中使用的时区中的DateTime值(WITHu TZ),还是将日期和时间表达式转换为UTC(协调世界时)。默认为带u TZ。迂腐地说,GeoPackage v1.3当前不支持非UTC时区(请参阅https://github.com/opengeospatial/geopackage/issues/530). 使用UTC格式时,如果时区未指定,将假定为UTC。

Other options are available for raster. See the GeoPackage raster documentation page.

图层创建选项

以下图层创建选项可用:

  • GEOMETRY_NAME :用于几何列的列。默认为“geom”。注意:此选项在GDAL 2之前的版本中称为GEOMETRY_列

  • GEOMETRY_NULLABLE :geometry列的值是否可以为NULL。可以设置为“否”,以便需要几何图形。默认为“是”

  • FID :用于OGR FID(SQLite数据库中的主键)的列名。默认为“fid”

  • OVERWRITE :如果设置为“是”,将删除与正在创建的图层同名的任何现有图层。默认为否

  • SPATIAL_INDEX :如果设置为“是”,将为此层创建空间索引。默认为“是”

  • PRECISION :如果可以使用文本(宽度)类型,则这可能是“是”以强制在此层上创建的新字段尝试并表示文本字段的宽度(以UTF-8字符而不是字节表示)。如果“否”,则使用类型文本。默认值为“是”。

  • TRUNCATE_FIELDS :这可以是“是”以强制截断超过文本字段最大允许宽度的字段值,如果需要,还可以“修复”传递的字符串以使其成为有效的UTF-8字符串。如果“否”,则不会截断或修改该值。默认值为“否”。

  • IDENTIFIER =string:层的标识符,放在contents表中。

  • DESCRIPTION =string:层的描述,放在contents表中。

  • ASPATIAL_VARIANT=GPKG_ATTRIBUTES/NOT_REGISTERED: (GDAL >=2.2) How to register non spatial tables. Defaults to GPKG_ATTRIBUTES in GDAL 2.2 or later (behavior in previous version was equivalent to OGR_ASPATIAL). Starting with GeoPackage 1.2, non spatial tables are part of the specification. They are recorded with data_type="attributes" in the gpkg_contents table. This is only compatible of GDAL 2.2 or later. It is also possible to use the NOT_REGISTERED option, in which case the non spatial table is not registered at all in any GeoPackage system tables. Priorly, in OGR 2.0 and 2.1, the "aspatial" extension had been developed for similar purposes, so if selecting OGR_ASPATIAL, non spatial tables will be recorded with data_type="aspatial" and the "aspatial" extension was declared in the gpkg_extensions table. Starting with GDAL 3.3, OGR_ASPATIAL is no longer available on creation.

配置选项

The following configuration options are available:

  • OGR_SQLITE_JOURNAL can be used to set the journal mode of the GeoPackage (and thus SQLite) file, see also https://www.sqlite.org/pragma.html#pragma_journal_mode.

  • OGR_SQLITE_CACHE: see Performance hints.

  • OGR_SQLITE_SYNCHRONOUS: see Performance hints.

  • OGR_SQLITE_LOAD_EXTENSIONS =extension1,...,extensionN,ENABLE_SQL_LOAD_EXTENSION: (GDAL >= 3.5.0). Comma separated list of names of shared libraries containing extensions to load at database opening. If a file cannot be loaded directly, attempts are made to load with various operating-system specific extensions added. So for example, if "samplelib" cannot be loaded, then names like "samplelib.so" or "samplelib.dylib" or "samplelib.dll" might be tried also. The special value ENABLE_SQL_LOAD_EXTENSION can be used to enable the use of the SQL load_extension() function, which is normally disabled in standard builds of sqlite3. Loading extensions as a potential security impact if they are untrusted.

  • OGR_SQLITE_PRAGMA can be used to specify any SQLite pragma . The syntax is OGR_SQLITE_PRAGMA = "pragma_name=pragma_value[,pragma_name2=pragma_value2]*".

  • OGR_CURRENT_DATE: the driver updates the GeoPackage last_change timestamp when the file is created or modified. If consistent binary output is required for reproducibility, the timestamp can be forced to a specific value by setting this global configuration option. When setting the option, take care to meet the specific time format requirement of the GeoPackage standard, e.g. for version 1.2.

  • SQLITE_USE_OGR_VFS =YES enables extra buffering/caching by the GDAL/OGR I/O layer and can speed up I/O. More information here. Be aware that no file locking will occur if this option is activated, so concurrent edits may lead to database corruption.

元数据

GDAL使用标准 gpkg_metadatagpkg_metadata_reference 在数据集和图层对象上读取和写入元数据的表。

来自默认元数据域和其他元数据域的GDAL元数据在单个XML文档中序列化,与GDAL PAM(Persistent Auxiliary metadata).aux.XML文件中使用的格式一致,并在gpkg_metadata中使用md_scope=dataset和md_standard_uri=http://GDAL.org进行注册。对于数据集,此项在gpkg_metadata_reference中被引用,引用范围为geopackage。对于一个层,这个条目在gpkg_metadata_reference中被引用,引用范围为table,table_name={name of the table}

驱动程序可以读取非源于GDAL的元数据,并将其公开为具有GPKG_Metadata_ITEM_XXX格式键的元数据项,并将 元数据 gpkg_元数据表的列。目前不支持通过GDAL接口(尽管可以通过直接的SQL命令)更新此类元数据。

默认元数据域的特定描述和标识符元数据项可用于读/写以从gpkg_contents表的相应列读取/更新。

非空间表

GeoPackage 1.0和1.1的核心GeoPackage规范不支持非空间表。这是作为“属性”数据类型添加到GeoPackage 1.2中的。

驱动程序允许使用 无空间伸展的地质包 .

Starting with GDAL 2.2, the driver will also, by default, list non spatial tables that are not registered through the gdal_aspatial extension, and support the GeoPackage 1.2 "attributes" data type as well. Starting with GDAL 2.2, non spatial tables are by default created following the GeoPackage 1.2 "attributes" data type (can be controlled with the ASPATIAL_VARIANT layer creation option).

空间视图

如果在gpkg_contents和gpkg_geometry_columns表中插入相应的记录,则可以创建视图并将其识别为有效的空间层。

从GDAL 2.2开始,如果视图的SELECT子句中的列充当一个整型主键,则OGR可以将其识别为视图的FID列,前提是将其重命名为OGC_FID。不重命名就从源表中选择要素id是不够的,因为由于连接的原因,此要素id可能会出现多次。因此,用户必须明确地承认列实际上是主键。

例如:

CREATE VIEW my_view AS SELECT foo.fid AS OGC_FID, foo.geom, ... FROM foo JOIN another_table ON foo.some_id = another_table.other_id
INSERT INTO gpkg_contents (table_name, identifier, data_type, srs_id) VALUES ( 'my_view', 'my_view', 'features', 4326)
INSERT INTO gpkg_geometry_columns (table_name, column_name, geometry_type_name, srs_id, z, m) values ('my_view', 'my_geom', 'GEOMETRY', 4326, 0, 0)

This requires GDAL to be compiled with the SQLITE_HAS_COLUMN_METADATA option and SQLite3 with the SQLITE_ENABLE_COLUMN_METADATA option. Starting with GDAL 2.3, this can be easily verified if the SQLITE_HAS_COLUMN_METADATA=YES driver metadata item is declared (for example with "ogrinfo --format GPKG").

Coordinate Reference Systems

Valid geographic, projected and compound CRS supported in general by GDAL are also supported by GeoPackage and stored in the gpkg_spatial_ref_sys table.

Two special hard-coded CRS are reserved per the GeoPackage specification:

  • SRID 0, for a Undefined Geographic CRS. This one is selected by default if creating a spatial layer without any explicit CRS

  • SRID -1, for a Undefined Projected CRS. It might be selected by creating a layer with a CRS instantiated from the following WKT string: LOCAL_CS["Undefined cartesian SRS"]. (GDAL >= 3.3)

地质包扩展的支持级别

(Restricted to those that have a vector scope)

扩展

扩展名

OGC采用了扩展?

由GDAL支持?

Non-Linear Geometry Types

是的

是的,因为GDAL 2.1

RTree Spatial Indexes

是的

是的

Metadata

是的

是的

Schema

是的

Yes, since GDAL 3.3 (Geopackage constraints exposed as field domains)

WKT for Coordinate Reference Systems (第二周)

是的

部分,自GDAL 2.2以来。GDAL可以使用此扩展读取数据库,但不能解释只有WKT v2项的SRS项。

无空间伸展的地质包

对。gdal2.2中针对 属性 官方数据类型

性能提示

The same performance hints apply as those mentioned for the SQLite driver.

实例

  • 将单个形状文件简单转换为地质包。将使用abc.shp中的功能和abc.dbf中的属性创建表“abc”。文件 filename.gpkg 必须 not 已经存在,因为它将被创建。若要向现有地质包中添加新层,请运行ogr2ogr -update .

    ogr2ogr -f GPKG filename.gpkg abc.shp
    
  • 将shapefile目录转换为GeoPackage。每个文件都将作为GPKG文件中的新表结束。文件 filename.gpkg 必须 not 已经存在,因为它将被创建。

    ogr2ogr -f GPKG filename.gpkg ./path/to/dir
    
  • 将PostGIS数据库转换为地质包。数据库中的每个表都将作为GPKG文件中的表结束。文件 filename.gpkg 必须 not 已经存在,因为它将被创建。

    ogr2ogr -f GPKG filename.gpkg PG:'dbname=mydatabase host=localhost'
    
  • 在两个地理包数据库之间执行联接:

    ogrinfo my_spatial.gpkg \
      -sql "SELECT poly.id, other.foo FROM poly JOIN other_schema.other USING (id)" \
      -oo PRELUDE_STATEMENTS="ATTACH DATABASE 'other.gpkg' AS other_schema"
    

也见