durcno 1.0.0-alpha.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/LICENSE +201 -0
- package/README.md +56 -0
- package/dist/bin.cjs +13522 -0
- package/dist/src/_virtual/_rolldown/runtime.mjs +28 -0
- package/dist/src/cli/helpers.mjs +16 -0
- package/dist/src/columns/bigint.d.mts +19 -0
- package/dist/src/columns/bigint.mjs +32 -0
- package/dist/src/columns/bigserial.d.mts +24 -0
- package/dist/src/columns/bigserial.mjs +35 -0
- package/dist/src/columns/boolean.d.mts +19 -0
- package/dist/src/columns/boolean.mjs +31 -0
- package/dist/src/columns/bytea.d.mts +19 -0
- package/dist/src/columns/bytea.mjs +33 -0
- package/dist/src/columns/char.d.mts +32 -0
- package/dist/src/columns/char.mjs +44 -0
- package/dist/src/columns/cidr.d.mts +19 -0
- package/dist/src/columns/cidr.mjs +31 -0
- package/dist/src/columns/common.d.mts +233 -0
- package/dist/src/columns/common.mjs +276 -0
- package/dist/src/columns/date.d.mts +19 -0
- package/dist/src/columns/date.mjs +32 -0
- package/dist/src/columns/enum.d.mts +21 -0
- package/dist/src/columns/enum.mjs +35 -0
- package/dist/src/columns/inet.d.mts +19 -0
- package/dist/src/columns/inet.mjs +36 -0
- package/dist/src/columns/integer.d.mts +19 -0
- package/dist/src/columns/integer.mjs +32 -0
- package/dist/src/columns/json.d.mts +52 -0
- package/dist/src/columns/json.mjs +67 -0
- package/dist/src/columns/jsonb.d.mts +53 -0
- package/dist/src/columns/jsonb.mjs +68 -0
- package/dist/src/columns/macaddr.d.mts +19 -0
- package/dist/src/columns/macaddr.mjs +31 -0
- package/dist/src/columns/numeric.d.mts +42 -0
- package/dist/src/columns/numeric.mjs +57 -0
- package/dist/src/columns/postgis/geography/index.d.mts +18 -0
- package/dist/src/columns/postgis/geography/index.mjs +17 -0
- package/dist/src/columns/postgis/geography/linestring.d.mts +38 -0
- package/dist/src/columns/postgis/geography/linestring.mjs +70 -0
- package/dist/src/columns/postgis/geography/multilinestring.d.mts +39 -0
- package/dist/src/columns/postgis/geography/multilinestring.mjs +70 -0
- package/dist/src/columns/postgis/geography/multipoint.d.mts +38 -0
- package/dist/src/columns/postgis/geography/multipoint.mjs +70 -0
- package/dist/src/columns/postgis/geography/multipolygon.d.mts +40 -0
- package/dist/src/columns/postgis/geography/multipolygon.mjs +70 -0
- package/dist/src/columns/postgis/geography/point.d.mts +36 -0
- package/dist/src/columns/postgis/geography/point.mjs +69 -0
- package/dist/src/columns/postgis/geography/polygon.d.mts +39 -0
- package/dist/src/columns/postgis/geography/polygon.mjs +70 -0
- package/dist/src/columns/serial.d.mts +24 -0
- package/dist/src/columns/serial.mjs +35 -0
- package/dist/src/columns/smallint.d.mts +19 -0
- package/dist/src/columns/smallint.mjs +32 -0
- package/dist/src/columns/smallserial.d.mts +24 -0
- package/dist/src/columns/smallserial.mjs +35 -0
- package/dist/src/columns/text.d.mts +19 -0
- package/dist/src/columns/text.mjs +30 -0
- package/dist/src/columns/time.d.mts +44 -0
- package/dist/src/columns/time.mjs +47 -0
- package/dist/src/columns/timestamp.d.mts +44 -0
- package/dist/src/columns/timestamp.mjs +47 -0
- package/dist/src/columns/uuid.d.mts +33 -0
- package/dist/src/columns/uuid.mjs +44 -0
- package/dist/src/columns/varchar.d.mts +32 -0
- package/dist/src/columns/varchar.mjs +44 -0
- package/dist/src/connectors/bun.d.mts +18 -0
- package/dist/src/connectors/bun.mjs +97 -0
- package/dist/src/connectors/common.d.mts +148 -0
- package/dist/src/connectors/common.mjs +65 -0
- package/dist/src/connectors/pg.d.mts +18 -0
- package/dist/src/connectors/pg.mjs +103 -0
- package/dist/src/connectors/pglite.d.mts +19 -0
- package/dist/src/connectors/pglite.mjs +94 -0
- package/dist/src/connectors/postgres.d.mts +18 -0
- package/dist/src/connectors/postgres.mjs +93 -0
- package/dist/src/constraints/check.d.mts +88 -0
- package/dist/src/constraints/check.mjs +307 -0
- package/dist/src/constraints/primary-key.d.mts +28 -0
- package/dist/src/constraints/primary-key.mjs +36 -0
- package/dist/src/constraints/unique.d.mts +28 -0
- package/dist/src/constraints/unique.mjs +36 -0
- package/dist/src/db.d.mts +180 -0
- package/dist/src/db.mjs +191 -0
- package/dist/src/entity.mjs +23 -0
- package/dist/src/enumtype.d.mts +27 -0
- package/dist/src/enumtype.mjs +42 -0
- package/dist/src/filters/array.d.mts +97 -0
- package/dist/src/filters/array.mjs +150 -0
- package/dist/src/filters/custom.d.mts +12 -0
- package/dist/src/filters/custom.mjs +7 -0
- package/dist/src/filters/index.d.mts +155 -0
- package/dist/src/filters/index.mjs +318 -0
- package/dist/src/functions/index.d.mts +24 -0
- package/dist/src/functions/index.mjs +29 -0
- package/dist/src/index.d.mts +129 -0
- package/dist/src/index.mjs +78 -0
- package/dist/src/indexes.d.mts +31 -0
- package/dist/src/indexes.mjs +43 -0
- package/dist/src/migration/consts.d.mts +8 -0
- package/dist/src/migration/consts.mjs +8 -0
- package/dist/src/migration/ddl.d.mts +747 -0
- package/dist/src/migration/ddl.mjs +1084 -0
- package/dist/src/migration/index.d.mts +15 -0
- package/dist/src/migration/index.mjs +5 -0
- package/dist/src/migration/snapshot.d.mts +169 -0
- package/dist/src/migration/snapshot.mjs +123 -0
- package/dist/src/migration/statement.d.mts +89 -0
- package/dist/src/migration/statement.mjs +61 -0
- package/dist/src/models.d.mts +34 -0
- package/dist/src/models.mjs +27 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.mjs +126 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.mjs +29 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.mjs +165 -0
- package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.mjs +92 -0
- package/dist/src/query-builders/aggregates.d.mts +20 -0
- package/dist/src/query-builders/aggregates.mjs +43 -0
- package/dist/src/query-builders/count.d.mts +19 -0
- package/dist/src/query-builders/count.mjs +36 -0
- package/dist/src/query-builders/delete.d.mts +19 -0
- package/dist/src/query-builders/delete.mjs +57 -0
- package/dist/src/query-builders/distinct.d.mts +19 -0
- package/dist/src/query-builders/distinct.mjs +42 -0
- package/dist/src/query-builders/exists.d.mts +19 -0
- package/dist/src/query-builders/exists.mjs +37 -0
- package/dist/src/query-builders/first.d.mts +17 -0
- package/dist/src/query-builders/first.mjs +46 -0
- package/dist/src/query-builders/insert-returning.d.mts +16 -0
- package/dist/src/query-builders/insert-returning.mjs +63 -0
- package/dist/src/query-builders/insert.d.mts +22 -0
- package/dist/src/query-builders/insert.mjs +93 -0
- package/dist/src/query-builders/orderby-clause.d.mts +14 -0
- package/dist/src/query-builders/orderby-clause.mjs +20 -0
- package/dist/src/query-builders/pre.d.mts +36 -0
- package/dist/src/query-builders/pre.mjs +60 -0
- package/dist/src/query-builders/query-promise.d.mts +14 -0
- package/dist/src/query-builders/query-promise.mjs +21 -0
- package/dist/src/query-builders/query.d.mts +14 -0
- package/dist/src/query-builders/query.mjs +17 -0
- package/dist/src/query-builders/raw.d.mts +14 -0
- package/dist/src/query-builders/raw.mjs +26 -0
- package/dist/src/query-builders/rq.d.mts +36 -0
- package/dist/src/query-builders/rq.mjs +231 -0
- package/dist/src/query-builders/select.d.mts +48 -0
- package/dist/src/query-builders/select.mjs +118 -0
- package/dist/src/query-builders/update.d.mts +24 -0
- package/dist/src/query-builders/update.mjs +99 -0
- package/dist/src/sequence.d.mts +48 -0
- package/dist/src/sequence.mjs +53 -0
- package/dist/src/sql.d.mts +15 -0
- package/dist/src/sql.mjs +36 -0
- package/dist/src/symbols.d.mts +4 -0
- package/dist/src/symbols.mjs +4 -0
- package/dist/src/table.d.mts +144 -0
- package/dist/src/table.mjs +134 -0
- package/dist/src/types.d.mts +4 -0
- package/dist/src/utils.mjs +10 -0
- package/dist/src/validators/zod.d.mts +23 -0
- package/dist/src/validators/zod.mjs +27 -0
- package/dist/src/wkx/binaryreader.mjs +56 -0
- package/dist/src/wkx/binarywriter.mjs +110 -0
- package/dist/src/wkx/geometry.mjs +101 -0
- package/dist/src/wkx/geometrycollection.mjs +113 -0
- package/dist/src/wkx/index.mjs +18 -0
- package/dist/src/wkx/linestring.mjs +124 -0
- package/dist/src/wkx/multilinestring.mjs +133 -0
- package/dist/src/wkx/multipoint.mjs +120 -0
- package/dist/src/wkx/multipolygon.mjs +155 -0
- package/dist/src/wkx/parser.mjs +183 -0
- package/dist/src/wkx/point.mjs +159 -0
- package/dist/src/wkx/polygon.mjs +189 -0
- package/dist/src/wkx/types.mjs +37 -0
- package/dist/src/wkx/wktparser.mjs +109 -0
- package/dist/src/wkx/zigzag.mjs +18 -0
- package/package.json +100 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
|
|
2
|
+
import { Geometry, init_geometry } from "./geometry.mjs";
|
|
3
|
+
import { Types, init_types } from "./types.mjs";
|
|
4
|
+
//#region src/wkx/geometrycollection.ts
|
|
5
|
+
init_geometry();
|
|
6
|
+
init_types();
|
|
7
|
+
init_binarywriter();
|
|
8
|
+
var GeometryCollection = class GeometryCollection extends Geometry {
|
|
9
|
+
geometries;
|
|
10
|
+
constructor(geometries, srid) {
|
|
11
|
+
super();
|
|
12
|
+
this.geometries = geometries || [];
|
|
13
|
+
this.srid = srid;
|
|
14
|
+
if (this.geometries.length > 0) {
|
|
15
|
+
this.hasZ = this.geometries[0].hasZ;
|
|
16
|
+
this.hasM = this.geometries[0].hasM;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static Z(geometries, srid) {
|
|
20
|
+
const geometryCollection = new GeometryCollection(geometries, srid);
|
|
21
|
+
geometryCollection.hasZ = true;
|
|
22
|
+
return geometryCollection;
|
|
23
|
+
}
|
|
24
|
+
static M(geometries, srid) {
|
|
25
|
+
const geometryCollection = new GeometryCollection(geometries, srid);
|
|
26
|
+
geometryCollection.hasM = true;
|
|
27
|
+
return geometryCollection;
|
|
28
|
+
}
|
|
29
|
+
static ZM(geometries, srid) {
|
|
30
|
+
const geometryCollection = new GeometryCollection(geometries, srid);
|
|
31
|
+
geometryCollection.hasZ = true;
|
|
32
|
+
geometryCollection.hasM = true;
|
|
33
|
+
return geometryCollection;
|
|
34
|
+
}
|
|
35
|
+
static _parseWkt(value, options) {
|
|
36
|
+
const geometryCollection = new GeometryCollection();
|
|
37
|
+
geometryCollection.srid = options.srid;
|
|
38
|
+
geometryCollection.hasZ = options.hasZ;
|
|
39
|
+
geometryCollection.hasM = options.hasM;
|
|
40
|
+
if (value.isMatch(["EMPTY"])) return geometryCollection;
|
|
41
|
+
value.expectGroupStart();
|
|
42
|
+
do
|
|
43
|
+
geometryCollection.geometries.push(Geometry.parse(value));
|
|
44
|
+
while (value.isMatch([","]));
|
|
45
|
+
value.expectGroupEnd();
|
|
46
|
+
return geometryCollection;
|
|
47
|
+
}
|
|
48
|
+
static _parseWkb(value, options) {
|
|
49
|
+
const geometryCollection = new GeometryCollection();
|
|
50
|
+
geometryCollection.srid = options.srid;
|
|
51
|
+
geometryCollection.hasZ = options.hasZ || false;
|
|
52
|
+
geometryCollection.hasM = options.hasM || false;
|
|
53
|
+
const geometryCount = value.readUInt32();
|
|
54
|
+
for (let i = 0; i < geometryCount; i++) geometryCollection.geometries.push(Geometry.parse(value, options));
|
|
55
|
+
return geometryCollection;
|
|
56
|
+
}
|
|
57
|
+
static _parseTwkb(value, options) {
|
|
58
|
+
const geometryCollection = new GeometryCollection();
|
|
59
|
+
geometryCollection.hasZ = options.hasZ || false;
|
|
60
|
+
geometryCollection.hasM = options.hasM || false;
|
|
61
|
+
if (options.isEmpty) return geometryCollection;
|
|
62
|
+
const geometryCount = value.readVarInt();
|
|
63
|
+
for (let i = 0; i < geometryCount; i++) geometryCollection.geometries.push(Geometry.parseTwkb(value));
|
|
64
|
+
return geometryCollection;
|
|
65
|
+
}
|
|
66
|
+
static _parseGeoJSON(value) {
|
|
67
|
+
const geometryCollection = new GeometryCollection();
|
|
68
|
+
for (let i = 0; i < value.geometries.length; i++) geometryCollection.geometries.push(Geometry._parseGeoJSON(value.geometries[i], true));
|
|
69
|
+
if (geometryCollection.geometries.length > 0) geometryCollection.hasZ = geometryCollection.geometries[0].hasZ;
|
|
70
|
+
return geometryCollection;
|
|
71
|
+
}
|
|
72
|
+
toWkt() {
|
|
73
|
+
if (this.geometries.length === 0) return this._getWktType(Types.wkt.GeometryCollection, true);
|
|
74
|
+
let wkt = this._getWktType(Types.wkt.GeometryCollection, false) + "(";
|
|
75
|
+
for (let i = 0; i < this.geometries.length; i++) wkt += this.geometries[i].toWkt() + ",";
|
|
76
|
+
wkt = wkt.slice(0, -1);
|
|
77
|
+
wkt += ")";
|
|
78
|
+
return wkt;
|
|
79
|
+
}
|
|
80
|
+
toWkb() {
|
|
81
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
82
|
+
wkb.writeInt8(1);
|
|
83
|
+
this._writeWkbType(wkb, Types.wkb.GeometryCollection);
|
|
84
|
+
wkb.writeUInt32LE(this.geometries.length);
|
|
85
|
+
for (let i = 0; i < this.geometries.length; i++) wkb.writeBuffer(this.geometries[i].toWkb({ srid: this.srid }));
|
|
86
|
+
return wkb.buffer;
|
|
87
|
+
}
|
|
88
|
+
toTwkb() {
|
|
89
|
+
const twkb = new BinaryWriter(0, true);
|
|
90
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
91
|
+
const isEmpty = this.geometries.length === 0;
|
|
92
|
+
this._writeTwkbHeader(twkb, Types.wkb.GeometryCollection, precision, isEmpty);
|
|
93
|
+
if (this.geometries.length > 0) {
|
|
94
|
+
twkb.writeVarInt(this.geometries.length);
|
|
95
|
+
for (let i = 0; i < this.geometries.length; i++) twkb.writeBuffer(this.geometries[i].toTwkb());
|
|
96
|
+
}
|
|
97
|
+
return twkb.buffer;
|
|
98
|
+
}
|
|
99
|
+
_getWkbSize() {
|
|
100
|
+
let size = 9;
|
|
101
|
+
for (let i = 0; i < this.geometries.length; i++) size += this.geometries[i]._getWkbSize();
|
|
102
|
+
return size;
|
|
103
|
+
}
|
|
104
|
+
toGeoJSON(options) {
|
|
105
|
+
const geoJSON = super.toGeoJSON(options);
|
|
106
|
+
geoJSON.type = Types.geoJSON.GeometryCollection;
|
|
107
|
+
geoJSON.geometries = [];
|
|
108
|
+
for (let i = 0; i < this.geometries.length; i++) geoJSON.geometries.push(this.geometries[i].toGeoJSON());
|
|
109
|
+
return geoJSON;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { GeometryCollection };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "./binaryreader.mjs";
|
|
2
|
+
import "./binarywriter.mjs";
|
|
3
|
+
import "./zigzag.mjs";
|
|
4
|
+
import "./geometry.mjs";
|
|
5
|
+
import "./types.mjs";
|
|
6
|
+
import "./geometrycollection.mjs";
|
|
7
|
+
import { init_point } from "./point.mjs";
|
|
8
|
+
import "./linestring.mjs";
|
|
9
|
+
import "./multilinestring.mjs";
|
|
10
|
+
import "./multipoint.mjs";
|
|
11
|
+
import "./polygon.mjs";
|
|
12
|
+
import "./multipolygon.mjs";
|
|
13
|
+
import "./wktparser.mjs";
|
|
14
|
+
import "./parser.mjs";
|
|
15
|
+
//#region src/wkx/index.ts
|
|
16
|
+
init_point();
|
|
17
|
+
//#endregion
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
|
|
2
|
+
import { Geometry, init_geometry } from "./geometry.mjs";
|
|
3
|
+
import { Types, init_types } from "./types.mjs";
|
|
4
|
+
import { Point, init_point } from "./point.mjs";
|
|
5
|
+
//#region src/wkx/linestring.ts
|
|
6
|
+
init_binarywriter();
|
|
7
|
+
init_geometry();
|
|
8
|
+
init_point();
|
|
9
|
+
init_types();
|
|
10
|
+
var LineString = class LineString extends Geometry {
|
|
11
|
+
points;
|
|
12
|
+
constructor(points, srid) {
|
|
13
|
+
super();
|
|
14
|
+
this.points = points || [];
|
|
15
|
+
this.srid = srid;
|
|
16
|
+
if (this.points.length > 0) {
|
|
17
|
+
this.hasZ = this.points[0].hasZ;
|
|
18
|
+
this.hasM = this.points[0].hasM;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
static Z(points, srid) {
|
|
22
|
+
const lineString = new LineString(points, srid);
|
|
23
|
+
lineString.hasZ = true;
|
|
24
|
+
return lineString;
|
|
25
|
+
}
|
|
26
|
+
static M(points, srid) {
|
|
27
|
+
const lineString = new LineString(points, srid);
|
|
28
|
+
lineString.hasM = true;
|
|
29
|
+
return lineString;
|
|
30
|
+
}
|
|
31
|
+
static ZM(points, srid) {
|
|
32
|
+
const lineString = new LineString(points, srid);
|
|
33
|
+
lineString.hasZ = true;
|
|
34
|
+
lineString.hasM = true;
|
|
35
|
+
return lineString;
|
|
36
|
+
}
|
|
37
|
+
static _parseWkt(value, options) {
|
|
38
|
+
const lineString = new LineString();
|
|
39
|
+
lineString.srid = options.srid;
|
|
40
|
+
lineString.hasZ = options.hasZ;
|
|
41
|
+
lineString.hasM = options.hasM;
|
|
42
|
+
if (value.isMatch(["EMPTY"])) return lineString;
|
|
43
|
+
value.expectGroupStart();
|
|
44
|
+
lineString.points = lineString.points.concat(value.matchCoordinates(options));
|
|
45
|
+
value.expectGroupEnd();
|
|
46
|
+
return lineString;
|
|
47
|
+
}
|
|
48
|
+
static _parseWkb(value, options) {
|
|
49
|
+
const lineString = new LineString();
|
|
50
|
+
lineString.srid = options.srid;
|
|
51
|
+
lineString.hasZ = options.hasZ || false;
|
|
52
|
+
lineString.hasM = options.hasM || false;
|
|
53
|
+
const pointCount = value.readUInt32();
|
|
54
|
+
for (let i = 0; i < pointCount; i++) lineString.points.push(Point._readWkbPoint(value, options));
|
|
55
|
+
return lineString;
|
|
56
|
+
}
|
|
57
|
+
static _parseTwkb(value, options) {
|
|
58
|
+
const lineString = new LineString();
|
|
59
|
+
lineString.hasZ = options.hasZ || false;
|
|
60
|
+
lineString.hasM = options.hasM || false;
|
|
61
|
+
if (options.isEmpty) return lineString;
|
|
62
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : void 0, options.hasM ? 0 : void 0);
|
|
63
|
+
const pointCount = value.readVarInt();
|
|
64
|
+
for (let i = 0; i < pointCount; i++) lineString.points.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
65
|
+
return lineString;
|
|
66
|
+
}
|
|
67
|
+
static _parseGeoJSON(value) {
|
|
68
|
+
const lineString = new LineString();
|
|
69
|
+
if (value.coordinates.length > 0) lineString.hasZ = value.coordinates[0].length > 2;
|
|
70
|
+
for (let i = 0; i < value.coordinates.length; i++) lineString.points.push(Point._readGeoJSONPoint(value.coordinates[i]));
|
|
71
|
+
return lineString;
|
|
72
|
+
}
|
|
73
|
+
toWkt() {
|
|
74
|
+
if (this.points.length === 0) return this._getWktType(Types.wkt.LineString, true);
|
|
75
|
+
return this._getWktType(Types.wkt.LineString, false) + this._toInnerWkt();
|
|
76
|
+
}
|
|
77
|
+
_toInnerWkt() {
|
|
78
|
+
let innerWkt = "(";
|
|
79
|
+
for (let i = 0; i < this.points.length; i++) innerWkt += this._getWktCoordinate(this.points[i]) + ",";
|
|
80
|
+
innerWkt = innerWkt.slice(0, -1);
|
|
81
|
+
innerWkt += ")";
|
|
82
|
+
return innerWkt;
|
|
83
|
+
}
|
|
84
|
+
toWkb(parentOptions) {
|
|
85
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
86
|
+
wkb.writeInt8(1);
|
|
87
|
+
this._writeWkbType(wkb, Types.wkb.LineString, parentOptions);
|
|
88
|
+
wkb.writeUInt32LE(this.points.length);
|
|
89
|
+
for (let i = 0; i < this.points.length; i++) this.points[i]._writeWkbPoint(wkb);
|
|
90
|
+
return wkb.buffer;
|
|
91
|
+
}
|
|
92
|
+
toTwkb() {
|
|
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.LineString, 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++) this.points[i]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
101
|
+
}
|
|
102
|
+
return twkb.buffer;
|
|
103
|
+
}
|
|
104
|
+
_getWkbSize() {
|
|
105
|
+
let coordinateSize = 16;
|
|
106
|
+
if (this.hasZ) coordinateSize += 8;
|
|
107
|
+
if (this.hasM) coordinateSize += 8;
|
|
108
|
+
return 9 + this.points.length * coordinateSize;
|
|
109
|
+
}
|
|
110
|
+
toGeoJSON(options) {
|
|
111
|
+
const geoJSON = super.toGeoJSON(options);
|
|
112
|
+
geoJSON.type = Types.geoJSON.LineString;
|
|
113
|
+
geoJSON.coordinates = [];
|
|
114
|
+
for (let i = 0; i < this.points.length; i++) if (this.hasZ) geoJSON.coordinates.push([
|
|
115
|
+
this.points[i].x,
|
|
116
|
+
this.points[i].y,
|
|
117
|
+
this.points[i].z
|
|
118
|
+
]);
|
|
119
|
+
else geoJSON.coordinates.push([this.points[i].x, this.points[i].y]);
|
|
120
|
+
return geoJSON;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
124
|
+
export { LineString };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
|
|
2
|
+
import { Geometry, init_geometry } from "./geometry.mjs";
|
|
3
|
+
import { Types, init_types } from "./types.mjs";
|
|
4
|
+
import { Point, init_point } from "./point.mjs";
|
|
5
|
+
import { LineString } from "./linestring.mjs";
|
|
6
|
+
//#region src/wkx/multilinestring.ts
|
|
7
|
+
init_geometry();
|
|
8
|
+
init_types();
|
|
9
|
+
init_point();
|
|
10
|
+
init_binarywriter();
|
|
11
|
+
var MultiLineString = class MultiLineString extends Geometry {
|
|
12
|
+
lineStrings;
|
|
13
|
+
constructor(lineStrings, srid) {
|
|
14
|
+
super();
|
|
15
|
+
this.lineStrings = lineStrings || [];
|
|
16
|
+
this.srid = srid;
|
|
17
|
+
if (this.lineStrings.length > 0) {
|
|
18
|
+
this.hasZ = this.lineStrings[0].hasZ;
|
|
19
|
+
this.hasM = this.lineStrings[0].hasM;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
static Z(lineStrings, srid) {
|
|
23
|
+
const multiLineString = new MultiLineString(lineStrings, srid);
|
|
24
|
+
multiLineString.hasZ = true;
|
|
25
|
+
return multiLineString;
|
|
26
|
+
}
|
|
27
|
+
static M(lineStrings, srid) {
|
|
28
|
+
const multiLineString = new MultiLineString(lineStrings, srid);
|
|
29
|
+
multiLineString.hasM = true;
|
|
30
|
+
return multiLineString;
|
|
31
|
+
}
|
|
32
|
+
static ZM(lineStrings, srid) {
|
|
33
|
+
const multiLineString = new MultiLineString(lineStrings, srid);
|
|
34
|
+
multiLineString.hasZ = true;
|
|
35
|
+
multiLineString.hasM = true;
|
|
36
|
+
return multiLineString;
|
|
37
|
+
}
|
|
38
|
+
static _parseWkt(value, options) {
|
|
39
|
+
const multiLineString = new MultiLineString();
|
|
40
|
+
multiLineString.srid = options.srid;
|
|
41
|
+
multiLineString.hasZ = options.hasZ;
|
|
42
|
+
multiLineString.hasM = options.hasM;
|
|
43
|
+
if (value.isMatch(["EMPTY"])) return multiLineString;
|
|
44
|
+
value.expectGroupStart();
|
|
45
|
+
do {
|
|
46
|
+
value.expectGroupStart();
|
|
47
|
+
multiLineString.lineStrings.push(new LineString(value.matchCoordinates(options)));
|
|
48
|
+
value.expectGroupEnd();
|
|
49
|
+
} while (value.isMatch([","]));
|
|
50
|
+
value.expectGroupEnd();
|
|
51
|
+
return multiLineString;
|
|
52
|
+
}
|
|
53
|
+
static _parseWkb(value, options) {
|
|
54
|
+
const multiLineString = new MultiLineString();
|
|
55
|
+
multiLineString.srid = options.srid;
|
|
56
|
+
multiLineString.hasZ = options.hasZ || false;
|
|
57
|
+
multiLineString.hasM = options.hasM || false;
|
|
58
|
+
const lineStringCount = value.readUInt32();
|
|
59
|
+
for (let i = 0; i < lineStringCount; i++) multiLineString.lineStrings.push(Geometry.parse(value, options));
|
|
60
|
+
return multiLineString;
|
|
61
|
+
}
|
|
62
|
+
static _parseTwkb(value, options) {
|
|
63
|
+
const multiLineString = new MultiLineString();
|
|
64
|
+
multiLineString.hasZ = options.hasZ || false;
|
|
65
|
+
multiLineString.hasM = options.hasM || false;
|
|
66
|
+
if (options.isEmpty) return multiLineString;
|
|
67
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : void 0, options.hasM ? 0 : void 0);
|
|
68
|
+
const lineStringCount = value.readVarInt();
|
|
69
|
+
for (let i = 0; i < lineStringCount; i++) {
|
|
70
|
+
const lineString = new LineString();
|
|
71
|
+
lineString.hasZ = options.hasZ || false;
|
|
72
|
+
lineString.hasM = options.hasM || false;
|
|
73
|
+
const pointCount = value.readVarInt();
|
|
74
|
+
for (let j = 0; j < pointCount; j++) lineString.points.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
75
|
+
multiLineString.lineStrings.push(lineString);
|
|
76
|
+
}
|
|
77
|
+
return multiLineString;
|
|
78
|
+
}
|
|
79
|
+
static _parseGeoJSON(value) {
|
|
80
|
+
const multiLineString = new MultiLineString();
|
|
81
|
+
if (value.coordinates.length > 0 && value.coordinates[0].length > 0) multiLineString.hasZ = value.coordinates[0][0].length > 2;
|
|
82
|
+
for (let i = 0; i < value.coordinates.length; i++) multiLineString.lineStrings.push(LineString._parseGeoJSON({
|
|
83
|
+
type: "LineString",
|
|
84
|
+
coordinates: value.coordinates[i]
|
|
85
|
+
}));
|
|
86
|
+
return multiLineString;
|
|
87
|
+
}
|
|
88
|
+
toWkt() {
|
|
89
|
+
if (this.lineStrings.length === 0) return this._getWktType(Types.wkt.MultiLineString, true);
|
|
90
|
+
let wkt = this._getWktType(Types.wkt.MultiLineString, false) + "(";
|
|
91
|
+
for (let i = 0; i < this.lineStrings.length; i++) wkt += this.lineStrings[i]._toInnerWkt() + ",";
|
|
92
|
+
wkt = wkt.slice(0, -1);
|
|
93
|
+
wkt += ")";
|
|
94
|
+
return wkt;
|
|
95
|
+
}
|
|
96
|
+
toWkb() {
|
|
97
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
98
|
+
wkb.writeInt8(1);
|
|
99
|
+
this._writeWkbType(wkb, Types.wkb.MultiLineString);
|
|
100
|
+
wkb.writeUInt32LE(this.lineStrings.length);
|
|
101
|
+
for (let i = 0; i < this.lineStrings.length; i++) wkb.writeBuffer(this.lineStrings[i].toWkb({ srid: this.srid }));
|
|
102
|
+
return wkb.buffer;
|
|
103
|
+
}
|
|
104
|
+
toTwkb() {
|
|
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++) this.lineStrings[i].points[j]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return twkb.buffer;
|
|
118
|
+
}
|
|
119
|
+
_getWkbSize() {
|
|
120
|
+
let size = 9;
|
|
121
|
+
for (let i = 0; i < this.lineStrings.length; i++) size += this.lineStrings[i]._getWkbSize();
|
|
122
|
+
return size;
|
|
123
|
+
}
|
|
124
|
+
toGeoJSON(options) {
|
|
125
|
+
const geoJSON = super.toGeoJSON(options);
|
|
126
|
+
geoJSON.type = Types.geoJSON.MultiLineString;
|
|
127
|
+
geoJSON.coordinates = [];
|
|
128
|
+
for (let i = 0; i < this.lineStrings.length; i++) geoJSON.coordinates.push(this.lineStrings[i].toGeoJSON().coordinates);
|
|
129
|
+
return geoJSON;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
//#endregion
|
|
133
|
+
export { MultiLineString };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
|
|
2
|
+
import { Geometry, init_geometry } from "./geometry.mjs";
|
|
3
|
+
import { Types, init_types } from "./types.mjs";
|
|
4
|
+
import { Point, init_point } from "./point.mjs";
|
|
5
|
+
//#region src/wkx/multipoint.ts
|
|
6
|
+
init_geometry();
|
|
7
|
+
init_types();
|
|
8
|
+
init_point();
|
|
9
|
+
init_binarywriter();
|
|
10
|
+
var MultiPoint = class MultiPoint extends Geometry {
|
|
11
|
+
points;
|
|
12
|
+
constructor(points, srid) {
|
|
13
|
+
super();
|
|
14
|
+
this.points = points || [];
|
|
15
|
+
this.srid = srid;
|
|
16
|
+
if (this.points.length > 0) {
|
|
17
|
+
this.hasZ = this.points[0].hasZ;
|
|
18
|
+
this.hasM = this.points[0].hasM;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
static Z(points, srid) {
|
|
22
|
+
const multiPoint = new MultiPoint(points, srid);
|
|
23
|
+
multiPoint.hasZ = true;
|
|
24
|
+
return multiPoint;
|
|
25
|
+
}
|
|
26
|
+
static M(points, srid) {
|
|
27
|
+
const multiPoint = new MultiPoint(points, srid);
|
|
28
|
+
multiPoint.hasM = true;
|
|
29
|
+
return multiPoint;
|
|
30
|
+
}
|
|
31
|
+
static ZM(points, srid) {
|
|
32
|
+
const multiPoint = new MultiPoint(points, srid);
|
|
33
|
+
multiPoint.hasZ = true;
|
|
34
|
+
multiPoint.hasM = true;
|
|
35
|
+
return multiPoint;
|
|
36
|
+
}
|
|
37
|
+
static _parseWkt(value, options) {
|
|
38
|
+
const multiPoint = new MultiPoint();
|
|
39
|
+
multiPoint.srid = options.srid;
|
|
40
|
+
multiPoint.hasZ = options.hasZ;
|
|
41
|
+
multiPoint.hasM = options.hasM;
|
|
42
|
+
if (value.isMatch(["EMPTY"])) return multiPoint;
|
|
43
|
+
value.expectGroupStart();
|
|
44
|
+
multiPoint.points = multiPoint.points.concat(value.matchCoordinates(options));
|
|
45
|
+
value.expectGroupEnd();
|
|
46
|
+
return multiPoint;
|
|
47
|
+
}
|
|
48
|
+
static _parseWkb(value, options) {
|
|
49
|
+
const multiPoint = new MultiPoint();
|
|
50
|
+
multiPoint.srid = options.srid;
|
|
51
|
+
multiPoint.hasZ = options.hasZ || false;
|
|
52
|
+
multiPoint.hasM = options.hasM || false;
|
|
53
|
+
const pointCount = value.readUInt32();
|
|
54
|
+
for (let i = 0; i < pointCount; i++) multiPoint.points.push(Geometry.parse(value, options));
|
|
55
|
+
return multiPoint;
|
|
56
|
+
}
|
|
57
|
+
static _parseTwkb(value, options) {
|
|
58
|
+
const multiPoint = new MultiPoint();
|
|
59
|
+
multiPoint.hasZ = options.hasZ || false;
|
|
60
|
+
multiPoint.hasM = options.hasM || false;
|
|
61
|
+
if (options.isEmpty) return multiPoint;
|
|
62
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : void 0, options.hasM ? 0 : void 0);
|
|
63
|
+
const pointCount = value.readVarInt();
|
|
64
|
+
for (let i = 0; i < pointCount; i++) multiPoint.points.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
65
|
+
return multiPoint;
|
|
66
|
+
}
|
|
67
|
+
static _parseGeoJSON(value) {
|
|
68
|
+
const multiPoint = new MultiPoint();
|
|
69
|
+
if (value.coordinates.length > 0) multiPoint.hasZ = value.coordinates[0].length > 2;
|
|
70
|
+
for (let i = 0; i < value.coordinates.length; i++) multiPoint.points.push(Point._parseGeoJSON({
|
|
71
|
+
type: "Point",
|
|
72
|
+
coordinates: value.coordinates[i]
|
|
73
|
+
}));
|
|
74
|
+
return multiPoint;
|
|
75
|
+
}
|
|
76
|
+
toWkt() {
|
|
77
|
+
if (this.points.length === 0) return this._getWktType(Types.wkt.MultiPoint, true);
|
|
78
|
+
let wkt = this._getWktType(Types.wkt.MultiPoint, false) + "(";
|
|
79
|
+
for (let i = 0; i < this.points.length; i++) wkt += this._getWktCoordinate(this.points[i]) + ",";
|
|
80
|
+
wkt = wkt.slice(0, -1);
|
|
81
|
+
wkt += ")";
|
|
82
|
+
return wkt;
|
|
83
|
+
}
|
|
84
|
+
toWkb() {
|
|
85
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
86
|
+
wkb.writeInt8(1);
|
|
87
|
+
this._writeWkbType(wkb, Types.wkb.MultiPoint);
|
|
88
|
+
wkb.writeUInt32LE(this.points.length);
|
|
89
|
+
for (let i = 0; i < this.points.length; i++) wkb.writeBuffer(this.points[i].toWkb({ srid: this.srid }));
|
|
90
|
+
return wkb.buffer;
|
|
91
|
+
}
|
|
92
|
+
toTwkb() {
|
|
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++) this.points[i]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
101
|
+
}
|
|
102
|
+
return twkb.buffer;
|
|
103
|
+
}
|
|
104
|
+
_getWkbSize() {
|
|
105
|
+
let coordinateSize = 16;
|
|
106
|
+
if (this.hasZ) coordinateSize += 8;
|
|
107
|
+
if (this.hasM) coordinateSize += 8;
|
|
108
|
+
coordinateSize += 5;
|
|
109
|
+
return 9 + this.points.length * coordinateSize;
|
|
110
|
+
}
|
|
111
|
+
toGeoJSON(options) {
|
|
112
|
+
const geoJSON = super.toGeoJSON(options);
|
|
113
|
+
geoJSON.type = Types.geoJSON.MultiPoint;
|
|
114
|
+
geoJSON.coordinates = [];
|
|
115
|
+
for (let i = 0; i < this.points.length; i++) geoJSON.coordinates.push(this.points[i].toGeoJSON().coordinates);
|
|
116
|
+
return geoJSON;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
120
|
+
export { MultiPoint };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
|
|
2
|
+
import { Geometry, init_geometry } from "./geometry.mjs";
|
|
3
|
+
import { Types, init_types } from "./types.mjs";
|
|
4
|
+
import { Point, init_point } from "./point.mjs";
|
|
5
|
+
import { Polygon } from "./polygon.mjs";
|
|
6
|
+
//#region src/wkx/multipolygon.ts
|
|
7
|
+
init_geometry();
|
|
8
|
+
init_types();
|
|
9
|
+
init_point();
|
|
10
|
+
init_binarywriter();
|
|
11
|
+
var MultiPolygon = class MultiPolygon extends Geometry {
|
|
12
|
+
polygons;
|
|
13
|
+
constructor(polygons, srid) {
|
|
14
|
+
super();
|
|
15
|
+
this.polygons = polygons || [];
|
|
16
|
+
this.srid = srid;
|
|
17
|
+
if (this.polygons.length > 0) {
|
|
18
|
+
this.hasZ = this.polygons[0].hasZ;
|
|
19
|
+
this.hasM = this.polygons[0].hasM;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
static Z(polygons, srid) {
|
|
23
|
+
const multiPolygon = new MultiPolygon(polygons, srid);
|
|
24
|
+
multiPolygon.hasZ = true;
|
|
25
|
+
return multiPolygon;
|
|
26
|
+
}
|
|
27
|
+
static M(polygons, srid) {
|
|
28
|
+
const multiPolygon = new MultiPolygon(polygons, srid);
|
|
29
|
+
multiPolygon.hasM = true;
|
|
30
|
+
return multiPolygon;
|
|
31
|
+
}
|
|
32
|
+
static ZM(polygons, srid) {
|
|
33
|
+
const multiPolygon = new MultiPolygon(polygons, srid);
|
|
34
|
+
multiPolygon.hasZ = true;
|
|
35
|
+
multiPolygon.hasM = true;
|
|
36
|
+
return multiPolygon;
|
|
37
|
+
}
|
|
38
|
+
static _parseWkt(value, options) {
|
|
39
|
+
const multiPolygon = new MultiPolygon();
|
|
40
|
+
multiPolygon.srid = options.srid;
|
|
41
|
+
multiPolygon.hasZ = options.hasZ;
|
|
42
|
+
multiPolygon.hasM = options.hasM;
|
|
43
|
+
if (value.isMatch(["EMPTY"])) return multiPolygon;
|
|
44
|
+
value.expectGroupStart();
|
|
45
|
+
do {
|
|
46
|
+
value.expectGroupStart();
|
|
47
|
+
let exteriorRing = [];
|
|
48
|
+
const interiorRings = [];
|
|
49
|
+
value.expectGroupStart();
|
|
50
|
+
exteriorRing = exteriorRing.concat(value.matchCoordinates(options));
|
|
51
|
+
value.expectGroupEnd();
|
|
52
|
+
while (value.isMatch([","])) {
|
|
53
|
+
value.expectGroupStart();
|
|
54
|
+
interiorRings.push(value.matchCoordinates(options));
|
|
55
|
+
value.expectGroupEnd();
|
|
56
|
+
}
|
|
57
|
+
multiPolygon.polygons.push(new Polygon(exteriorRing, interiorRings));
|
|
58
|
+
value.expectGroupEnd();
|
|
59
|
+
} while (value.isMatch([","]));
|
|
60
|
+
value.expectGroupEnd();
|
|
61
|
+
return multiPolygon;
|
|
62
|
+
}
|
|
63
|
+
static _parseWkb(value, options) {
|
|
64
|
+
const multiPolygon = new MultiPolygon();
|
|
65
|
+
multiPolygon.srid = options.srid;
|
|
66
|
+
multiPolygon.hasZ = options.hasZ || false;
|
|
67
|
+
multiPolygon.hasM = options.hasM || false;
|
|
68
|
+
const polygonCount = value.readUInt32();
|
|
69
|
+
for (let i = 0; i < polygonCount; i++) multiPolygon.polygons.push(Geometry.parse(value, options));
|
|
70
|
+
return multiPolygon;
|
|
71
|
+
}
|
|
72
|
+
static _parseTwkb(value, options) {
|
|
73
|
+
const multiPolygon = new MultiPolygon();
|
|
74
|
+
multiPolygon.hasZ = options.hasZ || false;
|
|
75
|
+
multiPolygon.hasM = options.hasM || false;
|
|
76
|
+
if (options.isEmpty) return multiPolygon;
|
|
77
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : void 0, options.hasM ? 0 : void 0);
|
|
78
|
+
const polygonCount = value.readVarInt();
|
|
79
|
+
for (let i = 0; i < polygonCount; i++) {
|
|
80
|
+
const polygon = new Polygon();
|
|
81
|
+
polygon.hasZ = options.hasZ || false;
|
|
82
|
+
polygon.hasM = options.hasM || false;
|
|
83
|
+
const ringCount = value.readVarInt();
|
|
84
|
+
const exteriorRingCount = value.readVarInt();
|
|
85
|
+
for (let j = 0; j < exteriorRingCount; j++) polygon.exteriorRing.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
86
|
+
for (let j = 1; j < ringCount; j++) {
|
|
87
|
+
const interiorRing = [];
|
|
88
|
+
const interiorRingCount = value.readVarInt();
|
|
89
|
+
for (let k = 0; k < interiorRingCount; k++) interiorRing.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
90
|
+
polygon.interiorRings.push(interiorRing);
|
|
91
|
+
}
|
|
92
|
+
multiPolygon.polygons.push(polygon);
|
|
93
|
+
}
|
|
94
|
+
return multiPolygon;
|
|
95
|
+
}
|
|
96
|
+
static _parseGeoJSON(value) {
|
|
97
|
+
const multiPolygon = new MultiPolygon();
|
|
98
|
+
if (value.coordinates.length > 0 && value.coordinates[0].length > 0 && value.coordinates[0][0].length > 0) multiPolygon.hasZ = value.coordinates[0][0][0].length > 2;
|
|
99
|
+
for (let i = 0; i < value.coordinates.length; i++) multiPolygon.polygons.push(Polygon._parseGeoJSON({
|
|
100
|
+
type: "Polygon",
|
|
101
|
+
coordinates: value.coordinates[i]
|
|
102
|
+
}));
|
|
103
|
+
return multiPolygon;
|
|
104
|
+
}
|
|
105
|
+
toWkt() {
|
|
106
|
+
if (this.polygons.length === 0) return this._getWktType(Types.wkt.MultiPolygon, true);
|
|
107
|
+
let wkt = this._getWktType(Types.wkt.MultiPolygon, false) + "(";
|
|
108
|
+
for (let i = 0; i < this.polygons.length; i++) wkt += this.polygons[i]._toInnerWkt() + ",";
|
|
109
|
+
wkt = wkt.slice(0, -1);
|
|
110
|
+
wkt += ")";
|
|
111
|
+
return wkt;
|
|
112
|
+
}
|
|
113
|
+
toWkb() {
|
|
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++) wkb.writeBuffer(this.polygons[i].toWkb({ srid: this.srid }));
|
|
119
|
+
return wkb.buffer;
|
|
120
|
+
}
|
|
121
|
+
toTwkb() {
|
|
122
|
+
const twkb = new BinaryWriter(0, true);
|
|
123
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
124
|
+
const isEmpty = this.polygons.length === 0;
|
|
125
|
+
this._writeTwkbHeader(twkb, Types.wkb.MultiPolygon, precision, isEmpty);
|
|
126
|
+
if (this.polygons.length > 0) {
|
|
127
|
+
twkb.writeVarInt(this.polygons.length);
|
|
128
|
+
const previousPoint = new Point(0, 0, 0, 0);
|
|
129
|
+
for (let i = 0; i < this.polygons.length; i++) {
|
|
130
|
+
twkb.writeVarInt(1 + this.polygons[i].interiorRings.length);
|
|
131
|
+
twkb.writeVarInt(this.polygons[i].exteriorRing.length);
|
|
132
|
+
for (let j = 0; j < this.polygons[i].exteriorRing.length; j++) this.polygons[i].exteriorRing[j]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
133
|
+
for (let j = 0; j < this.polygons[i].interiorRings.length; j++) {
|
|
134
|
+
twkb.writeVarInt(this.polygons[i].interiorRings[j].length);
|
|
135
|
+
for (let k = 0; k < this.polygons[i].interiorRings[j].length; k++) this.polygons[i].interiorRings[j][k]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return twkb.buffer;
|
|
140
|
+
}
|
|
141
|
+
_getWkbSize() {
|
|
142
|
+
let size = 9;
|
|
143
|
+
for (let i = 0; i < this.polygons.length; i++) size += this.polygons[i]._getWkbSize();
|
|
144
|
+
return size;
|
|
145
|
+
}
|
|
146
|
+
toGeoJSON(options) {
|
|
147
|
+
const geoJSON = super.toGeoJSON(options);
|
|
148
|
+
geoJSON.type = Types.geoJSON.MultiPolygon;
|
|
149
|
+
geoJSON.coordinates = [];
|
|
150
|
+
for (let i = 0; i < this.polygons.length; i++) geoJSON.coordinates.push(this.polygons[i].toGeoJSON().coordinates);
|
|
151
|
+
return geoJSON;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
//#endregion
|
|
155
|
+
export { MultiPolygon };
|