ol-load-geopackage 1.0.2 → 2.0.0
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/API.md +66 -0
- package/CONTRIBUTING.md +17 -17
- package/LICENCE.md +15 -15
- package/README.md +142 -118
- package/dist/ol-load-geopackage.d.ts +1 -0
- package/dist/ol-load-geopackage.js +293 -259
- package/package.json +42 -29
- package/.eslintrc.json +0 -14
package/API.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# API Specification (OpenLayers OGC GeoPackage Loader)
|
|
2
|
+
|
|
3
|
+
This page describes the 3 exported functions/constants of the [ol-load-geopackage](README.md) module:
|
|
4
|
+
|
|
5
|
+
- [initSqlJsWasm()](#initsqljswasmsqljswasmdir) - initialisation: start loading of required sql.js WASM file
|
|
6
|
+
- [loadGpkg()](#loadgpkggpkgfile-displayprojection) - start loading and data extraction of GeoPackage
|
|
7
|
+
- [sql_js_version](#sql_js_version) - NPM version number of underlying sql.js module
|
|
8
|
+
|
|
9
|
+
## initSqlJsWasm(sqlJsWasmDir)
|
|
10
|
+
|
|
11
|
+
Initialisation: start asynchronous loading of the required WebAssembly binary (sql-wasm.wasm) file (~660 kB) associated with the underlying sql.js module.
|
|
12
|
+
|
|
13
|
+
Parameters:
|
|
14
|
+
|
|
15
|
+
- string `sqlJsWasmDir` (optional): URL or path relative to root of folder containing sql-wasm.wasm file. Default value is root folder.
|
|
16
|
+
|
|
17
|
+
(No return value)
|
|
18
|
+
|
|
19
|
+
If you want to load the associated WebAssembly binary (sql-wasm.wasm) from an external Content Delivery Network (CDN) then it is important that you load the WASM file that matches the version of the sql.js module being imported by ol-load-geopackage. Thus you will need to incorporate the _sql_js_version_ constant in the calling parameter, for example (from the proj4_example):
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { initSqlJsWasm, loadGpkg , sql_js_version} from 'ol-load-geopackage';
|
|
23
|
+
const sqlJsWasmDir = 'https://cdnjs.cloudflare.com/ajax/libs/sql.js/' + sql_js_version;
|
|
24
|
+
initSqlJsWasm(sqlJsWasmDir);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## loadGpkg(gpkgFile, displayProjection)
|
|
28
|
+
|
|
29
|
+
Begin asynchronous loading of a single OGC GeoPackage, then extract vector data tables into OpenLayers Vector Sources, transforming the data (if necessary) to match the specified display projection. If a "layer_styles" table is found (as generated by QGIS [Package Layers](https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/database.html#package-layers) Processing Toolbox command), it will extract the constituent SLD XML styling data associated with each vector data table.
|
|
30
|
+
|
|
31
|
+
Parameters:
|
|
32
|
+
|
|
33
|
+
- string `gpkgFile`: OGC GeoPackage file URL or path relative to root
|
|
34
|
+
- string `displayProjection`: Map display projection for output sources (e.g. 'EPSG:3857'). Note that projections not built in to OpenLayers must be defined before calling the function. This is most easily done using the Proj4JS library - see Proj4 [Example](README.md#examples-in-github-repository).
|
|
35
|
+
|
|
36
|
+
Returns a Promise which delivers an array of 2 objects:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
[dataFromGpkg, sldsFromGpkg]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
- object `dataFromGpkg`: data tables (OpenLayers vector sources, indexed by table name),
|
|
43
|
+
- object `sldsFromGpkg`: styles (SLD layer_styles XML strings, indexed by layer name)
|
|
44
|
+
|
|
45
|
+
For information only, the original data projection (SRS ID) will be returned as the string Property "origProjection" of each data source, so can be accessed with:
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
dataFromGpkg[table].getProperties()["origProjection"]
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Notes:
|
|
52
|
+
|
|
53
|
+
1. After loading the GeoPackage file, extraction of GeoPackage data will wait (if necessary) for the loading of the sql.js WASM file to complete (as initiated by [initSqlJsWasm()](#initsqljswasmsqljswasmdir)).
|
|
54
|
+
2. `sldsFromGpkg` will be an empty object if no table named "layer_styles" is found in the GeoPackage.
|
|
55
|
+
3. In the output GeoPackage from QGIS [Package Layers](https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/database.html#package-layers) the "table name" used for each vector data table will be exactly the same as the "layer name" used to index the SLD style strings in the "layer_styles" table.
|
|
56
|
+
|
|
57
|
+
Errors thrown on these events:
|
|
58
|
+
- Unable to load WebAssembly binary (sql-wasm.wasm)
|
|
59
|
+
- Unable to load requested OGC GeoPackage
|
|
60
|
+
- Missing requested display projection
|
|
61
|
+
- Missing a data projection (from any of Geopackage tables)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
## sql_js_version
|
|
65
|
+
|
|
66
|
+
Constant string value: NPM version number of the underlying sql.js module. This is useful if you want to load the associated WebAssembly binary (sql-wasm.wasm) from an external CDN - details in earlier section: [initSqlJsWasm()](#initsqljswasmsqljswasmdir).
|
package/CONTRIBUTING.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
# Contributing
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Enhancement requests are also welcome, but please bear in mind that this package is intended to be as lightweight as possible - for more fully fledged handling of OGC GeoPackages you might want to consider the [NGA GeoPackage Libraries](https://github.com/ngageoint/GeoPackage#geopackage).
|
|
7
|
-
|
|
8
|
-
## Bug Reports
|
|
9
|
-
|
|
10
|
-
When filing an issue, it would be very helpful if you could include answers to these questions in your report:
|
|
11
|
-
|
|
12
|
-
1. What device/OS are you using?
|
|
13
|
-
2. Which browser(s) show the problem?
|
|
14
|
-
3. What versions of OpenLayers and sql.js are you using?
|
|
15
|
-
4. What did you do?
|
|
16
|
-
5. What did you expect to see?
|
|
17
|
-
6. What did you see instead?
|
|
1
|
+
|
|
2
|
+
# Contributing
|
|
3
|
+
|
|
4
|
+
Bug reports or suggested documentation updates are very welcome - please raise an issue (see below).
|
|
5
|
+
|
|
6
|
+
Enhancement requests are also welcome, but please bear in mind that this package is intended to be as lightweight as possible - for more fully fledged handling of OGC GeoPackages you might want to consider the [NGA GeoPackage Libraries](https://github.com/ngageoint/GeoPackage#geopackage).
|
|
7
|
+
|
|
8
|
+
## Bug Reports
|
|
9
|
+
|
|
10
|
+
When filing an issue, it would be very helpful if you could include answers to these questions in your report:
|
|
11
|
+
|
|
12
|
+
1. What device/OS are you using?
|
|
13
|
+
2. Which browser(s) show the problem?
|
|
14
|
+
3. What versions of OpenLayers and sql.js are you using?
|
|
15
|
+
4. What did you do?
|
|
16
|
+
5. What did you expect to see?
|
|
17
|
+
6. What did you see instead?
|
package/LICENCE.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Richard Thomas
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
-
copyright notice and this permission notice appear in all copies.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Richard Thomas
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,118 +1,142 @@
|
|
|
1
|
-
# OpenLayers OGC GeoPackage Loader
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/ol-load-geopackage)
|
|
4
|
-
|
|
5
|
-
A JavaScript module to load OGC GeoPackage vector data tables into OpenLayers Vector Sources, transforming the data (if necessary) to match the specified display projection. This was primarily designed to directly load data exported by the QGIS [Package Layers](https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/database.html#package-layers) Processing Toolbox operation. As such, it will also (if it exists) load the associated "layer_styles" table of SLD XML styling data exported by QGIS in the same GeoPackage.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Examples
|
|
10
|
-
|
|
11
|
-
Each example is presented as HTML/JavaScript source code and
|
|
12
|
-
|
|
13
|
-
- Basic Example:
|
|
14
|
-
[JavaScript](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/src/basic_example.js))
|
|
15
|
-
- Loads vector tables and associated QGIS "layer_styles" SLD XML strings from an OGC GeoPackage and render all tables as layers on an OpenLayers map. Displays details of package contents.
|
|
16
|
-
|
|
17
|
-
- Proj4 Example:
|
|
18
|
-
[JavaScript](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/src/proj4_example.js))
|
|
19
|
-
- Used in conjunction with Proj4js module to enable additional projections to those built in to OpenLayers. These other projections can be for the input source data and/or the output display projection.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
1
|
+
# OpenLayers OGC GeoPackage Loader
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ol-load-geopackage)
|
|
4
|
+
|
|
5
|
+
A JavaScript module to load OGC GeoPackage vector data tables into OpenLayers Vector Sources, transforming the data (if necessary) to match the specified display projection. This was primarily designed to directly load data exported by the QGIS [Package Layers](https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/qgis/database.html#package-layers) Processing Toolbox operation. As such, it will also (if it exists) load the associated "layer_styles" table of SLD XML styling data exported by QGIS in the same GeoPackage. It is implemented as an NPM module and is a lightweight wrapper around the [sql.js](https://github.com/sql-js/sql.js) SQLite JavaScript library.
|
|
6
|
+
|
|
7
|
+
The current version was tested with OpenLayers 10.7, but should work with OpenLayers 6+.
|
|
8
|
+
|
|
9
|
+
## Examples (in GitHub repository)
|
|
10
|
+
|
|
11
|
+
Each example (in the [GitHub repository](https://github.com/richard-thomas/ol-load-geopackage)) is presented as HTML/JavaScript source code and as directly viewable web pages (built using both [Vite](https://vite.dev/) and the [Webpack](https://webpack.js.org/) module bundler).
|
|
12
|
+
|
|
13
|
+
- Basic Example: web page: [Vite](https://richard-thomas.github.io/ol-load-geopackage/examples-vite/basic_example.html), [Webpack](https://richard-thomas.github.io/ol-load-geopackage/examples/dist/basic_example.html) (sources: [Vite HTML](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples-vite/basic_example.html), [Webpack HTML](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/dist/basic_example.html),
|
|
14
|
+
[JavaScript (common)](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/src/basic_example.js))
|
|
15
|
+
- Loads vector tables and associated QGIS "layer_styles" SLD XML strings from an OGC GeoPackage and render all tables as layers on an OpenLayers map. Displays details of package contents.
|
|
16
|
+
|
|
17
|
+
- Proj4 Example: web page: [Vite](https://richard-thomas.github.io/ol-load-geopackage/examples-vite/proj4_example.html), [Webpack](https://richard-thomas.github.io/ol-load-geopackage/examples/dist/proj4_example.html) (sources: [Vite HTML](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples-vite/proj4_example.html), [Webpack HTML](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/dist/proj4_example.html),
|
|
18
|
+
[JavaScript (common)](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/src/proj4_example.js))
|
|
19
|
+
- Used in conjunction with Proj4js module to enable additional projections to those built in to OpenLayers. These other projections can be for the input source data and/or the output display projection. Also demonstrates loading required sql.js WebAssembly binary (WASM) from an external Content Delivery Network (CDN) site.
|
|
20
|
+
|
|
21
|
+
Note: identical JavaScript code is used in the Webpack/Vite versions, with the HTML code only being very subtly different.
|
|
22
|
+
|
|
23
|
+
You can try the examples with your own GeoPackage data files (without having to install Node.js or WebPack) by cloning the GitHub repository then editing the "gpkgFile" definition in the HTML files. In order to ensure all the files are able to load you will have to host them with a (simple) local HTTP server, for example by running in the examples/dist or examples-vite/dist folder...
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python -m http.server (Windows)
|
|
27
|
+
python3 -m http.server (macOS/Linux)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
...which will allow you to view them in a browser at [http://localhost:8000/](http://localhost:8000/). Note however that if your source data uses projections (SRS) other than the few built in to OpenLayers, then you would need to modify the .js source files (as in the Proj4 example) to add more SRS and rebuild the .js bundles.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Use Node.js to install the NPM package: [ol-load-geopackage](https://www.npmjs.com/package/ol-load-geopackage)
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install --save ol-load-geopackage
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
After running npm install, the sql.js WebAssembly file (sql-wasm.wasm) will need to be copied from folder _node_modules/sql.js/dist/_ to a folder where the web page can load it from.
|
|
41
|
+
|
|
42
|
+
## Basic usage
|
|
43
|
+
|
|
44
|
+
This package must be imported as a module - it is not designed to be loaded directly with a \<script\> tag. The examples above best demonstrate usage, but the following code segment outlines the basic methodology:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import { initSqlJsWasm, loadGpkg } from 'ol-load-geopackage';
|
|
48
|
+
|
|
49
|
+
initSqlJsWasm();
|
|
50
|
+
var gpkgPromise = loadGpkg(<gpkgFile>, <displayProjection>);
|
|
51
|
+
gpkgPromise
|
|
52
|
+
.then(([dataFromGpkg, sldsFromGpkg]) => {
|
|
53
|
+
for (var table in dataFromGpkg) {
|
|
54
|
+
// Handle each OpenLayers Vector Source:
|
|
55
|
+
// dataFromGpkg[table]
|
|
56
|
+
}
|
|
57
|
+
for (var layerName in sldsFromGpkg) {
|
|
58
|
+
// Handle each SLD XML string:
|
|
59
|
+
// sldsFromGpkg[layerName]
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
.catch(error => alert('ol-load-geopackage error: ' + error));
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Note that the _initSqlJsWasm()_ statement will start the asynchronous loading of the required sql.js WebAssembly binary file sql-wasm.wasm (from the root folder if no path specified), so is best placed early in the code.
|
|
66
|
+
|
|
67
|
+
### Building with Webpack
|
|
68
|
+
|
|
69
|
+
The (shared) support files used to build the examples using [Webpack 5](https://webpack.js.org/) ([package.json](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/package.json), [webpack.config.js](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/webpack.config.js)) are in the _examples_ folder. If you clone the repository then you can (re-)build the code bundles (for both examples) with the commands:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
cd examples
|
|
73
|
+
npm install
|
|
74
|
+
npm run-script sql-install
|
|
75
|
+
npm run-script build
|
|
76
|
+
```
|
|
77
|
+
You can then test the output code placed in the dist folder in a web browser at URL [http://localhost:8000/](http://localhost:8000/) using a simple HTTP server:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
cd dist
|
|
81
|
+
python -m http.server (Windows)
|
|
82
|
+
python3 -m http.server (macOS/Linux)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The Webpack dev-server can be used to automatically re-build, act as a webhost and trigger the browser to reload every time the code changes. The following script commands (defined in [package.json](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples/package.json)) will start the dev-server for one or the other example:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm run-script start-basic
|
|
89
|
+
npm run-script start-proj4
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Building with Vite
|
|
93
|
+
|
|
94
|
+
The (shared) support files used to build the examples using [Vite](https://vite.dev/) ([package.json](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples-vite/package.json), [vite.config.js](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples-vite/vite.config.js)) are in the _examples-vite_ folder. If you clone the repository then you can (re-)build the code bundles (for both examples) with the commands:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
cd examples-vite
|
|
98
|
+
npm install
|
|
99
|
+
npm run-script sql-install
|
|
100
|
+
npm run-script build
|
|
101
|
+
```
|
|
102
|
+
You can then test the output code placed in the dist folder in a web browser at URL [http://localhost:8000/](http://localhost:8000/) using Vite's built in HTTP server with:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm run-script preview
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The Vite dev-server can be used to automatically re-build, act as a webhost and trigger the browser to reload every time the code changes. The following script commands (defined in [package.json](https://github.com/richard-thomas/ol-load-geopackage/tree/master/examples-vite/package.json)) will start the dev-server at a top level _index.html_ file which has links to the 2 examples:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm run-script dev
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## API
|
|
115
|
+
|
|
116
|
+
The JavaScript module has 3 exported functions/constants which are described in the separate [API Specification](API.md):
|
|
117
|
+
|
|
118
|
+
- [initSqlJsWasm()](#initsqljswasmsqljswasmdir) - Initialisation: start loading of required sql.js WASM file
|
|
119
|
+
- [loadGpkg()](#loadgpkggpkgfile-displayprojection) - start loading and data extraction of GeoPackage
|
|
120
|
+
- [sql_js_version](#sql_js_version) - NPM version number of underlying sql.js module
|
|
121
|
+
|
|
122
|
+
## Migrating from ol-load-geopackage v1.x.x
|
|
123
|
+
|
|
124
|
+
In v1.x.x the sql.js WASM file (sql-wasm.wasm) was implicitly loaded from the current folder as a side effect of loading the module:
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
import loadGpkg from 'ol-load-geopackage';
|
|
128
|
+
```
|
|
129
|
+
From v2.0.0 the WASM must be explicitly loaded by invoking the new [initSqlJsWasm()](#initsqljswasmsqljswasmdir) function, with the sql-wasm.wasm file placed in the root folder if not specified as a parameter:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import { initSqlJsWasm, loadGpkg } from 'ol-load-geopackage';
|
|
133
|
+
initSqlJsWasm();
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Contributions
|
|
137
|
+
|
|
138
|
+
For bug reports, enhancement requests or code contributions please see [CONTRIBUTING](CONTRIBUTING.md).
|
|
139
|
+
|
|
140
|
+
## Licence
|
|
141
|
+
|
|
142
|
+
ISC - see [LICENCE](LICENCE.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'ol-load-geopackage';
|
|
@@ -1,259 +1,293 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module ol-load-geopackage
|
|
3
|
-
* @overview Loads OGC GeoPackage vector data into OpenLayers Vector Sources.
|
|
4
|
-
* Also (if it exists), loads the "layer_styles" table of SLD XML styling data
|
|
5
|
-
* as exported by the QGIS "Package Layers" Processing operation into strings.
|
|
6
|
-
* Vector data will be reprojected into the specified display projection.
|
|
7
|
-
* Both Sources and SLDs are returned in objects with table names used as keys.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import initSqlJs from "sql.js";
|
|
11
|
-
import {get as ol_proj_get} from 'ol/proj';
|
|
12
|
-
import ol_source_Vector from 'ol/source/Vector';
|
|
13
|
-
import ol_format_WKB from 'ol/format/WKB';
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// -------- Public Functions --------
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
* @param {string}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
function loadGpkg(gpkgFile) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module ol-load-geopackage
|
|
3
|
+
* @overview Loads OGC GeoPackage vector data into OpenLayers Vector Sources.
|
|
4
|
+
* Also (if it exists), loads the "layer_styles" table of SLD XML styling data
|
|
5
|
+
* as exported by the QGIS "Package Layers" Processing operation into strings.
|
|
6
|
+
* Vector data will be reprojected into the specified display projection.
|
|
7
|
+
* Both Sources and SLDs are returned in objects with table names used as keys.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import initSqlJs from "sql.js";
|
|
11
|
+
import {get as ol_proj_get} from 'ol/proj.js';
|
|
12
|
+
import ol_source_Vector from 'ol/source/Vector.js';
|
|
13
|
+
import ol_format_WKB from 'ol/format/WKB.js';
|
|
14
|
+
|
|
15
|
+
// Extract sql.js version (to enable use of CDN for loading associated WASM)
|
|
16
|
+
import sqlJsPkg from 'sql.js/package.json' with { type: 'json' };
|
|
17
|
+
const sql_js_version = sqlJsPkg.version;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Whether sql.js WASM file has been (successfully) loaded yet
|
|
21
|
+
*/
|
|
22
|
+
var promiseSqlWasmLoaded;
|
|
23
|
+
|
|
24
|
+
// -------- Public Functions --------
|
|
25
|
+
export { initSqlJsWasm, loadGpkg, sql_js_version };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initialisation: start asynchronous loading of WASM file required by sql.js
|
|
29
|
+
* @param {string} sqlJsWasmDir - URL of folder containing sql-wasm.wasm file to load for sql.js
|
|
30
|
+
*/
|
|
31
|
+
function initSqlJsWasm(sqlJsWasmDir) {
|
|
32
|
+
// If the WASM file location isn't specified look for it in the root folder
|
|
33
|
+
if (sqlJsWasmDir === undefined) {
|
|
34
|
+
sqlJsWasmDir = "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// For reading OGC GeoPackage files, use the sql.js SQLite reader;
|
|
38
|
+
// initSqlJs() will load the sql-wasm.wasm file from the specified location
|
|
39
|
+
promiseSqlWasmLoaded = initSqlJs({
|
|
40
|
+
locateFile: file => `${sqlJsWasmDir}/${file}`
|
|
41
|
+
});
|
|
42
|
+
promiseSqlWasmLoaded
|
|
43
|
+
.catch(error => {
|
|
44
|
+
// Only need report error here - any later calls to loadGpkg() will throw error
|
|
45
|
+
console.error(`initSqlJsWasm() unable to load SQLite JS binary (sql-wasm.wasm) from folder:\n` +
|
|
46
|
+
`${sqlJsWasmDir}/\n` +
|
|
47
|
+
`[sql.js error message]: ${error}`);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Wrapper to load a single OGC GeoPackage
|
|
53
|
+
* @param {string} gpkgFile - OGC GeoPackage file path
|
|
54
|
+
* @param {string} displayProjection - map display projection (e.g. EPSG:3857)
|
|
55
|
+
* @returns {Promise} Promise which delivers array of 2 objects:
|
|
56
|
+
* data tables (OpenLayers vector sources, indexed by table name),
|
|
57
|
+
* styles (SLD layer_styles XML strings, indexed by layer name)
|
|
58
|
+
*/
|
|
59
|
+
function loadGpkg(gpkgFile, displayProjection) {
|
|
60
|
+
|
|
61
|
+
// Start OGC GeoPackage load and processing to extract data/SLDs
|
|
62
|
+
var gpkgReadPromise = readRawGpkg(gpkgFile);
|
|
63
|
+
|
|
64
|
+
// Check if we have a definition for the display projection (SRS)
|
|
65
|
+
if (!ol_proj_get(displayProjection)) {
|
|
66
|
+
throw new Error("Missing requested display projection [" +
|
|
67
|
+
displayProjection +
|
|
68
|
+
'] - can be added beforehand with ol/proj/proj4');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return Promise.allSettled([promiseSqlWasmLoaded, gpkgReadPromise])
|
|
72
|
+
.then((results) => {
|
|
73
|
+
if (results[0].status === 'rejected') {
|
|
74
|
+
throw new Error('Unable to load SQLite JS binary (sql-wasm.wasm)');
|
|
75
|
+
}
|
|
76
|
+
if (results[1].status === 'rejected') {
|
|
77
|
+
throw new Error(`Unable to read raw GeoPackage data from file: ${gpkgFile}`);
|
|
78
|
+
}
|
|
79
|
+
const sqlWasm = results[0].value;
|
|
80
|
+
const gpkgArrayBuffer = results[1].value;
|
|
81
|
+
return processGpkgData(gpkgFile, gpkgArrayBuffer, sqlWasm, displayProjection);
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// -------- Private Functions --------
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Read raw data from source for a single OGC GeoPackage
|
|
90
|
+
* @param {string} gpkgFile - OGC GeoPackage file path
|
|
91
|
+
* @returns {Promise} Promise with Gpkg contents in ArrayBuffer format
|
|
92
|
+
*/
|
|
93
|
+
function readRawGpkg(gpkgFile) {
|
|
94
|
+
return new Promise(function(succeed, fail) {
|
|
95
|
+
var oReq = new XMLHttpRequest();
|
|
96
|
+
oReq.responseType = "arraybuffer";
|
|
97
|
+
oReq.onreadystatechange = function() {
|
|
98
|
+
|
|
99
|
+
// When request finished and response is ready
|
|
100
|
+
if (this.readyState == 4) {
|
|
101
|
+
var gpkgArrayBuffer = this.response;
|
|
102
|
+
if (this.status === 200 && gpkgArrayBuffer) {
|
|
103
|
+
succeed(gpkgArrayBuffer);
|
|
104
|
+
} else {
|
|
105
|
+
fail(new Error(
|
|
106
|
+
'Requested GPKG file could not be loaded: ' +
|
|
107
|
+
gpkgFile));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
oReq.open("GET", gpkgFile);
|
|
112
|
+
oReq.send();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Process OGC GeoPackage (SQLite database) once loaded
|
|
118
|
+
* @param {*} loadedGpkgFile - name of GeoPackage file (for diagnostics only)
|
|
119
|
+
* @param {ArrayBuffer} gpkgArrayBuffer - ArrayBuffer containing Gpkg data read
|
|
120
|
+
* @param {WebAssembly} sqlWasm - sql.js SQLITE database access library
|
|
121
|
+
* @param {string} displayProjection - map display projection (e.g. EPSG:3857)
|
|
122
|
+
* @returns {object[]} array of 2 objects: [<data tables>, <slds>]
|
|
123
|
+
* <data tables>: OpenLayers vector sources, indexed by table name
|
|
124
|
+
* <slds>: SLD XML strings, indexed by layer name
|
|
125
|
+
*/
|
|
126
|
+
function processGpkgData(loadedGpkgFile, gpkgArrayBuffer, sqlWasm,
|
|
127
|
+
displayProjection) {
|
|
128
|
+
var db;
|
|
129
|
+
|
|
130
|
+
// Data and associated SLD styles loaded both from GPKG
|
|
131
|
+
var dataFromGpkg = {};
|
|
132
|
+
var sldsFromGpkg = {};
|
|
133
|
+
|
|
134
|
+
// DEBUG: measure GPKG processing time
|
|
135
|
+
//var startProcessing = Date.now();
|
|
136
|
+
|
|
137
|
+
// Convert Array Buffer to Byte Array for SQLite
|
|
138
|
+
var gpkgByteArray = new Uint8Array(gpkgArrayBuffer);
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
db = new sqlWasm.Database(gpkgByteArray);
|
|
142
|
+
|
|
143
|
+
// Extract all feature tables, SRS IDs and their geometry types
|
|
144
|
+
// Note the following fields are not extracted:
|
|
145
|
+
// gpkg_contents.identifier - title (QGIS: same as table_name)
|
|
146
|
+
// gpkg_contents.description - human readable (QGIS: blank)
|
|
147
|
+
// gpkg_geometry_columns.geometry_type_name
|
|
148
|
+
// - e.g. LINESTRING (but info also embedded in each feature)
|
|
149
|
+
var featureTableNames = [];
|
|
150
|
+
var stmt;
|
|
151
|
+
stmt = db.prepare(`
|
|
152
|
+
SELECT gpkg_contents.table_name, gpkg_contents.srs_id,
|
|
153
|
+
gpkg_geometry_columns.column_name
|
|
154
|
+
FROM gpkg_contents JOIN gpkg_geometry_columns
|
|
155
|
+
WHERE gpkg_contents.data_type='features' AND
|
|
156
|
+
gpkg_contents.table_name=gpkg_geometry_columns.table_name;
|
|
157
|
+
`);
|
|
158
|
+
while (stmt.step()) {
|
|
159
|
+
let row = stmt.get();
|
|
160
|
+
featureTableNames.push({
|
|
161
|
+
"table_name": row[0],
|
|
162
|
+
"srs_id": row[1].toString(),
|
|
163
|
+
"geometry_column_name": row[2]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
'Unable to extract feature tables from OGC GeoPackage file "' +
|
|
170
|
+
loadedGpkgFile + '":\n' + err);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Extract SLD styles for each layer (if styles included in the gpkg)
|
|
174
|
+
stmt = db.prepare(`
|
|
175
|
+
SELECT gpkg_contents.table_name
|
|
176
|
+
FROM gpkg_contents
|
|
177
|
+
WHERE gpkg_contents.table_name='layer_styles'
|
|
178
|
+
`);
|
|
179
|
+
if (stmt.step()) {
|
|
180
|
+
stmt = db.prepare("SELECT f_table_name,styleSLD FROM layer_styles");
|
|
181
|
+
while (stmt.step()) {
|
|
182
|
+
let row = stmt.get();
|
|
183
|
+
sldsFromGpkg[row[0]] = row[1];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// For each table, extract geometry and other properties
|
|
188
|
+
// (Note: becomes OpenLayers-specific from here)
|
|
189
|
+
var formatWKB = new ol_format_WKB();
|
|
190
|
+
for (let table of featureTableNames) {
|
|
191
|
+
let features;
|
|
192
|
+
let table_name = table.table_name;
|
|
193
|
+
let tableDataProjection = 'EPSG:' + table.srs_id;
|
|
194
|
+
|
|
195
|
+
// Check if we have a definition for the data projection (SRS)
|
|
196
|
+
if (!ol_proj_get(tableDataProjection)) {
|
|
197
|
+
throw new Error("Missing data projection [" +
|
|
198
|
+
tableDataProjection + '] for table "' + table_name +
|
|
199
|
+
'" - can be added beforehand with ol/proj/proj4');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
stmt = db.prepare("SELECT * FROM '" + table_name + "'");
|
|
203
|
+
let vectorSource = new ol_source_Vector();
|
|
204
|
+
let geometry_column_name = table.geometry_column_name;
|
|
205
|
+
let properties = {};
|
|
206
|
+
while (stmt.step()) {
|
|
207
|
+
// Extract properties & geometry for a single feature
|
|
208
|
+
properties = stmt.getAsObject();
|
|
209
|
+
let geomProp = properties[geometry_column_name];
|
|
210
|
+
delete properties[geometry_column_name];
|
|
211
|
+
let featureWkb = parseGpkgGeom(geomProp);
|
|
212
|
+
/*
|
|
213
|
+
// DEBUG: show endianness of WKB data (can differ from header)
|
|
214
|
+
if (!vectorSource.getFeatures().length) {
|
|
215
|
+
console.log('WKB Geometry: ' +
|
|
216
|
+
(featureWkb[0] ? 'NDR (Little' : 'XDR (Big') + ' Endian)');
|
|
217
|
+
}
|
|
218
|
+
*/
|
|
219
|
+
// Put the feature into the vector source for the current table
|
|
220
|
+
features = formatWKB.readFeatures(featureWkb, {
|
|
221
|
+
dataProjection: tableDataProjection,
|
|
222
|
+
featureProjection: displayProjection
|
|
223
|
+
});
|
|
224
|
+
features[0].setProperties(properties);
|
|
225
|
+
vectorSource.addFeatures(features);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// For information only, save details of original projection (SRS)
|
|
229
|
+
vectorSource.setProperties({"origProjection": tableDataProjection});
|
|
230
|
+
dataFromGpkg[table_name] = vectorSource;
|
|
231
|
+
}
|
|
232
|
+
/*
|
|
233
|
+
// DEBUG: measure OGC GeoPackage processing time
|
|
234
|
+
var processingSecs = (Date.now() - startProcessing) / 1000;
|
|
235
|
+
console.log('INFO: OGC GeoPackage file ("' + loadedGpkgFile +
|
|
236
|
+
'") processing time = ' + processingSecs + ' s');
|
|
237
|
+
*/
|
|
238
|
+
return [dataFromGpkg, sldsFromGpkg];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Extract (SRS ID &) WKB from an OGC GeoPackage feature
|
|
243
|
+
* (i.e. strip off the variable length header)
|
|
244
|
+
* @param {object} gpkgBinGeom feature geometry property (includes header)
|
|
245
|
+
* @returns feature geometry in WKB (Well Known Binary) format
|
|
246
|
+
*/
|
|
247
|
+
function parseGpkgGeom(gpkgBinGeom) {
|
|
248
|
+
var flags = gpkgBinGeom[3];
|
|
249
|
+
var eFlags = (flags >> 1) & 7;
|
|
250
|
+
var envelopeSize;
|
|
251
|
+
switch (eFlags) {
|
|
252
|
+
case 0:
|
|
253
|
+
envelopeSize = 0;
|
|
254
|
+
break;
|
|
255
|
+
case 1:
|
|
256
|
+
envelopeSize = 32;
|
|
257
|
+
break;
|
|
258
|
+
case 2:
|
|
259
|
+
case 3:
|
|
260
|
+
envelopeSize = 48;
|
|
261
|
+
break;
|
|
262
|
+
case 4:
|
|
263
|
+
envelopeSize = 64;
|
|
264
|
+
break;
|
|
265
|
+
default:
|
|
266
|
+
throw new Error("Invalid geometry envelope size flag in GeoPackage");
|
|
267
|
+
}
|
|
268
|
+
/*
|
|
269
|
+
// Extract SRS (EPSG code)
|
|
270
|
+
// (not required as given for whole table in gpkg_contents table)
|
|
271
|
+
var littleEndian = flags & 1;
|
|
272
|
+
var srs = gpkgBinGeom.subarray(4,8);
|
|
273
|
+
var srsId;
|
|
274
|
+
if (littleEndian) {
|
|
275
|
+
srsId = srs[0] + (srs[1]<<8) + (srs[2]<<16) + (srs[3]<<24);
|
|
276
|
+
} else {
|
|
277
|
+
srsId = srs[3] + (srs[2]<<8) + (srs[1]<<16) + (srs[0]<<24);
|
|
278
|
+
}
|
|
279
|
+
*/
|
|
280
|
+
/*
|
|
281
|
+
// DEBUG: display other properties of the feature
|
|
282
|
+
console.log('gpkgBinGeom Header: ' + (littleEndian ? 'Little' : 'Big')
|
|
283
|
+
+ ' Endian');
|
|
284
|
+
console.log("gpkgBinGeom Magic: 0x${gpkgBinGeom[0].toString(16)}${gpkgBinGeom[1].toString(16)}");
|
|
285
|
+
console.log("gpkgBinGeom Version:", gpkgBinGeom[2]);
|
|
286
|
+
console.log("gpkgBinGeom Flags:", flags);
|
|
287
|
+
console.log("gpkgBinGeom srs_id:", srsId);
|
|
288
|
+
console.log("gpkgBinGeom envelope size (bytes):", envelopeSize);
|
|
289
|
+
*/
|
|
290
|
+
// Extract WKB which starts after variable-size "envelope" field
|
|
291
|
+
var wkbOffset = envelopeSize + 8;
|
|
292
|
+
return gpkgBinGeom.subarray(wkbOffset);
|
|
293
|
+
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ol-load-geopackage",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Loads OGC GeoPackage vector data tables into OpenLayers Vector Sources",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ol-load-geopackage",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Loads OGC GeoPackage vector data tables into OpenLayers Vector Sources",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist/",
|
|
7
|
+
"CONTRIBUTING.md",
|
|
8
|
+
"API.md"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/ol-load-geopackage.js",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"OGC",
|
|
17
|
+
"GeoPackage",
|
|
18
|
+
"OpenLayers",
|
|
19
|
+
"ol",
|
|
20
|
+
"QGIS",
|
|
21
|
+
"SLD"
|
|
22
|
+
],
|
|
23
|
+
"author": "Richard Thomas",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"ol": ">=6.7.0",
|
|
27
|
+
"sql.js": "^1.6.1",
|
|
28
|
+
"util": "^0.12.4"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/richard-thomas/ol-load-geopackage.git"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/richard-thomas/ol-load-geopackage#readme",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/eslintrc": "^3.3.3",
|
|
37
|
+
"@eslint/js": "^9.39.2",
|
|
38
|
+
"@stylistic/eslint-plugin": "^5.7.0",
|
|
39
|
+
"eslint": "^9.39.2",
|
|
40
|
+
"globals": "^17.0.0"
|
|
41
|
+
}
|
|
42
|
+
}
|