@loaders.gl/geopackage 3.1.3 → 4.0.0-alpha.5
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.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/geopackage-loader.js +15 -24
- package/dist/geopackage-loader.js.map +1 -0
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -0
- package/dist/lib/parse-geopackage.js +271 -329
- package/dist/lib/parse-geopackage.js.map +1 -0
- package/dist/lib/types.js +2 -2
- package/dist/{es5/lib → lib}/types.js.map +0 -0
- package/package.json +7 -7
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/geopackage-loader.js +0 -29
- package/dist/es5/geopackage-loader.js.map +0 -1
- package/dist/es5/index.js +0 -14
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/parse-geopackage.js +0 -395
- package/dist/es5/lib/parse-geopackage.js.map +0 -1
- package/dist/es5/lib/types.js +0 -2
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/geopackage-loader.js +0 -18
- package/dist/esm/geopackage-loader.js.map +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/parse-geopackage.js +0 -303
- package/dist/esm/lib/parse-geopackage.js.map +0 -1
- package/dist/esm/lib/types.js +0 -2
- package/dist/esm/lib/types.js.map +0 -1
|
@@ -1,361 +1,303 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const sql_js_1 = __importDefault(require("sql.js"));
|
|
7
|
-
const wkt_1 = require("@loaders.gl/wkt");
|
|
8
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
9
|
-
const gis_1 = require("@loaders.gl/gis");
|
|
10
|
-
const proj4_1 = require("@math.gl/proj4");
|
|
11
|
-
// https://www.geopackage.org/spec121/#flags_layout
|
|
1
|
+
import initSqlJs from 'sql.js';
|
|
2
|
+
import { WKBLoader } from '@loaders.gl/wkt';
|
|
3
|
+
import { Schema, Field, Bool, Utf8, Float64, Int32, Int8, Int16, Float32, Binary } from '@loaders.gl/schema';
|
|
4
|
+
import { binaryToGeometry, transformGeoJsonCoords } from '@loaders.gl/gis';
|
|
5
|
+
import { Proj4Projection } from '@math.gl/proj4';
|
|
12
6
|
const ENVELOPE_BYTE_LENGTHS = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
7: 0
|
|
7
|
+
0: 0,
|
|
8
|
+
1: 32,
|
|
9
|
+
2: 48,
|
|
10
|
+
3: 48,
|
|
11
|
+
4: 64,
|
|
12
|
+
5: 0,
|
|
13
|
+
6: 0,
|
|
14
|
+
7: 0
|
|
22
15
|
};
|
|
23
|
-
// Documentation: https://www.geopackage.org/spec130/index.html#table_column_data_types
|
|
24
16
|
const SQL_TYPE_MAPPING = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
BOOLEAN: Bool,
|
|
18
|
+
TINYINT: Int8,
|
|
19
|
+
SMALLINT: Int16,
|
|
20
|
+
MEDIUMINT: Int32,
|
|
21
|
+
INT: Int32,
|
|
22
|
+
INTEGER: Int32,
|
|
23
|
+
FLOAT: Float32,
|
|
24
|
+
DOUBLE: Float64,
|
|
25
|
+
REAL: Float64,
|
|
26
|
+
TEXT: Utf8,
|
|
27
|
+
BLOB: Binary,
|
|
28
|
+
DATE: Utf8,
|
|
29
|
+
DATETIME: Utf8,
|
|
30
|
+
GEOMETRY: Binary
|
|
39
31
|
};
|
|
40
|
-
async function parseGeoPackage(arrayBuffer, options) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
32
|
+
export default async function parseGeoPackage(arrayBuffer, options) {
|
|
33
|
+
const {
|
|
34
|
+
sqlJsCDN = 'https://sql.js.org/dist/'
|
|
35
|
+
} = (options === null || options === void 0 ? void 0 : options.geopackage) || {};
|
|
36
|
+
const {
|
|
37
|
+
reproject = false,
|
|
38
|
+
_targetCrs = 'WGS84'
|
|
39
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
40
|
+
const db = await loadDatabase(arrayBuffer, sqlJsCDN);
|
|
41
|
+
const tables = listVectorTables(db);
|
|
42
|
+
const projections = getProjections(db);
|
|
43
|
+
const result = {};
|
|
44
|
+
|
|
45
|
+
for (const table of tables) {
|
|
46
|
+
const {
|
|
47
|
+
table_name: tableName
|
|
48
|
+
} = table;
|
|
49
|
+
result[tableName] = getVectorTable(db, tableName, projections, {
|
|
50
|
+
reproject,
|
|
51
|
+
_targetCrs
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return result;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Initialize SQL.js and create database
|
|
60
|
-
*
|
|
61
|
-
* @param arrayBuffer input bytes
|
|
62
|
-
* @return SQL.js database object
|
|
63
|
-
*/
|
|
57
|
+
|
|
64
58
|
async function loadDatabase(arrayBuffer, sqlJsCDN) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
let SQL;
|
|
60
|
+
|
|
61
|
+
if (sqlJsCDN) {
|
|
62
|
+
SQL = await initSqlJs({
|
|
63
|
+
locateFile: file => "".concat(sqlJsCDN).concat(file)
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
SQL = await initSqlJs();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return new SQL.Database(new Uint8Array(arrayBuffer));
|
|
76
70
|
}
|
|
77
|
-
|
|
78
|
-
* Find all vector tables in GeoPackage
|
|
79
|
-
* This queries the `gpkg_contents` table to find a list of vector tables
|
|
80
|
-
*
|
|
81
|
-
* @param db GeoPackage to query
|
|
82
|
-
* @return list of table references
|
|
83
|
-
*/
|
|
71
|
+
|
|
84
72
|
function listVectorTables(db) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// eslint-disable-next-line quotes
|
|
95
|
-
const stmt = db.prepare("SELECT * FROM gpkg_contents WHERE data_type='features';");
|
|
96
|
-
const vectorTablesInfo = [];
|
|
97
|
-
while (stmt.step()) {
|
|
98
|
-
const vectorTableInfo = stmt.getAsObject();
|
|
99
|
-
vectorTablesInfo.push(vectorTableInfo);
|
|
100
|
-
}
|
|
101
|
-
return vectorTablesInfo;
|
|
73
|
+
const stmt = db.prepare("SELECT * FROM gpkg_contents WHERE data_type='features';");
|
|
74
|
+
const vectorTablesInfo = [];
|
|
75
|
+
|
|
76
|
+
while (stmt.step()) {
|
|
77
|
+
const vectorTableInfo = stmt.getAsObject();
|
|
78
|
+
vectorTablesInfo.push(vectorTableInfo);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return vectorTablesInfo;
|
|
102
82
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
83
|
+
|
|
84
|
+
function getVectorTable(db, tableName, projections, {
|
|
85
|
+
reproject,
|
|
86
|
+
_targetCrs
|
|
87
|
+
}) {
|
|
88
|
+
const dataColumns = getDataColumns(db, tableName);
|
|
89
|
+
const geomColumn = getGeometryColumn(db, tableName);
|
|
90
|
+
const featureIdColumn = getFeatureIdName(db, tableName);
|
|
91
|
+
const {
|
|
92
|
+
columns,
|
|
93
|
+
values
|
|
94
|
+
} = db.exec("SELECT * FROM `".concat(tableName, "`;"))[0];
|
|
95
|
+
let projection;
|
|
96
|
+
|
|
97
|
+
if (reproject) {
|
|
98
|
+
const geomColumnProjStr = projections[geomColumn.srs_id];
|
|
99
|
+
projection = new Proj4Projection({
|
|
100
|
+
from: geomColumnProjStr,
|
|
101
|
+
to: _targetCrs
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const geojsonFeatures = [];
|
|
106
|
+
|
|
107
|
+
for (const row of values) {
|
|
108
|
+
const geojsonFeature = constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn);
|
|
109
|
+
geojsonFeatures.push(geojsonFeature);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const schema = getArrowSchema(db, tableName);
|
|
113
|
+
|
|
114
|
+
if (projection) {
|
|
115
|
+
return {
|
|
116
|
+
geojsonFeatures: transformGeoJsonCoords(geojsonFeatures, projection.project),
|
|
117
|
+
schema
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
geojsonFeatures,
|
|
123
|
+
schema
|
|
124
|
+
};
|
|
138
125
|
}
|
|
139
|
-
|
|
140
|
-
* Find all projections defined in GeoPackage
|
|
141
|
-
* This queries the gpkg_spatial_ref_sys table
|
|
142
|
-
* @param db GeoPackage object
|
|
143
|
-
* @returns mapping from srid to WKT projection string
|
|
144
|
-
*/
|
|
126
|
+
|
|
145
127
|
function getProjections(db) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
128
|
+
const stmt = db.prepare('SELECT * FROM gpkg_spatial_ref_sys;');
|
|
129
|
+
const projectionMapping = {};
|
|
130
|
+
|
|
131
|
+
while (stmt.step()) {
|
|
132
|
+
const srsInfo = stmt.getAsObject();
|
|
133
|
+
const {
|
|
134
|
+
srs_id,
|
|
135
|
+
definition
|
|
136
|
+
} = srsInfo;
|
|
137
|
+
projectionMapping[srs_id] = definition;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return projectionMapping;
|
|
155
141
|
}
|
|
156
|
-
|
|
157
|
-
* Construct single GeoJSON feature given row's data
|
|
158
|
-
* @param columns array of ordered column identifiers
|
|
159
|
-
* @param row array of ordered values representing row's data
|
|
160
|
-
* @param geomColumn geometry column metadata
|
|
161
|
-
* @param dataColumns mapping from table column names to property name
|
|
162
|
-
* @returns GeoJSON Feature object
|
|
163
|
-
*/
|
|
142
|
+
|
|
164
143
|
function constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// @ts-ignore TODO - Check what happens if null?
|
|
176
|
-
properties[value] = row[idx];
|
|
177
|
-
}
|
|
144
|
+
const idIdx = columns.indexOf(featureIdColumn);
|
|
145
|
+
const id = row[idIdx];
|
|
146
|
+
const geomColumnIdx = columns.indexOf(geomColumn.column_name);
|
|
147
|
+
const geometry = parseGeometry(row[geomColumnIdx].buffer);
|
|
148
|
+
const properties = {};
|
|
149
|
+
|
|
150
|
+
if (dataColumns) {
|
|
151
|
+
for (const [key, value] of Object.entries(dataColumns)) {
|
|
152
|
+
const idx = columns.indexOf(key);
|
|
153
|
+
properties[value] = row[idx];
|
|
178
154
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
properties[columnName] = row[i];
|
|
188
|
-
}
|
|
155
|
+
} else {
|
|
156
|
+
for (let i = 0; i < columns.length; i++) {
|
|
157
|
+
if (i === idIdx || i === geomColumnIdx) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const columnName = columns[i];
|
|
162
|
+
properties[columnName] = row[i];
|
|
189
163
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
id,
|
|
168
|
+
type: 'Feature',
|
|
169
|
+
geometry,
|
|
170
|
+
properties
|
|
171
|
+
};
|
|
196
172
|
}
|
|
197
|
-
|
|
198
|
-
* Get GeoPackage version from database
|
|
199
|
-
* @param db database
|
|
200
|
-
* @returns version string. One of '1.0', '1.1', '1.2'
|
|
201
|
-
*/
|
|
202
|
-
// @ts-ignore
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
173
|
+
|
|
204
174
|
function getGeopackageVersion(db) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
175
|
+
const textDecoder = new TextDecoder();
|
|
176
|
+
const applicationIdQuery = db.exec('PRAGMA application_id;')[0];
|
|
177
|
+
const applicationId = applicationIdQuery.values[0][0];
|
|
178
|
+
const buffer = new ArrayBuffer(4);
|
|
179
|
+
const view = new DataView(buffer);
|
|
180
|
+
view.setInt32(0, Number(applicationId));
|
|
181
|
+
const versionString = textDecoder.decode(buffer);
|
|
182
|
+
|
|
183
|
+
if (versionString === 'GP10') {
|
|
184
|
+
return '1.0';
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (versionString === 'GP11') {
|
|
188
|
+
return '1.1';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const userVersionQuery = db.exec('PRAGMA user_version;')[0];
|
|
192
|
+
const userVersionInt = userVersionQuery.values[0][0];
|
|
193
|
+
|
|
194
|
+
if (userVersionInt && userVersionInt < 10300) {
|
|
195
|
+
return '1.2';
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return null;
|
|
227
199
|
}
|
|
228
|
-
|
|
229
|
-
* Find name of feature id column in table
|
|
230
|
-
* The feature ID is the primary key of the table.
|
|
231
|
-
* http://www.geopackage.org/spec121/#feature_user_tables
|
|
232
|
-
*
|
|
233
|
-
* @param db database
|
|
234
|
-
* @param tableName name of table
|
|
235
|
-
* @return name of feature id column
|
|
236
|
-
*/
|
|
200
|
+
|
|
237
201
|
function getFeatureIdName(db, tableName) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
202
|
+
const stmt = db.prepare("PRAGMA table_info(`".concat(tableName, "`)"));
|
|
203
|
+
|
|
204
|
+
while (stmt.step()) {
|
|
205
|
+
const pragmaTableInfo = stmt.getAsObject();
|
|
206
|
+
const {
|
|
207
|
+
name,
|
|
208
|
+
pk
|
|
209
|
+
} = pragmaTableInfo;
|
|
210
|
+
|
|
211
|
+
if (pk) {
|
|
212
|
+
return name;
|
|
246
213
|
}
|
|
247
|
-
|
|
248
|
-
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return null;
|
|
249
217
|
}
|
|
250
|
-
|
|
251
|
-
* Parse geometry buffer
|
|
252
|
-
* GeoPackage vector geometries are slightly extended past the WKB standard
|
|
253
|
-
* See: https://www.geopackage.org/spec121/#gpb_format
|
|
254
|
-
*
|
|
255
|
-
* @param arrayBuffer geometry buffer
|
|
256
|
-
* @return {object} GeoJSON geometry (in original CRS)
|
|
257
|
-
*/
|
|
218
|
+
|
|
258
219
|
function parseGeometry(arrayBuffer) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const wkbOffset = 8 + envelopeLength;
|
|
273
|
-
// Loaders should not depend on `core` and the context passed to the main loader doesn't include a
|
|
274
|
-
// `parseSync` option, so instead we call parseSync directly on WKBLoader
|
|
275
|
-
const binaryGeometry = wkt_1.WKBLoader.parseSync(arrayBuffer.slice(wkbOffset));
|
|
276
|
-
return (0, gis_1.binaryToGeometry)(binaryGeometry);
|
|
220
|
+
const view = new DataView(arrayBuffer);
|
|
221
|
+
const {
|
|
222
|
+
envelopeLength,
|
|
223
|
+
emptyGeometry
|
|
224
|
+
} = parseGeometryBitFlags(view.getUint8(3));
|
|
225
|
+
|
|
226
|
+
if (emptyGeometry) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const wkbOffset = 8 + envelopeLength;
|
|
231
|
+
const binaryGeometry = WKBLoader.parseSync(arrayBuffer.slice(wkbOffset));
|
|
232
|
+
return binaryToGeometry(binaryGeometry);
|
|
277
233
|
}
|
|
278
|
-
|
|
279
|
-
* Parse geometry header flags
|
|
280
|
-
* https://www.geopackage.org/spec121/#flags_layout
|
|
281
|
-
*
|
|
282
|
-
* @param byte uint8 number representing flags
|
|
283
|
-
* @return object representing information from bit flags
|
|
284
|
-
*/
|
|
234
|
+
|
|
285
235
|
function parseGeometryBitFlags(byte) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
extendedGeometryType: Boolean(byte & 0b00100000)
|
|
295
|
-
};
|
|
236
|
+
const envelopeValue = (byte & 0b00001110) / 2;
|
|
237
|
+
const envelopeLength = ENVELOPE_BYTE_LENGTHS[envelopeValue];
|
|
238
|
+
return {
|
|
239
|
+
littleEndian: Boolean(byte & 0b00000001),
|
|
240
|
+
envelopeLength,
|
|
241
|
+
emptyGeometry: Boolean(byte & 0b00010000),
|
|
242
|
+
extendedGeometryType: Boolean(byte & 0b00100000)
|
|
243
|
+
};
|
|
296
244
|
}
|
|
297
|
-
|
|
298
|
-
* Find geometry column in given vector table
|
|
299
|
-
*
|
|
300
|
-
* @param db GeoPackage object
|
|
301
|
-
* @param tableName Name of vector table
|
|
302
|
-
* @returns Array of geometry column definitions
|
|
303
|
-
*/
|
|
245
|
+
|
|
304
246
|
function getGeometryColumn(db, tableName) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
stmt.step();
|
|
313
|
-
const geometryColumn = stmt.getAsObject();
|
|
314
|
-
return geometryColumn;
|
|
247
|
+
const stmt = db.prepare('SELECT * FROM gpkg_geometry_columns WHERE table_name=:tableName;');
|
|
248
|
+
stmt.bind({
|
|
249
|
+
':tableName': tableName
|
|
250
|
+
});
|
|
251
|
+
stmt.step();
|
|
252
|
+
const geometryColumn = stmt.getAsObject();
|
|
253
|
+
return geometryColumn;
|
|
315
254
|
}
|
|
316
|
-
|
|
317
|
-
* Find property columns in given vector table
|
|
318
|
-
* @param db GeoPackage object
|
|
319
|
-
* @param tableName Name of vector table
|
|
320
|
-
* @returns Mapping from table column names to property name
|
|
321
|
-
*/
|
|
255
|
+
|
|
322
256
|
function getDataColumns(db, tableName) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
257
|
+
let stmt;
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
stmt = db.prepare('SELECT * FROM gpkg_data_columns WHERE table_name=:tableName;');
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (error.message.includes('no such table')) {
|
|
263
|
+
return null;
|
|
328
264
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
265
|
+
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
stmt.bind({
|
|
270
|
+
':tableName': tableName
|
|
271
|
+
});
|
|
272
|
+
const result = {};
|
|
273
|
+
|
|
274
|
+
while (stmt.step()) {
|
|
275
|
+
const column = stmt.getAsObject();
|
|
276
|
+
const {
|
|
277
|
+
column_name,
|
|
278
|
+
name
|
|
279
|
+
} = column;
|
|
280
|
+
result[column_name] = name || null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return result;
|
|
344
284
|
}
|
|
345
|
-
|
|
346
|
-
* Get arrow schema
|
|
347
|
-
* @param db GeoPackage object
|
|
348
|
-
* @param tableName table name
|
|
349
|
-
* @returns Arrow-like Schema
|
|
350
|
-
*/
|
|
285
|
+
|
|
351
286
|
function getArrowSchema(db, tableName) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
287
|
+
const stmt = db.prepare("PRAGMA table_info(`".concat(tableName, "`)"));
|
|
288
|
+
const fields = [];
|
|
289
|
+
|
|
290
|
+
while (stmt.step()) {
|
|
291
|
+
const pragmaTableInfo = stmt.getAsObject();
|
|
292
|
+
const {
|
|
293
|
+
name,
|
|
294
|
+
type,
|
|
295
|
+
notnull
|
|
296
|
+
} = pragmaTableInfo;
|
|
297
|
+
const field = new Field(name, new SQL_TYPE_MAPPING[type](), !notnull);
|
|
298
|
+
fields.push(field);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return new Schema(fields);
|
|
361
302
|
}
|
|
303
|
+
//# sourceMappingURL=parse-geopackage.js.map
|