@loaders.gl/wkt 3.1.1 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +5 -596
- package/dist/dist.min.js +983 -0
- package/dist/es5/index.js +8 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/encode-wkb.js +468 -0
- package/dist/es5/lib/encode-wkb.js.map +1 -0
- package/dist/es5/lib/encode-wkt.js +32 -34
- package/dist/es5/lib/encode-wkt.js.map +1 -1
- package/dist/es5/lib/utils/binary-writer.js +186 -0
- package/dist/es5/lib/utils/binary-writer.js.map +1 -0
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/wkb-writer.js +26 -0
- package/dist/es5/wkb-writer.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/encode-wkb.js +323 -0
- package/dist/esm/lib/encode-wkb.js.map +1 -0
- package/dist/esm/lib/encode-wkt.js +32 -34
- package/dist/esm/lib/encode-wkt.js.map +1 -1
- package/dist/esm/lib/utils/binary-writer.js +153 -0
- package/dist/esm/lib/utils/binary-writer.js.map +1 -0
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/wkb-writer.js +14 -0
- package/dist/esm/wkb-writer.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/lib/encode-wkb.d.ts +17 -0
- package/dist/lib/encode-wkb.d.ts.map +1 -0
- package/dist/lib/encode-wkb.js +290 -0
- package/dist/lib/encode-wkt.d.ts +2 -2
- package/dist/lib/encode-wkt.d.ts.map +1 -1
- package/dist/lib/encode-wkt.js +27 -29
- package/dist/lib/utils/binary-writer.d.ts +28 -0
- package/dist/lib/utils/binary-writer.d.ts.map +1 -0
- package/dist/lib/utils/binary-writer.js +120 -0
- package/dist/wkb-writer.d.ts +6 -0
- package/dist/wkb-writer.d.ts.map +1 -0
- package/dist/wkb-writer.js +23 -0
- package/dist/wkt-worker.js +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/lib/encode-wkb.ts +386 -0
- package/src/lib/encode-wkt.ts +34 -36
- package/src/lib/utils/binary-writer.ts +125 -0
- package/src/wkb-writer.ts +19 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var LE = true;
|
|
17
|
+
var BE = false;
|
|
18
|
+
|
|
19
|
+
var BinaryWriter = function () {
|
|
20
|
+
function BinaryWriter(size, allowResize) {
|
|
21
|
+
(0, _classCallCheck2.default)(this, BinaryWriter);
|
|
22
|
+
(0, _defineProperty2.default)(this, "arrayBuffer", void 0);
|
|
23
|
+
(0, _defineProperty2.default)(this, "dataView", void 0);
|
|
24
|
+
(0, _defineProperty2.default)(this, "byteOffset", 0);
|
|
25
|
+
(0, _defineProperty2.default)(this, "allowResize", false);
|
|
26
|
+
this.arrayBuffer = new ArrayBuffer(size);
|
|
27
|
+
this.dataView = new DataView(this.arrayBuffer);
|
|
28
|
+
this.byteOffset = 0;
|
|
29
|
+
this.allowResize = allowResize || false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
(0, _createClass2.default)(BinaryWriter, [{
|
|
33
|
+
key: "writeUInt8",
|
|
34
|
+
value: function writeUInt8(value) {
|
|
35
|
+
this._ensureSize(1);
|
|
36
|
+
|
|
37
|
+
this.dataView.setUint8(this.byteOffset, value);
|
|
38
|
+
this.byteOffset += 1;
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
key: "writeUInt16LE",
|
|
42
|
+
value: function writeUInt16LE(value) {
|
|
43
|
+
this._ensureSize(2);
|
|
44
|
+
|
|
45
|
+
this.dataView.setUint16(this.byteOffset, value, LE);
|
|
46
|
+
this.byteOffset += 2;
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: "writeUInt16BE",
|
|
50
|
+
value: function writeUInt16BE(value) {
|
|
51
|
+
this._ensureSize(2);
|
|
52
|
+
|
|
53
|
+
this.dataView.setUint16(this.byteOffset, value, BE);
|
|
54
|
+
this.byteOffset += 2;
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "writeUInt32LE",
|
|
58
|
+
value: function writeUInt32LE(value) {
|
|
59
|
+
this._ensureSize(4);
|
|
60
|
+
|
|
61
|
+
this.dataView.setUint32(this.byteOffset, value, LE);
|
|
62
|
+
this.byteOffset += 4;
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: "writeUInt32BE",
|
|
66
|
+
value: function writeUInt32BE(value) {
|
|
67
|
+
this._ensureSize(4);
|
|
68
|
+
|
|
69
|
+
this.dataView.setUint32(this.byteOffset, value, BE);
|
|
70
|
+
this.byteOffset += 4;
|
|
71
|
+
}
|
|
72
|
+
}, {
|
|
73
|
+
key: "writeInt8",
|
|
74
|
+
value: function writeInt8(value) {
|
|
75
|
+
this._ensureSize(1);
|
|
76
|
+
|
|
77
|
+
this.dataView.setInt8(this.byteOffset, value);
|
|
78
|
+
this.byteOffset += 1;
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "writeInt16LE",
|
|
82
|
+
value: function writeInt16LE(value) {
|
|
83
|
+
this._ensureSize(2);
|
|
84
|
+
|
|
85
|
+
this.dataView.setInt16(this.byteOffset, value, LE);
|
|
86
|
+
this.byteOffset += 2;
|
|
87
|
+
}
|
|
88
|
+
}, {
|
|
89
|
+
key: "writeInt16BE",
|
|
90
|
+
value: function writeInt16BE(value) {
|
|
91
|
+
this._ensureSize(2);
|
|
92
|
+
|
|
93
|
+
this.dataView.setInt16(this.byteOffset, value, BE);
|
|
94
|
+
this.byteOffset += 2;
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "writeInt32LE",
|
|
98
|
+
value: function writeInt32LE(value) {
|
|
99
|
+
this._ensureSize(4);
|
|
100
|
+
|
|
101
|
+
this.dataView.setInt32(this.byteOffset, value, LE);
|
|
102
|
+
this.byteOffset += 4;
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "writeInt32BE",
|
|
106
|
+
value: function writeInt32BE(value) {
|
|
107
|
+
this._ensureSize(4);
|
|
108
|
+
|
|
109
|
+
this.dataView.setInt32(this.byteOffset, value, BE);
|
|
110
|
+
this.byteOffset += 4;
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "writeFloatLE",
|
|
114
|
+
value: function writeFloatLE(value) {
|
|
115
|
+
this._ensureSize(4);
|
|
116
|
+
|
|
117
|
+
this.dataView.setFloat32(this.byteOffset, value, LE);
|
|
118
|
+
this.byteOffset += 4;
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
key: "writeFloatBE",
|
|
122
|
+
value: function writeFloatBE(value) {
|
|
123
|
+
this._ensureSize(4);
|
|
124
|
+
|
|
125
|
+
this.dataView.setFloat32(this.byteOffset, value, BE);
|
|
126
|
+
this.byteOffset += 4;
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "writeDoubleLE",
|
|
130
|
+
value: function writeDoubleLE(value) {
|
|
131
|
+
this._ensureSize(8);
|
|
132
|
+
|
|
133
|
+
this.dataView.setFloat64(this.byteOffset, value, LE);
|
|
134
|
+
this.byteOffset += 8;
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "writeDoubleBE",
|
|
138
|
+
value: function writeDoubleBE(value) {
|
|
139
|
+
this._ensureSize(8);
|
|
140
|
+
|
|
141
|
+
this.dataView.setFloat64(this.byteOffset, value, BE);
|
|
142
|
+
this.byteOffset += 8;
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
key: "writeVarInt",
|
|
146
|
+
value: function writeVarInt(value) {
|
|
147
|
+
var length = 1;
|
|
148
|
+
|
|
149
|
+
while ((value & 0xffffff80) !== 0) {
|
|
150
|
+
this.writeUInt8(value & 0x7f | 0x80);
|
|
151
|
+
value >>>= 7;
|
|
152
|
+
length++;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this.writeUInt8(value & 0x7f);
|
|
156
|
+
return length;
|
|
157
|
+
}
|
|
158
|
+
}, {
|
|
159
|
+
key: "writeBuffer",
|
|
160
|
+
value: function writeBuffer(arrayBuffer) {
|
|
161
|
+
this._ensureSize(arrayBuffer.byteLength);
|
|
162
|
+
|
|
163
|
+
var tempArray = new Uint8Array(this.arrayBuffer);
|
|
164
|
+
tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);
|
|
165
|
+
this.byteOffset += arrayBuffer.byteLength;
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
key: "_ensureSize",
|
|
169
|
+
value: function _ensureSize(size) {
|
|
170
|
+
if (this.arrayBuffer.byteLength < this.byteOffset + size) {
|
|
171
|
+
if (this.allowResize) {
|
|
172
|
+
var newArrayBuffer = new ArrayBuffer(this.byteOffset + size);
|
|
173
|
+
var tempArray = new Uint8Array(newArrayBuffer);
|
|
174
|
+
tempArray.set(new Uint8Array(this.arrayBuffer));
|
|
175
|
+
this.arrayBuffer = newArrayBuffer;
|
|
176
|
+
} else {
|
|
177
|
+
throw new Error('BinaryWriter overflow');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}]);
|
|
182
|
+
return BinaryWriter;
|
|
183
|
+
}();
|
|
184
|
+
|
|
185
|
+
exports.default = BinaryWriter;
|
|
186
|
+
//# sourceMappingURL=binary-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/binary-writer.ts"],"names":["LE","BE","BinaryWriter","size","allowResize","arrayBuffer","ArrayBuffer","dataView","DataView","byteOffset","value","_ensureSize","setUint8","setUint16","setUint32","setInt8","setInt16","setInt32","setFloat32","setFloat64","length","writeUInt8","byteLength","tempArray","Uint8Array","set","newArrayBuffer","Error"],"mappings":";;;;;;;;;;;;;;;AAGA,IAAMA,EAAE,GAAG,IAAX;AACA,IAAMC,EAAE,GAAG,KAAX;;IAEqBC,Y;AAMnB,wBAAYC,IAAZ,EAA0BC,WAA1B,EAAiD;AAAA;AAAA;AAAA;AAAA,sDAH5B,CAG4B;AAAA,uDAF1B,KAE0B;AAC/C,SAAKC,WAAL,GAAmB,IAAIC,WAAJ,CAAgBH,IAAhB,CAAnB;AACA,SAAKI,QAAL,GAAgB,IAAIC,QAAJ,CAAa,KAAKH,WAAlB,CAAhB;AACA,SAAKI,UAAL,GAAkB,CAAlB;AACA,SAAKL,WAAL,GAAmBA,WAAW,IAAI,KAAlC;AACD;;;;WAED,oBAAWM,KAAX,EAAgC;AAC9B,WAAKC,WAAL,CAAiB,CAAjB;;AACA,WAAKJ,QAAL,CAAcK,QAAd,CAAuB,KAAKH,UAA5B,EAAwCC,KAAxC;AACA,WAAKD,UAAL,IAAmB,CAAnB;AACD;;;WACD,uBAAcC,KAAd,EAAmC;AACjC,WAAKC,WAAL,CAAiB,CAAjB;;AACA,WAAKJ,QAAL,CAAcM,SAAd,CAAwB,KAAKJ,UAA7B,EAAyCC,KAAzC,EAAgDV,EAAhD;AACA,WAAKS,UAAL,IAAmB,CAAnB;AACD;;;WACD,uBAAcC,KAAd,EAAmC;AACjC,WAAKC,WAAL,CAAiB,CAAjB;;AACA,WAAKJ,QAAL,CAAcM,SAAd,CAAwB,KAAKJ,UAA7B,EAAyCC,KA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AiBN,WAAW,CAACiB,UAA7B;;AACA,UAAMC,SAAS,GAAG,IAAIC,UAAJ,CAAe,KAAKnB,WAApB,CAAlB;AACAkB,MAAAA,SAAS,CAACE,GAAV,CAAc,IAAID,UAAJ,CAAenB,WAAf,CAAd,EAA2C,KAAKI,UAAhD;AACA,WAAKA,UAAL,IAAmBJ,WAAW,CAACiB,UAA/B;AACD;;;WAGD,qBAAYnB,IAAZ,EAA0B;AACxB,UAAI,KAAKE,WAAL,CAAiBiB,UAAjB,GAA8B,KAAKb,UAAL,GAAkBN,IAApD,EAA0D;AACxD,YAAI,KAAKC,WAAT,EAAsB;AACpB,cAAMsB,cAAc,GAAG,IAAIpB,WAAJ,CAAgB,KAAKG,UAAL,GAAkBN,IAAlC,CAAvB;AACA,cAAMoB,SAAS,GAAG,IAAIC,UAAJ,CAAeE,cAAf,CAAlB;AACAH,UAAAA,SAAS,CAACE,GAAV,CAAc,IAAID,UAAJ,CAAe,KAAKnB,WAApB,CAAd;AACA,eAAKA,WAAL,GAAmBqB,cAAnB;AACD,SALD,MAKO;AACL,gBAAM,IAAIC,KAAJ,CAAU,uBAAV,CAAN;AACD;AACF;AACF","sourcesContent":["// loaders.gl, MIT license\n// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz\n\nconst LE = true;\nconst BE = false;\n\nexport default class BinaryWriter {\n arrayBuffer: ArrayBuffer;\n dataView: DataView;\n byteOffset: number = 0;\n allowResize: boolean = false;\n\n constructor(size: number, allowResize?: boolean) {\n this.arrayBuffer = new ArrayBuffer(size);\n this.dataView = new DataView(this.arrayBuffer);\n this.byteOffset = 0;\n this.allowResize = allowResize || false;\n }\n\n writeUInt8(value: number): void {\n this._ensureSize(1);\n this.dataView.setUint8(this.byteOffset, value);\n this.byteOffset += 1;\n }\n writeUInt16LE(value: number): void {\n this._ensureSize(2);\n this.dataView.setUint16(this.byteOffset, value, LE);\n this.byteOffset += 2;\n }\n writeUInt16BE(value: number): void {\n this._ensureSize(2);\n this.dataView.setUint16(this.byteOffset, value, BE);\n this.byteOffset += 2;\n }\n writeUInt32LE(value: number): void {\n this._ensureSize(4);\n this.dataView.setUint32(this.byteOffset, value, LE);\n this.byteOffset += 4;\n }\n writeUInt32BE(value: number): void {\n this._ensureSize(4);\n this.dataView.setUint32(this.byteOffset, value, BE);\n this.byteOffset += 4;\n }\n writeInt8(value: number): void {\n this._ensureSize(1);\n this.dataView.setInt8(this.byteOffset, value);\n this.byteOffset += 1;\n }\n writeInt16LE(value: number): void {\n this._ensureSize(2);\n this.dataView.setInt16(this.byteOffset, value, LE);\n this.byteOffset += 2;\n }\n writeInt16BE(value: number): void {\n this._ensureSize(2);\n this.dataView.setInt16(this.byteOffset, value, BE);\n this.byteOffset += 2;\n }\n writeInt32LE(value: number): void {\n this._ensureSize(4);\n this.dataView.setInt32(this.byteOffset, value, LE);\n this.byteOffset += 4;\n }\n writeInt32BE(value: number): void {\n this._ensureSize(4);\n this.dataView.setInt32(this.byteOffset, value, BE);\n this.byteOffset += 4;\n }\n writeFloatLE(value: number): void {\n this._ensureSize(4);\n this.dataView.setFloat32(this.byteOffset, value, LE);\n this.byteOffset += 4;\n }\n writeFloatBE(value: number): void {\n this._ensureSize(4);\n this.dataView.setFloat32(this.byteOffset, value, BE);\n this.byteOffset += 4;\n }\n writeDoubleLE(value: number): void {\n this._ensureSize(8);\n this.dataView.setFloat64(this.byteOffset, value, LE);\n this.byteOffset += 8;\n }\n writeDoubleBE(value: number): void {\n this._ensureSize(8);\n this.dataView.setFloat64(this.byteOffset, value, BE);\n this.byteOffset += 8;\n }\n\n /** A varint uses a variable number of bytes */\n writeVarInt(value: number): number {\n // TODO - ensure size?\n let length = 1;\n while ((value & 0xffffff80) !== 0) {\n this.writeUInt8((value & 0x7f) | 0x80);\n value >>>= 7;\n length++;\n }\n this.writeUInt8(value & 0x7f);\n return length;\n }\n\n /** Append another ArrayBuffer to this ArrayBuffer */\n writeBuffer(arrayBuffer: ArrayBuffer): void {\n this._ensureSize(arrayBuffer.byteLength);\n const tempArray = new Uint8Array(this.arrayBuffer);\n tempArray.set(new Uint8Array(arrayBuffer), this.byteOffset);\n this.byteOffset += arrayBuffer.byteLength;\n }\n\n /** Resizes this.arrayBuffer if not enough space */\n _ensureSize(size: number) {\n if (this.arrayBuffer.byteLength < this.byteOffset + size) {\n if (this.allowResize) {\n const newArrayBuffer = new ArrayBuffer(this.byteOffset + size);\n const tempArray = new Uint8Array(newArrayBuffer);\n tempArray.set(new Uint8Array(this.arrayBuffer));\n this.arrayBuffer = newArrayBuffer;\n } else {\n throw new Error('BinaryWriter overflow');\n }\n }\n }\n}\n"],"file":"binary-writer.js"}
|
|
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VERSION = void 0;
|
|
7
|
-
var VERSION = typeof "3.1.
|
|
7
|
+
var VERSION = typeof "3.1.5" !== 'undefined' ? "3.1.5" : 'latest';
|
|
8
8
|
exports.VERSION = VERSION;
|
|
9
9
|
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.WKBWriter = void 0;
|
|
9
|
+
|
|
10
|
+
var _version = require("./lib/utils/version");
|
|
11
|
+
|
|
12
|
+
var _encodeWkb = _interopRequireDefault(require("./lib/encode-wkb"));
|
|
13
|
+
|
|
14
|
+
var WKBWriter = {
|
|
15
|
+
name: 'WKB (Well Known Binary)',
|
|
16
|
+
id: 'wkb',
|
|
17
|
+
module: 'wkt',
|
|
18
|
+
version: _version.VERSION,
|
|
19
|
+
extensions: ['wkb'],
|
|
20
|
+
encode: _encodeWkb.default,
|
|
21
|
+
options: {
|
|
22
|
+
wkt: {}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.WKBWriter = WKBWriter;
|
|
26
|
+
//# sourceMappingURL=wkb-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/wkb-writer.ts"],"names":["WKBWriter","name","id","module","version","VERSION","extensions","encode","encodeWKB","options","wkt"],"mappings":";;;;;;;;;AACA;;AACA;;AAKO,IAAMA,SAAiB,GAAG;AAC/BC,EAAAA,IAAI,EAAE,yBADyB;AAE/BC,EAAAA,EAAE,EAAE,KAF2B;AAG/BC,EAAAA,MAAM,EAAE,KAHuB;AAI/BC,EAAAA,OAAO,EAAEC,gBAJsB;AAK/BC,EAAAA,UAAU,EAAE,CAAC,KAAD,CALmB;AAO/BC,EAAAA,MAAM,EAAEC,kBAPuB;AAQ/BC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AARsB,CAA1B","sourcesContent":["import type {Writer} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\nimport encodeWKB from './lib/encode-wkb';\n\n/**\n * WKT exporter\n */\nexport const WKBWriter: Writer = {\n name: 'WKB (Well Known Binary)',\n id: 'wkb',\n module: 'wkt',\n version: VERSION,\n extensions: ['wkb'],\n // @ts-ignore\n encode: encodeWKB,\n options: {\n wkt: {}\n }\n};\n"],"file":"wkb-writer.js"}
|
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":["WKBLoader","WKBWorkerLoader","WKTLoader","WKTWorkerLoader","WKTWriter"],"mappings":"AAAA,SAAQA,SAAR,EAAmBC,eAAnB,QAAyC,cAAzC;AACA,SAAQC,SAAR,EAAmBC,eAAnB,QAAyC,cAAzC;AACA,SAAQC,SAAR,QAAwB,cAAxB","sourcesContent":["export {WKBLoader, WKBWorkerLoader} from './wkb-loader';\nexport {WKTLoader, WKTWorkerLoader} from './wkt-loader';\nexport {WKTWriter} from './wkt-writer';\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["WKBLoader","WKBWorkerLoader","WKTLoader","WKTWorkerLoader","WKTWriter","WKBWriter"],"mappings":"AAAA,SAAQA,SAAR,EAAmBC,eAAnB,QAAyC,cAAzC;AACA,SAAQC,SAAR,EAAmBC,eAAnB,QAAyC,cAAzC;AACA,SAAQC,SAAR,QAAwB,cAAxB;AACA,SAAQC,SAAR,QAAwB,cAAxB","sourcesContent":["export {WKBLoader, WKBWorkerLoader} from './wkb-loader';\nexport {WKTLoader, WKTWorkerLoader} from './wkt-loader';\nexport {WKTWriter} from './wkt-writer';\nexport {WKBWriter} from './wkb-writer';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import BinaryWriter from './utils/binary-writer';
|
|
2
|
+
var WKB;
|
|
3
|
+
|
|
4
|
+
(function (WKB) {
|
|
5
|
+
WKB[WKB["Point"] = 1] = "Point";
|
|
6
|
+
WKB[WKB["LineString"] = 2] = "LineString";
|
|
7
|
+
WKB[WKB["Polygon"] = 3] = "Polygon";
|
|
8
|
+
WKB[WKB["MultiPoint"] = 4] = "MultiPoint";
|
|
9
|
+
WKB[WKB["MultiLineString"] = 5] = "MultiLineString";
|
|
10
|
+
WKB[WKB["MultiPolygon"] = 6] = "MultiPolygon";
|
|
11
|
+
WKB[WKB["GeometryCollection"] = 7] = "GeometryCollection";
|
|
12
|
+
})(WKB || (WKB = {}));
|
|
13
|
+
|
|
14
|
+
export default function encodeWKB(geometry, options = {
|
|
15
|
+
hasZ: false,
|
|
16
|
+
hasM: false
|
|
17
|
+
}) {
|
|
18
|
+
if (geometry.type === 'Feature') {
|
|
19
|
+
geometry = geometry.geometry;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
switch (geometry.type) {
|
|
23
|
+
case 'Point':
|
|
24
|
+
return encodePoint(geometry.coordinates, options);
|
|
25
|
+
|
|
26
|
+
case 'LineString':
|
|
27
|
+
return encodeLineString(geometry.coordinates, options);
|
|
28
|
+
|
|
29
|
+
case 'Polygon':
|
|
30
|
+
return encodePolygon(geometry.coordinates, options);
|
|
31
|
+
|
|
32
|
+
case 'MultiPoint':
|
|
33
|
+
return encodeMultiPoint(geometry, options);
|
|
34
|
+
|
|
35
|
+
case 'MultiPolygon':
|
|
36
|
+
return encodeMultiPolygon(geometry, options);
|
|
37
|
+
|
|
38
|
+
case 'MultiLineString':
|
|
39
|
+
return encodeMultiLineString(geometry, options);
|
|
40
|
+
|
|
41
|
+
case 'GeometryCollection':
|
|
42
|
+
return encodeGeometryCollection(geometry, options);
|
|
43
|
+
|
|
44
|
+
default:
|
|
45
|
+
const exhaustiveCheck = geometry;
|
|
46
|
+
throw new Error("Unhandled case: ".concat(exhaustiveCheck));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getGeometrySize(geometry, options) {
|
|
51
|
+
switch (geometry.type) {
|
|
52
|
+
case 'Point':
|
|
53
|
+
return getPointSize(options);
|
|
54
|
+
|
|
55
|
+
case 'LineString':
|
|
56
|
+
return getLineStringSize(geometry.coordinates, options);
|
|
57
|
+
|
|
58
|
+
case 'Polygon':
|
|
59
|
+
return getPolygonSize(geometry.coordinates, options);
|
|
60
|
+
|
|
61
|
+
case 'MultiPoint':
|
|
62
|
+
return getMultiPointSize(geometry, options);
|
|
63
|
+
|
|
64
|
+
case 'MultiPolygon':
|
|
65
|
+
return getMultiPolygonSize(geometry, options);
|
|
66
|
+
|
|
67
|
+
case 'MultiLineString':
|
|
68
|
+
return getMultiLineStringSize(geometry, options);
|
|
69
|
+
|
|
70
|
+
case 'GeometryCollection':
|
|
71
|
+
return getGeometryCollectionSize(geometry, options);
|
|
72
|
+
|
|
73
|
+
default:
|
|
74
|
+
const exhaustiveCheck = geometry;
|
|
75
|
+
throw new Error("Unhandled case: ".concat(exhaustiveCheck));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function encodePoint(coordinates, options) {
|
|
80
|
+
const writer = new BinaryWriter(getPointSize(options));
|
|
81
|
+
writer.writeInt8(1);
|
|
82
|
+
writeWkbType(writer, WKB.Point, options);
|
|
83
|
+
|
|
84
|
+
if (typeof coordinates[0] === 'undefined' && typeof coordinates[1] === 'undefined') {
|
|
85
|
+
writer.writeDoubleLE(NaN);
|
|
86
|
+
writer.writeDoubleLE(NaN);
|
|
87
|
+
|
|
88
|
+
if (options.hasZ) {
|
|
89
|
+
writer.writeDoubleLE(NaN);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (options.hasM) {
|
|
93
|
+
writer.writeDoubleLE(NaN);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
writeCoordinate(writer, coordinates, options);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return writer.arrayBuffer;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function writeCoordinate(writer, coordinate, options) {
|
|
103
|
+
writer.writeDoubleLE(coordinate[0]);
|
|
104
|
+
writer.writeDoubleLE(coordinate[1]);
|
|
105
|
+
|
|
106
|
+
if (options.hasZ) {
|
|
107
|
+
writer.writeDoubleLE(coordinate[2]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (options.hasM) {
|
|
111
|
+
writer.writeDoubleLE(coordinate[3]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getPointSize(options) {
|
|
116
|
+
const coordinateSize = getCoordinateSize(options);
|
|
117
|
+
return 1 + 4 + coordinateSize;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function encodeLineString(coordinates, options) {
|
|
121
|
+
const size = getLineStringSize(coordinates, options);
|
|
122
|
+
const writer = new BinaryWriter(size);
|
|
123
|
+
writer.writeInt8(1);
|
|
124
|
+
writeWkbType(writer, WKB.LineString, options);
|
|
125
|
+
writer.writeUInt32LE(coordinates.length);
|
|
126
|
+
|
|
127
|
+
for (const coordinate of coordinates) {
|
|
128
|
+
writeCoordinate(writer, coordinate, options);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return writer.arrayBuffer;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getLineStringSize(coordinates, options) {
|
|
135
|
+
const coordinateSize = getCoordinateSize(options);
|
|
136
|
+
return 1 + 4 + 4 + coordinates.length * coordinateSize;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function encodePolygon(coordinates, options) {
|
|
140
|
+
const writer = new BinaryWriter(getPolygonSize(coordinates, options));
|
|
141
|
+
writer.writeInt8(1);
|
|
142
|
+
writeWkbType(writer, WKB.Polygon, options);
|
|
143
|
+
const [exteriorRing, ...interiorRings] = coordinates;
|
|
144
|
+
|
|
145
|
+
if (exteriorRing.length > 0) {
|
|
146
|
+
writer.writeUInt32LE(1 + interiorRings.length);
|
|
147
|
+
writer.writeUInt32LE(exteriorRing.length);
|
|
148
|
+
} else {
|
|
149
|
+
writer.writeUInt32LE(0);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for (const coordinate of exteriorRing) {
|
|
153
|
+
writeCoordinate(writer, coordinate, options);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
for (const interiorRing of interiorRings) {
|
|
157
|
+
writer.writeUInt32LE(interiorRing.length);
|
|
158
|
+
|
|
159
|
+
for (const coordinate of interiorRing) {
|
|
160
|
+
writeCoordinate(writer, coordinate, options);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return writer.arrayBuffer;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function getPolygonSize(coordinates, options) {
|
|
168
|
+
const coordinateSize = getCoordinateSize(options);
|
|
169
|
+
const [exteriorRing, ...interiorRings] = coordinates;
|
|
170
|
+
let size = 1 + 4 + 4;
|
|
171
|
+
|
|
172
|
+
if (exteriorRing.length > 0) {
|
|
173
|
+
size += 4 + exteriorRing.length * coordinateSize;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
for (const interiorRing of interiorRings) {
|
|
177
|
+
size += 4 + interiorRing.length * coordinateSize;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return size;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function encodeMultiPoint(multiPoint, options) {
|
|
184
|
+
const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));
|
|
185
|
+
const points = multiPoint.coordinates;
|
|
186
|
+
writer.writeInt8(1);
|
|
187
|
+
writeWkbType(writer, WKB.MultiPoint, options);
|
|
188
|
+
writer.writeUInt32LE(points.length);
|
|
189
|
+
|
|
190
|
+
for (const point of points) {
|
|
191
|
+
const arrayBuffer = encodePoint(point, options);
|
|
192
|
+
writer.writeBuffer(arrayBuffer);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return writer.arrayBuffer;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function getMultiPointSize(multiPoint, options) {
|
|
199
|
+
let coordinateSize = getCoordinateSize(options);
|
|
200
|
+
const points = multiPoint.coordinates;
|
|
201
|
+
coordinateSize += 5;
|
|
202
|
+
return 1 + 4 + 4 + points.length * coordinateSize;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function encodeMultiLineString(multiLineString, options) {
|
|
206
|
+
const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));
|
|
207
|
+
const lineStrings = multiLineString.coordinates;
|
|
208
|
+
writer.writeInt8(1);
|
|
209
|
+
writeWkbType(writer, WKB.MultiLineString, options);
|
|
210
|
+
writer.writeUInt32LE(lineStrings.length);
|
|
211
|
+
|
|
212
|
+
for (const lineString of lineStrings) {
|
|
213
|
+
const encodedLineString = encodeLineString(lineString, options);
|
|
214
|
+
writer.writeBuffer(encodedLineString);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return writer.arrayBuffer;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function getMultiLineStringSize(multiLineString, options) {
|
|
221
|
+
let size = 1 + 4 + 4;
|
|
222
|
+
const lineStrings = multiLineString.coordinates;
|
|
223
|
+
|
|
224
|
+
for (const lineString of lineStrings) {
|
|
225
|
+
size += getLineStringSize(lineString, options);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return size;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function encodeMultiPolygon(multiPolygon, options) {
|
|
232
|
+
const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));
|
|
233
|
+
const polygons = multiPolygon.coordinates;
|
|
234
|
+
writer.writeInt8(1);
|
|
235
|
+
writeWkbType(writer, WKB.MultiPolygon, options);
|
|
236
|
+
writer.writeUInt32LE(polygons.length);
|
|
237
|
+
|
|
238
|
+
for (const polygon of polygons) {
|
|
239
|
+
const encodedPolygon = encodePolygon(polygon, options);
|
|
240
|
+
writer.writeBuffer(encodedPolygon);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return writer.arrayBuffer;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function getMultiPolygonSize(multiPolygon, options) {
|
|
247
|
+
let size = 1 + 4 + 4;
|
|
248
|
+
const polygons = multiPolygon.coordinates;
|
|
249
|
+
|
|
250
|
+
for (const polygon of polygons) {
|
|
251
|
+
size += getPolygonSize(polygon, options);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return size;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function encodeGeometryCollection(collection, options) {
|
|
258
|
+
const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));
|
|
259
|
+
writer.writeInt8(1);
|
|
260
|
+
writeWkbType(writer, WKB.GeometryCollection, options);
|
|
261
|
+
writer.writeUInt32LE(collection.geometries.length);
|
|
262
|
+
|
|
263
|
+
for (const geometry of collection.geometries) {
|
|
264
|
+
const arrayBuffer = encodeWKB(geometry, options);
|
|
265
|
+
writer.writeBuffer(arrayBuffer);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return writer.arrayBuffer;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function getGeometryCollectionSize(collection, options) {
|
|
272
|
+
let size = 1 + 4 + 4;
|
|
273
|
+
|
|
274
|
+
for (const geometry of collection.geometries) {
|
|
275
|
+
size += getGeometrySize(geometry, options);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return size;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function writeWkbType(writer, geometryType, options) {
|
|
282
|
+
const {
|
|
283
|
+
hasZ,
|
|
284
|
+
hasM,
|
|
285
|
+
srid
|
|
286
|
+
} = options;
|
|
287
|
+
let dimensionType = 0;
|
|
288
|
+
|
|
289
|
+
if (!srid) {
|
|
290
|
+
if (hasZ && hasM) {
|
|
291
|
+
dimensionType += 3000;
|
|
292
|
+
} else if (hasZ) {
|
|
293
|
+
dimensionType += 1000;
|
|
294
|
+
} else if (hasM) {
|
|
295
|
+
dimensionType += 2000;
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
if (hasZ) {
|
|
299
|
+
dimensionType |= 0x80000000;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (hasM) {
|
|
303
|
+
dimensionType |= 0x40000000;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
writer.writeUInt32LE(dimensionType + geometryType >>> 0);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function getCoordinateSize(options) {
|
|
311
|
+
let coordinateSize = 16;
|
|
312
|
+
|
|
313
|
+
if (options.hasZ) {
|
|
314
|
+
coordinateSize += 8;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (options.hasM) {
|
|
318
|
+
coordinateSize += 8;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return coordinateSize;
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=encode-wkb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/encode-wkb.ts"],"names":["BinaryWriter","WKB","encodeWKB","geometry","options","hasZ","hasM","type","encodePoint","coordinates","encodeLineString","encodePolygon","encodeMultiPoint","encodeMultiPolygon","encodeMultiLineString","encodeGeometryCollection","exhaustiveCheck","Error","getGeometrySize","getPointSize","getLineStringSize","getPolygonSize","getMultiPointSize","getMultiPolygonSize","getMultiLineStringSize","getGeometryCollectionSize","writer","writeInt8","writeWkbType","Point","writeDoubleLE","NaN","writeCoordinate","arrayBuffer","coordinate","coordinateSize","getCoordinateSize","size","LineString","writeUInt32LE","length","Polygon","exteriorRing","interiorRings","interiorRing","multiPoint","points","MultiPoint","point","writeBuffer","multiLineString","lineStrings","MultiLineString","lineString","encodedLineString","multiPolygon","polygons","MultiPolygon","polygon","encodedPolygon","collection","GeometryCollection","geometries","geometryType","srid","dimensionType"],"mappings":"AAgBA,OAAOA,YAAP,MAAyB,uBAAzB;IAMKC,G;;WAAAA,G;AAAAA,EAAAA,G,CAAAA,G;AAAAA,EAAAA,G,CAAAA,G;AAAAA,EAAAA,G,CAAAA,G;AAAAA,EAAAA,G,CAAAA,G;AAAAA,EAAAA,G,CAAAA,G;AAAAA,EAAAA,G,CAAAA,G;AAAAA,EAAAA,G,CAAAA,G;GAAAA,G,KAAAA,G;;AAwBL,eAAe,SAASC,SAAT,CACbC,QADa,EAEbC,OAAmB,GAAG;AAACC,EAAAA,IAAI,EAAE,KAAP;AAAcC,EAAAA,IAAI,EAAE;AAApB,CAFT,EAGA;AACb,MAAIH,QAAQ,CAACI,IAAT,KAAkB,SAAtB,EAAiC;AAC/BJ,IAAAA,QAAQ,GAAGA,QAAQ,CAACA,QAApB;AACD;;AAED,UAAQA,QAAQ,CAACI,IAAjB;AACE,SAAK,OAAL;AACE,aAAOC,WAAW,CAACL,QAAQ,CAACM,WAAV,EAAuBL,OAAvB,CAAlB;;AACF,SAAK,YAAL;AACE,aAAOM,gBAAgB,CAACP,QAAQ,CAACM,WAAV,EAAuBL,OAAvB,CAAvB;;AACF,SAAK,SAAL;AACE,aAAOO,aAAa,CA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ACT,QAAI3D,IAAI,IAAIC,IAAZ,EAAkB;AAChB2D,MAAAA,aAAa,IAAI,IAAjB;AACD,KAFD,MAEO,IAAI5D,IAAJ,EAAU;AACf4D,MAAAA,aAAa,IAAI,IAAjB;AACD,KAFM,MAEA,IAAI3D,IAAJ,EAAU;AACf2D,MAAAA,aAAa,IAAI,IAAjB;AACD;AACF,GARD,MAQO;AACL,QAAI5D,IAAJ,EAAU;AACR4D,MAAAA,aAAa,IAAI,UAAjB;AACD;;AACD,QAAI3D,IAAJ,EAAU;AACR2D,MAAAA,aAAa,IAAI,UAAjB;AACD;AACF;;AAEDvC,EAAAA,MAAM,CAACa,aAAP,CAAsB0B,aAAa,GAAGF,YAAjB,KAAmC,CAAxD;AACD;;AAGD,SAAS3B,iBAAT,CAA2BhC,OAA3B,EAAwD;AACtD,MAAI+B,cAAc,GAAG,EAArB;;AAEA,MAAI/B,OAAO,CAACC,IAAZ,EAAkB;AAChB8B,IAAAA,cAAc,IAAI,CAAlB;AACD;;AACD,MAAI/B,OAAO,CAACE,IAAZ,EAAkB;AAChB6B,IAAAA,cAAc,IAAI,CAAlB;AACD;;AAED,SAAOA,cAAP;AACD","sourcesContent":["// loaders.gl, MIT license\n// Forked from https://github.com/cschwarz/wkx under MIT license, Copyright (c) 2013 Christian Schwarz\n// Reference: https://www.ogc.org/standards/sfa\n\nimport type {\n Feature,\n Geometry,\n Point,\n MultiPoint,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon,\n GeometryCollection\n} from '@loaders.gl/schema';\n\nimport BinaryWriter from './utils/binary-writer';\n\n/**\n * Integer code for geometry type\n * Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary\n */\nenum WKB {\n Point = 1,\n LineString = 2,\n Polygon = 3,\n MultiPoint = 4,\n MultiLineString = 5,\n MultiPolygon = 6,\n GeometryCollection = 7\n}\n\n/**\n * Options for encodeWKB\n */\ninterface WKBOptions {\n hasZ?: boolean;\n hasM?: boolean;\n srid?: any;\n}\n\n/**\n * Encodes a GeoJSON object into WKB\n * @param geojson A GeoJSON Feature or Geometry\n * @returns string\n */\nexport default function encodeWKB(\n geometry: Geometry | Feature,\n options: WKBOptions = {hasZ: false, hasM: false}\n): ArrayBuffer {\n if (geometry.type === 'Feature') {\n geometry = geometry.geometry;\n }\n\n switch (geometry.type) {\n case 'Point':\n return encodePoint(geometry.coordinates, options);\n case 'LineString':\n return encodeLineString(geometry.coordinates, options);\n case 'Polygon':\n return encodePolygon(geometry.coordinates, options);\n case 'MultiPoint':\n return encodeMultiPoint(geometry, options);\n case 'MultiPolygon':\n return encodeMultiPolygon(geometry, options);\n case 'MultiLineString':\n return encodeMultiLineString(geometry, options);\n case 'GeometryCollection':\n return encodeGeometryCollection(geometry, options);\n default:\n const exhaustiveCheck: never = geometry;\n throw new Error(`Unhandled case: ${exhaustiveCheck}`);\n }\n}\n\n/** Calculate the binary size (in the WKB encoding) of a specific GeoJSON geometry */\nfunction getGeometrySize(geometry: Geometry, options: WKBOptions): number {\n switch (geometry.type) {\n case 'Point':\n return getPointSize(options);\n case 'LineString':\n return getLineStringSize(geometry.coordinates, options);\n case 'Polygon':\n return getPolygonSize(geometry.coordinates, options);\n case 'MultiPoint':\n return getMultiPointSize(geometry, options);\n case 'MultiPolygon':\n return getMultiPolygonSize(geometry, options);\n case 'MultiLineString':\n return getMultiLineStringSize(geometry, options);\n case 'GeometryCollection':\n return getGeometryCollectionSize(geometry, options);\n default:\n const exhaustiveCheck: never = geometry;\n throw new Error(`Unhandled case: ${exhaustiveCheck}`);\n }\n}\n\n/** Encode Point geometry as WKB ArrayBuffer */\nfunction encodePoint(coordinates: Point['coordinates'], options: WKBOptions): ArrayBuffer {\n const writer = new BinaryWriter(getPointSize(options));\n\n writer.writeInt8(1);\n writeWkbType(writer, WKB.Point, options);\n\n // I believe this special case is to handle writing Point(NaN, NaN) correctly\n if (typeof coordinates[0] === 'undefined' && typeof coordinates[1] === 'undefined') {\n writer.writeDoubleLE(NaN);\n writer.writeDoubleLE(NaN);\n\n if (options.hasZ) {\n writer.writeDoubleLE(NaN);\n }\n if (options.hasM) {\n writer.writeDoubleLE(NaN);\n }\n } else {\n writeCoordinate(writer, coordinates, options);\n }\n\n return writer.arrayBuffer;\n}\n\n/** Write coordinate to buffer */\nfunction writeCoordinate(\n writer: BinaryWriter,\n coordinate: Point['coordinates'],\n options: WKBOptions\n): void {\n writer.writeDoubleLE(coordinate[0]);\n writer.writeDoubleLE(coordinate[1]);\n\n if (options.hasZ) {\n writer.writeDoubleLE(coordinate[2]);\n }\n if (options.hasM) {\n writer.writeDoubleLE(coordinate[3]);\n }\n}\n\n/** Get encoded size of Point geometry */\nfunction getPointSize(options: WKBOptions): number {\n const coordinateSize = getCoordinateSize(options);\n return 1 + 4 + coordinateSize;\n}\n\n/** Encode LineString geometry as WKB ArrayBuffer */\nfunction encodeLineString(\n coordinates: LineString['coordinates'],\n options: WKBOptions\n): ArrayBuffer {\n const size = getLineStringSize(coordinates, options);\n\n const writer = new BinaryWriter(size);\n\n writer.writeInt8(1);\n\n writeWkbType(writer, WKB.LineString, options);\n writer.writeUInt32LE(coordinates.length);\n\n for (const coordinate of coordinates) {\n writeCoordinate(writer, coordinate, options);\n }\n\n return writer.arrayBuffer;\n}\n\n/** Get encoded size of LineString geometry */\nfunction getLineStringSize(coordinates: LineString['coordinates'], options: WKBOptions): number {\n const coordinateSize = getCoordinateSize(options);\n\n return 1 + 4 + 4 + coordinates.length * coordinateSize;\n}\n\n/** Encode Polygon geometry as WKB ArrayBuffer */\nfunction encodePolygon(coordinates: Polygon['coordinates'], options: WKBOptions): ArrayBuffer {\n const writer = new BinaryWriter(getPolygonSize(coordinates, options));\n\n writer.writeInt8(1);\n\n writeWkbType(writer, WKB.Polygon, options);\n const [exteriorRing, ...interiorRings] = coordinates;\n\n if (exteriorRing.length > 0) {\n writer.writeUInt32LE(1 + interiorRings.length);\n writer.writeUInt32LE(exteriorRing.length);\n } else {\n writer.writeUInt32LE(0);\n }\n\n for (const coordinate of exteriorRing) {\n writeCoordinate(writer, coordinate, options);\n }\n\n for (const interiorRing of interiorRings) {\n writer.writeUInt32LE(interiorRing.length);\n\n for (const coordinate of interiorRing) {\n writeCoordinate(writer, coordinate, options);\n }\n }\n\n return writer.arrayBuffer;\n}\n\n/** Get encoded size of Polygon geometry */\nfunction getPolygonSize(coordinates: Polygon['coordinates'], options: WKBOptions): number {\n const coordinateSize = getCoordinateSize(options);\n const [exteriorRing, ...interiorRings] = coordinates;\n\n let size = 1 + 4 + 4;\n\n if (exteriorRing.length > 0) {\n size += 4 + exteriorRing.length * coordinateSize;\n }\n\n for (const interiorRing of interiorRings) {\n size += 4 + interiorRing.length * coordinateSize;\n }\n\n return size;\n}\n\n/** Encode MultiPoint geometry as WKB ArrayBufer */\nfunction encodeMultiPoint(multiPoint: MultiPoint, options: WKBOptions) {\n const writer = new BinaryWriter(getMultiPointSize(multiPoint, options));\n const points = multiPoint.coordinates;\n\n writer.writeInt8(1);\n\n writeWkbType(writer, WKB.MultiPoint, options);\n writer.writeUInt32LE(points.length);\n\n for (const point of points) {\n // TODO: add srid to this options object? {srid: multiPoint.srid}\n const arrayBuffer = encodePoint(point, options);\n writer.writeBuffer(arrayBuffer);\n }\n\n return writer.arrayBuffer;\n}\n\n/** Get encoded size of MultiPoint geometry */\nfunction getMultiPointSize(multiPoint: MultiPoint, options: WKBOptions) {\n let coordinateSize = getCoordinateSize(options);\n const points = multiPoint.coordinates;\n\n // This is because each point has a 5-byte header?\n coordinateSize += 5;\n\n return 1 + 4 + 4 + points.length * coordinateSize;\n}\n\n/** Encode MultiLineString geometry as WKB ArrayBufer */\nfunction encodeMultiLineString(multiLineString: MultiLineString, options: WKBOptions) {\n const writer = new BinaryWriter(getMultiLineStringSize(multiLineString, options));\n const lineStrings = multiLineString.coordinates;\n\n writer.writeInt8(1);\n\n writeWkbType(writer, WKB.MultiLineString, options);\n writer.writeUInt32LE(lineStrings.length);\n\n for (const lineString of lineStrings) {\n // TODO: Handle srid?\n const encodedLineString = encodeLineString(lineString, options);\n writer.writeBuffer(encodedLineString);\n }\n\n return writer.arrayBuffer;\n}\n\n/** Get encoded size of MultiLineString geometry */\nfunction getMultiLineStringSize(multiLineString: MultiLineString, options: WKBOptions): number {\n let size = 1 + 4 + 4;\n const lineStrings = multiLineString.coordinates;\n\n for (const lineString of lineStrings) {\n size += getLineStringSize(lineString, options);\n }\n\n return size;\n}\n\nfunction encodeMultiPolygon(multiPolygon: MultiPolygon, options: WKBOptions): ArrayBuffer {\n const writer = new BinaryWriter(getMultiPolygonSize(multiPolygon, options));\n const polygons = multiPolygon.coordinates;\n\n writer.writeInt8(1);\n\n writeWkbType(writer, WKB.MultiPolygon, options);\n writer.writeUInt32LE(polygons.length);\n\n for (const polygon of polygons) {\n const encodedPolygon = encodePolygon(polygon, options);\n writer.writeBuffer(encodedPolygon);\n }\n\n return writer.arrayBuffer;\n}\n\nfunction getMultiPolygonSize(multiPolygon: MultiPolygon, options: WKBOptions): number {\n let size = 1 + 4 + 4;\n const polygons = multiPolygon.coordinates;\n\n for (const polygon of polygons) {\n size += getPolygonSize(polygon, options);\n }\n\n return size;\n}\n\nfunction encodeGeometryCollection(\n collection: GeometryCollection,\n options: WKBOptions\n): ArrayBuffer {\n const writer = new BinaryWriter(getGeometryCollectionSize(collection, options));\n\n writer.writeInt8(1);\n\n writeWkbType(writer, WKB.GeometryCollection, options);\n writer.writeUInt32LE(collection.geometries.length);\n\n for (const geometry of collection.geometries) {\n // TODO: handle srid? {srid: collection.srid}\n const arrayBuffer = encodeWKB(geometry, options);\n writer.writeBuffer(arrayBuffer);\n }\n\n return writer.arrayBuffer;\n}\n\nfunction getGeometryCollectionSize(collection: GeometryCollection, options: WKBOptions): number {\n let size = 1 + 4 + 4;\n\n for (const geometry of collection.geometries) {\n size += getGeometrySize(geometry, options);\n }\n\n return size;\n}\n\n// HELPERS\n\n/**\n * Construct and write WKB integer code\n * Reference: https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary\n */\nfunction writeWkbType(writer: BinaryWriter, geometryType: number, options: WKBOptions): void {\n const {hasZ, hasM, srid} = options;\n\n let dimensionType = 0;\n\n if (!srid) {\n if (hasZ && hasM) {\n dimensionType += 3000;\n } else if (hasZ) {\n dimensionType += 1000;\n } else if (hasM) {\n dimensionType += 2000;\n }\n } else {\n if (hasZ) {\n dimensionType |= 0x80000000;\n }\n if (hasM) {\n dimensionType |= 0x40000000;\n }\n }\n\n writer.writeUInt32LE((dimensionType + geometryType) >>> 0);\n}\n\n/** Get coordinate size given Z/M dimensions */\nfunction getCoordinateSize(options: WKBOptions): number {\n let coordinateSize = 16;\n\n if (options.hasZ) {\n coordinateSize += 8;\n }\n if (options.hasM) {\n coordinateSize += 8;\n }\n\n return coordinateSize;\n}\n"],"file":"encode-wkb.js"}
|