dgeoutils 2.4.14 → 2.4.17
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/cjs/DPoint.d.ts +5 -8
- package/dist/cjs/DPoint.js +22 -9
- package/dist/cjs/DPolygon.d.ts +2 -2
- package/dist/cjs/DPolygon.js +13 -6
- package/dist/cjs/utils.d.ts +8 -4
- package/dist/cjs/utils.js +11 -4
- package/dist/es2015/DPoint.js +20 -9
- package/dist/es2015/DPolygon.js +14 -7
- package/dist/es2015/utils.js +17 -4
- package/dist/esm/DPoint.js +23 -10
- package/dist/esm/DPolygon.js +14 -7
- package/dist/esm/utils.js +11 -4
- package/dist/umd/dgeoutils.js +47 -20
- package/dist/umd/dgeoutils.min.js +1 -1
- package/dist/umd/dgeoutils.min.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/DPoint.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DLine } from './DLine';
|
|
2
2
|
import { DPolygon } from './DPolygon';
|
|
3
|
-
import { Point } from 'geojson';
|
|
3
|
+
import { Point, Feature } from 'geojson';
|
|
4
4
|
export declare const EARTH_RADIUS_IN_METERS = 6378137;
|
|
5
5
|
export declare type DCoord = [number, number] | [number, number, number];
|
|
6
6
|
export interface LatLng {
|
|
@@ -19,15 +19,13 @@ export declare class DPoint {
|
|
|
19
19
|
x: number;
|
|
20
20
|
y: number;
|
|
21
21
|
z?: number | undefined;
|
|
22
|
-
properties:
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
};
|
|
22
|
+
properties: Record<string, any>;
|
|
25
23
|
constructor();
|
|
26
24
|
constructor(xy: number);
|
|
27
25
|
constructor(x: number, y: number);
|
|
28
26
|
constructor(x: number, y: number, z?: number);
|
|
29
27
|
static zero(): DPoint;
|
|
30
|
-
static parse(c: LatLng | number[] | DCoord | Point
|
|
28
|
+
static parse(c: LatLng | number[] | DCoord | Point | Feature<Point>, format?: string): DPoint;
|
|
31
29
|
static parseFromWKT(wkt: string): DPoint;
|
|
32
30
|
static random(): DPoint;
|
|
33
31
|
static getTileFromQuadKey(quadKey: string): DPoint;
|
|
@@ -36,6 +34,7 @@ export declare class DPoint {
|
|
|
36
34
|
getCoordsFromTile(zoom?: number): DPoint;
|
|
37
35
|
toCoords(format?: string): DCoord;
|
|
38
36
|
toGeoJSON(format?: string): Point;
|
|
37
|
+
toGeoJSONFeature(format?: string): Feature<Point>;
|
|
39
38
|
findLine(p: DPoint): DLine;
|
|
40
39
|
findInnerAngle(p1: DPoint, p3: DPoint): number;
|
|
41
40
|
toString(): string;
|
|
@@ -119,9 +118,7 @@ export declare class DPoint {
|
|
|
119
118
|
set lon(v: number);
|
|
120
119
|
get alt(): number | undefined;
|
|
121
120
|
set alt(v: number | undefined);
|
|
122
|
-
simple(xKey?: string, yKey?: string):
|
|
123
|
-
[key: string]: number;
|
|
124
|
-
};
|
|
121
|
+
simple<T extends Record<string, number>>(xKey?: string, yKey?: string, zKey?: string): T;
|
|
125
122
|
setIfLessThan(p: DPoint): DPoint;
|
|
126
123
|
minus(): DPoint;
|
|
127
124
|
orthodromicPath(point: DPoint, pointsCount?: number): DPolygon;
|
package/dist/cjs/DPoint.js
CHANGED
|
@@ -58,7 +58,7 @@ var DPoint = (function () {
|
|
|
58
58
|
return new DPoint();
|
|
59
59
|
};
|
|
60
60
|
DPoint.parse = function (c, format) {
|
|
61
|
-
if (format === void 0) { format =
|
|
61
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
62
62
|
var _a = c, lat = _a.lat, lon = _a.lon, _b = _a.lng, lng = _b === void 0 ? lon : _b, alt = _a.alt;
|
|
63
63
|
if (lat && lng) {
|
|
64
64
|
return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
|
|
@@ -67,6 +67,11 @@ var DPoint = (function () {
|
|
|
67
67
|
if (c.type === 'Point') {
|
|
68
68
|
t = c.coordinates;
|
|
69
69
|
}
|
|
70
|
+
if (c.type === 'Feature') {
|
|
71
|
+
var f = DPoint.parse(c.geometry, format);
|
|
72
|
+
f.properties = __assign({}, c.properties);
|
|
73
|
+
return f;
|
|
74
|
+
}
|
|
70
75
|
return format.replace(/[^x-z]/gmiu, '')
|
|
71
76
|
.split('')
|
|
72
77
|
.reduce(function (a, k, index) {
|
|
@@ -157,7 +162,7 @@ var DPoint = (function () {
|
|
|
157
162
|
};
|
|
158
163
|
DPoint.prototype.toCoords = function (format) {
|
|
159
164
|
var _this = this;
|
|
160
|
-
if (format === void 0) { format =
|
|
165
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
161
166
|
return format.replace(/[^x-z]/gmiu, '').split('')
|
|
162
167
|
.map(function (k) { return ({
|
|
163
168
|
x: _this.x,
|
|
@@ -167,12 +172,20 @@ var DPoint = (function () {
|
|
|
167
172
|
.filter(function (r) { return r !== undefined; });
|
|
168
173
|
};
|
|
169
174
|
DPoint.prototype.toGeoJSON = function (format) {
|
|
170
|
-
if (format === void 0) { format =
|
|
175
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
171
176
|
return {
|
|
172
177
|
type: 'Point',
|
|
173
178
|
coordinates: this.toCoords(format)
|
|
174
179
|
};
|
|
175
180
|
};
|
|
181
|
+
DPoint.prototype.toGeoJSONFeature = function (format) {
|
|
182
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
183
|
+
return {
|
|
184
|
+
type: 'Feature',
|
|
185
|
+
properties: __assign({}, this.properties),
|
|
186
|
+
geometry: this.toGeoJSON(format)
|
|
187
|
+
};
|
|
188
|
+
};
|
|
176
189
|
DPoint.prototype.findLine = function (p) {
|
|
177
190
|
(0, utils_1.checkFunction)('findLine')
|
|
178
191
|
.checkArgument('this')
|
|
@@ -691,14 +704,14 @@ var DPoint = (function () {
|
|
|
691
704
|
enumerable: false,
|
|
692
705
|
configurable: true
|
|
693
706
|
});
|
|
694
|
-
DPoint.prototype.simple = function (xKey, yKey) {
|
|
695
|
-
var _a;
|
|
707
|
+
DPoint.prototype.simple = function (xKey, yKey, zKey) {
|
|
708
|
+
var _a, _b;
|
|
696
709
|
if (xKey === void 0) { xKey = 'x'; }
|
|
697
710
|
if (yKey === void 0) { yKey = 'y'; }
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
711
|
+
if (zKey === void 0) { zKey = 'z'; }
|
|
712
|
+
return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), ((0, utils_1.isDefAndNotNull)(this.z) ? (_b = {},
|
|
713
|
+
_b[zKey] = this.z,
|
|
714
|
+
_b) : {}));
|
|
702
715
|
};
|
|
703
716
|
DPoint.prototype.setIfLessThan = function (p) {
|
|
704
717
|
this.x = Math.max(this.x, p.x);
|
package/dist/cjs/DPolygon.d.ts
CHANGED
|
@@ -94,13 +94,13 @@ export declare class DPolygon {
|
|
|
94
94
|
onBorder(p: DPoint): boolean;
|
|
95
95
|
nextStart(): DPolygon;
|
|
96
96
|
removeDuplicates(): DPolygon;
|
|
97
|
-
static toGeoJSONFeatureCollection(polygons: DPolygon[], format?: string): FeatureCollection<LineString | Polygon
|
|
97
|
+
static toGeoJSONFeatureCollection(polygons: DPolygon[], format?: string): FeatureCollection<LineString | Polygon>;
|
|
98
98
|
static parse(a: LatLng[], format?: string): DPolygon;
|
|
99
99
|
static parse(a: number[][], format?: string): DPolygon;
|
|
100
100
|
static parse(a: DCoord[], format?: string): DPolygon;
|
|
101
101
|
static parse(a: GeoJsonGeometry | Feature | FeatureCollection<LineString | Polygon>, format?: string): DPolygon | DeepArray<DPolygon>;
|
|
102
102
|
toArrayOfCoords(format?: string): DCoord[];
|
|
103
|
-
toGeoJSONFeature(format?: string): Feature<LineString | Polygon
|
|
103
|
+
toGeoJSONFeature(format?: string): Feature<LineString | Polygon>;
|
|
104
104
|
toGeoJSON(format?: string): LineString | Polygon;
|
|
105
105
|
divideToPieces(piecesCount: number, withAltitude?: boolean): DPolygon;
|
|
106
106
|
prepareToFastSearch(): void;
|
package/dist/cjs/DPolygon.js
CHANGED
|
@@ -967,14 +967,14 @@ var DPolygon = (function () {
|
|
|
967
967
|
return this;
|
|
968
968
|
};
|
|
969
969
|
DPolygon.toGeoJSONFeatureCollection = function (polygons, format) {
|
|
970
|
-
if (format === void 0) { format =
|
|
970
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
971
971
|
return {
|
|
972
972
|
type: 'FeatureCollection',
|
|
973
973
|
features: polygons.map(function (polygon) { return polygon.toGeoJSONFeature(format); })
|
|
974
974
|
};
|
|
975
975
|
};
|
|
976
976
|
DPolygon.parse = function (a, format) {
|
|
977
|
-
if (format === void 0) { format =
|
|
977
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
978
978
|
if (a.type) {
|
|
979
979
|
switch (a.type) {
|
|
980
980
|
case 'FeatureCollection':
|
|
@@ -990,7 +990,14 @@ var DPolygon = (function () {
|
|
|
990
990
|
}, []);
|
|
991
991
|
case 'Feature': {
|
|
992
992
|
var t = DPolygon.parse(a.geometry, format);
|
|
993
|
-
|
|
993
|
+
if (Array.isArray(t)) {
|
|
994
|
+
t.forEach(function (record) {
|
|
995
|
+
record.properties = __assign(__assign({}, a.properties), { id: a.id });
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
t.properties = __assign(__assign({}, a.properties), { id: a.id });
|
|
1000
|
+
}
|
|
994
1001
|
return t;
|
|
995
1002
|
}
|
|
996
1003
|
case 'LineString':
|
|
@@ -1031,11 +1038,11 @@ var DPolygon = (function () {
|
|
|
1031
1038
|
.map(function (r) { return DPoint_1.DPoint.parse(r, format); }));
|
|
1032
1039
|
};
|
|
1033
1040
|
DPolygon.prototype.toArrayOfCoords = function (format) {
|
|
1034
|
-
if (format === void 0) { format =
|
|
1041
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
1035
1042
|
return this.mapArray(function (r) { return r.toCoords(format); });
|
|
1036
1043
|
};
|
|
1037
1044
|
DPolygon.prototype.toGeoJSONFeature = function (format) {
|
|
1038
|
-
if (format === void 0) { format =
|
|
1045
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
1039
1046
|
return {
|
|
1040
1047
|
type: 'Feature',
|
|
1041
1048
|
properties: __assign({}, this.properties),
|
|
@@ -1043,7 +1050,7 @@ var DPolygon = (function () {
|
|
|
1043
1050
|
};
|
|
1044
1051
|
};
|
|
1045
1052
|
DPolygon.prototype.toGeoJSON = function (format) {
|
|
1046
|
-
if (format === void 0) { format =
|
|
1053
|
+
if (format === void 0) { format = utils_1.DGeo.parseFormat; }
|
|
1047
1054
|
if (this.closed) {
|
|
1048
1055
|
return {
|
|
1049
1056
|
type: 'Polygon',
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="offscreencanvas" />
|
|
2
2
|
import { DPoint } from './DPoint';
|
|
3
|
-
|
|
3
|
+
interface DGeoInterface {
|
|
4
4
|
DEBUG: boolean;
|
|
5
|
-
|
|
5
|
+
parseFormat: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const DGeo: DGeoInterface;
|
|
6
8
|
export declare const warn: (...args: any[]) => void;
|
|
7
9
|
export declare const isDefAndNotNull: (a: any) => boolean;
|
|
8
10
|
declare type CheckFunc = (p: DPoint) => CheckFunction;
|
|
@@ -19,8 +21,10 @@ interface CheckFunction {
|
|
|
19
21
|
checkArgument: (argName: string) => CheckArgument;
|
|
20
22
|
}
|
|
21
23
|
export declare const checkFunction: (funcName: string) => CheckFunction;
|
|
22
|
-
|
|
23
|
-
export declare const
|
|
24
|
+
declare type ArrayFillFunction<T> = (index: number) => T;
|
|
25
|
+
export declare const createArray: <T = number>(v: number, fillSymbol?: T | ArrayFillFunction<T> | undefined) => T[];
|
|
26
|
+
declare type MatrixFillFunction<T> = (x: number, y: number) => T;
|
|
27
|
+
export declare const createMatrix: <T>({ h, w }: DPoint, fillSymbol?: T | MatrixFillFunction<T> | undefined) => T[][];
|
|
24
28
|
export declare const gaussianElimination: {
|
|
25
29
|
(matrix: number[][]): number[];
|
|
26
30
|
MIN: number;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -28,7 +28,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
28
|
exports.div = exports.getCombinations = exports.cartesianProduct = exports.createCanvas = exports.gaussianElimination = exports.createMatrix = exports.createArray = exports.checkFunction = exports.isDefAndNotNull = exports.warn = exports.DGeo = void 0;
|
|
29
29
|
var DPoint_1 = require("./DPoint");
|
|
30
30
|
exports.DGeo = {
|
|
31
|
-
DEBUG: false
|
|
31
|
+
DEBUG: false,
|
|
32
|
+
parseFormat: 'xyz'
|
|
32
33
|
};
|
|
33
34
|
var warn = function () {
|
|
34
35
|
var args = [];
|
|
@@ -105,13 +106,19 @@ var checkFunction = function (funcName) { return ({
|
|
|
105
106
|
}); };
|
|
106
107
|
exports.checkFunction = checkFunction;
|
|
107
108
|
var createArray = function (v, fillSymbol) {
|
|
108
|
-
if (fillSymbol ===
|
|
109
|
-
|
|
109
|
+
if (typeof fillSymbol === 'function') {
|
|
110
|
+
return new Array(v).fill(false)
|
|
111
|
+
.map(function (_, i) { return fillSymbol(i); });
|
|
112
|
+
}
|
|
113
|
+
return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
|
|
110
114
|
};
|
|
111
115
|
exports.createArray = createArray;
|
|
112
116
|
var createMatrix = function (_a, fillSymbol) {
|
|
113
117
|
var h = _a.h, w = _a.w;
|
|
114
|
-
if (fillSymbol ===
|
|
118
|
+
if (typeof fillSymbol === 'function') {
|
|
119
|
+
return (0, exports.createArray)(h)
|
|
120
|
+
.map(function (_, y) { return (0, exports.createArray)(w, function (x) { return fillSymbol(x, y); }); });
|
|
121
|
+
}
|
|
115
122
|
return (0, exports.createArray)(h)
|
|
116
123
|
.map(function () { return (0, exports.createArray)(w, fillSymbol); });
|
|
117
124
|
};
|
package/dist/es2015/DPoint.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DLine } from './DLine';
|
|
2
2
|
import { DPolygon } from './DPolygon';
|
|
3
|
-
import { checkFunction, createArray, div, isDefAndNotNull } from './utils';
|
|
3
|
+
import { checkFunction, createArray, DGeo, div, isDefAndNotNull } from './utils';
|
|
4
4
|
const diff = 0;
|
|
5
5
|
const radiansPolygon = new DPolygon();
|
|
6
6
|
const pseudoMercatorPolygon = new DPolygon();
|
|
@@ -25,7 +25,7 @@ export class DPoint {
|
|
|
25
25
|
static zero() {
|
|
26
26
|
return new DPoint();
|
|
27
27
|
}
|
|
28
|
-
static parse(c, format =
|
|
28
|
+
static parse(c, format = DGeo.parseFormat) {
|
|
29
29
|
const { lat, lon, lng = lon, alt } = c;
|
|
30
30
|
if (lat && lng) {
|
|
31
31
|
return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
|
|
@@ -34,6 +34,11 @@ export class DPoint {
|
|
|
34
34
|
if (c.type === 'Point') {
|
|
35
35
|
t = c.coordinates;
|
|
36
36
|
}
|
|
37
|
+
if (c.type === 'Feature') {
|
|
38
|
+
const f = DPoint.parse(c.geometry, format);
|
|
39
|
+
f.properties = Object.assign({}, c.properties);
|
|
40
|
+
return f;
|
|
41
|
+
}
|
|
37
42
|
return format.replace(/[^x-z]/gmiu, '')
|
|
38
43
|
.split('')
|
|
39
44
|
.reduce((a, k, index) => {
|
|
@@ -119,7 +124,7 @@ export class DPoint {
|
|
|
119
124
|
const y = PI_IN_DEGREE / Math.PI * Math.atan((Math.exp(n) - Math.exp(-n)) / 2);
|
|
120
125
|
return new DPoint(x, y, zoom);
|
|
121
126
|
}
|
|
122
|
-
toCoords(format =
|
|
127
|
+
toCoords(format = DGeo.parseFormat) {
|
|
123
128
|
return format.replace(/[^x-z]/gmiu, '').split('')
|
|
124
129
|
.map((k) => ({
|
|
125
130
|
x: this.x,
|
|
@@ -128,12 +133,19 @@ export class DPoint {
|
|
|
128
133
|
})[k])
|
|
129
134
|
.filter((r) => r !== undefined);
|
|
130
135
|
}
|
|
131
|
-
toGeoJSON(format =
|
|
136
|
+
toGeoJSON(format = DGeo.parseFormat) {
|
|
132
137
|
return {
|
|
133
138
|
type: 'Point',
|
|
134
139
|
coordinates: this.toCoords(format)
|
|
135
140
|
};
|
|
136
141
|
}
|
|
142
|
+
toGeoJSONFeature(format = DGeo.parseFormat) {
|
|
143
|
+
return {
|
|
144
|
+
type: 'Feature',
|
|
145
|
+
properties: Object.assign({}, this.properties),
|
|
146
|
+
geometry: this.toGeoJSON(format)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
137
149
|
findLine(p) {
|
|
138
150
|
checkFunction('findLine')
|
|
139
151
|
.checkArgument('this')
|
|
@@ -573,11 +585,10 @@ export class DPoint {
|
|
|
573
585
|
set alt(v) {
|
|
574
586
|
this.z = v;
|
|
575
587
|
}
|
|
576
|
-
simple(xKey = 'x', yKey = 'y') {
|
|
577
|
-
return {
|
|
578
|
-
[
|
|
579
|
-
|
|
580
|
-
};
|
|
588
|
+
simple(xKey = 'x', yKey = 'y', zKey = 'z') {
|
|
589
|
+
return Object.assign({ [xKey]: this.x, [yKey]: this.y }, (isDefAndNotNull(this.z) ? {
|
|
590
|
+
[zKey]: this.z
|
|
591
|
+
} : {}));
|
|
581
592
|
}
|
|
582
593
|
setIfLessThan(p) {
|
|
583
594
|
this.x = Math.max(this.x, p.x);
|
package/dist/es2015/DPolygon.js
CHANGED
|
@@ -4,7 +4,7 @@ import { DCircle } from './DCircle';
|
|
|
4
4
|
import { DNumbers } from './DNumbers';
|
|
5
5
|
import { io as jstsIo, operation } from 'jsts';
|
|
6
6
|
import { DPolygonLoop } from './DPolygonLoop';
|
|
7
|
-
import { isDefAndNotNull } from './utils';
|
|
7
|
+
import { DGeo, isDefAndNotNull } from './utils';
|
|
8
8
|
const { buffer: { BufferParameters: { CAP_ROUND, CAP_FLAT, CAP_SQUARE } } } = operation;
|
|
9
9
|
export const MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
10
10
|
const APPROXIMATION_VALUE = 0.1;
|
|
@@ -618,13 +618,13 @@ export class DPolygon {
|
|
|
618
618
|
}
|
|
619
619
|
return this;
|
|
620
620
|
}
|
|
621
|
-
static toGeoJSONFeatureCollection(polygons, format =
|
|
621
|
+
static toGeoJSONFeatureCollection(polygons, format = DGeo.parseFormat) {
|
|
622
622
|
return {
|
|
623
623
|
type: 'FeatureCollection',
|
|
624
624
|
features: polygons.map((polygon) => polygon.toGeoJSONFeature(format))
|
|
625
625
|
};
|
|
626
626
|
}
|
|
627
|
-
static parse(a, format =
|
|
627
|
+
static parse(a, format = DGeo.parseFormat) {
|
|
628
628
|
if (a.type) {
|
|
629
629
|
switch (a.type) {
|
|
630
630
|
case 'FeatureCollection':
|
|
@@ -640,7 +640,14 @@ export class DPolygon {
|
|
|
640
640
|
}, []);
|
|
641
641
|
case 'Feature': {
|
|
642
642
|
const t = DPolygon.parse(a.geometry, format);
|
|
643
|
-
|
|
643
|
+
if (Array.isArray(t)) {
|
|
644
|
+
t.forEach((record) => {
|
|
645
|
+
record.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
t.properties = Object.assign(Object.assign({}, a.properties), { id: a.id });
|
|
650
|
+
}
|
|
644
651
|
return t;
|
|
645
652
|
}
|
|
646
653
|
case 'LineString':
|
|
@@ -680,17 +687,17 @@ export class DPolygon {
|
|
|
680
687
|
return new DPolygon(a
|
|
681
688
|
.map((r) => DPoint.parse(r, format)));
|
|
682
689
|
}
|
|
683
|
-
toArrayOfCoords(format =
|
|
690
|
+
toArrayOfCoords(format = DGeo.parseFormat) {
|
|
684
691
|
return this.mapArray((r) => r.toCoords(format));
|
|
685
692
|
}
|
|
686
|
-
toGeoJSONFeature(format =
|
|
693
|
+
toGeoJSONFeature(format = DGeo.parseFormat) {
|
|
687
694
|
return {
|
|
688
695
|
type: 'Feature',
|
|
689
696
|
properties: Object.assign({}, this.properties),
|
|
690
697
|
geometry: this.toGeoJSON(format)
|
|
691
698
|
};
|
|
692
699
|
}
|
|
693
|
-
toGeoJSON(format =
|
|
700
|
+
toGeoJSON(format = DGeo.parseFormat) {
|
|
694
701
|
if (this.closed) {
|
|
695
702
|
return {
|
|
696
703
|
type: 'Polygon',
|
package/dist/es2015/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DPoint } from './DPoint';
|
|
2
2
|
export const DGeo = {
|
|
3
|
-
DEBUG: false
|
|
3
|
+
DEBUG: false,
|
|
4
|
+
parseFormat: 'xyz'
|
|
4
5
|
};
|
|
5
6
|
export const warn = (...args) => {
|
|
6
7
|
if (DGeo.DEBUG) {
|
|
@@ -69,9 +70,21 @@ export const checkFunction = (funcName) => ({
|
|
|
69
70
|
};
|
|
70
71
|
}
|
|
71
72
|
});
|
|
72
|
-
export const createArray = (v, fillSymbol
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
export const createArray = (v, fillSymbol) => {
|
|
74
|
+
if (typeof fillSymbol === 'function') {
|
|
75
|
+
return new Array(v).fill(false)
|
|
76
|
+
.map((_, i) => fillSymbol(i));
|
|
77
|
+
}
|
|
78
|
+
return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
|
|
79
|
+
};
|
|
80
|
+
export const createMatrix = ({ h, w }, fillSymbol) => {
|
|
81
|
+
if (typeof fillSymbol === 'function') {
|
|
82
|
+
return createArray(h)
|
|
83
|
+
.map((_, y) => createArray(w, (x) => fillSymbol(x, y)));
|
|
84
|
+
}
|
|
85
|
+
return createArray(h)
|
|
86
|
+
.map(() => createArray(w, fillSymbol));
|
|
87
|
+
};
|
|
75
88
|
export const gaussianElimination = (matrix) => {
|
|
76
89
|
const n = matrix.length;
|
|
77
90
|
const matrixClone = createMatrix(new DPoint(n + 1, n));
|
package/dist/esm/DPoint.js
CHANGED
|
@@ -27,7 +27,7 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
27
27
|
};
|
|
28
28
|
import { DLine } from './DLine';
|
|
29
29
|
import { DPolygon } from './DPolygon';
|
|
30
|
-
import { checkFunction, createArray, div, isDefAndNotNull } from './utils';
|
|
30
|
+
import { checkFunction, createArray, DGeo, div, isDefAndNotNull } from './utils';
|
|
31
31
|
var diff = 0;
|
|
32
32
|
var radiansPolygon = new DPolygon();
|
|
33
33
|
var pseudoMercatorPolygon = new DPolygon();
|
|
@@ -55,7 +55,7 @@ var DPoint = (function () {
|
|
|
55
55
|
return new DPoint();
|
|
56
56
|
};
|
|
57
57
|
DPoint.parse = function (c, format) {
|
|
58
|
-
if (format === void 0) { format =
|
|
58
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
59
59
|
var _a = c, lat = _a.lat, lon = _a.lon, _b = _a.lng, lng = _b === void 0 ? lon : _b, alt = _a.alt;
|
|
60
60
|
if (lat && lng) {
|
|
61
61
|
return new DPoint(lng, lat, alt !== null && alt !== void 0 ? alt : 0);
|
|
@@ -64,6 +64,11 @@ var DPoint = (function () {
|
|
|
64
64
|
if (c.type === 'Point') {
|
|
65
65
|
t = c.coordinates;
|
|
66
66
|
}
|
|
67
|
+
if (c.type === 'Feature') {
|
|
68
|
+
var f = DPoint.parse(c.geometry, format);
|
|
69
|
+
f.properties = __assign({}, c.properties);
|
|
70
|
+
return f;
|
|
71
|
+
}
|
|
67
72
|
return format.replace(/[^x-z]/gmiu, '')
|
|
68
73
|
.split('')
|
|
69
74
|
.reduce(function (a, k, index) {
|
|
@@ -154,7 +159,7 @@ var DPoint = (function () {
|
|
|
154
159
|
};
|
|
155
160
|
DPoint.prototype.toCoords = function (format) {
|
|
156
161
|
var _this = this;
|
|
157
|
-
if (format === void 0) { format =
|
|
162
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
158
163
|
return format.replace(/[^x-z]/gmiu, '').split('')
|
|
159
164
|
.map(function (k) { return ({
|
|
160
165
|
x: _this.x,
|
|
@@ -164,12 +169,20 @@ var DPoint = (function () {
|
|
|
164
169
|
.filter(function (r) { return r !== undefined; });
|
|
165
170
|
};
|
|
166
171
|
DPoint.prototype.toGeoJSON = function (format) {
|
|
167
|
-
if (format === void 0) { format =
|
|
172
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
168
173
|
return {
|
|
169
174
|
type: 'Point',
|
|
170
175
|
coordinates: this.toCoords(format)
|
|
171
176
|
};
|
|
172
177
|
};
|
|
178
|
+
DPoint.prototype.toGeoJSONFeature = function (format) {
|
|
179
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
180
|
+
return {
|
|
181
|
+
type: 'Feature',
|
|
182
|
+
properties: __assign({}, this.properties),
|
|
183
|
+
geometry: this.toGeoJSON(format)
|
|
184
|
+
};
|
|
185
|
+
};
|
|
173
186
|
DPoint.prototype.findLine = function (p) {
|
|
174
187
|
checkFunction('findLine')
|
|
175
188
|
.checkArgument('this')
|
|
@@ -688,14 +701,14 @@ var DPoint = (function () {
|
|
|
688
701
|
enumerable: false,
|
|
689
702
|
configurable: true
|
|
690
703
|
});
|
|
691
|
-
DPoint.prototype.simple = function (xKey, yKey) {
|
|
692
|
-
var _a;
|
|
704
|
+
DPoint.prototype.simple = function (xKey, yKey, zKey) {
|
|
705
|
+
var _a, _b;
|
|
693
706
|
if (xKey === void 0) { xKey = 'x'; }
|
|
694
707
|
if (yKey === void 0) { yKey = 'y'; }
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
708
|
+
if (zKey === void 0) { zKey = 'z'; }
|
|
709
|
+
return __assign((_a = {}, _a[xKey] = this.x, _a[yKey] = this.y, _a), (isDefAndNotNull(this.z) ? (_b = {},
|
|
710
|
+
_b[zKey] = this.z,
|
|
711
|
+
_b) : {}));
|
|
699
712
|
};
|
|
700
713
|
DPoint.prototype.setIfLessThan = function (p) {
|
|
701
714
|
this.x = Math.max(this.x, p.x);
|
package/dist/esm/DPolygon.js
CHANGED
|
@@ -78,7 +78,7 @@ import { DCircle } from './DCircle';
|
|
|
78
78
|
import { DNumbers } from './DNumbers';
|
|
79
79
|
import { io as jstsIo, operation } from 'jsts';
|
|
80
80
|
import { DPolygonLoop } from './DPolygonLoop';
|
|
81
|
-
import { isDefAndNotNull } from './utils';
|
|
81
|
+
import { DGeo, isDefAndNotNull } from './utils';
|
|
82
82
|
var _a = operation.buffer.BufferParameters, CAP_ROUND = _a.CAP_ROUND, CAP_FLAT = _a.CAP_FLAT, CAP_SQUARE = _a.CAP_SQUARE;
|
|
83
83
|
export var MIN_POINTS_IN_VALID_POLYGON = 3;
|
|
84
84
|
var APPROXIMATION_VALUE = 0.1;
|
|
@@ -964,14 +964,14 @@ var DPolygon = (function () {
|
|
|
964
964
|
return this;
|
|
965
965
|
};
|
|
966
966
|
DPolygon.toGeoJSONFeatureCollection = function (polygons, format) {
|
|
967
|
-
if (format === void 0) { format =
|
|
967
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
968
968
|
return {
|
|
969
969
|
type: 'FeatureCollection',
|
|
970
970
|
features: polygons.map(function (polygon) { return polygon.toGeoJSONFeature(format); })
|
|
971
971
|
};
|
|
972
972
|
};
|
|
973
973
|
DPolygon.parse = function (a, format) {
|
|
974
|
-
if (format === void 0) { format =
|
|
974
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
975
975
|
if (a.type) {
|
|
976
976
|
switch (a.type) {
|
|
977
977
|
case 'FeatureCollection':
|
|
@@ -987,7 +987,14 @@ var DPolygon = (function () {
|
|
|
987
987
|
}, []);
|
|
988
988
|
case 'Feature': {
|
|
989
989
|
var t = DPolygon.parse(a.geometry, format);
|
|
990
|
-
|
|
990
|
+
if (Array.isArray(t)) {
|
|
991
|
+
t.forEach(function (record) {
|
|
992
|
+
record.properties = __assign(__assign({}, a.properties), { id: a.id });
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
t.properties = __assign(__assign({}, a.properties), { id: a.id });
|
|
997
|
+
}
|
|
991
998
|
return t;
|
|
992
999
|
}
|
|
993
1000
|
case 'LineString':
|
|
@@ -1028,11 +1035,11 @@ var DPolygon = (function () {
|
|
|
1028
1035
|
.map(function (r) { return DPoint.parse(r, format); }));
|
|
1029
1036
|
};
|
|
1030
1037
|
DPolygon.prototype.toArrayOfCoords = function (format) {
|
|
1031
|
-
if (format === void 0) { format =
|
|
1038
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
1032
1039
|
return this.mapArray(function (r) { return r.toCoords(format); });
|
|
1033
1040
|
};
|
|
1034
1041
|
DPolygon.prototype.toGeoJSONFeature = function (format) {
|
|
1035
|
-
if (format === void 0) { format =
|
|
1042
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
1036
1043
|
return {
|
|
1037
1044
|
type: 'Feature',
|
|
1038
1045
|
properties: __assign({}, this.properties),
|
|
@@ -1040,7 +1047,7 @@ var DPolygon = (function () {
|
|
|
1040
1047
|
};
|
|
1041
1048
|
};
|
|
1042
1049
|
DPolygon.prototype.toGeoJSON = function (format) {
|
|
1043
|
-
if (format === void 0) { format =
|
|
1050
|
+
if (format === void 0) { format = DGeo.parseFormat; }
|
|
1044
1051
|
if (this.closed) {
|
|
1045
1052
|
return {
|
|
1046
1053
|
type: 'Polygon',
|
package/dist/esm/utils.js
CHANGED
|
@@ -25,7 +25,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
};
|
|
26
26
|
import { DPoint } from './DPoint';
|
|
27
27
|
export var DGeo = {
|
|
28
|
-
DEBUG: false
|
|
28
|
+
DEBUG: false,
|
|
29
|
+
parseFormat: 'xyz'
|
|
29
30
|
};
|
|
30
31
|
export var warn = function () {
|
|
31
32
|
var args = [];
|
|
@@ -99,12 +100,18 @@ export var checkFunction = function (funcName) { return ({
|
|
|
99
100
|
}
|
|
100
101
|
}); };
|
|
101
102
|
export var createArray = function (v, fillSymbol) {
|
|
102
|
-
if (fillSymbol ===
|
|
103
|
-
|
|
103
|
+
if (typeof fillSymbol === 'function') {
|
|
104
|
+
return new Array(v).fill(false)
|
|
105
|
+
.map(function (_, i) { return fillSymbol(i); });
|
|
106
|
+
}
|
|
107
|
+
return new Array(v).fill(fillSymbol !== null && fillSymbol !== void 0 ? fillSymbol : 0);
|
|
104
108
|
};
|
|
105
109
|
export var createMatrix = function (_a, fillSymbol) {
|
|
106
110
|
var h = _a.h, w = _a.w;
|
|
107
|
-
if (fillSymbol ===
|
|
111
|
+
if (typeof fillSymbol === 'function') {
|
|
112
|
+
return createArray(h)
|
|
113
|
+
.map(function (_, y) { return createArray(w, function (x) { return fillSymbol(x, y); }); });
|
|
114
|
+
}
|
|
108
115
|
return createArray(h)
|
|
109
116
|
.map(function () { return createArray(w, fillSymbol); });
|
|
110
117
|
};
|