forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometry.js
More file actions
309 lines (308 loc) · 12.2 KB
/
Geometry.js
File metadata and controls
309 lines (308 loc) · 12.2 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
import Module from '../../../libs/UGCWasmAll';
import { geojson2UGGeometry, geojsonCoordsToPoint2Ds, ugGeometry2Geojson, getJSArrayFromUGDoubleArray, geojsonCoords2UGDoubleArray } from '../wasm/util';
export const GeometryUtil = {
buffer(geojson, radius) {
const ugcGeojson = geojson2UGGeometry(geojson);
const buffer = Module._UGCWasm_Geometrist_Buffer(ugcGeojson, radius);
const geometry = ugGeometry2Geojson(buffer);
return {
type: "Feature",
geometry
}
},
intersect(feature1, feature2, tolerance = 1e-6) {
if (this.hasOverlap(feature1, feature2, tolerance)) {
const ugFeature1 = geojson2UGGeometry(feature1);
const ugFeature2 = geojson2UGGeometry(feature2);
const pOverlapRegion = Module._UGCWasm_Geometrist_Intersect(ugFeature1, ugFeature2, tolerance);
if (pOverlapRegion !== 0) {
return {
type: "Feature",
geometry: ugGeometry2Geojson(pOverlapRegion)
};
}
}
},
computeConvexHull(points, size) {
const ugPoints = geojsonCoordsToPoint2Ds(points);
var result = Module._UGCWasm_Geometrist_ComputeConvexHull(ugPoints, size);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
}
},
isIdentical(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_IsIdentical(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
union(geojson1, geojson2) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Union(ugFeature1, ugFeature2);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
union2(geojson1, geojson2, tolerance) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Union2(ugFeature1, ugFeature2, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
isDisjointed(geojson1, geojson2, tolerance = 1e-6) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_IsDisjointed(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
hasIntersection(geojson1, geojson2, tolerance = 1e-6) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_HasIntersection(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
hasAreaIntersection(geojson1, geojson2, tolerance) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_HasAreaIntersection(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
hasTouch(geojson1, geojson2, tolerance = 1e-6) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_HasTouch(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
hasCross(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_HasCross(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
isWithin(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_IsWithin(ugFeature1, ugFeature2, tolerance);
return result === 1;
},
erase(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Erase(ugFeature1, ugFeature2, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
hasOverlap(feature1, feature2, tolerance) {
const ugFeature1 = geojson2UGGeometry(feature1);
const ugFeature2 = geojson2UGGeometry(feature2);
return Module._UGCWasm_Geometrist_HasOverlap(ugFeature1, ugFeature2, tolerance);
},
update(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Update(ugFeature1, ugFeature2, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
identity(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Identity(ugFeature1, ugFeature2, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
xor(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_XOR(ugFeature1, ugFeature2, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
clip(geojson1, geojson2, tolerance = 1e-10) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Clip(ugFeature1, ugFeature2, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
resample(geojson, tolerance) {
const ugFeature = geojson2UGGeometry(geojson);
const result = Module._UGCWasm_Geometrist_Resample(ugFeature, tolerance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
distance(geojson1, geojson2) {
const ugFeature1 = geojson2UGGeometry(geojson1);
const ugFeature2 = geojson2UGGeometry(geojson2);
const result = Module._UGCWasm_Geometrist_Distance(ugFeature1, ugFeature2);
return result;
},
// 无效
// closestPoint(geojson1, geojson2) {
// const ugFeature1 = geojson2UGGeometry(geojson1);
// const ugFeature2 = geojson2UGGeometry(geojson2);
// const result = Module._UGCWasm_Geometrist_ClosestPoint(ugFeature1, ugFeature2, 1e-10);
// return {
// type: "Feature",
// geometry: ugGeometry2Geojson(result)
// };
// },
isParallel(x1, y1, x2, y2, x3, y3, x4, y4) {
const result = Module._UGCWasm_Geometrist_IsParallel(x1, y1, x2, y2, x3, y3, x4, y4);
return result === 1;
},
isPerpendicular(x1, y1, x2, y2, x3, y3, x4, y4) {
const result = Module._UGCWasm_Geometrist_IsPerpendicular(x1, y1, x2, y2, x3, y3, x4, y4);
return result === 1;
},
computePerpendicularPosition(x1, y1, x2, y2, x3, y3) {
let values = Module._UGCWasm_Helper_CreateDoubleArray(0, 2);
Module._UGCWasm_Geometrist_ComputePerpendicularPosition(x1, y1, x2, y2, x3, y3, values);
const coords = getJSArrayFromUGDoubleArray(values);
values = coords;
return values;
},
isPointOnLine(x1, y1, x2, y2, x3, y3, extended) {
const result = Module._UGCWasm_Geometrist_IsPointOnLine(x1, y1, x2, y2, x3, y3, extended);
return result === 1;
},
isProjectOnLineSegment(px, py, spx, spy, epx, epy) {
const result = Module._UGCWasm_Geometrist_IsProjectOnLineSegment(px, py, spx, spy, epx, epy);
return result === 1;
},
distanceToLineSegment(px, py, spx, spy, epx, epy) {
return Module._UGCWasm_Geometrist_DistanceToLineSegment(px, py, spx, spy, epx, epy);
},
nearestPointToVertex(px, py, geojson) {
let values = Module._UGCWasm_Helper_CreateDoubleArray(0, 2);
const ugFeature = geojson2UGGeometry(geojson);
const result = Module._UGCWasm_Geometrist_NearestPointToVertex(px, py, ugFeature, values);
const coords = getJSArrayFromUGDoubleArray(values);
values = coords;
return { find: result === 1, values };
},
computeConcaveHullPoints(xArray, yArray, angle) {
let pXArray = geojsonCoords2UGDoubleArray(xArray);
let pYArray = geojsonCoords2UGDoubleArray(yArray);
let pGeoRegionHull = Module._UGCWasm_Geometrist_ComputeConcaveHullPoints(pXArray, pYArray, xArray.length, angle);
var polyJson = ugGeometry2Geojson(pGeoRegionHull);
return {
type: "Feature",
geometry: polyJson
};
},
isSegmentIntersect(x1, y1, x2, y2, x3, y3, x4, y4) {
const result = Module._UGCWasm_Geometrist_IsSegmentIntersect(x1, y1, x2, y2, x3, y3, x4, y4);
return result === 1;
},
isIntersectRegionWithRect(geojson, left, top, right, bottom) {
const ugFeature = geojson2UGGeometry(geojson);
return Module._UGCWasm_Geometrist_isIntersectRegionWithRect(ugFeature, left, top, right, bottom);
},
// linearFitting(xArray, yArray, degree) {
// let pXArray = geojsonCoords2UGDoubleArray(xArray);
// let pYArray = geojsonCoords2UGDoubleArray(yArray);
// let pGeoRegionHull = Module._UGCWasm_Geometrist_LinearFitting(pXArray, pYArray, xArray.length, degree);
// const features = [];
// var polyJson = ugGeometry2Geojson(pGeoRegionHull);
// const feature = {
// type: "Feature",
// geometry: polyJson
// }
// features.push(feature);
// return {
// "type": "FeatureCollection",
// "features": features
// }
// },
isOnSameSide(px1, py1, px2, py2, spx, spy, epx, epy) {
const result = Module._UGCWasm_Geometrist_IsOnSameSide(px1, py1, px2, py2, spx, spy, epx, epy);
return result === 1;
},
isRight(px, py, spx, spy, epx, epy) {
const result = Module._UGCWasm_Geometrist_IsRight(px, py, spx, spy, epx, epy);
return result === 1;
},
isLeft(px, py, spx, spy, epx, epy) {
const result = Module._UGCWasm_Geometrist_IsLeft(px, py, spx, spy, epx, epy);
return result === 1;
},
// computeGeodesicArea(geojson, epsgCode) {
// const ugFeature = geojson2UGGeometry(geojson);
// const prjCoordSys = Module._UGCWasm_Geometry_NewUGPrjCoordSys(epsgCode);
// return Module._UGCWasm_Geometrist_ComputeGeodesicArea(ugFeature, prjCoordSys);
// },
computeGeodesicArea(geojson, prjCoordSys) {
const ugFeature = geojson2UGGeometry(geojson);
return Module._UGCWasm_Geometrist_ComputeGeodesicArea(ugFeature, prjCoordSys);
},
hasHollow(geojson) {
const ugFeature = geojson2UGGeometry(geojson);
const result = Module._UGCWasm_Geometrist_HasHollow(ugFeature);
return result === 1;
},
clipRect(geojson, left, top, right, bottom) {
const ugFeature = geojson2UGGeometry(geojson);
const result = Module._UGCWasm_Geometrist_ClipRect(ugFeature, left, top, right, bottom);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
smooth(geojson, smoothness = 2) {
const ugFeature = geojson2UGGeometry(geojson);
const result = Module._UGCWasm_Geometrist_Smooth(ugFeature, smoothness);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
computeGeodesicDistance(xArray, yArray, majorAxis, flatten) {
let pXArray = geojsonCoords2UGDoubleArray(xArray);
let pYArray = geojsonCoords2UGDoubleArray(yArray);
return Module._UGCWasm_Geometrist_ComputeGeodesicDistance(pXArray, pYArray, majorAxis, flatten);
},
computeParallel(geojson, distance) {
const ugFeature = geojson2UGGeometry(geojson);
const result = Module._UGCWasm_Geometrist_ComputeParallel(ugFeature, distance);
return {
type: "Feature",
geometry: ugGeometry2Geojson(result)
};
},
computeConvexHullPoints(xArray, yArray) {
let pXArray = geojsonCoords2UGDoubleArray(xArray);
let pYArray = geojsonCoords2UGDoubleArray(yArray);
let pGeoRegionHull = Module._UGCWasm_Geometrist_ComputeConvexHullPoints(pXArray, pYArray, xArray.length);
var polyJson = ugGeometry2Geojson(pGeoRegionHull);
return {
type: "Feature",
geometry: polyJson
};
},
intersectLine(x1, y1, x2, y2, x3, y3, x4, y4, extended) {
let values = Module._UGCWasm_Helper_CreateDoubleArray(0, 2);
const result = Module._UGCWasm_Geometrist_IntersectLine(x1, y1, x2, y2, x3, y3, x4, y4, extended, values);
const coords = getJSArrayFromUGDoubleArray(values);
values = coords;
return { intersect: result === 1, values };
}
}