@loaders.gl/geopackage 3.1.0-alpha.4 → 3.1.0-beta.3
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 +5 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/geopackage-loader.js +2 -2
- package/dist/es5/geopackage-loader.js.map +1 -1
- package/dist/es5/index.js +1 -1
- package/dist/es5/lib/parse-geopackage.js +124 -199
- package/dist/es5/lib/parse-geopackage.js.map +1 -1
- package/dist/esm/lib/parse-geopackage.js +4 -4
- package/dist/esm/lib/parse-geopackage.js.map +1 -1
- package/dist/geopackage-loader.d.ts +13 -0
- package/dist/geopackage-loader.d.ts.map +1 -0
- package/dist/geopackage-loader.js +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/lib/parse-geopackage.d.ts +3 -0
- package/dist/lib/parse-geopackage.d.ts.map +1 -0
- package/dist/lib/parse-geopackage.js +361 -0
- package/dist/lib/types.d.ts +188 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/package.json +6 -6
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
|
package/dist/bundle.js
ADDED
package/dist/es5/bundle.js
CHANGED
package/dist/es5/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":";;AACA,
|
|
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"}
|
|
@@ -9,8 +9,8 @@ exports.GeoPackageLoader = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _parseGeopackage = _interopRequireDefault(require("./lib/parse-geopackage"));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const VERSION = 'latest';
|
|
13
|
+
const GeoPackageLoader = {
|
|
14
14
|
id: 'geopackage',
|
|
15
15
|
name: 'GeoPackage',
|
|
16
16
|
module: 'geopackage',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/geopackage-loader.ts"],"names":["VERSION","GeoPackageLoader","id","name","module","version","extensions","mimeTypes","category","parse","parseGeoPackage","options","geopackage","sqlJsCDN"],"mappings":";;;;;;;;;AACA;;AAKA,
|
|
1
|
+
{"version":3,"sources":["../../src/geopackage-loader.ts"],"names":["VERSION","GeoPackageLoader","id","name","module","version","extensions","mimeTypes","category","parse","parseGeoPackage","options","geopackage","sqlJsCDN"],"mappings":";;;;;;;;;AACA;;AAKA,MAAMA,OAAO,GAAG,QAAhB;AAcO,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,EAAEC,wBARyC;AAShDC,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/es5/index.js
CHANGED
|
@@ -7,12 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = parseGeoPackage;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
-
|
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
10
|
var _sql = _interopRequireDefault(require("sql.js"));
|
|
17
11
|
|
|
18
12
|
var _wkt = require("@loaders.gl/wkt");
|
|
@@ -23,13 +17,7 @@ var _gis = require("@loaders.gl/gis");
|
|
|
23
17
|
|
|
24
18
|
var _proj = require("@math.gl/proj4");
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
-
|
|
30
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
-
|
|
32
|
-
var ENVELOPE_BYTE_LENGTHS = {
|
|
20
|
+
const ENVELOPE_BYTE_LENGTHS = {
|
|
33
21
|
0: 0,
|
|
34
22
|
1: 32,
|
|
35
23
|
2: 48,
|
|
@@ -39,7 +27,7 @@ var ENVELOPE_BYTE_LENGTHS = {
|
|
|
39
27
|
6: 0,
|
|
40
28
|
7: 0
|
|
41
29
|
};
|
|
42
|
-
|
|
30
|
+
const SQL_TYPE_MAPPING = {
|
|
43
31
|
BOOLEAN: _schema.Bool,
|
|
44
32
|
TINYINT: _schema.Int8,
|
|
45
33
|
SMALLINT: _schema.Int16,
|
|
@@ -56,176 +44,111 @@ var SQL_TYPE_MAPPING = {
|
|
|
56
44
|
GEOMETRY: _schema.Binary
|
|
57
45
|
};
|
|
58
46
|
|
|
59
|
-
function parseGeoPackage(
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
async function parseGeoPackage(arrayBuffer, options) {
|
|
48
|
+
const {
|
|
49
|
+
sqlJsCDN = 'https://sql.js.org/dist/'
|
|
50
|
+
} = (options === null || options === void 0 ? void 0 : options.geopackage) || {};
|
|
51
|
+
const {
|
|
52
|
+
reproject = false,
|
|
53
|
+
_targetCrs = 'WGS84'
|
|
54
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
55
|
+
const db = await loadDatabase(arrayBuffer, sqlJsCDN);
|
|
56
|
+
const tables = listVectorTables(db);
|
|
57
|
+
const projections = getProjections(db);
|
|
58
|
+
const result = {};
|
|
59
|
+
|
|
60
|
+
for (const table of tables) {
|
|
61
|
+
const {
|
|
62
|
+
table_name: tableName
|
|
63
|
+
} = table;
|
|
64
|
+
result[tableName] = getVectorTable(db, tableName, projections, {
|
|
65
|
+
reproject,
|
|
66
|
+
_targetCrs
|
|
67
|
+
});
|
|
68
|
+
}
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
_parseGeoPackage = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options) {
|
|
65
|
-
var _ref2, _ref2$sqlJsCDN, sqlJsCDN, _ref3, _ref3$reproject, reproject, _ref3$_targetCrs, _targetCrs, db, tables, projections, result, _iterator2, _step2, table, tableName;
|
|
66
|
-
|
|
67
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
68
|
-
while (1) {
|
|
69
|
-
switch (_context.prev = _context.next) {
|
|
70
|
-
case 0:
|
|
71
|
-
_ref2 = (options === null || options === void 0 ? void 0 : options.geopackage) || {}, _ref2$sqlJsCDN = _ref2.sqlJsCDN, sqlJsCDN = _ref2$sqlJsCDN === void 0 ? 'https://sql.js.org/dist/' : _ref2$sqlJsCDN;
|
|
72
|
-
_ref3 = (options === null || options === void 0 ? void 0 : options.gis) || {}, _ref3$reproject = _ref3.reproject, reproject = _ref3$reproject === void 0 ? false : _ref3$reproject, _ref3$_targetCrs = _ref3._targetCrs, _targetCrs = _ref3$_targetCrs === void 0 ? 'WGS84' : _ref3$_targetCrs;
|
|
73
|
-
_context.next = 4;
|
|
74
|
-
return loadDatabase(arrayBuffer, sqlJsCDN);
|
|
75
|
-
|
|
76
|
-
case 4:
|
|
77
|
-
db = _context.sent;
|
|
78
|
-
tables = listVectorTables(db);
|
|
79
|
-
projections = getProjections(db);
|
|
80
|
-
result = {};
|
|
81
|
-
_iterator2 = _createForOfIteratorHelper(tables);
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
85
|
-
table = _step2.value;
|
|
86
|
-
tableName = table.table_name;
|
|
87
|
-
result[tableName] = getVectorTable(db, tableName, projections, {
|
|
88
|
-
reproject: reproject,
|
|
89
|
-
_targetCrs: _targetCrs
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
} catch (err) {
|
|
93
|
-
_iterator2.e(err);
|
|
94
|
-
} finally {
|
|
95
|
-
_iterator2.f();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return _context.abrupt("return", result);
|
|
99
|
-
|
|
100
|
-
case 11:
|
|
101
|
-
case "end":
|
|
102
|
-
return _context.stop();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}, _callee);
|
|
106
|
-
}));
|
|
107
|
-
return _parseGeoPackage.apply(this, arguments);
|
|
70
|
+
return result;
|
|
108
71
|
}
|
|
109
72
|
|
|
110
|
-
function loadDatabase(
|
|
111
|
-
|
|
112
|
-
}
|
|
73
|
+
async function loadDatabase(arrayBuffer, sqlJsCDN) {
|
|
74
|
+
let SQL;
|
|
113
75
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
_context2.next = 3;
|
|
127
|
-
return (0, _sql.default)({
|
|
128
|
-
locateFile: function locateFile(file) {
|
|
129
|
-
return "".concat(sqlJsCDN).concat(file);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
case 3:
|
|
134
|
-
SQL = _context2.sent;
|
|
135
|
-
_context2.next = 9;
|
|
136
|
-
break;
|
|
137
|
-
|
|
138
|
-
case 6:
|
|
139
|
-
_context2.next = 8;
|
|
140
|
-
return (0, _sql.default)();
|
|
141
|
-
|
|
142
|
-
case 8:
|
|
143
|
-
SQL = _context2.sent;
|
|
144
|
-
|
|
145
|
-
case 9:
|
|
146
|
-
return _context2.abrupt("return", new SQL.Database(new Uint8Array(arrayBuffer)));
|
|
147
|
-
|
|
148
|
-
case 10:
|
|
149
|
-
case "end":
|
|
150
|
-
return _context2.stop();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}, _callee2);
|
|
154
|
-
}));
|
|
155
|
-
return _loadDatabase.apply(this, arguments);
|
|
76
|
+
if (sqlJsCDN) {
|
|
77
|
+
SQL = await (0, _sql.default)({
|
|
78
|
+
locateFile: file => "".concat(sqlJsCDN).concat(file)
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
SQL = await (0, _sql.default)();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return new SQL.Database(new Uint8Array(arrayBuffer));
|
|
156
85
|
}
|
|
157
86
|
|
|
158
87
|
function listVectorTables(db) {
|
|
159
|
-
|
|
160
|
-
|
|
88
|
+
const stmt = db.prepare("SELECT * FROM gpkg_contents WHERE data_type='features';");
|
|
89
|
+
const vectorTablesInfo = [];
|
|
161
90
|
|
|
162
91
|
while (stmt.step()) {
|
|
163
|
-
|
|
92
|
+
const vectorTableInfo = stmt.getAsObject();
|
|
164
93
|
vectorTablesInfo.push(vectorTableInfo);
|
|
165
94
|
}
|
|
166
95
|
|
|
167
96
|
return vectorTablesInfo;
|
|
168
97
|
}
|
|
169
98
|
|
|
170
|
-
function getVectorTable(db, tableName, projections,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
99
|
+
function getVectorTable(db, tableName, projections, {
|
|
100
|
+
reproject,
|
|
101
|
+
_targetCrs
|
|
102
|
+
}) {
|
|
103
|
+
const dataColumns = getDataColumns(db, tableName);
|
|
104
|
+
const geomColumn = getGeometryColumn(db, tableName);
|
|
105
|
+
const featureIdColumn = getFeatureIdName(db, tableName);
|
|
106
|
+
const {
|
|
107
|
+
columns,
|
|
108
|
+
values
|
|
109
|
+
} = db.exec("SELECT * FROM `".concat(tableName, "`;"))[0];
|
|
110
|
+
let projection;
|
|
180
111
|
|
|
181
112
|
if (reproject) {
|
|
182
|
-
|
|
113
|
+
const geomColumnProjStr = projections[geomColumn.srs_id];
|
|
183
114
|
projection = new _proj.Proj4Projection({
|
|
184
115
|
from: geomColumnProjStr,
|
|
185
116
|
to: _targetCrs
|
|
186
117
|
});
|
|
187
118
|
}
|
|
188
119
|
|
|
189
|
-
|
|
120
|
+
const geojsonFeatures = [];
|
|
190
121
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
196
|
-
var row = _step.value;
|
|
197
|
-
var geojsonFeature = constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn);
|
|
198
|
-
geojsonFeatures.push(geojsonFeature);
|
|
199
|
-
}
|
|
200
|
-
} catch (err) {
|
|
201
|
-
_iterator.e(err);
|
|
202
|
-
} finally {
|
|
203
|
-
_iterator.f();
|
|
122
|
+
for (const row of values) {
|
|
123
|
+
const geojsonFeature = constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn);
|
|
124
|
+
geojsonFeatures.push(geojsonFeature);
|
|
204
125
|
}
|
|
205
126
|
|
|
206
|
-
|
|
127
|
+
const schema = getArrowSchema(db, tableName);
|
|
207
128
|
|
|
208
129
|
if (projection) {
|
|
209
130
|
return {
|
|
210
131
|
geojsonFeatures: (0, _gis.transformGeoJsonCoords)(geojsonFeatures, projection.project),
|
|
211
|
-
schema
|
|
132
|
+
schema
|
|
212
133
|
};
|
|
213
134
|
}
|
|
214
135
|
|
|
215
136
|
return {
|
|
216
|
-
geojsonFeatures
|
|
217
|
-
schema
|
|
137
|
+
geojsonFeatures,
|
|
138
|
+
schema
|
|
218
139
|
};
|
|
219
140
|
}
|
|
220
141
|
|
|
221
142
|
function getProjections(db) {
|
|
222
|
-
|
|
223
|
-
|
|
143
|
+
const stmt = db.prepare('SELECT * FROM gpkg_spatial_ref_sys;');
|
|
144
|
+
const projectionMapping = {};
|
|
224
145
|
|
|
225
146
|
while (stmt.step()) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
147
|
+
const srsInfo = stmt.getAsObject();
|
|
148
|
+
const {
|
|
149
|
+
srs_id,
|
|
150
|
+
definition
|
|
151
|
+
} = srsInfo;
|
|
229
152
|
projectionMapping[srs_id] = definition;
|
|
230
153
|
}
|
|
231
154
|
|
|
@@ -233,48 +156,44 @@ function getProjections(db) {
|
|
|
233
156
|
}
|
|
234
157
|
|
|
235
158
|
function constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
159
|
+
const idIdx = columns.indexOf(featureIdColumn);
|
|
160
|
+
const id = row[idIdx];
|
|
161
|
+
const geomColumnIdx = columns.indexOf(geomColumn.column_name);
|
|
162
|
+
const geometry = parseGeometry(row[geomColumnIdx].buffer);
|
|
163
|
+
const properties = {};
|
|
241
164
|
|
|
242
165
|
if (dataColumns) {
|
|
243
|
-
for (
|
|
244
|
-
|
|
245
|
-
key = _Object$entries$_i[0],
|
|
246
|
-
value = _Object$entries$_i[1];
|
|
247
|
-
|
|
248
|
-
var idx = columns.indexOf(key);
|
|
166
|
+
for (const [key, value] of Object.entries(dataColumns)) {
|
|
167
|
+
const idx = columns.indexOf(key);
|
|
249
168
|
properties[value] = row[idx];
|
|
250
169
|
}
|
|
251
170
|
} else {
|
|
252
|
-
for (
|
|
171
|
+
for (let i = 0; i < columns.length; i++) {
|
|
253
172
|
if (i === idIdx || i === geomColumnIdx) {
|
|
254
173
|
continue;
|
|
255
174
|
}
|
|
256
175
|
|
|
257
|
-
|
|
176
|
+
const columnName = columns[i];
|
|
258
177
|
properties[columnName] = row[i];
|
|
259
178
|
}
|
|
260
179
|
}
|
|
261
180
|
|
|
262
181
|
return {
|
|
263
|
-
id
|
|
182
|
+
id,
|
|
264
183
|
type: 'Feature',
|
|
265
|
-
geometry
|
|
266
|
-
properties
|
|
184
|
+
geometry,
|
|
185
|
+
properties
|
|
267
186
|
};
|
|
268
187
|
}
|
|
269
188
|
|
|
270
189
|
function getGeopackageVersion(db) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
190
|
+
const textDecoder = new TextDecoder();
|
|
191
|
+
const applicationIdQuery = db.exec('PRAGMA application_id;')[0];
|
|
192
|
+
const applicationId = applicationIdQuery.values[0][0];
|
|
193
|
+
const buffer = new ArrayBuffer(4);
|
|
194
|
+
const view = new DataView(buffer);
|
|
276
195
|
view.setInt32(0, Number(applicationId));
|
|
277
|
-
|
|
196
|
+
const versionString = textDecoder.decode(buffer);
|
|
278
197
|
|
|
279
198
|
if (versionString === 'GP10') {
|
|
280
199
|
return '1.0';
|
|
@@ -284,8 +203,8 @@ function getGeopackageVersion(db) {
|
|
|
284
203
|
return '1.1';
|
|
285
204
|
}
|
|
286
205
|
|
|
287
|
-
|
|
288
|
-
|
|
206
|
+
const userVersionQuery = db.exec('PRAGMA user_version;')[0];
|
|
207
|
+
const userVersionInt = userVersionQuery.values[0][0];
|
|
289
208
|
|
|
290
209
|
if (userVersionInt && userVersionInt < 10300) {
|
|
291
210
|
return '1.2';
|
|
@@ -295,12 +214,14 @@ function getGeopackageVersion(db) {
|
|
|
295
214
|
}
|
|
296
215
|
|
|
297
216
|
function getFeatureIdName(db, tableName) {
|
|
298
|
-
|
|
217
|
+
const stmt = db.prepare("PRAGMA table_info(`".concat(tableName, "`)"));
|
|
299
218
|
|
|
300
219
|
while (stmt.step()) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
220
|
+
const pragmaTableInfo = stmt.getAsObject();
|
|
221
|
+
const {
|
|
222
|
+
name,
|
|
223
|
+
pk
|
|
224
|
+
} = pragmaTableInfo;
|
|
304
225
|
|
|
305
226
|
if (pk) {
|
|
306
227
|
return name;
|
|
@@ -311,46 +232,46 @@ function getFeatureIdName(db, tableName) {
|
|
|
311
232
|
}
|
|
312
233
|
|
|
313
234
|
function parseGeometry(arrayBuffer) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
235
|
+
const view = new DataView(arrayBuffer);
|
|
236
|
+
const {
|
|
237
|
+
envelopeLength,
|
|
238
|
+
emptyGeometry
|
|
239
|
+
} = parseGeometryBitFlags(view.getUint8(3));
|
|
319
240
|
|
|
320
241
|
if (emptyGeometry) {
|
|
321
242
|
return null;
|
|
322
243
|
}
|
|
323
244
|
|
|
324
|
-
|
|
245
|
+
const wkbOffset = 8 + envelopeLength;
|
|
325
246
|
|
|
326
|
-
|
|
247
|
+
const binaryGeometry = _wkt.WKBLoader.parseSync(arrayBuffer.slice(wkbOffset));
|
|
327
248
|
|
|
328
249
|
return (0, _gis.binaryToGeometry)(binaryGeometry);
|
|
329
250
|
}
|
|
330
251
|
|
|
331
252
|
function parseGeometryBitFlags(byte) {
|
|
332
|
-
|
|
333
|
-
|
|
253
|
+
const envelopeValue = (byte & 0b00001110) / 2;
|
|
254
|
+
const envelopeLength = ENVELOPE_BYTE_LENGTHS[envelopeValue];
|
|
334
255
|
return {
|
|
335
|
-
littleEndian: Boolean(byte &
|
|
336
|
-
envelopeLength
|
|
337
|
-
emptyGeometry: Boolean(byte &
|
|
338
|
-
extendedGeometryType: Boolean(byte &
|
|
256
|
+
littleEndian: Boolean(byte & 0b00000001),
|
|
257
|
+
envelopeLength,
|
|
258
|
+
emptyGeometry: Boolean(byte & 0b00010000),
|
|
259
|
+
extendedGeometryType: Boolean(byte & 0b00100000)
|
|
339
260
|
};
|
|
340
261
|
}
|
|
341
262
|
|
|
342
263
|
function getGeometryColumn(db, tableName) {
|
|
343
|
-
|
|
264
|
+
const stmt = db.prepare('SELECT * FROM gpkg_geometry_columns WHERE table_name=:tableName;');
|
|
344
265
|
stmt.bind({
|
|
345
266
|
':tableName': tableName
|
|
346
267
|
});
|
|
347
268
|
stmt.step();
|
|
348
|
-
|
|
269
|
+
const geometryColumn = stmt.getAsObject();
|
|
349
270
|
return geometryColumn;
|
|
350
271
|
}
|
|
351
272
|
|
|
352
273
|
function getDataColumns(db, tableName) {
|
|
353
|
-
|
|
274
|
+
let stmt;
|
|
354
275
|
|
|
355
276
|
try {
|
|
356
277
|
stmt = db.prepare('SELECT * FROM gpkg_data_columns WHERE table_name=:tableName;');
|
|
@@ -365,12 +286,14 @@ function getDataColumns(db, tableName) {
|
|
|
365
286
|
stmt.bind({
|
|
366
287
|
':tableName': tableName
|
|
367
288
|
});
|
|
368
|
-
|
|
289
|
+
const result = {};
|
|
369
290
|
|
|
370
291
|
while (stmt.step()) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
292
|
+
const column = stmt.getAsObject();
|
|
293
|
+
const {
|
|
294
|
+
column_name,
|
|
295
|
+
name
|
|
296
|
+
} = column;
|
|
374
297
|
result[column_name] = name || null;
|
|
375
298
|
}
|
|
376
299
|
|
|
@@ -378,15 +301,17 @@ function getDataColumns(db, tableName) {
|
|
|
378
301
|
}
|
|
379
302
|
|
|
380
303
|
function getArrowSchema(db, tableName) {
|
|
381
|
-
|
|
382
|
-
|
|
304
|
+
const stmt = db.prepare("PRAGMA table_info(`".concat(tableName, "`)"));
|
|
305
|
+
const fields = [];
|
|
383
306
|
|
|
384
307
|
while (stmt.step()) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
308
|
+
const pragmaTableInfo = stmt.getAsObject();
|
|
309
|
+
const {
|
|
310
|
+
name,
|
|
311
|
+
type,
|
|
312
|
+
notnull
|
|
313
|
+
} = pragmaTableInfo;
|
|
314
|
+
const field = new _schema.Field(name, new SQL_TYPE_MAPPING[type](), !notnull);
|
|
390
315
|
fields.push(field);
|
|
391
316
|
}
|
|
392
317
|
|