@sap/cds 1.15.1 → 1.17.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/CHANGELOG.md +19 -0
- package/{developer-license-3.1.txt → LICENSE} +37 -35
- package/_hdbext/README.md +373 -0
- package/_hdbext/index.js +4 -0
- package/_hdbext/lib/client-factory.js +62 -0
- package/_hdbext/lib/client-session.js +96 -0
- package/_hdbext/lib/conn-options.js +84 -0
- package/_hdbext/lib/constants.js +79 -0
- package/_hdbext/lib/internal-constants.js +7 -0
- package/_hdbext/lib/middleware.js +46 -0
- package/_hdbext/lib/pool.js +236 -0
- package/_hdbext/lib/safe-sql.js +17 -0
- package/_hdbext/lib/sql-injection-utils.js +149 -0
- package/cds-queries-geo.js +347 -371
- package/cds-queries.js +2692 -2229
- package/cds.js +111 -104
- package/exprs.js +118 -107
- package/manager.js +696 -614
- package/metadata.js +604 -542
- package/npm-shrinkwrap.json +175 -0
- package/package.json +40 -1
- package/transaction.js +45 -51
- package/util/Queue.js +32 -30
- package/utils.js +182 -159
- package/xsjs-cds.js +231 -221
- package/.project +0 -11
- package/SIGNATURE.SMF +0 -1747
- package/TUTORIAL.md +0 -1236
- package/dependencies +0 -56
package/cds-queries-geo.js
CHANGED
|
@@ -1,85 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const queries = require('./cds-queries');
|
|
2
|
+
const Expr = queries.Query.F;
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/** *******************************************************************************
|
|
6
6
|
* Spatial methods
|
|
7
7
|
*********************************************************************************/
|
|
8
|
-
queries.Query.F.$convexHull = geoPostfix(
|
|
9
|
-
queries.Query.F.$area = geoPostfix(
|
|
10
|
-
queries.Query.F.$buffer = geoPostfix(
|
|
11
|
-
queries.Query.F.$boundary = geoPostfix(
|
|
12
|
-
queries.Query.F.$contains = geoPostfix(
|
|
13
|
-
queries.Query.F.$covers = geoPostfix(
|
|
14
|
-
queries.Query.F.$coveredBy = geoPostfix(
|
|
15
|
-
queries.Query.F.$crosses = geoPostfix(
|
|
16
|
-
queries.Query.F.$isEmpty = geoPostfix(
|
|
17
|
-
queries.Query.F.$isSimple = geoPostfix(
|
|
18
|
-
queries.Query.F.$disjoint = geoPostfix(
|
|
19
|
-
queries.Query.F.$equals = geoPostfix(
|
|
20
|
-
queries.Query.F.$overlaps = geoPostfix(
|
|
21
|
-
queries.Query.F.$intersects = geoPostfix(
|
|
22
|
-
queries.Query.F.$centroid = geoPostfix(
|
|
23
|
-
queries.Query.F.$difference = geoPostfix(
|
|
24
|
-
queries.Query.F.$dimension = geoPostfix(
|
|
25
|
-
queries.Query.F.$distance = geoPostfix(
|
|
26
|
-
queries.Query.F.$endPoint = geoPostfix(
|
|
27
|
-
queries.Query.F.$envelope = geoPostfix(
|
|
28
|
-
queries.Query.F.$exteriorRing = geoPostfix(
|
|
29
|
-
queries.Query.F.$geometryType = geoPostfix(
|
|
30
|
-
queries.Query.F.$geometryN = geoPostfix(
|
|
31
|
-
queries.Query.F.$interiorRingN = geoPostfix(
|
|
32
|
-
queries.Query.F.$intersection = geoPostfix(
|
|
33
|
-
queries.Query.F.$intersectsFilter = geoPostfix(
|
|
34
|
-
queries.Query.F.$intersectsRect = geoPostfix(
|
|
35
|
-
queries.Query.F.$is3D = geoPostfix(
|
|
36
|
-
queries.Query.F.$isClosed = geoPostfix(
|
|
37
|
-
queries.Query.F.$isRing = geoPostfix(
|
|
38
|
-
queries.Query.F.$isValid = geoPostfix(
|
|
39
|
-
queries.Query.F.$length = geoPostfix(
|
|
40
|
-
queries.Query.F.$numGeometries = geoPostfix(
|
|
41
|
-
queries.Query.F.$numInteriorRing = geoPostfix(
|
|
42
|
-
queries.Query.F.$numInteriorRings = geoPostfix(
|
|
43
|
-
queries.Query.F.$numPoints = geoPostfix(
|
|
44
|
-
queries.Query.F.$orderingEquals = geoPostfix(
|
|
45
|
-
queries.Query.F.$pointN = geoPostfix(
|
|
46
|
-
queries.Query.F.$pointOnSurface = geoPostfix(
|
|
47
|
-
queries.Query.F.$relate = geoPostfix(
|
|
48
|
-
queries.Query.F.$srid = geoPostfix(
|
|
49
|
-
queries.Query.F.$snapToGrid = geoPostfix(
|
|
50
|
-
queries.Query.F.$symDifference = geoPostfix(
|
|
51
|
-
queries.Query.F.$touches = geoPostfix(
|
|
52
|
-
|
|
53
|
-
//queries.Query.F.$unionAggr = geoPostfix("ST_UnionAggr", [1]);
|
|
8
|
+
queries.Query.F.$convexHull = geoPostfix('ST_ConvexHull', [0]);
|
|
9
|
+
queries.Query.F.$area = geoPostfix('ST_Area', [0, 1]);
|
|
10
|
+
queries.Query.F.$buffer = geoPostfix('ST_Buffer', [1, 2]);
|
|
11
|
+
queries.Query.F.$boundary = geoPostfix('ST_Boundary', [0]);
|
|
12
|
+
queries.Query.F.$contains = geoPostfix('ST_Contains', [1]);
|
|
13
|
+
queries.Query.F.$covers = geoPostfix('ST_Covers', [1]);
|
|
14
|
+
queries.Query.F.$coveredBy = geoPostfix('ST_CoveredBy', [1]);
|
|
15
|
+
queries.Query.F.$crosses = geoPostfix('ST_Crosses', [1]);
|
|
16
|
+
queries.Query.F.$isEmpty = geoPostfix('ST_IsEmpty', [0]);
|
|
17
|
+
queries.Query.F.$isSimple = geoPostfix('ST_IsSimple', [0]);
|
|
18
|
+
queries.Query.F.$disjoint = geoPostfix('ST_Disjoint', [1]);
|
|
19
|
+
queries.Query.F.$equals = geoPostfix('ST_Equals', [1]);
|
|
20
|
+
queries.Query.F.$overlaps = geoPostfix('ST_Overlaps', [1]);
|
|
21
|
+
queries.Query.F.$intersects = geoPostfix('ST_Intersects', [1]);
|
|
22
|
+
queries.Query.F.$centroid = geoPostfix('ST_Centroid', [0]);
|
|
23
|
+
queries.Query.F.$difference = geoPostfix('ST_Difference', [1]);
|
|
24
|
+
queries.Query.F.$dimension = geoPostfix('ST_Dimension', [0]);
|
|
25
|
+
queries.Query.F.$distance = geoPostfix('ST_Distance', [1, 2]);
|
|
26
|
+
queries.Query.F.$endPoint = geoPostfix('ST_EndPoint', [0]);
|
|
27
|
+
queries.Query.F.$envelope = geoPostfix('ST_Envelope', [0]);
|
|
28
|
+
queries.Query.F.$exteriorRing = geoPostfix('ST_ExteriorRing', [0]);
|
|
29
|
+
queries.Query.F.$geometryType = geoPostfix('ST_GeometryType', [0]);
|
|
30
|
+
queries.Query.F.$geometryN = geoPostfix('ST_GeometryN', [1]);
|
|
31
|
+
queries.Query.F.$interiorRingN = geoPostfix('ST_InteriorRingN', [1]);
|
|
32
|
+
queries.Query.F.$intersection = geoPostfix('ST_Intersection', [1]);
|
|
33
|
+
queries.Query.F.$intersectsFilter = geoPostfix('ST_IntersectsFilter', [1]);
|
|
34
|
+
queries.Query.F.$intersectsRect = geoPostfix('ST_IntersectsRect', [2]);
|
|
35
|
+
queries.Query.F.$is3D = geoPostfix('ST_Is3D', [0]);
|
|
36
|
+
queries.Query.F.$isClosed = geoPostfix('ST_IsClosed', [0]);
|
|
37
|
+
queries.Query.F.$isRing = geoPostfix('ST_IsRing', [0]);
|
|
38
|
+
queries.Query.F.$isValid = geoPostfix('ST_IsValid', [0]);
|
|
39
|
+
queries.Query.F.$length = geoPostfix('ST_Length', [0, 1]);
|
|
40
|
+
queries.Query.F.$numGeometries = geoPostfix('ST_NumGeometries', [0]);
|
|
41
|
+
queries.Query.F.$numInteriorRing = geoPostfix('ST_NumInteriorRing', [0]);
|
|
42
|
+
queries.Query.F.$numInteriorRings = geoPostfix('ST_NumInteriorRings', [0]);
|
|
43
|
+
queries.Query.F.$numPoints = geoPostfix('ST_NumPoints', [0]);
|
|
44
|
+
queries.Query.F.$orderingEquals = geoPostfix('ST_OrderingEquals', [1]);
|
|
45
|
+
queries.Query.F.$pointN = geoPostfix('ST_PointN', [1]);
|
|
46
|
+
queries.Query.F.$pointOnSurface = geoPostfix('ST_PointOnSurface', [0]);
|
|
47
|
+
queries.Query.F.$relate = geoPostfix('ST_Relate', [1]);
|
|
48
|
+
queries.Query.F.$srid = geoPostfix('ST_SRID', [0]);
|
|
49
|
+
queries.Query.F.$snapToGrid = geoPostfix('ST_SnapToGrid', [1]);
|
|
50
|
+
queries.Query.F.$symDifference = geoPostfix('ST_SymDifference', [1]);
|
|
51
|
+
queries.Query.F.$touches = geoPostfix('ST_Touches', [1]);
|
|
52
|
+
|
|
53
|
+
// queries.Query.F.$unionAggr = geoPostfix("ST_UnionAggr", [1]);
|
|
54
54
|
exports.unionAggr = unionAggr;
|
|
55
55
|
|
|
56
56
|
function unionAggr(arg) {
|
|
57
|
-
|
|
57
|
+
return Expr.$geoPreOp('ST_UnionAggr', arg);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
queries.Query.F.$startPoint = geoPostfix(
|
|
61
|
-
queries.Query.F.$withinDistance = geoPostfix(
|
|
62
|
-
queries.Query.F.$within = geoPostfix(
|
|
63
|
-
queries.Query.F.$x = geoPostfix(
|
|
64
|
-
queries.Query.F.$y = geoPostfix(
|
|
65
|
-
queries.Query.F.$xMax = geoPostfix(
|
|
66
|
-
queries.Query.F.$xMin = geoPostfix(
|
|
67
|
-
queries.Query.F.$yMax = geoPostfix(
|
|
68
|
-
queries.Query.F.$yMin = geoPostfix(
|
|
60
|
+
queries.Query.F.$startPoint = geoPostfix('ST_StartPoint', [0]);
|
|
61
|
+
queries.Query.F.$withinDistance = geoPostfix('ST_WithinDistance', [3]);
|
|
62
|
+
queries.Query.F.$within = geoPostfix('ST_Within', [1]);
|
|
63
|
+
queries.Query.F.$x = geoPostfix('ST_X', [0]);
|
|
64
|
+
queries.Query.F.$y = geoPostfix('ST_Y', [0]);
|
|
65
|
+
queries.Query.F.$xMax = geoPostfix('ST_XMax', [0]);
|
|
66
|
+
queries.Query.F.$xMin = geoPostfix('ST_XMin', [0]);
|
|
67
|
+
queries.Query.F.$yMax = geoPostfix('ST_YMax', [0]);
|
|
68
|
+
queries.Query.F.$yMin = geoPostfix('ST_YMin', [0]);
|
|
69
69
|
|
|
70
70
|
function geoPostfix(name, numArgs) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
71
|
+
return function(args) {
|
|
72
|
+
if (numArgs.indexOf(args.length-1) != -1) {
|
|
73
|
+
return Expr.$postOp(name, args);
|
|
74
|
+
} else {
|
|
75
|
+
throw new Error('Invalid number of arguments');
|
|
76
|
+
}
|
|
77
|
+
};
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
/** *******************************************************************************
|
|
83
82
|
* Spatial geometry from string representation
|
|
84
83
|
*********************************************************************************/
|
|
85
84
|
exports.geomFromEWKB = geomFromEWKB;
|
|
@@ -90,79 +89,77 @@ exports.geomFromWKT = geomFromWKT;
|
|
|
90
89
|
|
|
91
90
|
|
|
92
91
|
function geomFromEWKB(stringRep) {
|
|
93
|
-
|
|
92
|
+
return Expr.$geoPreOp('ST_GeomFromEWKB', stringRep);
|
|
94
93
|
}
|
|
95
94
|
|
|
96
95
|
function geomFromEWKT(stringRep) {
|
|
97
|
-
|
|
96
|
+
return Expr.$geoPreOp('ST_GeomFromEWKT', stringRep);
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
function geomFromText(stringRep, srid) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
100
|
+
if (typeof srid === 'undefined') {
|
|
101
|
+
return Expr.$geoPreOp('ST_GeomFromText', stringRep);
|
|
102
|
+
} else {
|
|
103
|
+
return Expr.$geoPreOp('ST_GeomFromText', stringRep, srid);
|
|
104
|
+
}
|
|
107
105
|
}
|
|
108
106
|
|
|
109
107
|
function geomFromWKB(stringRep, srid) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
108
|
+
if (typeof srid === 'undefined') {
|
|
109
|
+
return Expr.$geoPreOp('ST_GeomFromWKB', stringRep);
|
|
110
|
+
} else {
|
|
111
|
+
return Expr.$geoPreOp('ST_GeomFromWKB', stringRep, srid);
|
|
112
|
+
}
|
|
116
113
|
}
|
|
117
114
|
|
|
118
115
|
function geomFromWKT(stringRep, srid) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
116
|
+
if (typeof srid === 'undefined') {
|
|
117
|
+
return Expr.$geoPreOp('ST_GeomFromWKT', stringRep);
|
|
118
|
+
} else {
|
|
119
|
+
return Expr.$geoPreOp('ST_GeomFromWKT', stringRep, srid);
|
|
120
|
+
}
|
|
125
121
|
}
|
|
126
122
|
|
|
127
123
|
|
|
128
|
-
|
|
124
|
+
/** *******************************************************************************
|
|
129
125
|
* Spatial formats
|
|
130
126
|
*********************************************************************************/
|
|
131
|
-
queries.Query.F.$asBinary = geoFormat(
|
|
132
|
-
queries.Query.F.$asEWKB = geoFormat(
|
|
133
|
-
queries.Query.F.$asEWKT = geoFormat(
|
|
134
|
-
queries.Query.F.$asGeoJSON = geoFormat(
|
|
135
|
-
queries.Query.F.$asSVG = geoFormat(
|
|
136
|
-
queries.Query.F.$asText = geoFormat(
|
|
137
|
-
queries.Query.F.$asWKB = geoFormat(
|
|
138
|
-
queries.Query.F.$asWKT = geoFormat(
|
|
127
|
+
queries.Query.F.$asBinary = geoFormat('Binary');
|
|
128
|
+
queries.Query.F.$asEWKB = geoFormat('EWKB');
|
|
129
|
+
queries.Query.F.$asEWKT = geoFormat('EWKT');
|
|
130
|
+
queries.Query.F.$asGeoJSON = geoFormat('GeoJSON');
|
|
131
|
+
queries.Query.F.$asSVG = geoFormat('SVG');
|
|
132
|
+
queries.Query.F.$asText = geoFormat('Text');
|
|
133
|
+
queries.Query.F.$asWKB = geoFormat('WKB');
|
|
134
|
+
queries.Query.F.$asWKT = geoFormat('WKT');
|
|
139
135
|
|
|
140
136
|
function geoFormat(format) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
return function(args) {
|
|
138
|
+
return Expr.$postOp(`ST_As${ format}`, args);
|
|
139
|
+
};
|
|
144
140
|
};
|
|
145
141
|
|
|
146
142
|
|
|
147
|
-
|
|
143
|
+
/** *******************************************************************************
|
|
148
144
|
* Spatial queries
|
|
149
145
|
*********************************************************************************/
|
|
146
|
+
|
|
150
147
|
queries.Query.F.$query = function(args) {
|
|
151
|
-
|
|
148
|
+
return query([args[0]]);
|
|
152
149
|
};
|
|
153
150
|
|
|
154
151
|
function query(exprs) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
152
|
+
const q = new queries.Query(null, {t0: 'DUMMY'}, 't0').$project({});
|
|
153
|
+
const fields = exprs.reduce(function(acc, e, i) {
|
|
154
|
+
acc[`geo_${ i}`] = e;
|
|
155
|
+
return acc;
|
|
156
|
+
}, {});
|
|
157
|
+
const res = q.$addFields(fields);
|
|
158
|
+
return res;
|
|
162
159
|
}
|
|
163
160
|
|
|
164
161
|
|
|
165
|
-
|
|
162
|
+
/** *******************************************************************************
|
|
166
163
|
* Spatial data types
|
|
167
164
|
*********************************************************************************/
|
|
168
165
|
exports.stPolygon = stPolygon;
|
|
@@ -176,308 +173,287 @@ exports.stGeometryCollection = stGeometryCollection;
|
|
|
176
173
|
|
|
177
174
|
|
|
178
175
|
function stType(constr, data, srid) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
176
|
+
if (typeof data === 'undefined') {
|
|
177
|
+
return Expr.$geoPreOp(`NEW ST_${ constr}`);
|
|
178
|
+
}
|
|
182
179
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
180
|
+
if (typeof srid === 'undefined') {
|
|
181
|
+
return Expr.$geoPreOp(`NEW ST_${ constr}`, data);
|
|
182
|
+
}
|
|
186
183
|
|
|
187
|
-
|
|
184
|
+
return Expr.$geoPreOp(`NEW ST_${ constr}`, data, srid);
|
|
188
185
|
}
|
|
189
186
|
|
|
190
187
|
function point(p) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
return {
|
|
189
|
+
type: 'Point',
|
|
190
|
+
coordinates: p,
|
|
191
|
+
};
|
|
195
192
|
}
|
|
196
193
|
|
|
197
194
|
function jsonPoints(points) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
return points.map(function(p) {
|
|
196
|
+
return point(p);
|
|
197
|
+
});
|
|
201
198
|
}
|
|
202
199
|
|
|
203
200
|
function jsonPoint(points) {
|
|
204
|
-
|
|
201
|
+
return point(points);
|
|
205
202
|
}
|
|
206
203
|
|
|
207
204
|
function polygon(points) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
205
|
+
return [{
|
|
206
|
+
type: 'Polygon',
|
|
207
|
+
coordinates: points,
|
|
208
|
+
}];
|
|
212
209
|
}
|
|
213
210
|
|
|
214
211
|
function stLineString(points, srid) {
|
|
215
|
-
|
|
212
|
+
return stMultiplePoints('LineString', points, srid);
|
|
216
213
|
}
|
|
217
214
|
|
|
218
215
|
function stCircularString(points, srid) {
|
|
219
|
-
|
|
216
|
+
return stMultiplePoints('CircularString', points, srid);
|
|
220
217
|
}
|
|
221
218
|
|
|
222
219
|
function stMultiLineString(points, srid) {
|
|
223
|
-
|
|
220
|
+
return stMultipleLines('MultiLineString', points, srid);
|
|
224
221
|
}
|
|
225
222
|
|
|
226
223
|
function stPolygon(points, srid) {
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
return stMultipleLines('Polygon', points, srid);
|
|
229
225
|
}
|
|
230
226
|
|
|
231
227
|
function stPoint(point, y) {
|
|
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
|
-
textRep = "Point " + '(' + point.coordinates.join(" ") + ")";
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return stType("Point", textRep, srid);
|
|
228
|
+
let textRep;
|
|
229
|
+
let srid;
|
|
230
|
+
|
|
231
|
+
// GeoJson-Object as param
|
|
232
|
+
if (Object.prototype.toString.call(point) === '[object Object]') {
|
|
233
|
+
if (point.coordinates) {
|
|
234
|
+
point = point.coordinates;
|
|
235
|
+
} else {
|
|
236
|
+
throw new Error('GeoJSON-Object has no \'position\' property.');
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// point undefined --> empty constructor
|
|
241
|
+
if (typeof point === 'undefined') {
|
|
242
|
+
return stType('Point', textRep, srid);
|
|
243
|
+
} else if (typeof point === 'number') {
|
|
244
|
+
// constructor with 2 doubles is used and 2nd param 'srid' is abused for the 2nd double value
|
|
245
|
+
textRep = point;
|
|
246
|
+
srid = y;
|
|
247
|
+
} else if (typeof point === 'string') {
|
|
248
|
+
// --> wkb constructor
|
|
249
|
+
textRep = point;
|
|
250
|
+
} else {
|
|
251
|
+
// point is described in (well known) text format with optional srid parameter
|
|
252
|
+
if (!point.coordinates) {
|
|
253
|
+
point = jsonPoint(point);
|
|
254
|
+
}
|
|
255
|
+
textRep = `${'Point ' + '('}${ point.coordinates.join(' ') })`;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return stType('Point', textRep, srid);
|
|
268
259
|
}
|
|
269
260
|
|
|
270
261
|
function stMultiplePoints(type, points, srid) {
|
|
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
|
-
return stType(type, textRep, srid);
|
|
262
|
+
let textRep;
|
|
263
|
+
|
|
264
|
+
// GeoJson-Object as param
|
|
265
|
+
if (Object.prototype.toString.call(points) === '[object Object]') {
|
|
266
|
+
if (points.coordinates) {
|
|
267
|
+
points = points.coordinates;
|
|
268
|
+
} else {
|
|
269
|
+
throw new Error('GeoJSON-Object has no \'position\' property.');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// points undefined --> empty constructor
|
|
274
|
+
if (typeof points === 'undefined') {
|
|
275
|
+
|
|
276
|
+
} else if (typeof points === 'string') {
|
|
277
|
+
// wkb constructor
|
|
278
|
+
textRep = points;
|
|
279
|
+
} else {
|
|
280
|
+
// points are described in (well known) text format with optional srid parameter
|
|
281
|
+
if (!points[0].coordinates) {
|
|
282
|
+
points = jsonPoints(points);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
textRep = `${type}(${ points.map(function(p) {
|
|
286
|
+
return p.coordinates.join(' ');
|
|
287
|
+
}).join(', ')})`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return stType(type, textRep, srid);
|
|
303
291
|
}
|
|
304
292
|
|
|
305
293
|
function stMultipleLines(type, lines, srid) {
|
|
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
|
-
return stType(type, textRep, srid);
|
|
294
|
+
let textRep;
|
|
295
|
+
|
|
296
|
+
// GeoJson-Object as param
|
|
297
|
+
if (Object.prototype.toString.call(lines) === '[object Object]') {
|
|
298
|
+
if (lines.coordinates) {
|
|
299
|
+
lines = lines.coordinates;
|
|
300
|
+
} else {
|
|
301
|
+
throw new Error('GeoJSON-Object has no \'position\' property.');
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// lines undefined --> empty constructor
|
|
306
|
+
if (typeof lines === 'undefined') {
|
|
307
|
+
return stType(type, textRep, srid);
|
|
308
|
+
} else if (typeof lines === 'string') {
|
|
309
|
+
// wkb constructor
|
|
310
|
+
textRep = lines;
|
|
311
|
+
} else {
|
|
312
|
+
// lines are described in (well known) text format with optional srid parameter
|
|
313
|
+
if (!lines[0].coordinates) {
|
|
314
|
+
lines = polygon(lines);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
textRep = type + lines.map(function(points) {
|
|
318
|
+
return `(${ points.coordinates.map(function(points0) {
|
|
319
|
+
return `(${ points0.map(function(p) {
|
|
320
|
+
return p.join(' ');
|
|
321
|
+
}).join(', ')})`;
|
|
322
|
+
}).join(', ')})`;
|
|
323
|
+
}).join(', ');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return stType(type, textRep, srid);
|
|
342
327
|
}
|
|
343
328
|
|
|
344
329
|
function stMultiPoint(points, srid) {
|
|
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
|
-
return stType("MultiPoint", textRep, srid);
|
|
330
|
+
let textRep;
|
|
331
|
+
|
|
332
|
+
// GeoJson-Object as param
|
|
333
|
+
if (Object.prototype.toString.call(points) === '[object Object]') {
|
|
334
|
+
if (points.coordinates) {
|
|
335
|
+
points = points.coordinates;
|
|
336
|
+
} else {
|
|
337
|
+
throw new Error('GeoJSON-Object has no \'position\' property.');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// points undefined --> empty constructor
|
|
342
|
+
if (typeof points === 'undefined') {
|
|
343
|
+
return stType('MultiPoint', textRep, srid);
|
|
344
|
+
} else if (typeof points === 'string') {
|
|
345
|
+
// wkb constructor
|
|
346
|
+
textRep = points;
|
|
347
|
+
} else {
|
|
348
|
+
// points are described in (well known) text format with optional srid parameter
|
|
349
|
+
if (!points[0].coordinates) {
|
|
350
|
+
points = jsonPoints(points);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
textRep = `${'MultiPoint' + '('}${ points.map(function(p) {
|
|
354
|
+
return `(${p.coordinates.join(' ')})`;
|
|
355
|
+
}).join(', ')})`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
return stType('MultiPoint', textRep, srid);
|
|
377
359
|
}
|
|
378
360
|
|
|
379
361
|
function stMultiPolygon(polygons, srid) {
|
|
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
|
-
return stType("MultiPolygon", textRep, srid);
|
|
362
|
+
let textRep;
|
|
363
|
+
|
|
364
|
+
// GeoJson-Object as param
|
|
365
|
+
if (Object.prototype.toString.call(polygons) === '[object Object]') {
|
|
366
|
+
if (polygons.coordinates) {
|
|
367
|
+
polygons = polygons.coordinates;
|
|
368
|
+
} else {
|
|
369
|
+
throw new Error('GeoJSON-Object has no \'position\' property.');
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// polygons undefined --> empty constructor
|
|
374
|
+
if (typeof polygons === 'undefined') {
|
|
375
|
+
return stType('MultiPolygon', textRep, srid);
|
|
376
|
+
} else if (typeof polygons === 'string') {
|
|
377
|
+
// wkb constructor
|
|
378
|
+
textRep = polygons;
|
|
379
|
+
} else {
|
|
380
|
+
// polygons are described in (well known) text format with optional srid parameter
|
|
381
|
+
textRep = `${'MultiPolygon' +'('}${ polygons.map(function(lines) {
|
|
382
|
+
if (!lines[0].coordinates) {
|
|
383
|
+
lines = polygon(lines);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return (lines.map(function(points) {
|
|
387
|
+
return `(${ points.coordinates.map(function(points0) {
|
|
388
|
+
return `(${ points0.map(function(p) {
|
|
389
|
+
return p.join(' ');
|
|
390
|
+
}).join(', ')})`;
|
|
391
|
+
}).join(', ')})`;
|
|
392
|
+
}).join(', '));
|
|
393
|
+
}).join(', ')})`;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return stType('MultiPolygon', textRep, srid);
|
|
418
397
|
}
|
|
419
398
|
|
|
420
399
|
function stGeometryCollection(geometries, srid) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
//return stType(obj);
|
|
482
|
-
return stType("GeometryCollection", textRep, srid);
|
|
483
|
-
}
|
|
400
|
+
let textRep;
|
|
401
|
+
|
|
402
|
+
// GeoJson-Object as param
|
|
403
|
+
if (Object.prototype.toString.call(geometries) === '[object Object]') {
|
|
404
|
+
if (geometries.geometries) {
|
|
405
|
+
geometries = geometries.geometries;
|
|
406
|
+
} else {
|
|
407
|
+
throw new Error('GeoJSON-Object has no \'position\' property.');
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
geometries = geometries.map(function(jsonGeom) {
|
|
411
|
+
let geoConstr;
|
|
412
|
+
|
|
413
|
+
switch (jsonGeom.type) {
|
|
414
|
+
case 'Point':
|
|
415
|
+
geoConstr = stPoint(jsonGeom.coordinates);
|
|
416
|
+
break;
|
|
417
|
+
case 'MultiPoint':
|
|
418
|
+
geoConstr = stMultiPoint(jsonGeom.coordinates);
|
|
419
|
+
break;
|
|
420
|
+
case 'LineString':
|
|
421
|
+
geoConstr = stLineString(jsonGeom.coordinates);
|
|
422
|
+
break;
|
|
423
|
+
case 'CircularString':
|
|
424
|
+
geoConstr = stCircularString(jsonGeom.coordinates);
|
|
425
|
+
break;
|
|
426
|
+
case 'MultiLineString':
|
|
427
|
+
geoConstr = stMultiLineString(jsonGeom.coordinates);
|
|
428
|
+
break;
|
|
429
|
+
case 'Polygon':
|
|
430
|
+
geoConstr = stPolygon(jsonGeom.coordinates);
|
|
431
|
+
break;
|
|
432
|
+
case 'MultiPolygon':
|
|
433
|
+
geoConstr = stMultiPolygon(jsonGeom.coordinates);
|
|
434
|
+
break;
|
|
435
|
+
default:
|
|
436
|
+
// TODO error
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return geoConstr;
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// geometries undefined --> empty constructor
|
|
445
|
+
if (typeof geometries === 'undefined') {
|
|
446
|
+
return stType('GeometryCollection', textRep, srid);
|
|
447
|
+
} else if (typeof geometries === 'string') {
|
|
448
|
+
// wkb constructor
|
|
449
|
+
textRep = geometries;
|
|
450
|
+
} else {
|
|
451
|
+
// take representations of the geometries (in whatever format they are) as constructor params
|
|
452
|
+
textRep = `${'GeometryCollection ' + '('}${ geometries.map(function(geo) {
|
|
453
|
+
return geo._geoPreOp[1];
|
|
454
|
+
}).join(', ') })`;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// return stType(obj);
|
|
458
|
+
return stType('GeometryCollection', textRep, srid);
|
|
459
|
+
}
|