spl.js 0.1.0-beta.3 → 0.1.0-beta.4
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/Makefile +1 -1
- package/README.md +50 -26
- package/dist/index.js +1 -1
- package/examples/lights-performance.html +297 -0
- package/examples/lights.zip +0 -0
- package/package.json +1 -1
- package/src/spl-worker.ts +18 -6
package/Makefile
CHANGED
package/README.md
CHANGED
|
@@ -9,13 +9,11 @@ Comments, bug reports and suggestions are welcome! spl.js will remain beta at le
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm install spl.js@0.1.0-beta.
|
|
12
|
+
npm install spl.js@0.1.0-beta.4
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
The library for browsers bundles both the WebWorker script and the wasm file (~ 4MB). PROJ files (like proj.db) are not bundled but available from the `dist/proj` folder.
|
|
16
16
|
|
|
17
|
-
## Code Examples
|
|
18
|
-
|
|
19
17
|
[Apparently](https://github.com/jvail/spl.js/issues/1) typescript has no option to switch between `main` and `browser` entrypoints in `package.json`. For typescript & browser development you need to import spl.js (async version) as
|
|
20
18
|
|
|
21
19
|
```ts
|
|
@@ -35,8 +33,9 @@ or add this option to tsconfig.json
|
|
|
35
33
|
}
|
|
36
34
|
```
|
|
37
35
|
|
|
36
|
+
## Code Examples
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
Hello SpatiaLite
|
|
40
39
|
|
|
41
40
|
```js
|
|
42
41
|
import SPL from 'spl.js';
|
|
@@ -49,13 +48,15 @@ db.exec('select ? as hello', ['spatialite']).get.objs
|
|
|
49
48
|
.catch(err => console.log(err));
|
|
50
49
|
```
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
Import a GeoPackage
|
|
53
52
|
|
|
54
53
|
```js
|
|
55
54
|
import SPL from 'spl.js';
|
|
55
|
+
|
|
56
56
|
const spl = await SPL();
|
|
57
|
+
const url = 'https://data.london.gov.uk/download/london_boroughs/9502cdec-5df0-46e3-8aa1-2b5c5233a31f/london_boroughs.gpkg'
|
|
57
58
|
|
|
58
|
-
const london = await fetch(
|
|
59
|
+
const london = await fetch(url)
|
|
59
60
|
.then(response => response.arrayBuffer());
|
|
60
61
|
|
|
61
62
|
const db = await spl.db(london)
|
|
@@ -66,16 +67,16 @@ const srid = await db.exec('select srid(geom) from london_boroughs').get.first;
|
|
|
66
67
|
console.assert(srid === 27700)
|
|
67
68
|
```
|
|
68
69
|
|
|
69
|
-
|
|
70
|
+
Handle JSON & GeoJSON automatically (parse, stringify, geometry blob to GeoJSON)
|
|
70
71
|
|
|
71
72
|
```js
|
|
72
|
-
|
|
73
|
-
const db =
|
|
73
|
+
import SPL from 'spl.js';
|
|
74
|
+
const db = await SPL([], {
|
|
74
75
|
autoGeoJSON: {
|
|
75
76
|
precision: 0,
|
|
76
77
|
options: 0
|
|
77
78
|
}
|
|
78
|
-
}).db()
|
|
79
|
+
}).db();
|
|
79
80
|
|
|
80
81
|
console.assert(
|
|
81
82
|
db.exec('select json(@js)', { '@js': { hello: 'json' }}).get.first.hello === 'json'
|
|
@@ -86,34 +87,55 @@ console.assert(
|
|
|
86
87
|
);
|
|
87
88
|
```
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
Import a zipped Shapefile
|
|
90
91
|
|
|
91
92
|
```js
|
|
92
|
-
|
|
93
|
-
const
|
|
93
|
+
import SPL from 'spl.js';
|
|
94
|
+
const spl = await SPL();
|
|
95
|
+
|
|
96
|
+
const lights = await fetch('examples/lights.zip')
|
|
97
|
+
.then(response => response.blob());
|
|
98
|
+
|
|
99
|
+
const db = await spl
|
|
100
|
+
.mount('data', [
|
|
101
|
+
{ name: 'lights.zip', data: lights }
|
|
102
|
+
])
|
|
103
|
+
.db()
|
|
104
|
+
.exec('SELECT ImportZipSHP(?, ?, ?, ?, ?)', [
|
|
105
|
+
'/data/lights.zip', 'lights', 'lights', 'UTF-8', 4326
|
|
106
|
+
]);
|
|
94
107
|
|
|
95
108
|
console.assert(
|
|
96
|
-
db.exec('
|
|
97
|
-
$zip_path: 'shp.zip',
|
|
98
|
-
$basename: 'ne_110m_admin_0_countries',
|
|
99
|
-
$table: 'shp',
|
|
100
|
-
$charset: 'CP1252'
|
|
101
|
-
}).get.first === 177
|
|
109
|
+
db.exec('SELECT count(*) FROM lights').get.first === 17976
|
|
102
110
|
);
|
|
103
111
|
```
|
|
104
112
|
|
|
105
113
|
## Live Examples
|
|
106
114
|
|
|
107
|
-
|
|
115
|
+
Be patient - spl.js, data and other packages need to be fetched.
|
|
108
116
|
|
|
109
|
-
|
|
117
|
+
Create a topology from a GeoPackage layer and simplify polygon boundaries:
|
|
110
118
|
|
|
119
|
+
https://jvail.github.io/spl.js/examples/topology.html
|
|
111
120
|
|
|
112
|
-
Load proj.db remotely, transform and display GeoPackage geometries in OpenLayers
|
|
121
|
+
Load proj.db remotely, transform and display GeoPackage geometries in OpenLayers:
|
|
113
122
|
|
|
114
123
|
https://jvail.github.io/spl.js/examples/openlayers.html
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
Buffers & Intersections: A little test for GeoJSON vs WKB serialization and WebWorker transfer:
|
|
126
|
+
|
|
127
|
+
https://jvail.github.io/spl.js/examples/lights-performance.html
|
|
128
|
+
|
|
129
|
+
Sources: https://github.com/jvail/spl.js/tree/main/examples
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### Notebook (observablehq) examples:
|
|
133
|
+
|
|
134
|
+
https://observablehq.com/collection/@abenrob/spatialite
|
|
135
|
+
|
|
136
|
+
https://observablehq.com/@bert/spatialite-with-spl-js
|
|
137
|
+
|
|
138
|
+
https://observablehq.com/@visionscarto/hello-spl-js
|
|
117
139
|
|
|
118
140
|
## API
|
|
119
141
|
|
|
@@ -203,20 +225,22 @@ Import a database into the current database. This is using SQLite's backup API.
|
|
|
203
225
|
### `.save`([`dest`: string]) -> `DB` | ArrayBuffer
|
|
204
226
|
|
|
205
227
|
Export the current database. This is using SQLite's backup API.
|
|
206
|
-
If `dest` is undefined or empty an ArrayBuffer is returned.
|
|
228
|
+
If `dest` [**Node Only**] is undefined or empty an ArrayBuffer is returned.
|
|
207
229
|
|
|
208
230
|
### `.close`() -> `SPL`
|
|
209
231
|
|
|
210
232
|
### `.get`
|
|
211
233
|
|
|
212
|
-
A result object with the following properties:
|
|
234
|
+
A result object with the following properties (*thenables* in a browser):
|
|
213
235
|
|
|
214
236
|
### `.first` -> any
|
|
215
237
|
### `.flat` -> any[]
|
|
216
238
|
### `.rows` -> any[][]
|
|
217
239
|
### `.cols` -> string[]
|
|
218
240
|
### `.objs` -> {}[]
|
|
219
|
-
### `.sync` ->
|
|
241
|
+
### `.sync` -> a synchronous result object
|
|
242
|
+
|
|
243
|
+
With `sync` (browser only) all ArrayBuffers will be transfered without copying (transferables) from the WebWorker.
|
|
220
244
|
|
|
221
245
|
## Extensions API (Browser only)
|
|
222
246
|
|