@loaders.gl/geopackage 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/geopackage-loader.js +31 -0
- package/dist/es5/geopackage-loader.js.map +1 -0
- package/dist/es5/index.js +13 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/parse-geopackage.js +364 -0
- package/dist/es5/lib/parse-geopackage.js.map +1 -0
- package/dist/es5/lib/types.js +2 -0
- package/dist/es5/lib/types.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/geopackage-loader.js +21 -0
- package/dist/esm/geopackage-loader.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/parse-geopackage.js +292 -0
- package/dist/esm/lib/parse-geopackage.js.map +1 -0
- package/dist/esm/lib/types.js +2 -0
- package/dist/esm/lib/types.js.map +1 -0
- package/dist/geopackage-loader.d.ts +14 -0
- package/dist/geopackage-loader.d.ts.map +1 -0
- package/dist/geopackage-loader.js +47 -15
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -2
- package/dist/lib/parse-geopackage.d.ts +5 -0
- package/dist/lib/parse-geopackage.d.ts.map +1 -0
- package/dist/lib/parse-geopackage.js +361 -272
- package/dist/lib/types.d.ts +195 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -2
- package/package.json +9 -9
- package/src/geopackage-loader.ts +6 -2
- package/src/lib/parse-geopackage.ts +74 -43
- package/src/lib/types.ts +17 -2
- package/dist/bundle.js.map +0 -1
- package/dist/geopackage-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/parse-geopackage.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
export interface GeometryBitFlags {
|
|
2
|
+
littleEndian: boolean;
|
|
3
|
+
envelopeLength: number;
|
|
4
|
+
emptyGeometry: boolean;
|
|
5
|
+
extendedGeometryType: boolean;
|
|
6
|
+
}
|
|
7
|
+
export type ProjectionMapping = {
|
|
8
|
+
[srsId: number]: string;
|
|
9
|
+
};
|
|
10
|
+
export type DataColumnsMapping = {
|
|
11
|
+
[columnName: string]: string | null;
|
|
12
|
+
};
|
|
13
|
+
export type SQLiteTypes = 'BOOLEAN' | 'TINYINT' | 'SMALLINT' | 'MEDIUMINT' | 'INT' | 'INTEGER' | 'FLOAT' | 'DOUBLE' | 'REAL' | 'TEXT' | 'BLOB' | 'DATE' | 'DATETIME';
|
|
14
|
+
/** Type names for geopackage geometries
|
|
15
|
+
*
|
|
16
|
+
* As defined in https://www.geopackage.org/spec130/index.html#table_column_data_types, geometries
|
|
17
|
+
* can be stored with any geometry name listed here:
|
|
18
|
+
* https://www.geopackage.org/spec130/index.html#geometry_types
|
|
19
|
+
*/
|
|
20
|
+
export type GeoPackageGeometryTypes = 'GEOMETRY' | 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'GEOMETRYCOLLECTION';
|
|
21
|
+
/**
|
|
22
|
+
* https://www.geopackage.org/spec121/#spatial_ref_sys
|
|
23
|
+
*/
|
|
24
|
+
export interface SpatialRefSysRow {
|
|
25
|
+
/**
|
|
26
|
+
* Human readable name of this SRS
|
|
27
|
+
*/
|
|
28
|
+
srs_name: string;
|
|
29
|
+
/**
|
|
30
|
+
* Unique identifier for each Spatial Reference System within a GeoPackage
|
|
31
|
+
*/
|
|
32
|
+
srs_id: number;
|
|
33
|
+
/**
|
|
34
|
+
* Case-insensitive name of the defining organization e.g. EPSG or epsg
|
|
35
|
+
*/
|
|
36
|
+
organization: string;
|
|
37
|
+
/**
|
|
38
|
+
* Numeric ID of the Spatial Reference System assigned by the organization
|
|
39
|
+
*/
|
|
40
|
+
organization_coordsys_id: number;
|
|
41
|
+
/**
|
|
42
|
+
* Well-known Text [A32] Representation of the Spatial Reference System
|
|
43
|
+
*/
|
|
44
|
+
definition: string;
|
|
45
|
+
/**
|
|
46
|
+
* Human readable description of this SRS
|
|
47
|
+
*/
|
|
48
|
+
description?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* https://www.geopackage.org/spec121/#_contents
|
|
52
|
+
*/
|
|
53
|
+
export interface ContentsRow {
|
|
54
|
+
/**
|
|
55
|
+
* The name of the actual content (e.g., tiles, features, or attributes) table
|
|
56
|
+
*/
|
|
57
|
+
table_name: string;
|
|
58
|
+
/**
|
|
59
|
+
* Type of data stored in the table
|
|
60
|
+
*/
|
|
61
|
+
data_type: 'features' | 'attributes' | 'tiles';
|
|
62
|
+
/**
|
|
63
|
+
* A human-readable identifier (e.g. short name) for the table_name content
|
|
64
|
+
*/
|
|
65
|
+
identifier?: string;
|
|
66
|
+
/**
|
|
67
|
+
* A human-readable description for the table_name content
|
|
68
|
+
*/
|
|
69
|
+
description?: string;
|
|
70
|
+
/**
|
|
71
|
+
* timestamp of last change to content, in ISO 8601 format
|
|
72
|
+
*/
|
|
73
|
+
last_change: string;
|
|
74
|
+
/**
|
|
75
|
+
* Bounding box minimum easting or longitude for all content in table_name. If tiles, this is informational and the tile matrix set should be used for calculating tile coordinates.
|
|
76
|
+
*/
|
|
77
|
+
min_x?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Bounding box minimum northing or latitude for all content in table_name. If tiles, this is informational and the tile matrix set should be used for calculating tile coordinates.
|
|
80
|
+
*/
|
|
81
|
+
min_y?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Bounding box maximum easting or longitude for all content in table_name. If tiles, this is informational and the tile matrix set should be used for calculating tile coordinates.
|
|
84
|
+
*/
|
|
85
|
+
max_x?: number;
|
|
86
|
+
/**
|
|
87
|
+
* Bounding box maximum northing or latitude for all content in table_name. If tiles, this is informational and the tile matrix set should be used for calculating tile coordinates.
|
|
88
|
+
*/
|
|
89
|
+
max_y?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Spatial Reference System ID: gpkg_spatial_ref_sys.srs_id; when data_type is features, SHALL also match gpkg_geometry_columns.srs_id; When data_type is tiles, SHALL also match gpkg_tile_matrix_set.srs_id
|
|
92
|
+
*/
|
|
93
|
+
srs_id?: number;
|
|
94
|
+
}
|
|
95
|
+
type GeometryType = 'GEOMETRY' | 'POINT' | 'LINESTRING' | 'POLYGON' | 'MULTIPOINT' | 'MULTILINESTRING' | 'MULTIPOLYGON' | 'GEOMETRYCOLLECTION' | 'CIRCULARSTRING' | 'COMPOUNDCURVE' | 'CURVEPOLYGON' | 'MULTICURVE' | 'MULTISURFACE' | 'CURVE' | 'SURFACE';
|
|
96
|
+
/**
|
|
97
|
+
* https://www.geopackage.org/spec121/#_geometry_columns
|
|
98
|
+
*/
|
|
99
|
+
export interface GeometryColumnsRow {
|
|
100
|
+
/**
|
|
101
|
+
* Name of the table containing the geometry column
|
|
102
|
+
*/
|
|
103
|
+
table_name: string;
|
|
104
|
+
/**
|
|
105
|
+
* Name of a column in the feature table that is a Geometry Column
|
|
106
|
+
*/
|
|
107
|
+
column_name: string;
|
|
108
|
+
/**
|
|
109
|
+
* Name from Geometry Type Codes (Core) or Geometry Type Codes (Extension) in Geometry Types (Normative)
|
|
110
|
+
*/
|
|
111
|
+
geometry_type_name: GeometryType;
|
|
112
|
+
/**
|
|
113
|
+
* Spatial Reference System ID: gpkg_spatial_ref_sys.srs_id
|
|
114
|
+
*/
|
|
115
|
+
srs_id: number;
|
|
116
|
+
/**
|
|
117
|
+
* 0: z values prohibited; 1: z values mandatory; 2: z values optional
|
|
118
|
+
*/
|
|
119
|
+
z: 0 | 1 | 2;
|
|
120
|
+
/**
|
|
121
|
+
* 0: m values prohibited; 1: m values mandatory; 2: m values optional
|
|
122
|
+
*/
|
|
123
|
+
m: 0 | 1 | 2;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* https://www.geopackage.org/spec121/#extensions_table_definition
|
|
127
|
+
*/
|
|
128
|
+
export interface ExtensionsRow {
|
|
129
|
+
/**
|
|
130
|
+
* Name of the table that requires the extension. When NULL, the extension is required for the entire GeoPackage. SHALL NOT be NULL when the column_name is not NULL.
|
|
131
|
+
*/
|
|
132
|
+
table_name?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Name of the column that requires the extension. When NULL, the extension is required for the entire table.
|
|
135
|
+
*/
|
|
136
|
+
column_name?: string;
|
|
137
|
+
/**
|
|
138
|
+
* The case sensitive name of the extension that is required, in the form <author>_<extension_name>.
|
|
139
|
+
*/
|
|
140
|
+
extension_name: string;
|
|
141
|
+
/**
|
|
142
|
+
* Permalink, URI, or reference to a document that defines the extension
|
|
143
|
+
*/
|
|
144
|
+
definition: string;
|
|
145
|
+
/**
|
|
146
|
+
* Indicates scope of extension effects on readers / writers: 'read-write' or 'write-only' in lowercase.
|
|
147
|
+
*/
|
|
148
|
+
scope: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* https://www.geopackage.org/spec121/#gpkg_data_columns_cols
|
|
152
|
+
*/
|
|
153
|
+
export interface DataColumnsRow {
|
|
154
|
+
/**
|
|
155
|
+
* Name of the tiles or feature table
|
|
156
|
+
*/
|
|
157
|
+
table_name: string;
|
|
158
|
+
/**
|
|
159
|
+
* Name of the table column
|
|
160
|
+
*/
|
|
161
|
+
column_name: string;
|
|
162
|
+
/**
|
|
163
|
+
* A human-readable identifier (e.g. short name) for the column_name content
|
|
164
|
+
*/
|
|
165
|
+
name?: string;
|
|
166
|
+
/**
|
|
167
|
+
* A human-readable formal title for the column_name content
|
|
168
|
+
*/
|
|
169
|
+
title?: string;
|
|
170
|
+
/**
|
|
171
|
+
* A human-readable description for the column_name content
|
|
172
|
+
*/
|
|
173
|
+
description?: string;
|
|
174
|
+
/**
|
|
175
|
+
* MIME [A21] type of column_name if BLOB type, or NULL for other types
|
|
176
|
+
*/
|
|
177
|
+
mime_type?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Column value constraint name (lowercase) specified by reference to gpkg_data_column_constraints.constraint name
|
|
180
|
+
*/
|
|
181
|
+
constraint_name?: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Type for PRAGMA table_info(tableName);
|
|
185
|
+
*/
|
|
186
|
+
export interface PragmaTableInfoRow {
|
|
187
|
+
cid: number;
|
|
188
|
+
name: string;
|
|
189
|
+
type: SQLiteTypes;
|
|
190
|
+
notnull: 0 | 1;
|
|
191
|
+
dflt_value: any;
|
|
192
|
+
pk: 0 | 1;
|
|
193
|
+
}
|
|
194
|
+
export {};
|
|
195
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAC,CAAC;AAC1D,MAAM,MAAM,kBAAkB,GAAG;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CAAC,CAAC;AACvE,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,SAAS,GACT,UAAU,GACV,WAAW,GACX,KAAK,GACL,SAAS,GACT,OAAO,GACP,QAAQ,GACR,MAAM,GACN,MAAM,GACN,MAAM,GACN,MAAM,GACN,UAAU,CAAC;AAEf;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAC/B,UAAU,GACV,OAAO,GACP,Y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ineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/geopackage",
|
|
3
3
|
"description": "GeoPackage data loaders",
|
|
4
|
-
"version": "4.0.0-alpha.
|
|
4
|
+
"version": "4.0.0-alpha.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"sql",
|
|
15
15
|
"GeoPackage"
|
|
16
16
|
],
|
|
17
|
-
"types": "
|
|
18
|
-
"main": "dist/index.js",
|
|
19
|
-
"module": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"main": "dist/es5/index.js",
|
|
19
|
+
"module": "dist/esm/index.js",
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"files": [
|
|
22
22
|
"src",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/runtime": "^7.3.1",
|
|
28
|
-
"@loaders.gl/gis": "4.0.0-alpha.
|
|
29
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
30
|
-
"@loaders.gl/wkt": "4.0.0-alpha.
|
|
28
|
+
"@loaders.gl/gis": "4.0.0-alpha.6",
|
|
29
|
+
"@loaders.gl/schema": "4.0.0-alpha.6",
|
|
30
|
+
"@loaders.gl/wkt": "4.0.0-alpha.6",
|
|
31
31
|
"@math.gl/proj4": "^3.5.1",
|
|
32
32
|
"@types/sql.js": "^1.4.2",
|
|
33
|
-
"sql.js": "
|
|
33
|
+
"sql.js": "1.5.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
|
|
36
36
|
}
|
package/src/geopackage-loader.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
2
|
-
import parseGeoPackage from './lib/parse-geopackage';
|
|
2
|
+
import parseGeoPackage, {DEFAULT_SQLJS_CDN} from './lib/parse-geopackage';
|
|
3
3
|
|
|
4
4
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
5
5
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
@@ -14,6 +14,7 @@ export type GeoPackageLoaderOptions = LoaderOptions & {
|
|
|
14
14
|
gis?: {
|
|
15
15
|
reproject?: boolean;
|
|
16
16
|
_targetCrs?: string;
|
|
17
|
+
format?: 'geojson' | 'tables';
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
20
|
|
|
@@ -29,7 +30,10 @@ export const GeoPackageLoader: LoaderWithParser = {
|
|
|
29
30
|
parse: parseGeoPackage,
|
|
30
31
|
options: {
|
|
31
32
|
geopackage: {
|
|
32
|
-
sqlJsCDN:
|
|
33
|
+
sqlJsCDN: DEFAULT_SQLJS_CDN
|
|
34
|
+
},
|
|
35
|
+
gis: {
|
|
36
|
+
format: 'tables'
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
};
|
|
@@ -7,14 +7,9 @@ import {
|
|
|
7
7
|
Field,
|
|
8
8
|
Geometry,
|
|
9
9
|
DataType,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Int32,
|
|
14
|
-
Int8,
|
|
15
|
-
Int16,
|
|
16
|
-
Float32,
|
|
17
|
-
Binary
|
|
10
|
+
Tables,
|
|
11
|
+
ObjectRowTable,
|
|
12
|
+
Feature
|
|
18
13
|
} from '@loaders.gl/schema';
|
|
19
14
|
import {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';
|
|
20
15
|
import {Proj4Projection} from '@math.gl/proj4';
|
|
@@ -27,9 +22,14 @@ import {
|
|
|
27
22
|
DataColumnsRow,
|
|
28
23
|
DataColumnsMapping,
|
|
29
24
|
PragmaTableInfoRow,
|
|
30
|
-
SQLiteTypes
|
|
25
|
+
SQLiteTypes,
|
|
26
|
+
GeoPackageGeometryTypes
|
|
31
27
|
} from './types';
|
|
32
28
|
|
|
29
|
+
// We pin to the same version as sql.js that we use.
|
|
30
|
+
// As of March 2022, versions 1.6.0, 1.6.1, and 1.6.2 of sql.js appeared not to work.
|
|
31
|
+
export const DEFAULT_SQLJS_CDN = 'https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.5.0/';
|
|
32
|
+
|
|
33
33
|
// https://www.geopackage.org/spec121/#flags_layout
|
|
34
34
|
const ENVELOPE_BYTE_LENGTHS = {
|
|
35
35
|
0: 0,
|
|
@@ -44,45 +44,63 @@ const ENVELOPE_BYTE_LENGTHS = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
// Documentation: https://www.geopackage.org/spec130/index.html#table_column_data_types
|
|
47
|
-
const SQL_TYPE_MAPPING: {[type in SQLiteTypes]:
|
|
48
|
-
BOOLEAN:
|
|
49
|
-
TINYINT:
|
|
50
|
-
SMALLINT:
|
|
51
|
-
MEDIUMINT:
|
|
52
|
-
INT:
|
|
53
|
-
INTEGER:
|
|
54
|
-
FLOAT:
|
|
55
|
-
DOUBLE:
|
|
56
|
-
REAL:
|
|
57
|
-
TEXT:
|
|
58
|
-
BLOB:
|
|
59
|
-
DATE:
|
|
60
|
-
DATETIME:
|
|
61
|
-
GEOMETRY:
|
|
47
|
+
const SQL_TYPE_MAPPING: {[type in SQLiteTypes | GeoPackageGeometryTypes]: DataType} = {
|
|
48
|
+
BOOLEAN: 'bool',
|
|
49
|
+
TINYINT: 'int8',
|
|
50
|
+
SMALLINT: 'int16',
|
|
51
|
+
MEDIUMINT: 'int32',
|
|
52
|
+
INT: 'int32',
|
|
53
|
+
INTEGER: 'int32',
|
|
54
|
+
FLOAT: 'float32',
|
|
55
|
+
DOUBLE: 'float64',
|
|
56
|
+
REAL: 'float64',
|
|
57
|
+
TEXT: 'utf8',
|
|
58
|
+
BLOB: 'binary',
|
|
59
|
+
DATE: 'utf8',
|
|
60
|
+
DATETIME: 'utf8',
|
|
61
|
+
GEOMETRY: 'binary',
|
|
62
|
+
POINT: 'binary',
|
|
63
|
+
LINESTRING: 'binary',
|
|
64
|
+
POLYGON: 'binary',
|
|
65
|
+
MULTIPOINT: 'binary',
|
|
66
|
+
MULTILINESTRING: 'binary',
|
|
67
|
+
MULTIPOLYGON: 'binary',
|
|
68
|
+
GEOMETRYCOLLECTION: 'binary'
|
|
62
69
|
};
|
|
63
70
|
|
|
64
71
|
export default async function parseGeoPackage(
|
|
65
72
|
arrayBuffer: ArrayBuffer,
|
|
66
73
|
options?: GeoPackageLoaderOptions
|
|
67
|
-
) {
|
|
68
|
-
const {sqlJsCDN =
|
|
69
|
-
const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};
|
|
74
|
+
): Promise<Tables<ObjectRowTable> | Record<string, Feature[]>> {
|
|
75
|
+
const {sqlJsCDN = DEFAULT_SQLJS_CDN} = options?.geopackage || {};
|
|
76
|
+
const {reproject = false, _targetCrs = 'WGS84', format = 'tables'} = options?.gis || {};
|
|
70
77
|
|
|
71
78
|
const db = await loadDatabase(arrayBuffer, sqlJsCDN);
|
|
72
79
|
const tables = listVectorTables(db);
|
|
73
80
|
const projections = getProjections(db);
|
|
74
81
|
|
|
75
82
|
// Mapping from tableName to geojson feature collection
|
|
76
|
-
const
|
|
83
|
+
const outputTables: Tables<ObjectRowTable> = {
|
|
84
|
+
shape: 'tables',
|
|
85
|
+
tables: []
|
|
86
|
+
};
|
|
87
|
+
|
|
77
88
|
for (const table of tables) {
|
|
78
89
|
const {table_name: tableName} = table;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
outputTables.tables.push({
|
|
91
|
+
name: tableName,
|
|
92
|
+
table: getVectorTable(db, tableName, projections, {
|
|
93
|
+
reproject,
|
|
94
|
+
_targetCrs
|
|
95
|
+
})
|
|
82
96
|
});
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
if (format === 'geojson') {
|
|
100
|
+
return formatTablesAsGeojson(outputTables);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return outputTables;
|
|
86
104
|
}
|
|
87
105
|
|
|
88
106
|
/**
|
|
@@ -147,7 +165,7 @@ function getVectorTable(
|
|
|
147
165
|
tableName: string,
|
|
148
166
|
projections: ProjectionMapping,
|
|
149
167
|
{reproject, _targetCrs}: {reproject: boolean; _targetCrs: string}
|
|
150
|
-
):
|
|
168
|
+
): ObjectRowTable {
|
|
151
169
|
const dataColumns = getDataColumns(db, tableName);
|
|
152
170
|
const geomColumn = getGeometryColumn(db, tableName);
|
|
153
171
|
const featureIdColumn = getFeatureIdName(db, tableName);
|
|
@@ -178,12 +196,16 @@ function getVectorTable(
|
|
|
178
196
|
geojsonFeatures.push(geojsonFeature);
|
|
179
197
|
}
|
|
180
198
|
|
|
181
|
-
const schema =
|
|
199
|
+
const schema = getSchema(db, tableName);
|
|
182
200
|
if (projection) {
|
|
183
|
-
return {
|
|
201
|
+
return {
|
|
202
|
+
shape: 'object-row-table',
|
|
203
|
+
data: transformGeoJsonCoords(geojsonFeatures, projection.project),
|
|
204
|
+
schema
|
|
205
|
+
};
|
|
184
206
|
}
|
|
185
207
|
|
|
186
|
-
return {geojsonFeatures, schema};
|
|
208
|
+
return {data: geojsonFeatures, schema, shape: 'object-row-table'};
|
|
187
209
|
}
|
|
188
210
|
|
|
189
211
|
/**
|
|
@@ -220,7 +242,7 @@ function constructGeoJsonFeature(
|
|
|
220
242
|
geomColumn: GeometryColumnsRow,
|
|
221
243
|
dataColumns: DataColumnsMapping,
|
|
222
244
|
featureIdColumn: string
|
|
223
|
-
) {
|
|
245
|
+
): Feature<Geometry | null> {
|
|
224
246
|
// Find feature id
|
|
225
247
|
const idIdx = columns.indexOf(featureIdColumn);
|
|
226
248
|
const id = row[idIdx];
|
|
@@ -290,7 +312,7 @@ function getGeopackageVersion(db: Database): string | null {
|
|
|
290
312
|
const userVersionQuery = db.exec('PRAGMA user_version;')[0];
|
|
291
313
|
const userVersionInt = userVersionQuery.values[0][0];
|
|
292
314
|
|
|
293
|
-
if (userVersionInt && userVersionInt < 10300) {
|
|
315
|
+
if (userVersionInt && typeof userVersionInt === 'number' && userVersionInt < 10300) {
|
|
294
316
|
return '1.2';
|
|
295
317
|
}
|
|
296
318
|
|
|
@@ -328,7 +350,7 @@ function getFeatureIdName(db: Database, tableName: string): string | null {
|
|
|
328
350
|
* See: https://www.geopackage.org/spec121/#gpb_format
|
|
329
351
|
*
|
|
330
352
|
* @param arrayBuffer geometry buffer
|
|
331
|
-
* @return
|
|
353
|
+
* @return GeoJSON geometry (in original CRS)
|
|
332
354
|
*/
|
|
333
355
|
function parseGeometry(arrayBuffer: ArrayBuffer): Geometry | null {
|
|
334
356
|
const view = new DataView(arrayBuffer);
|
|
@@ -438,16 +460,25 @@ function getDataColumns(db: Database, tableName: string): DataColumnsMapping | n
|
|
|
438
460
|
* @param tableName table name
|
|
439
461
|
* @returns Arrow-like Schema
|
|
440
462
|
*/
|
|
441
|
-
function
|
|
463
|
+
function getSchema(db: Database, tableName: string): Schema {
|
|
442
464
|
const stmt = db.prepare(`PRAGMA table_info(\`${tableName}\`)`);
|
|
443
465
|
|
|
444
466
|
const fields: Field[] = [];
|
|
445
467
|
while (stmt.step()) {
|
|
446
468
|
const pragmaTableInfo = stmt.getAsObject() as unknown as PragmaTableInfoRow;
|
|
447
|
-
const {name, type, notnull} = pragmaTableInfo;
|
|
448
|
-
const
|
|
469
|
+
const {name, type: sqlType, notnull} = pragmaTableInfo;
|
|
470
|
+
const type = SQL_TYPE_MAPPING[sqlType];
|
|
471
|
+
const field = {name, type, nullable: !notnull};
|
|
449
472
|
fields.push(field);
|
|
450
473
|
}
|
|
451
474
|
|
|
452
|
-
return
|
|
475
|
+
return {fields, metadata: {}};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function formatTablesAsGeojson(tables: Tables<ObjectRowTable>): Record<string, Feature[]> {
|
|
479
|
+
const geojsonMap = {};
|
|
480
|
+
for (const table of tables.tables) {
|
|
481
|
+
geojsonMap[table.name] = table.table.data;
|
|
482
|
+
}
|
|
483
|
+
return geojsonMap;
|
|
453
484
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -21,8 +21,23 @@ export type SQLiteTypes =
|
|
|
21
21
|
| 'TEXT'
|
|
22
22
|
| 'BLOB'
|
|
23
23
|
| 'DATE'
|
|
24
|
-
| 'DATETIME'
|
|
25
|
-
|
|
24
|
+
| 'DATETIME';
|
|
25
|
+
|
|
26
|
+
/** Type names for geopackage geometries
|
|
27
|
+
*
|
|
28
|
+
* As defined in https://www.geopackage.org/spec130/index.html#table_column_data_types, geometries
|
|
29
|
+
* can be stored with any geometry name listed here:
|
|
30
|
+
* https://www.geopackage.org/spec130/index.html#geometry_types
|
|
31
|
+
*/
|
|
32
|
+
export type GeoPackageGeometryTypes =
|
|
33
|
+
| 'GEOMETRY'
|
|
34
|
+
| 'POINT'
|
|
35
|
+
| 'LINESTRING'
|
|
36
|
+
| 'POLYGON'
|
|
37
|
+
| 'MULTIPOINT'
|
|
38
|
+
| 'MULTILINESTRING'
|
|
39
|
+
| 'MULTIPOLYGON'
|
|
40
|
+
| 'GEOMETRYCOLLECTION';
|
|
26
41
|
|
|
27
42
|
/**
|
|
28
43
|
* https://www.geopackage.org/spec121/#spatial_ref_sys
|
package/dist/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/geopackage-loader.ts"],"names":["parseGeoPackage","VERSION","GeoPackageLoader","id","name","module","version","extensions","mimeTypes","category","parse","options","geopackage","sqlJsCDN"],"mappings":"AACA,OAAOA,eAAP,MAA4B,wBAA5B;AAKA,MAAMC,OAAO,GAAG,QAAhB;AAcA,OAAO,MAAMC,gBAAkC,GAAG;AAChDC,EAAAA,EAAE,EAAE,YAD4C;AAEhDC,EAAAA,IAAI,EAAE,YAF0C;AAGhDC,EAAAA,MAAM,EAAE,YAHwC;AAIhDC,EAAAA,OAAO,EAAEL,OAJuC;AAKhDM,EAAAA,UAAU,EAAE,CAAC,MAAD,CALoC;AAMhDC,EAAAA,SAAS,EAAE,CAAC,gCAAD,CANqC;AAOhDC,EAAAA,QAAQ,EAAE,UAPsC;AAQhDC,EAAAA,KAAK,EAAEV,eARyC;AAShDW,EAAAA,OAAO,EAAE;AACPC,IAAAA,UAAU,EAAE;AACVC,MAAAA,QAAQ,EAAE;AADA;AADL;AATuC,CAA3C","sourcesContent":["import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport parseGeoPackage from './lib/parse-geopackage';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\n// const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\nconst VERSION = 'latest';\n\nexport type GeoPackageLoaderOptions = LoaderOptions & {\n geopackage?: {\n // Use null in Node\n sqlJsCDN: string | null;\n };\n gis?: {\n reproject?: boolean;\n _targetCrs?: string;\n };\n};\n\n/** Geopackage loader */\nexport const GeoPackageLoader: LoaderWithParser = {\n id: 'geopackage',\n name: 'GeoPackage',\n module: 'geopackage',\n version: VERSION,\n extensions: ['gpkg'],\n mimeTypes: ['application/geopackage+sqlite3'],\n category: 'geometry',\n parse: parseGeoPackage,\n options: {\n geopackage: {\n sqlJsCDN: 'https://sql.js.org/dist/'\n }\n }\n};\n"],"file":"geopackage-loader.js"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["GeoPackageLoader"],"mappings":"AAAA,SAAQA,gBAAR,QAA+B,qBAA/B","sourcesContent":["export {GeoPackageLoader} from './geopackage-loader';\n"],"file":"index.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/parse-geopackage.ts"],"names":["initSqlJs","WKBLoader","Schema","Field","Bool","Utf8","Float64","Int32","Int8","Int16","Float32","Binary","binaryToGeometry","transformGeoJsonCoords","Proj4Projection","ENVELOPE_BYTE_LENGTHS","SQL_TYPE_MAPPING","BOOLEAN","TINYINT","SMALLINT","MEDIUMINT","INT","INTEGER","FLOAT","DOUBLE","REAL","TEXT","BLOB","DATE","DATETIME","GEOMETRY","parseGeoPackage","arrayBuffer","options","sqlJsCDN","geopackage","reproject","_targetCrs","gis","db","loadDatabase","tables","listVectorTables","projections","getProjections","result","table","table_name","tableName","getVectorTable","SQL","locateFile","file","Database","Uint8Array","stmt","prepare","vectorTablesInfo","step","vectorTableInfo","getAsObject","push","dataColumns","getDataColumns","geomColumn","getGeometryColumn","featureIdColumn","getFeatureIdName","columns","values","exec","projection","geomColumnProjStr","srs_id","from","to","geojsonFeatures","row","geojsonFeature","constructGeoJsonFeature","schema","getArrowSchema","project","projectionMapping","srsInfo","definition","idIdx","indexOf","id","geomColumnIdx","column_name","geometry","parseGeometry","buffer","properties","key","value","Object","entries","idx","i","length","columnName","type","getGeopackageVersion","textDecoder","TextDecoder","applicationIdQuery","applicationId","ArrayBuffer","view","DataView","setInt32","Number","versionString","decode","userVersionQuery","userVersionInt","pragmaTableInfo","name","pk","envelopeLength","emptyGeometry","parseGeometryBitFlags","getUint8","wkbOffset","binaryGeometry","parseSync","slice","byte","envelopeValue","littleEndian","Boolean","extendedGeometryType","bind","geometryColumn","error","message","includes","column","fields","notnull","field"],"mappings":"AAEA,OAAOA,SAAP,MAA0D,QAA1D;AACA,SAAQC,SAAR,QAAwB,iBAAxB;AACA,SACEC,MADF,EAEEC,KAFF,EAKEC,IALF,EAMEC,IANF,EAOEC,OAPF,EAQEC,KARF,EASEC,IATF,EAUEC,KAVF,EAWEC,OAXF,EAYEC,MAZF,QAaO,oBAbP;AAcA,SAAQC,gBAAR,EAA0BC,sBAA1B,QAAuD,iBAAvD;AACA,SAAQC,eAAR,QAA8B,gBAA9B;AAcA,MAAMC,qBAAqB,GAAG;AAC5B,KAAG,CADyB;AAE5B,KAAG,EAFyB;AAG5B,KAAG,EAHyB;AAI5B,KAAG,EAJyB;AAK5B,KAAG,EALyB;AAO5B,KAAG,CAPyB;AAQ5B,KAAG,CARyB;AAS5B,KAAG;AATyB,CAA9B;AAaA,MAAMC,gBAA0D,GAAG;AACjEC,EAAAA,OAAO,EAAEb,IADwD;AAEjEc,EAAAA,OAAO,EAAEV,IAFwD;AAGjEW,EAAAA,QAAQ,EAAEV,KAHuD;AAIjEW,EAAAA,SAAS,EAAEb,KAJsD;AAKjEc,EAAAA,GAAG,EAAEd,KAL4D;AAMjEe,EAAAA,OAAO,EAAEf,KANwD;AAOjEgB,EAAAA,KAAK,EAAEb,OAP0D;AAQjEc,EAAAA,MAAM,EAAElB,OARyD;AASjEmB,EAAAA,IAAI,EAAEnB,OAT2D;AAUjEoB,EAAAA,IAAI,EAAErB,IAV2D;AAWjEsB,EAAAA,IAAI,EAAEhB,MAX2D;AAYjEiB,EAAAA,IAAI,EAAEvB,IAZ2D;AAajEwB,EAAAA,QAAQ,EAAExB,IAbuD;AAcjEyB,EAAAA,QAAQ,EAAEnB;AAduD,CAAnE;AAiBA,eAAe,eAAeoB,eAAf,CACbC,WADa,EAEbC,OAFa,EAGb;AACA,QAAM;AAACC,IAAAA,QAAQ,GAAG;AAAZ,MAA0C,CAAAD,O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B6B,IAAI,IAAI,IAA9B;AACD;;AAED,SAAO1E,MAAP;AACD;;AAQD,SAASoC,cAAT,CAAwB1C,EAAxB,EAAsCS,SAAtC,EAAiE;AAC/D,QAAMO,IAAI,GAAGhB,EAAE,CAACiB,OAAH,8BAAkCR,SAAlC,QAAb;AAEA,QAAM4F,MAAe,GAAG,EAAxB;;AACA,SAAOrF,IAAI,CAACG,IAAL,EAAP,EAAoB;AAClB,UAAM4D,eAAe,GAAG/D,IAAI,CAACK,WAAL,EAAxB;AACA,UAAM;AAAC2D,MAAAA,IAAD;AAAOhB,MAAAA,IAAP;AAAasC,MAAAA;AAAb,QAAwBvB,eAA9B;AACA,UAAMwB,KAAK,GAAG,IAAI3I,KAAJ,CAAUoH,IAAV,EAAgB,IAAIvG,gBAAgB,CAACuF,IAAD,CAApB,EAAhB,EAA8C,CAACsC,OAA/C,CAAd;AACAD,IAAAA,MAAM,CAAC/E,IAAP,CAAYiF,KAAZ;AACD;;AAED,SAAO,IAAI5I,MAAJ,CAAW0I,MAAX,CAAP;AACD","sourcesContent":["/* eslint-disable camelcase, @typescript-eslint/no-use-before-define */\nimport type {GeoPackageLoaderOptions} from '../geopackage-loader';\nimport initSqlJs, {SqlJsStatic, Database, Statement} from 'sql.js';\nimport {WKBLoader} from '@loaders.gl/wkt';\nimport {\n Schema,\n Field,\n Geometry,\n DataType,\n Bool,\n Utf8,\n Float64,\n Int32,\n Int8,\n Int16,\n Float32,\n Binary\n} from '@loaders.gl/schema';\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {\n GeometryColumnsRow,\n ContentsRow,\n SpatialRefSysRow,\n ProjectionMapping,\n GeometryBitFlags,\n DataColumnsRow,\n DataColumnsMapping,\n PragmaTableInfoRow,\n SQLiteTypes\n} from './types';\n\n// https://www.geopackage.org/spec121/#flags_layout\nconst ENVELOPE_BYTE_LENGTHS = {\n 0: 0,\n 1: 32,\n 2: 48,\n 3: 48,\n 4: 64,\n // values 5-7 are invalid and _should_ never show up\n 5: 0,\n 6: 0,\n 7: 0\n};\n\n// Documentation: https://www.geopackage.org/spec130/index.html#table_column_data_types\nconst SQL_TYPE_MAPPING: {[type in SQLiteTypes]: typeof DataType} = {\n BOOLEAN: Bool,\n TINYINT: Int8,\n SMALLINT: Int16,\n MEDIUMINT: Int32,\n INT: Int32,\n INTEGER: Int32,\n FLOAT: Float32,\n DOUBLE: Float64,\n REAL: Float64,\n TEXT: Utf8,\n BLOB: Binary,\n DATE: Utf8,\n DATETIME: Utf8,\n GEOMETRY: Binary\n};\n\nexport default async function parseGeoPackage(\n arrayBuffer: ArrayBuffer,\n options?: GeoPackageLoaderOptions\n) {\n const {sqlJsCDN = 'https://sql.js.org/dist/'} = options?.geopackage || {};\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n\n const db = await loadDatabase(arrayBuffer, sqlJsCDN);\n const tables = listVectorTables(db);\n const projections = getProjections(db);\n\n // Mapping from tableName to geojson feature collection\n const result = {};\n for (const table of tables) {\n const {table_name: tableName} = table;\n result[tableName] = getVectorTable(db, tableName, projections, {\n reproject,\n _targetCrs\n });\n }\n\n return result;\n}\n\n/**\n * Initialize SQL.js and create database\n *\n * @param arrayBuffer input bytes\n * @return SQL.js database object\n */\nasync function loadDatabase(arrayBuffer: ArrayBuffer, sqlJsCDN: string | null): Promise<Database> {\n // In Node, `locateFile` must not be passed\n let SQL: SqlJsStatic;\n if (sqlJsCDN) {\n SQL = await initSqlJs({\n locateFile: (file) => `${sqlJsCDN}${file}`\n });\n } else {\n SQL = await initSqlJs();\n }\n return new SQL.Database(new Uint8Array(arrayBuffer));\n}\n\n/**\n * Find all vector tables in GeoPackage\n * This queries the `gpkg_contents` table to find a list of vector tables\n *\n * @param db GeoPackage to query\n * @return list of table references\n */\nfunction listVectorTables(db: Database): ContentsRow[] {\n // The gpkg_contents table can have at least three categorical values for\n // data_type.\n // - 'features' refers to a vector geometry table\n // (https://www.geopackage.org/spec121/#_contents_2)\n // - 'tiles' refers to a raster table\n // (https://www.geopackage.org/spec121/#_contents_3)\n // - 'attributes' refers to a data table with no geometry\n // (https://www.geopackage.org/spec121/#_contents_4).\n\n // We hard code 'features' because for now we don't support raster data or pure attribute data\n // eslint-disable-next-line quotes\n const stmt = db.prepare(\"SELECT * FROM gpkg_contents WHERE data_type='features';\");\n\n const vectorTablesInfo: ContentsRow[] = [];\n while (stmt.step()) {\n const vectorTableInfo = stmt.getAsObject() as unknown as ContentsRow;\n vectorTablesInfo.push(vectorTableInfo);\n }\n\n return vectorTablesInfo;\n}\n\n/**\n * Load geometries from vector table\n *\n * @param db GeoPackage object\n * @param tableName name of vector table to query\n * @param projections keys are srs_id values, values are WKT strings\n * @returns Array of GeoJSON Feature objects\n */\nfunction getVectorTable(\n db: Database,\n tableName: string,\n projections: ProjectionMapping,\n {reproject, _targetCrs}: {reproject: boolean; _targetCrs: string}\n): object {\n const dataColumns = getDataColumns(db, tableName);\n const geomColumn = getGeometryColumn(db, tableName);\n const featureIdColumn = getFeatureIdName(db, tableName);\n\n // Get vector features from table\n // Don't think it's possible to parameterize the table name in SQLite?\n const {columns, values} = db.exec(`SELECT * FROM \\`${tableName}\\`;`)[0];\n\n let projection;\n if (reproject) {\n const geomColumnProjStr = projections[geomColumn.srs_id];\n projection = new Proj4Projection({\n from: geomColumnProjStr,\n to: _targetCrs\n });\n }\n\n const geojsonFeatures: object[] = [];\n for (const row of values) {\n const geojsonFeature = constructGeoJsonFeature(\n columns,\n row,\n geomColumn,\n // @ts-ignore\n dataColumns,\n featureIdColumn\n );\n geojsonFeatures.push(geojsonFeature);\n }\n\n const schema = getArrowSchema(db, tableName);\n if (projection) {\n return {geojsonFeatures: transformGeoJsonCoords(geojsonFeatures, projection.project), schema};\n }\n\n return {geojsonFeatures, schema};\n}\n\n/**\n * Find all projections defined in GeoPackage\n * This queries the gpkg_spatial_ref_sys table\n * @param db GeoPackage object\n * @returns mapping from srid to WKT projection string\n */\nfunction getProjections(db: Database): ProjectionMapping {\n // Query gpkg_spatial_ref_sys to get srid: srtext mappings\n const stmt = db.prepare('SELECT * FROM gpkg_spatial_ref_sys;');\n\n const projectionMapping: ProjectionMapping = {};\n while (stmt.step()) {\n const srsInfo = stmt.getAsObject() as unknown as SpatialRefSysRow;\n const {srs_id, definition} = srsInfo;\n projectionMapping[srs_id] = definition;\n }\n\n return projectionMapping;\n}\n\n/**\n * Construct single GeoJSON feature given row's data\n * @param columns array of ordered column identifiers\n * @param row array of ordered values representing row's data\n * @param geomColumn geometry column metadata\n * @param dataColumns mapping from table column names to property name\n * @returns GeoJSON Feature object\n */\nfunction constructGeoJsonFeature(\n columns: string[],\n row: any[],\n geomColumn: GeometryColumnsRow,\n dataColumns: DataColumnsMapping,\n featureIdColumn: string\n) {\n // Find feature id\n const idIdx = columns.indexOf(featureIdColumn);\n const id = row[idIdx];\n\n // Parse geometry columns to geojson\n const geomColumnIdx = columns.indexOf(geomColumn.column_name);\n const geometry = parseGeometry(row[geomColumnIdx].buffer);\n\n const properties = {};\n if (dataColumns) {\n for (const [key, value] of Object.entries(dataColumns)) {\n const idx = columns.indexOf(key);\n // @ts-ignore TODO - Check what happens if null?\n properties[value] = row[idx];\n }\n } else {\n // Put all columns except for the feature id and geometry in properties\n for (let i = 0; i < columns.length; i++) {\n if (i === idIdx || i === geomColumnIdx) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n const columnName = columns[i];\n properties[columnName] = row[i];\n }\n }\n\n return {\n id,\n type: 'Feature',\n geometry,\n properties\n };\n}\n\n/**\n * Get GeoPackage version from database\n * @param db database\n * @returns version string. One of '1.0', '1.1', '1.2'\n */\n\n// @ts-ignore\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction getGeopackageVersion(db: Database): string | null {\n const textDecoder = new TextDecoder();\n\n // Read application id from SQLite metadata\n const applicationIdQuery = db.exec('PRAGMA application_id;')[0];\n const applicationId = applicationIdQuery.values[0][0];\n\n // Convert 4-byte signed int32 application id to text\n const buffer = new ArrayBuffer(4);\n const view = new DataView(buffer);\n view.setInt32(0, Number(applicationId));\n const versionString = textDecoder.decode(buffer);\n\n if (versionString === 'GP10') {\n return '1.0';\n }\n\n if (versionString === 'GP11') {\n return '1.1';\n }\n\n // If versionString is GPKG, then read user_version\n const userVersionQuery = db.exec('PRAGMA user_version;')[0];\n const userVersionInt = userVersionQuery.values[0][0];\n\n if (userVersionInt && userVersionInt < 10300) {\n return '1.2';\n }\n\n return null;\n}\n\n/**\n * Find name of feature id column in table\n * The feature ID is the primary key of the table.\n * http://www.geopackage.org/spec121/#feature_user_tables\n *\n * @param db database\n * @param tableName name of table\n * @return name of feature id column\n */\nfunction getFeatureIdName(db: Database, tableName: string): string | null {\n // Again, not possible to parameterize table name?\n const stmt = db.prepare(`PRAGMA table_info(\\`${tableName}\\`)`);\n\n while (stmt.step()) {\n const pragmaTableInfo = stmt.getAsObject() as unknown as PragmaTableInfoRow;\n const {name, pk} = pragmaTableInfo;\n if (pk) {\n return name;\n }\n }\n\n // Is it guaranteed for there always to be at least one primary key column in the table?\n return null;\n}\n\n/**\n * Parse geometry buffer\n * GeoPackage vector geometries are slightly extended past the WKB standard\n * See: https://www.geopackage.org/spec121/#gpb_format\n *\n * @param arrayBuffer geometry buffer\n * @return {object} GeoJSON geometry (in original CRS)\n */\nfunction parseGeometry(arrayBuffer: ArrayBuffer): Geometry | null {\n const view = new DataView(arrayBuffer);\n const {envelopeLength, emptyGeometry} = parseGeometryBitFlags(view.getUint8(3));\n\n // A Feature object has a member with the name \"geometry\". The value of the\n // geometry member SHALL be either a Geometry object as defined above or, in\n // the case that the Feature is unlocated, a JSON null value.\n /** @see https://tools.ietf.org/html/rfc7946#section-3.2 */\n if (emptyGeometry) {\n return null;\n }\n\n // Do I need to find the srid here? Is it necessarily the same for every\n // geometry in a table?\n // const srid = view.getInt32(4, littleEndian);\n\n // 2 byte magic, 1 byte version, 1 byte flags, 4 byte int32 srid\n const wkbOffset = 8 + envelopeLength;\n\n // Loaders should not depend on `core` and the context passed to the main loader doesn't include a\n // `parseSync` option, so instead we call parseSync directly on WKBLoader\n const binaryGeometry = WKBLoader.parseSync(arrayBuffer.slice(wkbOffset));\n\n return binaryToGeometry(binaryGeometry);\n}\n\n/**\n * Parse geometry header flags\n * https://www.geopackage.org/spec121/#flags_layout\n *\n * @param byte uint8 number representing flags\n * @return object representing information from bit flags\n */\nfunction parseGeometryBitFlags(byte: number): GeometryBitFlags {\n // Are header values little endian?\n const envelopeValue = (byte & 0b00001110) / 2;\n\n // TODO: Not sure the best way to handle this. Throw an error if envelopeValue outside 0-7?\n const envelopeLength = ENVELOPE_BYTE_LENGTHS[envelopeValue] as number;\n\n return {\n littleEndian: Boolean(byte & 0b00000001),\n envelopeLength,\n emptyGeometry: Boolean(byte & 0b00010000),\n extendedGeometryType: Boolean(byte & 0b00100000)\n };\n}\n\n/**\n * Find geometry column in given vector table\n *\n * @param db GeoPackage object\n * @param tableName Name of vector table\n * @returns Array of geometry column definitions\n */\nfunction getGeometryColumn(db: Database, tableName: string): GeometryColumnsRow {\n const stmt = db.prepare('SELECT * FROM gpkg_geometry_columns WHERE table_name=:tableName;');\n stmt.bind({':tableName': tableName});\n\n // > Requirement 30\n // > A feature table SHALL have only one geometry column.\n // https://www.geopackage.org/spec121/#feature_user_tables\n // So we should need one and only one step, given that we use the WHERE clause in the SQL query\n // above\n stmt.step();\n const geometryColumn = stmt.getAsObject() as unknown as GeometryColumnsRow;\n return geometryColumn;\n}\n\n/**\n * Find property columns in given vector table\n * @param db GeoPackage object\n * @param tableName Name of vector table\n * @returns Mapping from table column names to property name\n */\nfunction getDataColumns(db: Database, tableName: string): DataColumnsMapping | null {\n // gpkg_data_columns is not required to exist\n // https://www.geopackage.org/spec121/#extension_schema\n let stmt: Statement;\n try {\n stmt = db.prepare('SELECT * FROM gpkg_data_columns WHERE table_name=:tableName;');\n } catch (error) {\n if ((error as Error).message.includes('no such table')) {\n return null;\n }\n\n throw error;\n }\n\n stmt.bind({':tableName': tableName});\n\n // Convert DataColumnsRow object this to a key-value {column_name: name}\n const result: DataColumnsMapping = {};\n while (stmt.step()) {\n const column = stmt.getAsObject() as unknown as DataColumnsRow;\n const {column_name, name} = column;\n result[column_name] = name || null;\n }\n\n return result;\n}\n\n/**\n * Get arrow schema\n * @param db GeoPackage object\n * @param tableName table name\n * @returns Arrow-like Schema\n */\nfunction getArrowSchema(db: Database, tableName: string): Schema {\n const stmt = db.prepare(`PRAGMA table_info(\\`${tableName}\\`)`);\n\n const fields: Field[] = [];\n while (stmt.step()) {\n const pragmaTableInfo = stmt.getAsObject() as unknown as PragmaTableInfoRow;\n const {name, type, notnull} = pragmaTableInfo;\n const field = new Field(name, new SQL_TYPE_MAPPING[type](), !notnull);\n fields.push(field);\n }\n\n return new Schema(fields);\n}\n"],"file":"parse-geopackage.js"}
|
package/dist/lib/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|