The schema extension provides a means to describe the columns of tables in a GeoPackage with more detail than can be captured by the SQL table definition directly. The information provided by this extension can be used by applications to, for instance, present data contained in a GeoPackage in a more user-friendly fashion or implement data validation logic.
GeoPackage SWG, author_name gpkg
gpkg_schema
New requirement dependent on clauses [features], [attributes], and [extension_mechanism].
This extension may apply to any [feature_user_tables], [attributes_user_tables], or extension tables (see [attributes_user_tables]).
Read-write
A GeoPackage MAY contain a table named gpkg_data_columns
.
If present it SHALL be defined per Table 1 and gpkg_data_columns Table Definition SQL.
Column Name | Column Type | Column Description | Null | Key |
---|---|---|---|---|
|
TEXT |
Name of a table specified in |
no |
PK, UK |
|
TEXT |
Name of the table column |
no |
PK |
|
TEXT |
A human-readable identifier (e.g. short name) for the column_name content |
yes |
UK |
|
TEXT |
A human-readable formal title for the column_name content |
yes |
|
|
TEXT |
A human-readable description for the column_name content |
yes |
|
|
TEXT |
MIME [I21] type of column_name if BLOB type, or NULL for other types |
yes |
|
|
TEXT |
Column value constraint name (lowercase) specified by reference to |
yes |
GeoPackage applications MAY [K38] use the gpkg_data_columns
table to store minimal application schema identifying, descriptive and MIME [I21] type [K39] information about columns in user vector feature and tile matrix data tables that supplements the data available from the SQLite sqlite_master
table and pragma table_info(table_name)
SQL function.
The gpkg_data_columns
data CAN be used to provide more specific column data types and value ranges and application specific structural and semantic information to enable more informative user menu displays and more effective user decisions on the suitability of GeoPackage contents for specific purposes.
Warning
|
In versions 1.2.1 and earlier, the |
A GeoPackage MAY contain a table named gpkg_data_column_constraints
.
If present it SHALL be defined per Table 2 and gpkg_data_columns Table Definition SQL.
The gpkg_data_column_constraints
table contains data to specify restrictions on basic data type column values.
The constraint_name
column is referenced by the constraint_name
column in the gpkg_data_columns
table defined in Table 1.
Column Name | Column Type | Column Description | Null | Key |
---|---|---|---|---|
|
TEXT |
Name of constraint (lowercase) |
no |
Jointly Unique |
|
TEXT |
Type name of constraint: 'range' | 'enum' | 'glob' |
no |
Jointly Unique |
|
TEXT |
Specified case sensitive value for 'enum' or 'glob' or NULL for 'range' constraint_type |
yes |
Jointly Unique |
|
NUMERIC |
Minimum value for 'range' or NULL for 'enum' or 'glob' constraint_type |
yes |
|
|
BOOLEAN |
0 (false) if min value is exclusive, or 1 (true) if min value is inclusive |
yes |
|
|
NUMERIC |
Maximum value for 'range' or NULL for 'enum' or 'glob' constraint_type |
yes |
|
|
BOOLEAN |
0 (false) if max value is exclusive, or 1 (true) if max value is inclusive |
yes |
|
|
TEXT |
For ranges and globs, describes the constraint; for enums, describes the enum value. |
yes |
The min
and max
columns are defined as NUMERIC to be able to contain range values for any numeric data column defined with a data type from Table 1. These are the only exceptions to the data type rule stated in Req 5.
Warning
|
In GeoPackage 1.0, this table had column names |
GeoPackages with rows in the gpkg_extensions
table with an extension_name
of "gpkg_schema" SHALL comply with this extension.
GeoPackages complying with this extension SHALL have rows in the gpkg_extensions
table as described in Table 3 (below).
Warning
|
Requirement 141 was updated as part of GeoPackage 1.2.1.
In 1.1.0 and 1.2.0, the details of required |
table_name | column_name | extension_name | definition | scope |
---|---|---|---|---|
|
null |
|
see note below |
|
|
null |
|
see note below |
|
Note
|
For the |
Values of the gpkg_data_columns
table table_name
column value SHALL reference values in the table_name
column from either gpkg_contents
or gpkg_extensions
.
The column_name
column value in a gpkg_data_columns
table row SHALL contain the name of a column in the SQLite table or view identified by the table_name
column value.
The constraint_name
column value in a gpkg_data_columns
table MAY be NULL.
If it is not NULL, it SHALL contain a constraint_name
column value (which SHALL be lowercase) from the gpkg_data_column_constraints
table.
The lowercase gpkg_data_column_constraints
constraint_type
column value specifies the type of constraint: "range", "enum", or "glob" (GLOB is a text pattern match - see [I33]).
The case sensitive value
column contains an enumerated legal value for constraint_type
"enum", a pattern match string for constraint_type
"glob", or NULL for constraint_type
"range". The set of value
column values in rows of constraint_type
"enum" with the same constraint_name
contains all possible enumerated values for the constraint name. The min
and max
column values specify the minimum and maximum valid values for constraint_type
"range", or are NULL for constraint_type
"enum" or "glob". The min_is_inclusive
and max_is_inclusive
column values contain 1 if the min
and max
values (respectively) are inclusive, 0 if they are exclusive, or are NULL for constraint_type
"enum" or "glob".
These restrictions MAY be enforced by SQL triggers or by code in applications that update GeoPackage data values.
constraint_name | constraint_type | value | min | min_is_inclusive | max | max_is_inclusive |
---|---|---|---|---|---|---|
sampleRange |
range |
NULL |
1 |
true |
10 |
true |
sampleEnum |
enum |
1 |
NULL |
NULL |
NULL |
NULL |
sampleEnum |
enum |
3 |
NULL |
NULL |
NULL |
NULL |
sampleEnum |
enum |
5 |
NULL |
NULL |
NULL |
NULL |
sampleEnum |
enum |
7 |
NULL |
NULL |
NULL |
NULL |
sampleEnum |
enum |
9 |
NULL |
NULL |
NULL |
NULL |
sampleGlob |
glob |
[1-2][0-9][0-9][0-9] |
NULL |
NULL |
NULL |
NULL |
The gpkg_data_column_constraints
table MAY be empty.
If it contains data, the lowercase constraint_type
column values SHALL be one of "range", "enum", or "glob".
The gpkg_data_column_constraint
constraint_name
values for rows with constraint_type
values of "range" and "glob" SHALL be unique.
The gpkg_data_column_constraints
table MAY be empty.
If it contains rows with constraint_type
column values of "range", the value
column values for those rows SHALL be NULL.
If the gpkg_data_column_constraints
table contains rows with constraint_type
column values of "range", the min
column values for those rows SHALL be NOT NULL and less than the max
column value which shall be NOT NULL.
If the gpkg_data_column_constraints
table contains rows with constraint_type
column values of "range", the min_is_inclusive
and max_is_inclusive
column values for those rows SHALL be 0 or 1.
If the gpkg_data_column_constraints
table contains rows with constraint_type
column values of "enum" or "glob", the min
, max
, min_is_inclusive
and max_is_inclusive
column values for those rows SHALL be NULL.
If the gpkg_data_column_constraints
table contains rows with constraint_type
column values of "enum" or "glob", the value
column SHALL NOT be NULL.
Test Case ID |
/extensions/schema/data_columns/table_def |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 103 |
Test Type |
Basic |
Test Case ID |
/extensions/schema/data_column_constraints/table_def |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 107 |
Test Type |
Basic |
Test Case ID |
/extensions/schema/extensions/data_values |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 141 |
Test Type: |
Capabilities |
Test Case ID |
/extensions/schema/data_columns/table_name |
Test Purpose |
Verify that for each |
Test Method |
|
Reference |
Annex F.9 Req 104 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_columns/column_name |
Test Purpose |
Verify that for each |
Test Method |
|
Reference |
Annex F.9 Req 105 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_columns/constraint_name |
Test Purpose |
Verify that for each |
Test Method |
|
Reference |
Annex F.9 Req 106 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_column_constraints/constraint_type |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 108 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_column_constraints/constraint_names_unique |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 109 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_column_constraints/value_for_range |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 110 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_column_constraints/min_max_for_range |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 111 |
Test Type |
Capability |
Test Case ID |
/extensions/schema/data_column_constraints/inclusive_for_range |
Test Purpose |
Verify that the |
Test Method |
|
Reference |
Annex F.9 Req 112 |
Test Type |
Capability |
Test Case ID: |
/extensions/schema/data_column_constraints/min_max_inclusive_for_enum_glob |
Test Purpose: |
Verify that the |
Test Method: |
|
Reference |
Annex F.9 Req 113 |
Test Type |
Capability |
Test Case ID: |
/extensions/schema/data_column_constraints/value_for_enum_glob |
Test Purpose: |
Verify that the |
Test Method: |
|
Reference |
Annex F.9 Req 114 |
Test Type |
Capability |
CREATE TABLE gpkg_data_columns (
table_name TEXT NOT NULL,
column_name TEXT NOT NULL,
name TEXT,
title TEXT,
description TEXT,
mime_type TEXT,
constraint_name TEXT,
CONSTRAINT pk_gdc PRIMARY KEY (table_name, column_name),
CONSTRAINT gdc_tn UNIQUE (table_name, name)
);
CREATE TABLE gpkg_data_column_constraints (
constraint_name TEXT NOT NULL,
constraint_type TEXT NOT NULL, // 'range' | 'enum' | 'glob'
value TEXT,
min NUMERIC,
min_is_inclusive BOOLEAN, // 0 = false, 1 = true
max NUMERIC,
max_is_inclusive BOOLEAN, // 0 = false, 1 = true
description TEXT,
CONSTRAINT gdcc_ntv UNIQUE (constraint_name, constraint_type, value)
)