@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,292 @@
|
|
|
1
|
+
import initSqlJs from 'sql.js';
|
|
2
|
+
import { WKBLoader } from '@loaders.gl/wkt';
|
|
3
|
+
import { binaryToGeometry, transformGeoJsonCoords } from '@loaders.gl/gis';
|
|
4
|
+
import { Proj4Projection } from '@math.gl/proj4';
|
|
5
|
+
export const DEFAULT_SQLJS_CDN = 'https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.5.0/';
|
|
6
|
+
const ENVELOPE_BYTE_LENGTHS = {
|
|
7
|
+
0: 0,
|
|
8
|
+
1: 32,
|
|
9
|
+
2: 48,
|
|
10
|
+
3: 48,
|
|
11
|
+
4: 64,
|
|
12
|
+
5: 0,
|
|
13
|
+
6: 0,
|
|
14
|
+
7: 0
|
|
15
|
+
};
|
|
16
|
+
const SQL_TYPE_MAPPING = {
|
|
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',
|
|
31
|
+
POINT: 'binary',
|
|
32
|
+
LINESTRING: 'binary',
|
|
33
|
+
POLYGON: 'binary',
|
|
34
|
+
MULTIPOINT: 'binary',
|
|
35
|
+
MULTILINESTRING: 'binary',
|
|
36
|
+
MULTIPOLYGON: 'binary',
|
|
37
|
+
GEOMETRYCOLLECTION: 'binary'
|
|
38
|
+
};
|
|
39
|
+
export default async function parseGeoPackage(arrayBuffer, options) {
|
|
40
|
+
const {
|
|
41
|
+
sqlJsCDN = DEFAULT_SQLJS_CDN
|
|
42
|
+
} = (options === null || options === void 0 ? void 0 : options.geopackage) || {};
|
|
43
|
+
const {
|
|
44
|
+
reproject = false,
|
|
45
|
+
_targetCrs = 'WGS84',
|
|
46
|
+
format = 'tables'
|
|
47
|
+
} = (options === null || options === void 0 ? void 0 : options.gis) || {};
|
|
48
|
+
const db = await loadDatabase(arrayBuffer, sqlJsCDN);
|
|
49
|
+
const tables = listVectorTables(db);
|
|
50
|
+
const projections = getProjections(db);
|
|
51
|
+
const outputTables = {
|
|
52
|
+
shape: 'tables',
|
|
53
|
+
tables: []
|
|
54
|
+
};
|
|
55
|
+
for (const table of tables) {
|
|
56
|
+
const {
|
|
57
|
+
table_name: tableName
|
|
58
|
+
} = table;
|
|
59
|
+
outputTables.tables.push({
|
|
60
|
+
name: tableName,
|
|
61
|
+
table: getVectorTable(db, tableName, projections, {
|
|
62
|
+
reproject,
|
|
63
|
+
_targetCrs
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (format === 'geojson') {
|
|
68
|
+
return formatTablesAsGeojson(outputTables);
|
|
69
|
+
}
|
|
70
|
+
return outputTables;
|
|
71
|
+
}
|
|
72
|
+
async function loadDatabase(arrayBuffer, sqlJsCDN) {
|
|
73
|
+
let SQL;
|
|
74
|
+
if (sqlJsCDN) {
|
|
75
|
+
SQL = await initSqlJs({
|
|
76
|
+
locateFile: file => "".concat(sqlJsCDN).concat(file)
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
SQL = await initSqlJs();
|
|
80
|
+
}
|
|
81
|
+
return new SQL.Database(new Uint8Array(arrayBuffer));
|
|
82
|
+
}
|
|
83
|
+
function listVectorTables(db) {
|
|
84
|
+
const stmt = db.prepare("SELECT * FROM gpkg_contents WHERE data_type='features';");
|
|
85
|
+
const vectorTablesInfo = [];
|
|
86
|
+
while (stmt.step()) {
|
|
87
|
+
const vectorTableInfo = stmt.getAsObject();
|
|
88
|
+
vectorTablesInfo.push(vectorTableInfo);
|
|
89
|
+
}
|
|
90
|
+
return vectorTablesInfo;
|
|
91
|
+
}
|
|
92
|
+
function getVectorTable(db, tableName, projections, _ref) {
|
|
93
|
+
let {
|
|
94
|
+
reproject,
|
|
95
|
+
_targetCrs
|
|
96
|
+
} = _ref;
|
|
97
|
+
const dataColumns = getDataColumns(db, tableName);
|
|
98
|
+
const geomColumn = getGeometryColumn(db, tableName);
|
|
99
|
+
const featureIdColumn = getFeatureIdName(db, tableName);
|
|
100
|
+
const {
|
|
101
|
+
columns,
|
|
102
|
+
values
|
|
103
|
+
} = db.exec("SELECT * FROM `".concat(tableName, "`;"))[0];
|
|
104
|
+
let projection;
|
|
105
|
+
if (reproject) {
|
|
106
|
+
const geomColumnProjStr = projections[geomColumn.srs_id];
|
|
107
|
+
projection = new Proj4Projection({
|
|
108
|
+
from: geomColumnProjStr,
|
|
109
|
+
to: _targetCrs
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const geojsonFeatures = [];
|
|
113
|
+
for (const row of values) {
|
|
114
|
+
const geojsonFeature = constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn);
|
|
115
|
+
geojsonFeatures.push(geojsonFeature);
|
|
116
|
+
}
|
|
117
|
+
const schema = getSchema(db, tableName);
|
|
118
|
+
if (projection) {
|
|
119
|
+
return {
|
|
120
|
+
shape: 'object-row-table',
|
|
121
|
+
data: transformGeoJsonCoords(geojsonFeatures, projection.project),
|
|
122
|
+
schema
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
data: geojsonFeatures,
|
|
127
|
+
schema,
|
|
128
|
+
shape: 'object-row-table'
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function getProjections(db) {
|
|
132
|
+
const stmt = db.prepare('SELECT * FROM gpkg_spatial_ref_sys;');
|
|
133
|
+
const projectionMapping = {};
|
|
134
|
+
while (stmt.step()) {
|
|
135
|
+
const srsInfo = stmt.getAsObject();
|
|
136
|
+
const {
|
|
137
|
+
srs_id,
|
|
138
|
+
definition
|
|
139
|
+
} = srsInfo;
|
|
140
|
+
projectionMapping[srs_id] = definition;
|
|
141
|
+
}
|
|
142
|
+
return projectionMapping;
|
|
143
|
+
}
|
|
144
|
+
function constructGeoJsonFeature(columns, row, geomColumn, dataColumns, featureIdColumn) {
|
|
145
|
+
const idIdx = columns.indexOf(featureIdColumn);
|
|
146
|
+
const id = row[idIdx];
|
|
147
|
+
const geomColumnIdx = columns.indexOf(geomColumn.column_name);
|
|
148
|
+
const geometry = parseGeometry(row[geomColumnIdx].buffer);
|
|
149
|
+
const properties = {};
|
|
150
|
+
if (dataColumns) {
|
|
151
|
+
for (const [key, value] of Object.entries(dataColumns)) {
|
|
152
|
+
const idx = columns.indexOf(key);
|
|
153
|
+
properties[value] = row[idx];
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
for (let i = 0; i < columns.length; i++) {
|
|
157
|
+
if (i === idIdx || i === geomColumnIdx) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const columnName = columns[i];
|
|
161
|
+
properties[columnName] = row[i];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
id,
|
|
166
|
+
type: 'Feature',
|
|
167
|
+
geometry,
|
|
168
|
+
properties
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function getGeopackageVersion(db) {
|
|
172
|
+
const textDecoder = new TextDecoder();
|
|
173
|
+
const applicationIdQuery = db.exec('PRAGMA application_id;')[0];
|
|
174
|
+
const applicationId = applicationIdQuery.values[0][0];
|
|
175
|
+
const buffer = new ArrayBuffer(4);
|
|
176
|
+
const view = new DataView(buffer);
|
|
177
|
+
view.setInt32(0, Number(applicationId));
|
|
178
|
+
const versionString = textDecoder.decode(buffer);
|
|
179
|
+
if (versionString === 'GP10') {
|
|
180
|
+
return '1.0';
|
|
181
|
+
}
|
|
182
|
+
if (versionString === 'GP11') {
|
|
183
|
+
return '1.1';
|
|
184
|
+
}
|
|
185
|
+
const userVersionQuery = db.exec('PRAGMA user_version;')[0];
|
|
186
|
+
const userVersionInt = userVersionQuery.values[0][0];
|
|
187
|
+
if (userVersionInt && typeof userVersionInt === 'number' && userVersionInt < 10300) {
|
|
188
|
+
return '1.2';
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
function getFeatureIdName(db, tableName) {
|
|
193
|
+
const stmt = db.prepare("PRAGMA table_info(`".concat(tableName, "`)"));
|
|
194
|
+
while (stmt.step()) {
|
|
195
|
+
const pragmaTableInfo = stmt.getAsObject();
|
|
196
|
+
const {
|
|
197
|
+
name,
|
|
198
|
+
pk
|
|
199
|
+
} = pragmaTableInfo;
|
|
200
|
+
if (pk) {
|
|
201
|
+
return name;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
function parseGeometry(arrayBuffer) {
|
|
207
|
+
const view = new DataView(arrayBuffer);
|
|
208
|
+
const {
|
|
209
|
+
envelopeLength,
|
|
210
|
+
emptyGeometry
|
|
211
|
+
} = parseGeometryBitFlags(view.getUint8(3));
|
|
212
|
+
if (emptyGeometry) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const wkbOffset = 8 + envelopeLength;
|
|
216
|
+
const binaryGeometry = WKBLoader.parseSync(arrayBuffer.slice(wkbOffset));
|
|
217
|
+
return binaryToGeometry(binaryGeometry);
|
|
218
|
+
}
|
|
219
|
+
function parseGeometryBitFlags(byte) {
|
|
220
|
+
const envelopeValue = (byte & 0b00001110) / 2;
|
|
221
|
+
const envelopeLength = ENVELOPE_BYTE_LENGTHS[envelopeValue];
|
|
222
|
+
return {
|
|
223
|
+
littleEndian: Boolean(byte & 0b00000001),
|
|
224
|
+
envelopeLength,
|
|
225
|
+
emptyGeometry: Boolean(byte & 0b00010000),
|
|
226
|
+
extendedGeometryType: Boolean(byte & 0b00100000)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function getGeometryColumn(db, tableName) {
|
|
230
|
+
const stmt = db.prepare('SELECT * FROM gpkg_geometry_columns WHERE table_name=:tableName;');
|
|
231
|
+
stmt.bind({
|
|
232
|
+
':tableName': tableName
|
|
233
|
+
});
|
|
234
|
+
stmt.step();
|
|
235
|
+
const geometryColumn = stmt.getAsObject();
|
|
236
|
+
return geometryColumn;
|
|
237
|
+
}
|
|
238
|
+
function getDataColumns(db, tableName) {
|
|
239
|
+
let stmt;
|
|
240
|
+
try {
|
|
241
|
+
stmt = db.prepare('SELECT * FROM gpkg_data_columns WHERE table_name=:tableName;');
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (error.message.includes('no such table')) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
stmt.bind({
|
|
249
|
+
':tableName': tableName
|
|
250
|
+
});
|
|
251
|
+
const result = {};
|
|
252
|
+
while (stmt.step()) {
|
|
253
|
+
const column = stmt.getAsObject();
|
|
254
|
+
const {
|
|
255
|
+
column_name,
|
|
256
|
+
name
|
|
257
|
+
} = column;
|
|
258
|
+
result[column_name] = name || null;
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
function getSchema(db, tableName) {
|
|
263
|
+
const stmt = db.prepare("PRAGMA table_info(`".concat(tableName, "`)"));
|
|
264
|
+
const fields = [];
|
|
265
|
+
while (stmt.step()) {
|
|
266
|
+
const pragmaTableInfo = stmt.getAsObject();
|
|
267
|
+
const {
|
|
268
|
+
name,
|
|
269
|
+
type: sqlType,
|
|
270
|
+
notnull
|
|
271
|
+
} = pragmaTableInfo;
|
|
272
|
+
const type = SQL_TYPE_MAPPING[sqlType];
|
|
273
|
+
const field = {
|
|
274
|
+
name,
|
|
275
|
+
type,
|
|
276
|
+
nullable: !notnull
|
|
277
|
+
};
|
|
278
|
+
fields.push(field);
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
fields,
|
|
282
|
+
metadata: {}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function formatTablesAsGeojson(tables) {
|
|
286
|
+
const geojsonMap = {};
|
|
287
|
+
for (const table of tables.tables) {
|
|
288
|
+
geojsonMap[table.name] = table.table.data;
|
|
289
|
+
}
|
|
290
|
+
return geojsonMap;
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=parse-geopackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-geopackage.js","names":["initSqlJs","WKBLoader","binaryToGeometry","transformGeoJsonCoords","Proj4Projection","DEFAULT_SQLJS_CDN","ENVELOPE_BYTE_LENGTHS","SQL_TYPE_MAPPING","BOOLEAN","TINYINT","SMALLINT","MEDIUMINT","INT","INTEGER","FLOAT","DOUBLE","REAL","TEXT","BLOB","DATE","DATETIME","GEOMETRY","POINT","LINESTRING","POLYGON","MULTIPOINT","MULTILINESTRING","MULTIPOLYGON","GEOMETRYCOLLECTION","parseGeoPackage","arrayBuffer","options","sqlJsCDN","geopackage","reproject","_targetCrs","format","gis","db","loadDatabase","tables","listVectorTables","projections","getProjections","outputTables","shape","table","table_name","tableName","push","name","getVectorTable","formatTablesAsGeojson","SQL","locateFile","file","concat","Database","Uint8Array","stmt","prepare","vectorTablesInfo","step","vectorTableInfo","getAsObject","_ref","dataColumns","getDataColumns","geomColumn","getGeometryColumn","featureIdColumn","getFeatureIdName","columns","values","exec","projection","geomColumnProjStr","srs_id","from","to","geojsonFeatures","row","geojsonFeature","constructGeoJsonFeature","schema","getSchema","data","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","pk","envelopeLength","emptyGeometry","parseGeometryBitFlags","getUint8","wkbOffset","binaryGeometry","parseSync","slice","byte","envelopeValue","littleEndian","Boolean","extendedGeometryType","bind","geometryColumn","error","message","includes","result","column","fields","sqlType","notnull","field","nullable","metadata","geojsonMap"],"sources":["../../../src/lib/parse-geopackage.ts"],"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 Tables,\n ObjectRowTable,\n Feature\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 GeoPackageGeometryTypes\n} from './types';\n\n// We pin to the same version as sql.js that we use.\n// As of March 2022, versions 1.6.0, 1.6.1, and 1.6.2 of sql.js appeared not to work.\nexport const DEFAULT_SQLJS_CDN = 'https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.5.0/';\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 | GeoPackageGeometryTypes]: 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 POINT: 'binary',\n LINESTRING: 'binary',\n POLYGON: 'binary',\n MULTIPOINT: 'binary',\n MULTILINESTRING: 'binary',\n MULTIPOLYGON: 'binary',\n GEOMETRYCOLLECTION: 'binary'\n};\n\nexport default async function parseGeoPackage(\n arrayBuffer: ArrayBuffer,\n options?: GeoPackageLoaderOptions\n): Promise<Tables<ObjectRowTable> | Record<string, Feature[]>> {\n const {sqlJsCDN = DEFAULT_SQLJS_CDN} = options?.geopackage || {};\n const {reproject = false, _targetCrs = 'WGS84', format = 'tables'} = 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 outputTables: Tables<ObjectRowTable> = {\n shape: 'tables',\n tables: []\n };\n\n for (const table of tables) {\n const {table_name: tableName} = table;\n outputTables.tables.push({\n name: tableName,\n table: getVectorTable(db, tableName, projections, {\n reproject,\n _targetCrs\n })\n });\n }\n\n if (format === 'geojson') {\n return formatTablesAsGeojson(outputTables);\n }\n\n return outputTables;\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): ObjectRowTable {\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 = getSchema(db, tableName);\n if (projection) {\n return {\n shape: 'object-row-table',\n data: transformGeoJsonCoords(geojsonFeatures, projection.project),\n schema\n };\n }\n\n return {data: geojsonFeatures, schema, shape: 'object-row-table'};\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): Feature<Geometry | null> {\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 && typeof userVersionInt === 'number' && 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 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 getSchema(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: sqlType, notnull} = pragmaTableInfo;\n const type = SQL_TYPE_MAPPING[sqlType];\n const field = {name, type, nullable: !notnull};\n fields.push(field);\n }\n\n return {fields, metadata: {}};\n}\n\nfunction formatTablesAsGeojson(tables: Tables<ObjectRowTable>): Record<string, Feature[]> {\n const geojsonMap = {};\n for (const table of tables.tables) {\n geojsonMap[table.name] = table.table.data;\n }\n return geojsonMap;\n}\n"],"mappings":"AAEA,OAAOA,SAAS,MAA0C,QAAQ;AAClE,SAAQC,SAAS,QAAO,iBAAiB;AAUzC,SAAQC,gBAAgB,EAAEC,sBAAsB,QAAO,iBAAiB;AACxE,SAAQC,eAAe,QAAO,gBAAgB;AAgB9C,OAAO,MAAMC,iBAAiB,GAAG,sDAAsD;AAGvF,MAAMC,qBAAqB,GAAG;EAC5B,CAAC,EAAE,CAAC;EACJ,CAAC,EAAE,EAAE;EACL,CAAC,EAAE,EAAE;EACL,CAAC,EAAE,EAAE;EACL,CAAC,EAAE,EAAE;EAEL,CAAC,EAAE,CAAC;EACJ,CAAC,EAAE,CAAC;EACJ,CAAC,EAAE;AACL,CAAC;AAGD,MAAMC,gBAA6E,GAAG;EACpFC,OAAO,EAAE,MAAM;EACfC,OAAO,EAAE,MAAM;EACfC,QAAQ,EA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AO,CAAC;IACtC,MAAME,KAAK,GAAG;MAAClG,IAAI;MAAE0D,IAAI;MAAEyC,QAAQ,EAAE,CAACF;IAAO,CAAC;IAC9CF,MAAM,CAAChG,IAAI,CAACmG,KAAK,CAAC;EACpB;EAEA,OAAO;IAACH,MAAM;IAAEK,QAAQ,EAAE,CAAC;EAAC,CAAC;AAC/B;AAEA,SAASlG,qBAAqBA,CAACZ,MAA8B,EAA6B;EACxF,MAAM+G,UAAU,GAAG,CAAC,CAAC;EACrB,KAAK,MAAMzG,KAAK,IAAIN,MAAM,CAACA,MAAM,EAAE;IACjC+G,UAAU,CAACzG,KAAK,CAACI,IAAI,CAAC,GAAGJ,KAAK,CAACA,KAAK,CAACwC,IAAI;EAC3C;EACA,OAAOiE,UAAU;AACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/lib/types.ts"],"sourcesContent":["/* eslint-disable camelcase */\nexport interface GeometryBitFlags {\n littleEndian: boolean;\n envelopeLength: number;\n emptyGeometry: boolean;\n extendedGeometryType: boolean;\n}\n\nexport type ProjectionMapping = {[srsId: number]: string};\nexport type DataColumnsMapping = {[columnName: string]: string | null};\nexport type SQLiteTypes =\n | 'BOOLEAN'\n | 'TINYINT'\n | 'SMALLINT'\n | 'MEDIUMINT'\n | 'INT'\n | 'INTEGER'\n | 'FLOAT'\n | 'DOUBLE'\n | 'REAL'\n | 'TEXT'\n | 'BLOB'\n | 'DATE'\n | 'DATETIME';\n\n/** Type names for geopackage geometries\n *\n * As defined in https://www.geopackage.org/spec130/index.html#table_column_data_types, geometries\n * can be stored with any geometry name listed here:\n * https://www.geopackage.org/spec130/index.html#geometry_types\n */\nexport type GeoPackageGeometryTypes =\n | 'GEOMETRY'\n | 'POINT'\n | 'LINESTRING'\n | 'POLYGON'\n | 'MULTIPOINT'\n | 'MULTILINESTRING'\n | 'MULTIPOLYGON'\n | 'GEOMETRYCOLLECTION';\n\n/**\n * https://www.geopackage.org/spec121/#spatial_ref_sys\n */\nexport interface SpatialRefSysRow {\n /**\n * Human readable name of this SRS\n */\n srs_name: string;\n\n /**\n * Unique identifier for each Spatial Reference System within a GeoPackage\n */\n srs_id: number;\n\n /**\n * Case-insensitive name of the defining organization e.g. EPSG or epsg\n */\n organization: string;\n\n /**\n * Numeric ID of the Spatial Reference System assigned by the organization\n */\n organization_coordsys_id: number;\n\n /**\n * Well-known Text [A32] Representation of the Spatial Reference System\n */\n definition: string;\n\n /**\n * Human readable description of this SRS\n */\n description?: string;\n}\n\n/**\n * https://www.geopackage.org/spec121/#_contents\n */\nexport interface ContentsRow {\n /**\n * The name of the actual content (e.g., tiles, features, or attributes) table\n */\n table_name: string;\n\n /**\n * Type of data stored in the table\n */\n data_type: 'features' | 'attributes' | 'tiles';\n\n /**\n * A human-readable identifier (e.g. short name) for the table_name content\n */\n identifier?: string;\n\n /**\n * A human-readable description for the table_name content\n */\n description?: string;\n\n /**\n * timestamp of last change to content, in ISO 8601 format\n */\n last_change: string;\n\n /**\n * 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.\n */\n min_x?: number;\n\n /**\n * 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.\n */\n min_y?: number;\n /**\n * 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.\n */\n max_x?: number;\n\n /**\n * 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.\n */\n max_y?: number;\n\n /**\n * 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\n */\n srs_id?: number;\n}\n\n// https://www.geopackage.org/spec121/#geometry_types_extension\ntype GeometryType =\n | 'GEOMETRY'\n | 'POINT'\n | 'LINESTRING'\n | 'POLYGON'\n | 'MULTIPOINT'\n | 'MULTILINESTRING'\n | 'MULTIPOLYGON'\n | 'GEOMETRYCOLLECTION'\n | 'CIRCULARSTRING'\n | 'COMPOUNDCURVE'\n | 'CURVEPOLYGON'\n | 'MULTICURVE'\n | 'MULTISURFACE'\n | 'CURVE'\n | 'SURFACE';\n\n/**\n * https://www.geopackage.org/spec121/#_geometry_columns\n */\nexport interface GeometryColumnsRow {\n /**\n * Name of the table containing the geometry column\n */\n table_name: string;\n\n /**\n * Name of a column in the feature table that is a Geometry Column\n */\n column_name: string;\n\n /**\n * Name from Geometry Type Codes (Core) or Geometry Type Codes (Extension) in Geometry Types (Normative)\n */\n geometry_type_name: GeometryType;\n\n /**\n * Spatial Reference System ID: gpkg_spatial_ref_sys.srs_id\n */\n srs_id: number;\n\n /**\n * 0: z values prohibited; 1: z values mandatory; 2: z values optional\n */\n z: 0 | 1 | 2;\n\n /**\n * 0: m values prohibited; 1: m values mandatory; 2: m values optional\n */\n m: 0 | 1 | 2;\n}\n\n/**\n * https://www.geopackage.org/spec121/#extensions_table_definition\n */\nexport interface ExtensionsRow {\n /**\n * 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.\n */\n table_name?: string;\n\n /**\n * Name of the column that requires the extension. When NULL, the extension is required for the entire table.\n */\n column_name?: string;\n\n /**\n * The case sensitive name of the extension that is required, in the form <author>_<extension_name>.\n */\n extension_name: string;\n\n /**\n * Permalink, URI, or reference to a document that defines the extension\n */\n definition: string;\n\n /**\n * Indicates scope of extension effects on readers / writers: 'read-write' or 'write-only' in lowercase.\n */\n scope: string;\n}\n\n/**\n * https://www.geopackage.org/spec121/#gpkg_data_columns_cols\n */\nexport interface DataColumnsRow {\n /**\n * Name of the tiles or feature table\n */\n table_name: string;\n\n /**\n * Name of the table column\n */\n column_name: string;\n\n /**\n * A human-readable identifier (e.g. short name) for the column_name content\n */\n name?: string;\n\n /**\n * A human-readable formal title for the column_name content\n */\n title?: string;\n\n /**\n * A human-readable description for the column_name content\n */\n description?: string;\n\n /**\n * MIME [A21] type of column_name if BLOB type, or NULL for other types\n */\n mime_type?: string;\n\n /**\n * Column value constraint name (lowercase) specified by reference to gpkg_data_column_constraints.constraint name\n */\n constraint_name?: string;\n}\n\n/**\n * Type for PRAGMA table_info(tableName);\n */\nexport interface PragmaTableInfoRow {\n cid: number;\n name: string;\n type: SQLiteTypes;\n notnull: 0 | 1;\n dflt_value: any;\n pk: 0 | 1;\n}\n"],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
export type GeoPackageLoaderOptions = LoaderOptions & {
|
|
3
|
+
geopackage?: {
|
|
4
|
+
sqlJsCDN: string | null;
|
|
5
|
+
};
|
|
6
|
+
gis?: {
|
|
7
|
+
reproject?: boolean;
|
|
8
|
+
_targetCrs?: string;
|
|
9
|
+
format?: 'geojson' | 'tables';
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** Geopackage loader */
|
|
13
|
+
export declare const GeoPackageLoader: LoaderWithParser;
|
|
14
|
+
//# sourceMappingURL=geopackage-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geopackage-loader.d.ts","sourceRoot":"","sources":["../src/geopackage-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAQ9E,MAAM,MAAM,uBAAuB,GAAG,aAAa,GAAG;IACpD,UAAU,CAAC,EAAE;QAEX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;KAC/B,CAAC;CACH,CAAC;AAEF,wBAAwB;AACxB,eAAO,MAAM,gBAAgB,EAAE,gBAiB9B,CAAC"}
|
|
@@ -1,18 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.GeoPackageLoader = void 0;
|
|
27
|
+
const parse_geopackage_1 = __importStar(require("./lib/parse-geopackage"));
|
|
28
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
29
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
30
|
+
// const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
2
31
|
const VERSION = 'latest';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
32
|
+
/** Geopackage loader */
|
|
33
|
+
exports.GeoPackageLoader = {
|
|
34
|
+
id: 'geopackage',
|
|
35
|
+
name: 'GeoPackage',
|
|
36
|
+
module: 'geopackage',
|
|
37
|
+
version: VERSION,
|
|
38
|
+
extensions: ['gpkg'],
|
|
39
|
+
mimeTypes: ['application/geopackage+sqlite3'],
|
|
40
|
+
category: 'geometry',
|
|
41
|
+
parse: parse_geopackage_1.default,
|
|
42
|
+
options: {
|
|
43
|
+
geopackage: {
|
|
44
|
+
sqlJsCDN: parse_geopackage_1.DEFAULT_SQLJS_CDN
|
|
45
|
+
},
|
|
46
|
+
gis: {
|
|
47
|
+
format: 'tables'
|
|
48
|
+
}
|
|
15
49
|
}
|
|
16
|
-
}
|
|
17
50
|
};
|
|
18
|
-
//# sourceMappingURL=geopackage-loader.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeoPackageLoader = void 0;
|
|
4
|
+
var geopackage_loader_1 = require("./geopackage-loader");
|
|
5
|
+
Object.defineProperty(exports, "GeoPackageLoader", { enumerable: true, get: function () { return geopackage_loader_1.GeoPackageLoader; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GeoPackageLoaderOptions } from '../geopackage-loader';
|
|
2
|
+
import { Tables, ObjectRowTable, Feature } from '@loaders.gl/schema';
|
|
3
|
+
export declare const DEFAULT_SQLJS_CDN = "https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.5.0/";
|
|
4
|
+
export default function parseGeoPackage(arrayBuffer: ArrayBuffer, options?: GeoPackageLoaderOptions): Promise<Tables<ObjectRowTable> | Record<string, Feature[]>>;
|
|
5
|
+
//# sourceMappingURL=parse-geopackage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-geopackage.d.ts","sourceRoot":"","sources":["../../src/lib/parse-geopackage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,uBAAuB,EAAC,MAAM,sBAAsB,CAAC;AAGlE,OAAO,EAKL,MAAM,EACN,cAAc,EACd,OAAO,EACR,MAAM,oBAAoB,CAAC;AAkB5B,eAAO,MAAM,iBAAiB,yDAAyD,CAAC;AAwCxF,wBAA8B,eAAe,CAC3C,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CA8B7D"}
|