powersync 0.1.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/README.md +339 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +9 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +8 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +49 -0
- package/dist/commands/instance/config.d.ts +6 -0
- package/dist/commands/instance/config.js +23 -0
- package/dist/commands/instance/create.d.ts +16 -0
- package/dist/commands/instance/create.js +163 -0
- package/dist/commands/instance/deploy.d.ts +15 -0
- package/dist/commands/instance/deploy.js +142 -0
- package/dist/commands/instance/destroy.d.ts +9 -0
- package/dist/commands/instance/destroy.js +42 -0
- package/dist/commands/instance/schema.d.ts +6 -0
- package/dist/commands/instance/schema.js +20 -0
- package/dist/commands/instance/set.d.ts +9 -0
- package/dist/commands/instance/set.js +31 -0
- package/dist/commands/instance/status.d.ts +6 -0
- package/dist/commands/instance/status.js +21 -0
- package/dist/commands/instance/stop.d.ts +9 -0
- package/dist/commands/instance/stop.js +42 -0
- package/dist/commands/instance/sync-rules/deploy.d.ts +10 -0
- package/dist/commands/instance/sync-rules/deploy.js +49 -0
- package/dist/commands/instance/sync-rules/generate-schema.d.ts +10 -0
- package/dist/commands/instance/sync-rules/generate-schema.js +55 -0
- package/dist/commands/instance/sync-rules/validate.d.ts +9 -0
- package/dist/commands/instance/sync-rules/validate.js +29 -0
- package/dist/commands/instances.d.ts +6 -0
- package/dist/commands/instances.js +20 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/powersync-sdk/accounts/api.d.ts +717 -0
- package/dist/powersync-sdk/accounts/api.js +182 -0
- package/dist/powersync-sdk/accounts/client.d.ts +1096 -0
- package/dist/powersync-sdk/accounts/client.js +124 -0
- package/dist/powersync-sdk/accounts/codecs.d.ts +32 -0
- package/dist/powersync-sdk/accounts/codecs.js +93 -0
- package/dist/powersync-sdk/accounts/index.d.ts +4 -0
- package/dist/powersync-sdk/accounts/index.js +4 -0
- package/dist/powersync-sdk/accounts/models.d.ts +260 -0
- package/dist/powersync-sdk/accounts/models.js +96 -0
- package/dist/powersync-sdk/accounts/routes.d.ts +44 -0
- package/dist/powersync-sdk/accounts/routes.js +45 -0
- package/dist/powersync-sdk/accounts/source.d.ts +76 -0
- package/dist/powersync-sdk/accounts/source.js +32 -0
- package/dist/powersync-sdk/errors/errors.d.ts +62 -0
- package/dist/powersync-sdk/errors/errors.js +115 -0
- package/dist/powersync-sdk/errors/index.d.ts +2 -0
- package/dist/powersync-sdk/errors/index.js +2 -0
- package/dist/powersync-sdk/errors/utils.d.ts +4 -0
- package/dist/powersync-sdk/errors/utils.js +18 -0
- package/dist/powersync-sdk/fetch-clients/codecs.d.ts +4 -0
- package/dist/powersync-sdk/fetch-clients/codecs.js +34 -0
- package/dist/powersync-sdk/fetch-clients/decoders.d.ts +3 -0
- package/dist/powersync-sdk/fetch-clients/decoders.js +35 -0
- package/dist/powersync-sdk/fetch-clients/definitions.d.ts +97 -0
- package/dist/powersync-sdk/fetch-clients/definitions.js +22 -0
- package/dist/powersync-sdk/fetch-clients/errors.d.ts +7 -0
- package/dist/powersync-sdk/fetch-clients/errors.js +19 -0
- package/dist/powersync-sdk/fetch-clients/index.d.ts +5 -0
- package/dist/powersync-sdk/fetch-clients/index.js +5 -0
- package/dist/powersync-sdk/fetch-clients/node-client.d.ts +9 -0
- package/dist/powersync-sdk/fetch-clients/node-client.js +107 -0
- package/dist/powersync-sdk/fetch-clients/request.d.ts +11 -0
- package/dist/powersync-sdk/fetch-clients/request.js +138 -0
- package/dist/powersync-sdk/fetch-clients/streaming.d.ts +65 -0
- package/dist/powersync-sdk/fetch-clients/streaming.js +99 -0
- package/dist/powersync-sdk/fetch-clients/utils.d.ts +13 -0
- package/dist/powersync-sdk/fetch-clients/utils.js +43 -0
- package/dist/powersync-sdk/fetch-clients/web-client.d.ts +14 -0
- package/dist/powersync-sdk/fetch-clients/web-client.js +56 -0
- package/dist/powersync-sdk/json/index.d.ts +4 -0
- package/dist/powersync-sdk/json/index.js +3 -0
- package/dist/powersync-sdk/json/json.d.ts +5 -0
- package/dist/powersync-sdk/json/json.js +35 -0
- package/dist/powersync-sdk/json/json_container.d.ts +18 -0
- package/dist/powersync-sdk/json/json_container.js +28 -0
- package/dist/powersync-sdk/json/json_stringify.d.ts +36 -0
- package/dist/powersync-sdk/json/json_stringify.js +162 -0
- package/dist/powersync-sdk/powersync/client.d.ts +449 -0
- package/dist/powersync-sdk/powersync/client.js +53 -0
- package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +327 -0
- package/dist/powersync-sdk/powersync/config/HostedConfig.js +92 -0
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +211 -0
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +97 -0
- package/dist/powersync-sdk/powersync/config/normalize.d.ts +32 -0
- package/dist/powersync-sdk/powersync/config/normalize.js +85 -0
- package/dist/powersync-sdk/powersync/definitions.d.ts +149 -0
- package/dist/powersync-sdk/powersync/definitions.js +97 -0
- package/dist/powersync-sdk/powersync/index.d.ts +8 -0
- package/dist/powersync-sdk/powersync/index.js +8 -0
- package/dist/powersync-sdk/powersync/internal_routes.d.ts +247 -0
- package/dist/powersync-sdk/powersync/internal_routes.js +69 -0
- package/dist/powersync-sdk/powersync/routes.d.ts +779 -0
- package/dist/powersync-sdk/powersync/routes.js +191 -0
- package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +31 -0
- package/dist/powersync-sdk/sdk-clients/endpoints.js +48 -0
- package/dist/powersync-sdk/sdk-clients/index.d.ts +3 -0
- package/dist/powersync-sdk/sdk-clients/index.js +3 -0
- package/dist/powersync-sdk/sdk-clients/pagination.d.ts +14 -0
- package/dist/powersync-sdk/sdk-clients/pagination.js +21 -0
- package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +17 -0
- package/dist/powersync-sdk/sdk-clients/sdk-client.js +30 -0
- package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +31 -0
- package/dist/powersync-sdk/streaming/bson/buffer-array.js +79 -0
- package/dist/powersync-sdk/streaming/bson/constants.d.ts +2 -0
- package/dist/powersync-sdk/streaming/bson/constants.js +1 -0
- package/dist/powersync-sdk/streaming/bson/decoder.d.ts +10 -0
- package/dist/powersync-sdk/streaming/bson/decoder.js +62 -0
- package/dist/powersync-sdk/streaming/bson/encoder.d.ts +10 -0
- package/dist/powersync-sdk/streaming/bson/encoder.js +23 -0
- package/dist/powersync-sdk/streaming/bson/header.d.ts +11 -0
- package/dist/powersync-sdk/streaming/bson/header.js +52 -0
- package/dist/powersync-sdk/streaming/bson/index.d.ts +5 -0
- package/dist/powersync-sdk/streaming/bson/index.js +5 -0
- package/dist/powersync-sdk/streaming/core/backpressure.d.ts +15 -0
- package/dist/powersync-sdk/streaming/core/backpressure.js +34 -0
- package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +6 -0
- package/dist/powersync-sdk/streaming/core/cross-stream.js +17 -0
- package/dist/powersync-sdk/streaming/core/index.d.ts +4 -0
- package/dist/powersync-sdk/streaming/core/index.js +4 -0
- package/dist/powersync-sdk/streaming/core/node-utils.d.ts +7 -0
- package/dist/powersync-sdk/streaming/core/node-utils.js +11 -0
- package/dist/powersync-sdk/streaming/core/transformers.d.ts +41 -0
- package/dist/powersync-sdk/streaming/core/transformers.js +70 -0
- package/dist/powersync-sdk/streaming/core/utils.d.ts +36 -0
- package/dist/powersync-sdk/streaming/core/utils.js +66 -0
- package/dist/powersync-sdk/streaming/index.d.ts +3 -0
- package/dist/powersync-sdk/streaming/index.js +3 -0
- package/dist/powersync-sdk/streaming/web.d.ts +4 -0
- package/dist/powersync-sdk/streaming/web.js +4 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +36 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +58 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +18 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +348 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +118 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +131 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +134 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +122 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +158 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +14 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +165 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +207 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +30 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +29 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +111 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +9 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +9 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +5 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +9 -0
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +12 -0
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +35 -0
- package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +33 -0
- package/dist/powersync-sdk/sync-rules/ExpressionType.js +62 -0
- package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +4 -0
- package/dist/powersync-sdk/sync-rules/IdSequence.js +7 -0
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +12 -0
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +38 -0
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +14 -0
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +24 -0
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +5 -0
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +1 -0
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +37 -0
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +116 -0
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +39 -0
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +245 -0
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +43 -0
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +254 -0
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +52 -0
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +252 -0
- package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +26 -0
- package/dist/powersync-sdk/sync-rules/StaticSchema.js +71 -0
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +24 -0
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +71 -0
- package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +17 -0
- package/dist/powersync-sdk/sync-rules/TablePattern.js +56 -0
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +9 -0
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +41 -0
- package/dist/powersync-sdk/sync-rules/errors.d.ts +22 -0
- package/dist/powersync-sdk/sync-rules/errors.js +60 -0
- package/dist/powersync-sdk/sync-rules/generators.d.ts +6 -0
- package/dist/powersync-sdk/sync-rules/generators.js +6 -0
- package/dist/powersync-sdk/sync-rules/index.d.ts +17 -0
- package/dist/powersync-sdk/sync-rules/index.js +17 -0
- package/dist/powersync-sdk/sync-rules/json_schema.d.ts +3 -0
- package/dist/powersync-sdk/sync-rules/json_schema.js +50 -0
- package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +91 -0
- package/dist/powersync-sdk/sync-rules/sql_filters.js +491 -0
- package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +53 -0
- package/dist/powersync-sdk/sync-rules/sql_functions.js +755 -0
- package/dist/powersync-sdk/sync-rules/sql_support.d.ts +22 -0
- package/dist/powersync-sdk/sync-rules/sql_support.js +208 -0
- package/dist/powersync-sdk/sync-rules/types.d.ts +174 -0
- package/dist/powersync-sdk/sync-rules/types.js +9 -0
- package/dist/powersync-sdk/sync-rules/utils.d.ts +45 -0
- package/dist/powersync-sdk/sync-rules/utils.js +163 -0
- package/dist/service/accounts.client.d.ts +26 -0
- package/dist/service/accounts.client.js +26 -0
- package/dist/service/powersync.client.d.ts +269 -0
- package/dist/service/powersync.client.js +135 -0
- package/dist/service/types.d.ts +69 -0
- package/dist/service/types.js +1 -0
- package/dist/service/utils.d.ts +5 -0
- package/dist/service/utils.js +7 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +52 -0
- package/oclif.manifest.json +514 -0
- package/package.json +81 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import BinaryWriter from './binarywriter.js';
|
|
2
|
+
import Geometry from './geometry.js';
|
|
3
|
+
import LineString from './linestring.js';
|
|
4
|
+
import Point from './point.js';
|
|
5
|
+
import Types from './types.js';
|
|
6
|
+
function MultiLineString(lineStrings, srid) {
|
|
7
|
+
Geometry.call(this);
|
|
8
|
+
this.lineStrings = lineStrings || [];
|
|
9
|
+
this.srid = srid;
|
|
10
|
+
if (this.lineStrings.length > 0) {
|
|
11
|
+
this.hasZ = this.lineStrings[0].hasZ;
|
|
12
|
+
this.hasM = this.lineStrings[0].hasM;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// util.inherits(MultiLineString, Geometry);
|
|
16
|
+
MultiLineString.Z = function (lineStrings, srid) {
|
|
17
|
+
const multiLineString = new MultiLineString(lineStrings, srid);
|
|
18
|
+
multiLineString.hasZ = true;
|
|
19
|
+
return multiLineString;
|
|
20
|
+
};
|
|
21
|
+
MultiLineString.M = function (lineStrings, srid) {
|
|
22
|
+
const multiLineString = new MultiLineString(lineStrings, srid);
|
|
23
|
+
multiLineString.hasM = true;
|
|
24
|
+
return multiLineString;
|
|
25
|
+
};
|
|
26
|
+
MultiLineString.ZM = function (lineStrings, srid) {
|
|
27
|
+
const multiLineString = new MultiLineString(lineStrings, srid);
|
|
28
|
+
multiLineString.hasZ = true;
|
|
29
|
+
multiLineString.hasM = true;
|
|
30
|
+
return multiLineString;
|
|
31
|
+
};
|
|
32
|
+
MultiLineString._parseWkt = function (value, options) {
|
|
33
|
+
const multiLineString = new MultiLineString();
|
|
34
|
+
multiLineString.srid = options.srid;
|
|
35
|
+
multiLineString.hasZ = options.hasZ;
|
|
36
|
+
multiLineString.hasM = options.hasM;
|
|
37
|
+
if (value.isMatch(['EMPTY']))
|
|
38
|
+
return multiLineString;
|
|
39
|
+
value.expectGroupStart();
|
|
40
|
+
do {
|
|
41
|
+
value.expectGroupStart();
|
|
42
|
+
multiLineString.lineStrings.push(new LineString(value.matchCoordinates(options)));
|
|
43
|
+
value.expectGroupEnd();
|
|
44
|
+
} while (value.isMatch([',']));
|
|
45
|
+
value.expectGroupEnd();
|
|
46
|
+
return multiLineString;
|
|
47
|
+
};
|
|
48
|
+
MultiLineString._parseWkb = function (value, options) {
|
|
49
|
+
const multiLineString = new MultiLineString();
|
|
50
|
+
multiLineString.srid = options.srid;
|
|
51
|
+
multiLineString.hasZ = options.hasZ;
|
|
52
|
+
multiLineString.hasM = options.hasM;
|
|
53
|
+
const lineStringCount = value.readUInt32();
|
|
54
|
+
for (let i = 0; i < lineStringCount; i++)
|
|
55
|
+
multiLineString.lineStrings.push(Geometry.parse(value, options));
|
|
56
|
+
return multiLineString;
|
|
57
|
+
};
|
|
58
|
+
MultiLineString._parseTwkb = function (value, options) {
|
|
59
|
+
const multiLineString = new MultiLineString();
|
|
60
|
+
multiLineString.hasZ = options.hasZ;
|
|
61
|
+
multiLineString.hasM = options.hasM;
|
|
62
|
+
if (options.isEmpty)
|
|
63
|
+
return multiLineString;
|
|
64
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
|
|
65
|
+
const lineStringCount = value.readVarInt();
|
|
66
|
+
for (let i = 0; i < lineStringCount; i++) {
|
|
67
|
+
const lineString = new LineString();
|
|
68
|
+
lineString.hasZ = options.hasZ;
|
|
69
|
+
lineString.hasM = options.hasM;
|
|
70
|
+
const pointCount = value.readVarInt();
|
|
71
|
+
for (let j = 0; j < pointCount; j++)
|
|
72
|
+
lineString.points.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
73
|
+
multiLineString.lineStrings.push(lineString);
|
|
74
|
+
}
|
|
75
|
+
return multiLineString;
|
|
76
|
+
};
|
|
77
|
+
MultiLineString._parseGeoJSON = function (value) {
|
|
78
|
+
const multiLineString = new MultiLineString();
|
|
79
|
+
if (value.coordinates.length > 0 && value.coordinates[0].length > 0)
|
|
80
|
+
multiLineString.hasZ = value.coordinates[0][0].length > 2;
|
|
81
|
+
for (let i = 0; i < value.coordinates.length; i++)
|
|
82
|
+
multiLineString.lineStrings.push(LineString._parseGeoJSON({ coordinates: value.coordinates[i] }));
|
|
83
|
+
return multiLineString;
|
|
84
|
+
};
|
|
85
|
+
MultiLineString.prototype.toWkt = function () {
|
|
86
|
+
if (this.lineStrings.length === 0)
|
|
87
|
+
return this._getWktType(Types.wkt.MultiLineString, true);
|
|
88
|
+
let wkt = this._getWktType(Types.wkt.MultiLineString, false) + '(';
|
|
89
|
+
for (let i = 0; i < this.lineStrings.length; i++)
|
|
90
|
+
wkt += this.lineStrings[i]._toInnerWkt() + ',';
|
|
91
|
+
wkt = wkt.slice(0, -1);
|
|
92
|
+
wkt += ')';
|
|
93
|
+
return wkt;
|
|
94
|
+
};
|
|
95
|
+
MultiLineString.prototype.toWkb = function () {
|
|
96
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
97
|
+
wkb.writeInt8(1);
|
|
98
|
+
this._writeWkbType(wkb, Types.wkb.MultiLineString);
|
|
99
|
+
wkb.writeUInt32LE(this.lineStrings.length);
|
|
100
|
+
for (let i = 0; i < this.lineStrings.length; i++)
|
|
101
|
+
wkb.writeBuffer(this.lineStrings[i].toWkb({ srid: this.srid }));
|
|
102
|
+
return wkb.buffer;
|
|
103
|
+
};
|
|
104
|
+
MultiLineString.prototype.toTwkb = function () {
|
|
105
|
+
const twkb = new BinaryWriter(0, true);
|
|
106
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
107
|
+
const isEmpty = this.lineStrings.length === 0;
|
|
108
|
+
this._writeTwkbHeader(twkb, Types.wkb.MultiLineString, precision, isEmpty);
|
|
109
|
+
if (this.lineStrings.length > 0) {
|
|
110
|
+
twkb.writeVarInt(this.lineStrings.length);
|
|
111
|
+
const previousPoint = new Point(0, 0, 0, 0);
|
|
112
|
+
for (let i = 0; i < this.lineStrings.length; i++) {
|
|
113
|
+
twkb.writeVarInt(this.lineStrings[i].points.length);
|
|
114
|
+
for (let j = 0; j < this.lineStrings[i].points.length; j++)
|
|
115
|
+
this.lineStrings[i].points[j]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return twkb.buffer;
|
|
119
|
+
};
|
|
120
|
+
MultiLineString.prototype._getWkbSize = function () {
|
|
121
|
+
let size = 1 + 4 + 4;
|
|
122
|
+
for (let i = 0; i < this.lineStrings.length; i++)
|
|
123
|
+
size += this.lineStrings[i]._getWkbSize();
|
|
124
|
+
return size;
|
|
125
|
+
};
|
|
126
|
+
MultiLineString.prototype.toGeoJSON = function (options) {
|
|
127
|
+
const geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
|
|
128
|
+
geoJSON.type = Types.geoJSON.MultiLineString;
|
|
129
|
+
geoJSON.coordinates = [];
|
|
130
|
+
for (let i = 0; i < this.lineStrings.length; i++)
|
|
131
|
+
geoJSON.coordinates.push(this.lineStrings[i].toGeoJSON().coordinates);
|
|
132
|
+
return geoJSON;
|
|
133
|
+
};
|
|
134
|
+
export default MultiLineString;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function MultiPoint(points: any, srid: any): void;
|
|
2
|
+
declare namespace MultiPoint {
|
|
3
|
+
var Z: (points: any, srid: any) => any;
|
|
4
|
+
var M: (points: any, srid: any) => any;
|
|
5
|
+
var ZM: (points: any, srid: any) => any;
|
|
6
|
+
var _parseWkt: (value: any, options: any) => any;
|
|
7
|
+
var _parseWkb: (value: any, options: any) => any;
|
|
8
|
+
var _parseTwkb: (value: any, options: any) => any;
|
|
9
|
+
var _parseGeoJSON: (value: any) => any;
|
|
10
|
+
}
|
|
11
|
+
export default MultiPoint;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as BinaryWriter from './binarywriter.js';
|
|
2
|
+
import * as Geometry from './geometry.js';
|
|
3
|
+
import * as Point from './point.js';
|
|
4
|
+
import * as Types from './types.js';
|
|
5
|
+
function MultiPoint(points, srid) {
|
|
6
|
+
Geometry.call(this);
|
|
7
|
+
this.points = points || [];
|
|
8
|
+
this.srid = srid;
|
|
9
|
+
if (this.points.length > 0) {
|
|
10
|
+
this.hasZ = this.points[0].hasZ;
|
|
11
|
+
this.hasM = this.points[0].hasM;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// util.inherits(MultiPoint, Geometry);
|
|
15
|
+
MultiPoint.Z = function (points, srid) {
|
|
16
|
+
const multiPoint = new MultiPoint(points, srid);
|
|
17
|
+
multiPoint.hasZ = true;
|
|
18
|
+
return multiPoint;
|
|
19
|
+
};
|
|
20
|
+
MultiPoint.M = function (points, srid) {
|
|
21
|
+
const multiPoint = new MultiPoint(points, srid);
|
|
22
|
+
multiPoint.hasM = true;
|
|
23
|
+
return multiPoint;
|
|
24
|
+
};
|
|
25
|
+
MultiPoint.ZM = function (points, srid) {
|
|
26
|
+
const multiPoint = new MultiPoint(points, srid);
|
|
27
|
+
multiPoint.hasZ = true;
|
|
28
|
+
multiPoint.hasM = true;
|
|
29
|
+
return multiPoint;
|
|
30
|
+
};
|
|
31
|
+
MultiPoint._parseWkt = function (value, options) {
|
|
32
|
+
const multiPoint = new MultiPoint();
|
|
33
|
+
multiPoint.srid = options.srid;
|
|
34
|
+
multiPoint.hasZ = options.hasZ;
|
|
35
|
+
multiPoint.hasM = options.hasM;
|
|
36
|
+
if (value.isMatch(['EMPTY']))
|
|
37
|
+
return multiPoint;
|
|
38
|
+
value.expectGroupStart();
|
|
39
|
+
multiPoint.points.push.apply(multiPoint.points, value.matchCoordinates(options));
|
|
40
|
+
value.expectGroupEnd();
|
|
41
|
+
return multiPoint;
|
|
42
|
+
};
|
|
43
|
+
MultiPoint._parseWkb = function (value, options) {
|
|
44
|
+
const multiPoint = new MultiPoint();
|
|
45
|
+
multiPoint.srid = options.srid;
|
|
46
|
+
multiPoint.hasZ = options.hasZ;
|
|
47
|
+
multiPoint.hasM = options.hasM;
|
|
48
|
+
const pointCount = value.readUInt32();
|
|
49
|
+
for (let i = 0; i < pointCount; i++)
|
|
50
|
+
multiPoint.points.push(Geometry.parse(value, options));
|
|
51
|
+
return multiPoint;
|
|
52
|
+
};
|
|
53
|
+
MultiPoint._parseTwkb = function (value, options) {
|
|
54
|
+
const multiPoint = new MultiPoint();
|
|
55
|
+
multiPoint.hasZ = options.hasZ;
|
|
56
|
+
multiPoint.hasM = options.hasM;
|
|
57
|
+
if (options.isEmpty)
|
|
58
|
+
return multiPoint;
|
|
59
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
|
|
60
|
+
const pointCount = value.readVarInt();
|
|
61
|
+
for (let i = 0; i < pointCount; i++)
|
|
62
|
+
multiPoint.points.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
63
|
+
return multiPoint;
|
|
64
|
+
};
|
|
65
|
+
MultiPoint._parseGeoJSON = function (value) {
|
|
66
|
+
const multiPoint = new MultiPoint();
|
|
67
|
+
if (value.coordinates.length > 0)
|
|
68
|
+
multiPoint.hasZ = value.coordinates[0].length > 2;
|
|
69
|
+
for (let i = 0; i < value.coordinates.length; i++)
|
|
70
|
+
multiPoint.points.push(Point._parseGeoJSON({ coordinates: value.coordinates[i] }));
|
|
71
|
+
return multiPoint;
|
|
72
|
+
};
|
|
73
|
+
MultiPoint.prototype.toWkt = function () {
|
|
74
|
+
if (this.points.length === 0)
|
|
75
|
+
return this._getWktType(Types.wkt.MultiPoint, true);
|
|
76
|
+
let wkt = this._getWktType(Types.wkt.MultiPoint, false) + '(';
|
|
77
|
+
for (let i = 0; i < this.points.length; i++)
|
|
78
|
+
wkt += this._getWktCoordinate(this.points[i]) + ',';
|
|
79
|
+
wkt = wkt.slice(0, -1);
|
|
80
|
+
wkt += ')';
|
|
81
|
+
return wkt;
|
|
82
|
+
};
|
|
83
|
+
MultiPoint.prototype.toWkb = function () {
|
|
84
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
85
|
+
wkb.writeInt8(1);
|
|
86
|
+
this._writeWkbType(wkb, Types.wkb.MultiPoint);
|
|
87
|
+
wkb.writeUInt32LE(this.points.length);
|
|
88
|
+
for (let i = 0; i < this.points.length; i++)
|
|
89
|
+
wkb.writeBuffer(this.points[i].toWkb({ srid: this.srid }));
|
|
90
|
+
return wkb.buffer;
|
|
91
|
+
};
|
|
92
|
+
MultiPoint.prototype.toTwkb = function () {
|
|
93
|
+
const twkb = new BinaryWriter(0, true);
|
|
94
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
95
|
+
const isEmpty = this.points.length === 0;
|
|
96
|
+
this._writeTwkbHeader(twkb, Types.wkb.MultiPoint, precision, isEmpty);
|
|
97
|
+
if (this.points.length > 0) {
|
|
98
|
+
twkb.writeVarInt(this.points.length);
|
|
99
|
+
const previousPoint = new Point(0, 0, 0, 0);
|
|
100
|
+
for (let i = 0; i < this.points.length; i++)
|
|
101
|
+
this.points[i]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
102
|
+
}
|
|
103
|
+
return twkb.buffer;
|
|
104
|
+
};
|
|
105
|
+
MultiPoint.prototype._getWkbSize = function () {
|
|
106
|
+
let coordinateSize = 16;
|
|
107
|
+
if (this.hasZ)
|
|
108
|
+
coordinateSize += 8;
|
|
109
|
+
if (this.hasM)
|
|
110
|
+
coordinateSize += 8;
|
|
111
|
+
coordinateSize += 5;
|
|
112
|
+
return 1 + 4 + 4 + this.points.length * coordinateSize;
|
|
113
|
+
};
|
|
114
|
+
MultiPoint.prototype.toGeoJSON = function (options) {
|
|
115
|
+
const geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
|
|
116
|
+
geoJSON.type = Types.geoJSON.MultiPoint;
|
|
117
|
+
geoJSON.coordinates = [];
|
|
118
|
+
for (let i = 0; i < this.points.length; i++)
|
|
119
|
+
geoJSON.coordinates.push(this.points[i].toGeoJSON().coordinates);
|
|
120
|
+
return geoJSON;
|
|
121
|
+
};
|
|
122
|
+
export default MultiPoint;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function MultiPolygon(polygons: any, srid: any): void;
|
|
2
|
+
declare namespace MultiPolygon {
|
|
3
|
+
var Z: (polygons: any, srid: any) => any;
|
|
4
|
+
var M: (polygons: any, srid: any) => any;
|
|
5
|
+
var ZM: (polygons: any, srid: any) => any;
|
|
6
|
+
var _parseWkt: (value: any, options: any) => any;
|
|
7
|
+
var _parseWkb: (value: any, options: any) => any;
|
|
8
|
+
var _parseTwkb: (value: any, options: any) => any;
|
|
9
|
+
var _parseGeoJSON: (value: any) => any;
|
|
10
|
+
}
|
|
11
|
+
export default MultiPolygon;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import BinaryWriter from './binarywriter.js';
|
|
2
|
+
import Geometry from './geometry.js';
|
|
3
|
+
import Point from './point.js';
|
|
4
|
+
import Polygon from './polygon.js';
|
|
5
|
+
import Types from './types.js';
|
|
6
|
+
function MultiPolygon(polygons, srid) {
|
|
7
|
+
Geometry.call(this);
|
|
8
|
+
this.polygons = polygons || [];
|
|
9
|
+
this.srid = srid;
|
|
10
|
+
if (this.polygons.length > 0) {
|
|
11
|
+
this.hasZ = this.polygons[0].hasZ;
|
|
12
|
+
this.hasM = this.polygons[0].hasM;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// util.inherits(MultiPolygon, Geometry);
|
|
16
|
+
MultiPolygon.Z = function (polygons, srid) {
|
|
17
|
+
const multiPolygon = new MultiPolygon(polygons, srid);
|
|
18
|
+
multiPolygon.hasZ = true;
|
|
19
|
+
return multiPolygon;
|
|
20
|
+
};
|
|
21
|
+
MultiPolygon.M = function (polygons, srid) {
|
|
22
|
+
const multiPolygon = new MultiPolygon(polygons, srid);
|
|
23
|
+
multiPolygon.hasM = true;
|
|
24
|
+
return multiPolygon;
|
|
25
|
+
};
|
|
26
|
+
MultiPolygon.ZM = function (polygons, srid) {
|
|
27
|
+
const multiPolygon = new MultiPolygon(polygons, srid);
|
|
28
|
+
multiPolygon.hasZ = true;
|
|
29
|
+
multiPolygon.hasM = true;
|
|
30
|
+
return multiPolygon;
|
|
31
|
+
};
|
|
32
|
+
MultiPolygon._parseWkt = function (value, options) {
|
|
33
|
+
const multiPolygon = new MultiPolygon();
|
|
34
|
+
multiPolygon.srid = options.srid;
|
|
35
|
+
multiPolygon.hasZ = options.hasZ;
|
|
36
|
+
multiPolygon.hasM = options.hasM;
|
|
37
|
+
if (value.isMatch(['EMPTY']))
|
|
38
|
+
return multiPolygon;
|
|
39
|
+
value.expectGroupStart();
|
|
40
|
+
do {
|
|
41
|
+
value.expectGroupStart();
|
|
42
|
+
const exteriorRing = [];
|
|
43
|
+
const interiorRings = [];
|
|
44
|
+
value.expectGroupStart();
|
|
45
|
+
exteriorRing.push.apply(exteriorRing, value.matchCoordinates(options));
|
|
46
|
+
value.expectGroupEnd();
|
|
47
|
+
while (value.isMatch([','])) {
|
|
48
|
+
value.expectGroupStart();
|
|
49
|
+
interiorRings.push(value.matchCoordinates(options));
|
|
50
|
+
value.expectGroupEnd();
|
|
51
|
+
}
|
|
52
|
+
multiPolygon.polygons.push(new Polygon(exteriorRing, interiorRings));
|
|
53
|
+
value.expectGroupEnd();
|
|
54
|
+
} while (value.isMatch([',']));
|
|
55
|
+
value.expectGroupEnd();
|
|
56
|
+
return multiPolygon;
|
|
57
|
+
};
|
|
58
|
+
MultiPolygon._parseWkb = function (value, options) {
|
|
59
|
+
const multiPolygon = new MultiPolygon();
|
|
60
|
+
multiPolygon.srid = options.srid;
|
|
61
|
+
multiPolygon.hasZ = options.hasZ;
|
|
62
|
+
multiPolygon.hasM = options.hasM;
|
|
63
|
+
const polygonCount = value.readUInt32();
|
|
64
|
+
for (let i = 0; i < polygonCount; i++)
|
|
65
|
+
multiPolygon.polygons.push(Geometry.parse(value, options));
|
|
66
|
+
return multiPolygon;
|
|
67
|
+
};
|
|
68
|
+
MultiPolygon._parseTwkb = function (value, options) {
|
|
69
|
+
const multiPolygon = new MultiPolygon();
|
|
70
|
+
multiPolygon.hasZ = options.hasZ;
|
|
71
|
+
multiPolygon.hasM = options.hasM;
|
|
72
|
+
if (options.isEmpty)
|
|
73
|
+
return multiPolygon;
|
|
74
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
|
|
75
|
+
const polygonCount = value.readVarInt();
|
|
76
|
+
for (let i = 0; i < polygonCount; i++) {
|
|
77
|
+
const polygon = new Polygon();
|
|
78
|
+
polygon.hasZ = options.hasZ;
|
|
79
|
+
polygon.hasM = options.hasM;
|
|
80
|
+
const ringCount = value.readVarInt();
|
|
81
|
+
const exteriorRingCount = value.readVarInt();
|
|
82
|
+
for (var j = 0; j < exteriorRingCount; j++)
|
|
83
|
+
polygon.exteriorRing.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
84
|
+
for (j = 1; j < ringCount; j++) {
|
|
85
|
+
const interiorRing = [];
|
|
86
|
+
const interiorRingCount = value.readVarInt();
|
|
87
|
+
for (let k = 0; k < interiorRingCount; k++)
|
|
88
|
+
interiorRing.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
89
|
+
polygon.interiorRings.push(interiorRing);
|
|
90
|
+
}
|
|
91
|
+
multiPolygon.polygons.push(polygon);
|
|
92
|
+
}
|
|
93
|
+
return multiPolygon;
|
|
94
|
+
};
|
|
95
|
+
MultiPolygon._parseGeoJSON = function (value) {
|
|
96
|
+
const multiPolygon = new MultiPolygon();
|
|
97
|
+
if (value.coordinates.length > 0 && value.coordinates[0].length > 0 && value.coordinates[0][0].length > 0)
|
|
98
|
+
multiPolygon.hasZ = value.coordinates[0][0][0].length > 2;
|
|
99
|
+
for (let i = 0; i < value.coordinates.length; i++)
|
|
100
|
+
multiPolygon.polygons.push(Polygon._parseGeoJSON({ coordinates: value.coordinates[i] }));
|
|
101
|
+
return multiPolygon;
|
|
102
|
+
};
|
|
103
|
+
MultiPolygon.prototype.toWkt = function () {
|
|
104
|
+
if (this.polygons.length === 0)
|
|
105
|
+
return this._getWktType(Types.wkt.MultiPolygon, true);
|
|
106
|
+
let wkt = this._getWktType(Types.wkt.MultiPolygon, false) + '(';
|
|
107
|
+
for (let i = 0; i < this.polygons.length; i++)
|
|
108
|
+
wkt += this.polygons[i]._toInnerWkt() + ',';
|
|
109
|
+
wkt = wkt.slice(0, -1);
|
|
110
|
+
wkt += ')';
|
|
111
|
+
return wkt;
|
|
112
|
+
};
|
|
113
|
+
MultiPolygon.prototype.toWkb = function () {
|
|
114
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
115
|
+
wkb.writeInt8(1);
|
|
116
|
+
this._writeWkbType(wkb, Types.wkb.MultiPolygon);
|
|
117
|
+
wkb.writeUInt32LE(this.polygons.length);
|
|
118
|
+
for (let i = 0; i < this.polygons.length; i++)
|
|
119
|
+
wkb.writeBuffer(this.polygons[i].toWkb({ srid: this.srid }));
|
|
120
|
+
return wkb.buffer;
|
|
121
|
+
};
|
|
122
|
+
MultiPolygon.prototype.toTwkb = function () {
|
|
123
|
+
const twkb = new BinaryWriter(0, true);
|
|
124
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
125
|
+
const isEmpty = this.polygons.length === 0;
|
|
126
|
+
this._writeTwkbHeader(twkb, Types.wkb.MultiPolygon, precision, isEmpty);
|
|
127
|
+
if (this.polygons.length > 0) {
|
|
128
|
+
twkb.writeVarInt(this.polygons.length);
|
|
129
|
+
const previousPoint = new Point(0, 0, 0, 0);
|
|
130
|
+
for (let i = 0; i < this.polygons.length; i++) {
|
|
131
|
+
twkb.writeVarInt(1 + this.polygons[i].interiorRings.length);
|
|
132
|
+
twkb.writeVarInt(this.polygons[i].exteriorRing.length);
|
|
133
|
+
for (var j = 0; j < this.polygons[i].exteriorRing.length; j++)
|
|
134
|
+
this.polygons[i].exteriorRing[j]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
135
|
+
for (j = 0; j < this.polygons[i].interiorRings.length; j++) {
|
|
136
|
+
twkb.writeVarInt(this.polygons[i].interiorRings[j].length);
|
|
137
|
+
for (let k = 0; k < this.polygons[i].interiorRings[j].length; k++)
|
|
138
|
+
this.polygons[i].interiorRings[j][k]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return twkb.buffer;
|
|
143
|
+
};
|
|
144
|
+
MultiPolygon.prototype._getWkbSize = function () {
|
|
145
|
+
let size = 1 + 4 + 4;
|
|
146
|
+
for (let i = 0; i < this.polygons.length; i++)
|
|
147
|
+
size += this.polygons[i]._getWkbSize();
|
|
148
|
+
return size;
|
|
149
|
+
};
|
|
150
|
+
MultiPolygon.prototype.toGeoJSON = function (options) {
|
|
151
|
+
const geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
|
|
152
|
+
geoJSON.type = Types.geoJSON.MultiPolygon;
|
|
153
|
+
geoJSON.coordinates = [];
|
|
154
|
+
for (let i = 0; i < this.polygons.length; i++)
|
|
155
|
+
geoJSON.coordinates.push(this.polygons[i].toGeoJSON().coordinates);
|
|
156
|
+
return geoJSON;
|
|
157
|
+
};
|
|
158
|
+
export default MultiPolygon;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare function Point(x: any, y: any, z: any, m: any, srid: any): void;
|
|
2
|
+
declare namespace Point {
|
|
3
|
+
var Z: (x: any, y: any, z: any, srid: any) => any;
|
|
4
|
+
var M: (x: any, y: any, m: any, srid: any) => any;
|
|
5
|
+
var ZM: (x: any, y: any, z: any, m: any, srid: any) => any;
|
|
6
|
+
var _parseWkt: (value: any, options: any) => any;
|
|
7
|
+
var _parseWkb: (value: any, options: any) => any;
|
|
8
|
+
var _readWkbPoint: (value: any, options: any) => any;
|
|
9
|
+
var _parseTwkb: (value: any, options: any) => any;
|
|
10
|
+
var _readTwkbPoint: (value: any, options: any, previousPoint: any) => any;
|
|
11
|
+
var _parseGeoJSON: (value: any) => any;
|
|
12
|
+
var _readGeoJSONPoint: (coordinates: any) => any;
|
|
13
|
+
}
|
|
14
|
+
export default Point;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import BinaryWriter from './binarywriter.js';
|
|
4
|
+
import Geometry from './geometry.js';
|
|
5
|
+
import Types from './types.js';
|
|
6
|
+
import ZigZag from './zigzag.js';
|
|
7
|
+
function Point(x, y, z, m, srid) {
|
|
8
|
+
Geometry.call(this);
|
|
9
|
+
this.x = x;
|
|
10
|
+
this.y = y;
|
|
11
|
+
this.z = z;
|
|
12
|
+
this.m = m;
|
|
13
|
+
this.srid = srid;
|
|
14
|
+
this.hasZ = this.z !== undefined;
|
|
15
|
+
this.hasM = this.m !== undefined;
|
|
16
|
+
}
|
|
17
|
+
// util.inherits(Point, Geometry);
|
|
18
|
+
Point.Z = function (x, y, z, srid) {
|
|
19
|
+
const point = new Point(x, y, z, undefined, srid);
|
|
20
|
+
point.hasZ = true;
|
|
21
|
+
return point;
|
|
22
|
+
};
|
|
23
|
+
Point.M = function (x, y, m, srid) {
|
|
24
|
+
const point = new Point(x, y, undefined, m, srid);
|
|
25
|
+
point.hasM = true;
|
|
26
|
+
return point;
|
|
27
|
+
};
|
|
28
|
+
Point.ZM = function (x, y, z, m, srid) {
|
|
29
|
+
const point = new Point(x, y, z, m, srid);
|
|
30
|
+
point.hasZ = true;
|
|
31
|
+
point.hasM = true;
|
|
32
|
+
return point;
|
|
33
|
+
};
|
|
34
|
+
Point._parseWkt = function (value, options) {
|
|
35
|
+
const point = new Point();
|
|
36
|
+
point.srid = options.srid;
|
|
37
|
+
point.hasZ = options.hasZ;
|
|
38
|
+
point.hasM = options.hasM;
|
|
39
|
+
if (value.isMatch(['EMPTY']))
|
|
40
|
+
return point;
|
|
41
|
+
value.expectGroupStart();
|
|
42
|
+
const coordinate = value.matchCoordinate(options);
|
|
43
|
+
point.x = coordinate.x;
|
|
44
|
+
point.y = coordinate.y;
|
|
45
|
+
point.z = coordinate.z;
|
|
46
|
+
point.m = coordinate.m;
|
|
47
|
+
value.expectGroupEnd();
|
|
48
|
+
return point;
|
|
49
|
+
};
|
|
50
|
+
Point._parseWkb = function (value, options) {
|
|
51
|
+
const point = Point._readWkbPoint(value, options);
|
|
52
|
+
point.srid = options.srid;
|
|
53
|
+
return point;
|
|
54
|
+
};
|
|
55
|
+
Point._readWkbPoint = function (value, options) {
|
|
56
|
+
return new Point(value.readDouble(), value.readDouble(), options.hasZ ? value.readDouble() : undefined, options.hasM ? value.readDouble() : undefined);
|
|
57
|
+
};
|
|
58
|
+
Point._parseTwkb = function (value, options) {
|
|
59
|
+
const point = new Point();
|
|
60
|
+
point.hasZ = options.hasZ;
|
|
61
|
+
point.hasM = options.hasM;
|
|
62
|
+
if (options.isEmpty)
|
|
63
|
+
return point;
|
|
64
|
+
point.x = ZigZag.decode(value.readVarInt()) / options.precisionFactor;
|
|
65
|
+
point.y = ZigZag.decode(value.readVarInt()) / options.precisionFactor;
|
|
66
|
+
point.z = options.hasZ ? ZigZag.decode(value.readVarInt()) / options.zPrecisionFactor : undefined;
|
|
67
|
+
point.m = options.hasM ? ZigZag.decode(value.readVarInt()) / options.mPrecisionFactor : undefined;
|
|
68
|
+
return point;
|
|
69
|
+
};
|
|
70
|
+
Point._readTwkbPoint = function (value, options, previousPoint) {
|
|
71
|
+
previousPoint.x += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
|
|
72
|
+
previousPoint.y += ZigZag.decode(value.readVarInt()) / options.precisionFactor;
|
|
73
|
+
if (options.hasZ)
|
|
74
|
+
previousPoint.z += ZigZag.decode(value.readVarInt()) / options.zPrecisionFactor;
|
|
75
|
+
if (options.hasM)
|
|
76
|
+
previousPoint.m += ZigZag.decode(value.readVarInt()) / options.mPrecisionFactor;
|
|
77
|
+
return new Point(previousPoint.x, previousPoint.y, previousPoint.z, previousPoint.m);
|
|
78
|
+
};
|
|
79
|
+
Point._parseGeoJSON = function (value) {
|
|
80
|
+
return Point._readGeoJSONPoint(value.coordinates);
|
|
81
|
+
};
|
|
82
|
+
Point._readGeoJSONPoint = function (coordinates) {
|
|
83
|
+
if (coordinates.length === 0)
|
|
84
|
+
return new Point();
|
|
85
|
+
if (coordinates.length > 2)
|
|
86
|
+
return new Point(coordinates[0], coordinates[1], coordinates[2]);
|
|
87
|
+
return new Point(coordinates[0], coordinates[1]);
|
|
88
|
+
};
|
|
89
|
+
Point.prototype.toWkt = function () {
|
|
90
|
+
if (this.x === undefined && this.y === undefined && this.z === undefined && this.m === undefined)
|
|
91
|
+
return this._getWktType(Types.wkt.Point, true);
|
|
92
|
+
return this._getWktType(Types.wkt.Point, false) + '(' + this._getWktCoordinate(this) + ')';
|
|
93
|
+
};
|
|
94
|
+
Point.prototype.toWkb = function (parentOptions) {
|
|
95
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
96
|
+
wkb.writeInt8(1);
|
|
97
|
+
this._writeWkbType(wkb, Types.wkb.Point, parentOptions);
|
|
98
|
+
if (this.x === undefined && this.y === undefined) {
|
|
99
|
+
wkb.writeDoubleLE(Number.NaN);
|
|
100
|
+
wkb.writeDoubleLE(Number.NaN);
|
|
101
|
+
if (this.hasZ)
|
|
102
|
+
wkb.writeDoubleLE(Number.NaN);
|
|
103
|
+
if (this.hasM)
|
|
104
|
+
wkb.writeDoubleLE(Number.NaN);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this._writeWkbPoint(wkb);
|
|
108
|
+
}
|
|
109
|
+
return wkb.buffer;
|
|
110
|
+
};
|
|
111
|
+
Point.prototype._writeWkbPoint = function (wkb) {
|
|
112
|
+
wkb.writeDoubleLE(this.x);
|
|
113
|
+
wkb.writeDoubleLE(this.y);
|
|
114
|
+
if (this.hasZ)
|
|
115
|
+
wkb.writeDoubleLE(this.z);
|
|
116
|
+
if (this.hasM)
|
|
117
|
+
wkb.writeDoubleLE(this.m);
|
|
118
|
+
};
|
|
119
|
+
Point.prototype.toTwkb = function () {
|
|
120
|
+
const twkb = new BinaryWriter(0, true);
|
|
121
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
122
|
+
const isEmpty = this.x === undefined && this.y === undefined;
|
|
123
|
+
this._writeTwkbHeader(twkb, Types.wkb.Point, precision, isEmpty);
|
|
124
|
+
if (!isEmpty)
|
|
125
|
+
this._writeTwkbPoint(twkb, precision, new Point(0, 0, 0, 0));
|
|
126
|
+
return twkb.buffer;
|
|
127
|
+
};
|
|
128
|
+
Point.prototype._writeTwkbPoint = function (twkb, precision, previousPoint) {
|
|
129
|
+
const x = this.x * precision.xyFactor;
|
|
130
|
+
const y = this.y * precision.xyFactor;
|
|
131
|
+
const z = this.z * precision.zFactor;
|
|
132
|
+
const m = this.m * precision.mFactor;
|
|
133
|
+
twkb.writeVarInt(ZigZag.encode(x - previousPoint.x));
|
|
134
|
+
twkb.writeVarInt(ZigZag.encode(y - previousPoint.y));
|
|
135
|
+
if (this.hasZ)
|
|
136
|
+
twkb.writeVarInt(ZigZag.encode(z - previousPoint.z));
|
|
137
|
+
if (this.hasM)
|
|
138
|
+
twkb.writeVarInt(ZigZag.encode(m - previousPoint.m));
|
|
139
|
+
previousPoint.x = x;
|
|
140
|
+
previousPoint.y = y;
|
|
141
|
+
previousPoint.z = z;
|
|
142
|
+
previousPoint.m = m;
|
|
143
|
+
};
|
|
144
|
+
Point.prototype._getWkbSize = function () {
|
|
145
|
+
let size = 1 + 4 + 8 + 8;
|
|
146
|
+
if (this.hasZ)
|
|
147
|
+
size += 8;
|
|
148
|
+
if (this.hasM)
|
|
149
|
+
size += 8;
|
|
150
|
+
return size;
|
|
151
|
+
};
|
|
152
|
+
Point.prototype.toGeoJSON = function (options) {
|
|
153
|
+
const geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
|
|
154
|
+
geoJSON.type = Types.geoJSON.Point;
|
|
155
|
+
if (this.x === undefined && this.y === undefined)
|
|
156
|
+
geoJSON.coordinates = [];
|
|
157
|
+
else if (this.z === undefined) {
|
|
158
|
+
geoJSON.coordinates = [this.x, this.y];
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
geoJSON.coordinates = [this.x, this.y, this.z];
|
|
162
|
+
}
|
|
163
|
+
return geoJSON;
|
|
164
|
+
};
|
|
165
|
+
export default Point;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function Polygon(this: any, exteriorRing: any, interiorRings: any, srid: any): void;
|
|
2
|
+
declare namespace Polygon {
|
|
3
|
+
var Z: (exteriorRing: any, interiorRings: any, srid: any) => any;
|
|
4
|
+
var M: (exteriorRing: any, interiorRings: any, srid: any) => any;
|
|
5
|
+
var ZM: (exteriorRing: any, interiorRings: any, srid: any) => any;
|
|
6
|
+
var _parseWkt: (value: any, options: any) => any;
|
|
7
|
+
var _parseWkb: (value: any, options: any) => any;
|
|
8
|
+
var _parseTwkb: (value: any, options: any) => any;
|
|
9
|
+
var _parseGeoJSON: (value: any) => any;
|
|
10
|
+
}
|
|
11
|
+
export default Polygon;
|