forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometryAnalysis.js
More file actions
422 lines (421 loc) · 16.6 KB
/
GeometryAnalysis.js
File metadata and controls
422 lines (421 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import { geojson2UGGeometry, geojsonCoordsToPoint2Ds, ugGeometry2Geojson, getJSArrayFromUGDoubleArray, geojsonCoords2UGDoubleArray } from '../wasm/util';
import { Events } from '../commontypes/Events';
import * as defaultModule from './UGCWasmAll';
/**
* @class GeometryAnalysis
* @category BaseTypes Util
* @classdesc 几何分析。
* @param {Object} [Module] - 几何分析模块。
* @usage
* ```
* // 浏览器
* <script type="text/javascript" src="{cdn}"></script>
* <script type="text/javascript" src="https://iclient.supermap.io/web/libs/ugcwasm/1.0.0/UGCWasmAll.js"></script>
* <script>
* new {namespace}.GeometryAnalysis(Module);
*
* </script>
*
* // ES6 Import
* import { GeometryAnalysis } from "{npm}";
*
* new GeometryAnalysis();
* ```
*/
export class GeometryAnalysis extends Events {
constructor(Module) {
super();
if (Module) {
window.Module = Module;
}
if (!window.Module) {
window.Module = defaultModule;
}
this.module = window.Module;
this.addEventType('loaded');
if (this.module.calledRun) {
this.triggerEvent('loaded', {});
} else {
this.module.onRuntimeInitialized = () => {
this.triggerEvent('loaded', {});
}
}
}
/**
* @function GeometryAnalysis.prototype.buffer
* @version 11.2.0
* @description 缓冲区分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {number} radius - 缓冲区距离,单位与数据单位一致。
* @returns {GeoJSONFeature} 结果要素。
*/
buffer(feature, radius) {
const ugcGeojson = geojson2UGGeometry(feature);
const buffer = this.module._UGCWasm_Geometrist_Buffer(ugcGeojson, radius);
const geometry = ugGeometry2Geojson(buffer);
return {
type: "Feature",
geometry
}
}
/**
* @function GeometryAnalysis.prototype.computeConvexHull
* @version 11.2.0
* @description 凸多边形计算。
* @param {Array} points - 点坐标数组。
* @returns {GeoJSONFeature} 结果要素。
*/
computeConvexHull(points) {
const size = points.length;
const ugPoints = geojsonCoordsToPoint2Ds(points);
var result = this.module._UGCWasm_Geometrist_ComputeConvexHull(ugPoints, size);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
}
}
/**
* @function GeometryAnalysis.prototype.isIdentical
* @version 11.2.0
* @description 几何对象相等分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {GeoJSONFeature} compareFeature - geojson 对比要素。
* @param {number} [tolerance=1e-6] - 容限。
* @returns {boolean} 要素是否完全相等。
*/
isIdentical(feature, compareFeature, tolerance = 1e-6) {
const ugFeature1 = geojson2UGGeometry(feature);
const ugFeature2 = geojson2UGGeometry(compareFeature);
const result = this.module._UGCWasm_Geometrist_IsIdentical(ugFeature1, ugFeature2, tolerance);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.hasIntersection
* @version 11.2.0
* @description 几何对象是否相交分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {GeoJSONFeature} compareFeature - geojson 对比要素。
* @param {number} [tolerance=1e-6] - 容限。
* @returns {boolean} 要素是否相交。
*/
hasIntersection(feature, compareFeature, tolerance = 1e-6) {
const ugFeature1 = geojson2UGGeometry(feature);
const ugFeature2 = geojson2UGGeometry(compareFeature);
const result = this.module._UGCWasm_Geometrist_HasIntersection(ugFeature1, ugFeature2, tolerance);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.hasTouch
* @version 11.2.0
* @description 几何对象边界是否接触分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {GeoJSONFeature} compareFeature - geojson 对比要素。
* @param {number} [tolerance=1e-6] - 容限。
* @returns {boolean} 几何对象边界是否接触。
*/
hasTouch(feature, compareFeature, tolerance = 1e-6) {
const ugFeature1 = geojson2UGGeometry(feature);
const ugFeature2 = geojson2UGGeometry(compareFeature);
const result = this.module._UGCWasm_Geometrist_HasTouch(ugFeature1, ugFeature2, tolerance);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.resample
* @version 11.2.0
* @description 重采样分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {number} [tolerance=1e-6] - 容限。
* @returns {GeoJSONFeature} 结果要素。
*/
resample(feature, tolerance = 1e-6) {
const ugFeature = geojson2UGGeometry(feature);
const result = this.module._UGCWasm_Geometrist_Resample(ugFeature, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
}
/**
* @function GeometryAnalysis.prototype.isParallel
* @version 11.2.0
* @description 线平行分析。
* @param {number} x1 - 第一条线的起点X。
* @param {number} y1 - 第一条线的起点Y。
* @param {number} x2 - 第一条线的终点X。
* @param {number} y2 - 第一条线的终点Y。
* @param {number} x3 - 第二条线的起点X。
* @param {number} y3 - 第二条线的起点Y。
* @param {number} x4 - 第二条线的终点X。
* @param {number} y4 - 第二条线的终点Y。
* @returns {boolean} 两条线是否平行。
*/
isParallel(x1, y1, x2, y2, x3, y3, x4, y4) {
const result = this.module._UGCWasm_Geometrist_IsParallel(x1, y1, x2, y2, x3, y3, x4, y4);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.computePerpendicularPosition
* @version 11.2.0
* @description 点到线的垂线分析。
* @param {number} x1 - 点坐标 X。
* @param {number} y1 - 点坐标 Y。
* @param {number} x2 - 第一条线的起点X。
* @param {number} y2 - 第一条线的起点Y。
* @param {number} x3 - 第一条线的终点X。
* @param {number} y3 - 第一条线的终点Y。
* @returns {Array} 垂线点坐标。
*/
computePerpendicularPosition(x1, y1, x2, y2, x3, y3) {
let values = this.module._UGCWasm_Helper_CreateDoubleArray(0, 2);
this.module._UGCWasm_Geometrist_ComputePerpendicularPosition(x1, y1, x2, y2, x3, y3, values);
const coords = getJSArrayFromUGDoubleArray(values);
values = coords;
return values;
}
/**
* @function GeometryAnalysis.prototype.isPointOnLine
* @version 11.2.0
* @description 点是否在已知线段上。
* @param {number} x1 - 点坐标 X。
* @param {number} y1 - 点坐标 Y。
* @param {number} x2 - 第一条线的起点X。
* @param {number} y2 - 第一条线的起点Y。
* @param {number} x3 - 第一条线的终点X。
* @param {number} y3 - 第一条线的终点Y。
* @param {boolean} extended - 是否将线段进行延长计算。
* @returns {boolean} 点是否在已知线段上。
*/
isPointOnLine(x1, y1, x2, y2, x3, y3, extended) {
const result = this.module._UGCWasm_Geometrist_IsPointOnLine(x1, y1, x2, y2, x3, y3, extended);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.isProjectOnLineSegment
* @version 11.2.0
* @description 判断点到线段的垂足是否在该线段上。
* @param {number} px- 点 X 坐标。
* @param {number} px - 点 Y 坐标。
* @param {number} spx - 线起点 X 坐标。
* @param {number} spy - 线起点 Y 坐标。
* @param {number} epx - 线终点 X 坐标。
* @param {number} epy - 线终点 Y 坐标。
* @returns {boolean} 点到线段的垂足是否在该线段上。
*/
isProjectOnLineSegment(px, py, spx, spy, epx, epy) {
const result = this.module._UGCWasm_Geometrist_IsProjectOnLineSegment(px, py, spx, spy, epx, epy);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.distanceToLineSegment
* @version 11.2.0
* @description 计算点到线段的距离。
* @param {number} px- 点 X 坐标。
* @param {number} px - 点 Y 坐标。
* @param {number} spx - 线起点 X 坐标。
* @param {number} spy - 线起点 Y 坐标。
* @param {number} epx - 线终点 X 坐标。
* @param {number} epy - 线终点 Y 坐标。
* @returns {number} 点到线段的距离。如果点到线段的垂足不在线段上,则返回点到线段较近的端点的距离。。
*/
distanceToLineSegment(px, py, spx, spy, epx, epy) {
return this.module._UGCWasm_Geometrist_DistanceToLineSegment(px, py, spx, spy, epx, epy);
}
/**
* @function GeometryAnalysis.prototype.nearestPointToVertex
* @version 11.2.0
* @description 计算线到点的最近距离点。
* @param {number} px - 点 X 坐标。
* @param {number} py - 点 Y 坐标。
* @param {GeoJSONFeature} lineFeature - geojson 线要素。
* @returns {Array} 线到点最近点的坐标数组。
*/
nearestPointToVertex(px, py, lineFeature) {
let values = this.module._UGCWasm_Helper_CreateDoubleArray(0, 2);
const ugFeature = geojson2UGGeometry(lineFeature);
this.module._UGCWasm_Geometrist_NearestPointToVertex(px, py, ugFeature, values);
const coords = getJSArrayFromUGDoubleArray(values);
values = coords;
return values;
}
/**
* @function GeometryAnalysis.prototype.computeConcaveHullPoints
* @version 11.2.0
* @description 点数组凹闭包计算。
* @param {Array} xArray - x 坐标数组。
* @param {Array} yArray - y 坐标数组。
* @param {number} angle - 凹包内最小角度。
* @returns {GeoJSONFeature} 结果要素。
*/
computeConcaveHullPoints(xArray, yArray, angle) {
let pXArray = geojsonCoords2UGDoubleArray(xArray);
let pYArray = geojsonCoords2UGDoubleArray(yArray);
let pGeoRegionHull = this.module._UGCWasm_Geometrist_ComputeConcaveHullPoints(pXArray, pYArray, xArray.length, angle);
var polyJson = ugGeometry2Geojson(pGeoRegionHull);
return {
type: "Feature",
geometry: polyJson
};
}
/**
* @function GeometryAnalysis.prototype.isSegmentIntersect
* @version 11.2.0
* @description 计算线段是否相交。
* @param {number} x1 - 第一条线的起点X。
* @param {number} y1 - 第一条线的起点Y。
* @param {number} x2 - 第一条线的终点X。
* @param {number} y2 - 第一条线的终点Y。
* @param {number} x3 - 第二条线的起点X。
* @param {number} y3 - 第二条线的起点Y。
* @param {number} x4 - 第二条线的终点X。
* @param {number} y4 - 第二条线的终点Y。
* @returns {boolean} 线是否相交。
*/
isSegmentIntersect(x1, y1, x2, y2, x3, y3, x4, y4) {
const result = this.module._UGCWasm_Geometrist_IsSegmentIntersect(x1, y1, x2, y2, x3, y3, x4, y4);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.isIntersectRegionWithRect
* @version 11.2.0
* @description 几何对象与矩形是否相交分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {number} left - 矩形左坐标。
* @param {number} top - 矩形上坐标。
* @param {number} right - 矩形右坐标。
* @param {number} bottom - 矩形下坐标。
* @param {number} [tolerance=1e-6] - 容限。
* @returns {boolean} 要素是否与矩形相交。
*/
isIntersectRegionWithRect(feature, left, top, right, bottom, tolerance = 1e-6) {
const ugFeature = geojson2UGGeometry(feature);
const result = this.module._UGCWasm_Geometrist_isIntersectRegionWithRect(ugFeature, left, top, right, bottom, tolerance);
return result !== 0;
}
/**
* @function GeometryAnalysis.prototype.isOnSameSide
* @version 11.2.0
* @description 判断两点是否在线的同一侧。
* @param {number} px1- 点1 X 坐标。
* @param {number} px2 - 点1 Y 坐标。
* @param {number} px1- 点2 X 坐标。
* @param {number} px2 - 点2 Y 坐标。
* @param {number} spx - 线起点 X 坐标。
* @param {number} spy - 线起点 Y 坐标。
* @param {number} epx - 线终点 X 坐标。
* @param {number} epy - 线终点 Y 坐标。
* @returns {boolean} 是否两点在线的同一侧。
*/
isOnSameSide(px1, py1, px2, py2, spx, spy, epx, epy) {
const result = this.module._UGCWasm_Geometrist_IsOnSameSide(px1, py1, px2, py2, spx, spy, epx, epy);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.isRight
* @version 11.2.0
* @description 判断点是否在线的右侧。
* @param {number} px- 点 X 坐标。
* @param {number} px - 点 Y 坐标。
* @param {number} spx - 线起点 X 坐标。
* @param {number} spy - 线起点 Y 坐标。
* @param {number} epx - 线终点 X 坐标。
* @param {number} epy - 线终点 Y 坐标。
* @returns {boolean} 点是否在线的右侧。
*/
isRight(px, py, spx, spy, epx, epy) {
const result = this.module._UGCWasm_Geometrist_IsRight(px, py, spx, spy, epx, epy);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.isLeft
* @version 11.2.0
* @description 判断点是否在线的左侧。
* @param {number} px- 点 X 坐标。
* @param {number} px - 点 Y 坐标。
* @param {number} spx - 线起点 X 坐标。
* @param {number} spy - 线起点 Y 坐标。
* @param {number} epx - 线终点 X 坐标。
* @param {number} epy - 线终点 Y 坐标。
* @returns {boolean} 点是否在线的左侧。
*/
isLeft(px, py, spx, spy, epx, epy) {
const result = this.module._UGCWasm_Geometrist_IsLeft(px, py, spx, spy, epx, epy);
return result === 1;
}
/**
* @function GeometryAnalysis.prototype.computeGeodesicArea
* @version 11.2.0
* @description 计算经纬度面积。
* @param {GeoJSONFeature} feature - geojson 面要素。
* @returns {number} 经纬度面积,结果单位与参数单位一致。
*/
computeGeodesicArea(feature) {
const ugFeature = geojson2UGGeometry(feature);
const prjCoordSys = this.module._UGCWasm_Geometry_NewUGPrjCoordSys(4326);
return this.module._UGCWasm_Geometrist_ComputeGeodesicArea(ugFeature, prjCoordSys);
}
/**
* @function GeometryAnalysis.prototype.smooth
* @version 11.2.0
* @description 线要素光滑分析。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {number} [smoothness=2] - 光滑系数。
* @returns {GeoJSONFeature} 结果要素。
*/
smooth(feature, smoothness = 2) {
const ugFeature = geojson2UGGeometry(feature);
const result = this.module._UGCWasm_Geometrist_Smooth(ugFeature, smoothness);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
}
/**
* @function GeometryAnalysis.prototype.computeGeodesicDistance
* @version 11.2.0
* @description 计算测地线长度。
* @param {Array} xArray - x 坐标数组。
* @param {Array} yArray - y 坐标数组。
* @param {number} majorAxis - 测地线所在椭球体的长轴,单位为米。
* @param {number} flatten - 测地线所在椭球体的扁率。
* @returns {number} 测地线的长度,结果单位为米。
*/
computeGeodesicDistance(xArray, yArray, majorAxis, flatten) {
let pXArray = geojsonCoords2UGDoubleArray(xArray);
let pYArray = geojsonCoords2UGDoubleArray(yArray);
return this.module._UGCWasm_Geometrist_ComputeGeodesicDistance(pXArray, pYArray, majorAxis, flatten);
}
/**
* @function GeometryAnalysis.prototype.computeParallel
* @version 11.2.0
* @description 根据距离获取线要素的平行线。
* @param {GeoJSONFeature} feature - geojson 要素。
* @param {number} distance - 平行线距离,单位与数据单位一致。
* @returns {GeoJSONFeature} 结果要素。
*/
computeParallel(feature, distance) {
const ugFeature = geojson2UGGeometry(feature);
const result = this.module._UGCWasm_Geometrist_ComputeParallel(ugFeature, distance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
}
/**
* @function GeometryAnalysis.prototype.computeConvexHullPoints
* @version 11.2.0
* @description 点数组的凸闭包计算,即最小外接多边形。
* @param {Array} xArray - x 坐标数组。
* @param {Array} yArray - y 坐标数组。
* @returns {GeoJSONFeature} 结果要素。
*/
computeConvexHullPoints(xArray, yArray) {
let pXArray = geojsonCoords2UGDoubleArray(xArray);
let pYArray = geojsonCoords2UGDoubleArray(yArray);
let pGeoRegionHull = this.module._UGCWasm_Geometrist_ComputeConvexHullPoints(pXArray, pYArray, xArray.length);
var polyJson = ugGeometry2Geojson(pGeoRegionHull);
return {
type: "Feature",
geometry: polyJson
};
}
}