@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.
@@ -1,85 +1,84 @@
1
- var queries = require("./cds-queries");
2
- var Expr = queries.Query.F;
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("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]);
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
- return Expr.$geoPreOp("ST_UnionAggr", arg);
57
+ return Expr.$geoPreOp('ST_UnionAggr', arg);
58
58
  }
59
59
 
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]);
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
- return function(args) {
72
- if (numArgs.indexOf(args.length-1) != -1) {
73
- return Expr.$postOp(name, args);
74
- }
75
- else {
76
- throw new Error("Invalid number of arguments")
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
- return Expr.$geoPreOp("ST_GeomFromEWKB", stringRep);
92
+ return Expr.$geoPreOp('ST_GeomFromEWKB', stringRep);
94
93
  }
95
94
 
96
95
  function geomFromEWKT(stringRep) {
97
- return Expr.$geoPreOp("ST_GeomFromEWKT", stringRep);
96
+ return Expr.$geoPreOp('ST_GeomFromEWKT', stringRep);
98
97
  }
99
98
 
100
99
  function geomFromText(stringRep, srid) {
101
- if (typeof srid === 'undefined') {
102
- return Expr.$geoPreOp("ST_GeomFromText", stringRep);
103
- }
104
- else {
105
- return Expr.$geoPreOp("ST_GeomFromText", stringRep, srid);
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
- if (typeof srid === 'undefined') {
111
- return Expr.$geoPreOp("ST_GeomFromWKB", stringRep);
112
- }
113
- else {
114
- return Expr.$geoPreOp("ST_GeomFromWKB", stringRep, srid);
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
- if (typeof srid === 'undefined') {
120
- return Expr.$geoPreOp("ST_GeomFromWKT", stringRep);
121
- }
122
- else {
123
- return Expr.$geoPreOp("ST_GeomFromWKT", stringRep, srid);
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("Binary");
132
- queries.Query.F.$asEWKB = geoFormat("EWKB");
133
- queries.Query.F.$asEWKT = geoFormat("EWKT");
134
- queries.Query.F.$asGeoJSON = geoFormat("GeoJSON");
135
- queries.Query.F.$asSVG = geoFormat("SVG");
136
- queries.Query.F.$asText = geoFormat("Text");
137
- queries.Query.F.$asWKB = geoFormat("WKB");
138
- queries.Query.F.$asWKT = geoFormat("WKT");
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
- return function(args) {
142
- return Expr.$postOp("ST_As" + format, args);
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
- return query([args[0]]);
148
+ return query([args[0]]);
152
149
  };
153
150
 
154
151
  function query(exprs) {
155
- var q = new queries.Query(null, {t0: "DUMMY"}, "t0").$project({});
156
- var fields = exprs.reduce(function(acc, e, i) {
157
- acc["geo_" + i] = e;
158
- return acc;
159
- }, {});
160
- var res = q.$addFields(fields);
161
- return res;
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
- if (typeof data === 'undefined') {
180
- return Expr.$geoPreOp("NEW ST_" + constr);
181
- }
176
+ if (typeof data === 'undefined') {
177
+ return Expr.$geoPreOp(`NEW ST_${ constr}`);
178
+ }
182
179
 
183
- if (typeof srid === 'undefined') {
184
- return Expr.$geoPreOp("NEW ST_" + constr, data);
185
- }
180
+ if (typeof srid === 'undefined') {
181
+ return Expr.$geoPreOp(`NEW ST_${ constr}`, data);
182
+ }
186
183
 
187
- return Expr.$geoPreOp("NEW ST_" + constr, data, srid);
184
+ return Expr.$geoPreOp(`NEW ST_${ constr}`, data, srid);
188
185
  }
189
186
 
190
187
  function point(p) {
191
- return {
192
- type: "Point",
193
- coordinates : p
194
- };
188
+ return {
189
+ type: 'Point',
190
+ coordinates: p,
191
+ };
195
192
  }
196
193
 
197
194
  function jsonPoints(points) {
198
- return points.map(function(p){
199
- return point(p);
200
- });
195
+ return points.map(function(p) {
196
+ return point(p);
197
+ });
201
198
  }
202
199
 
203
200
  function jsonPoint(points) {
204
- return point(points);
201
+ return point(points);
205
202
  }
206
203
 
207
204
  function polygon(points) {
208
- return [{
209
- type: "Polygon",
210
- coordinates: points
211
- }];
205
+ return [{
206
+ type: 'Polygon',
207
+ coordinates: points,
208
+ }];
212
209
  }
213
210
 
214
211
  function stLineString(points, srid) {
215
- return stMultiplePoints("LineString", points, srid);
212
+ return stMultiplePoints('LineString', points, srid);
216
213
  }
217
214
 
218
215
  function stCircularString(points, srid) {
219
- return stMultiplePoints("CircularString", points, srid);
216
+ return stMultiplePoints('CircularString', points, srid);
220
217
  }
221
218
 
222
219
  function stMultiLineString(points, srid) {
223
- return stMultipleLines("MultiLineString", points, srid);
220
+ return stMultipleLines('MultiLineString', points, srid);
224
221
  }
225
222
 
226
223
  function stPolygon(points, srid) {
227
- return stMultipleLines("Polygon", points, srid);
228
-
224
+ return stMultipleLines('Polygon', points, srid);
229
225
  }
230
226
 
231
227
  function stPoint(point, y) {
232
- var textRep;
233
- var srid;
234
-
235
- //GeoJson-Object as param
236
- if (Object.prototype.toString.call(point) === "[object Object]") {
237
- if(point.coordinates) {
238
- point = point.coordinates;
239
- }
240
- else {
241
- throw new Error("GeoJSON-Object has no \'position\' property.")
242
- }
243
- }
244
-
245
- //point undefined --> empty constructor
246
- if (typeof point === 'undefined') {
247
-
248
- }
249
- //point is a number --> constructor with 2 doubles is used and 2nd param 'srid' is abused for the 2nd double value
250
- else if (typeof point === 'number') {
251
- textRep = point;
252
- srid = y;
253
- }
254
- //point is a string --> wkb constructor
255
- else if (typeof point === 'string') {
256
- textRep = point;
257
- }
258
- //point is described in (well known) text format with optional srid parameter
259
- else {
260
- if (!point.coordinates) {
261
- point = jsonPoint(point);
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
- var textRep;
272
-
273
- //GeoJson-Object as param
274
- if (Object.prototype.toString.call(points) === "[object Object]") {
275
- if(points.coordinates) {
276
- points = points.coordinates;
277
- }
278
- else {
279
- throw new Error("GeoJSON-Object has no \'position\' property.")
280
- }
281
- }
282
-
283
- //points undefined --> empty constructor
284
- if (typeof points === 'undefined') {
285
-
286
- }
287
- //points is a string --> wkb constructor
288
- else if (typeof points === 'string') {
289
- textRep = points;
290
- }
291
- //points are described in (well known) text format with optional srid parameter
292
- else {
293
- if (!points[0].coordinates) {
294
- points = jsonPoints(points);
295
- }
296
-
297
- textRep = type+'(' + points.map(function(p) {
298
- return p.coordinates.join(" ");
299
- }).join(", ")+")";
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
- var textRep;
307
-
308
- //GeoJson-Object as param
309
- if (Object.prototype.toString.call(lines) === "[object Object]") {
310
- if(lines.coordinates) {
311
- lines = lines.coordinates;
312
- }
313
- else {
314
- throw new Error("GeoJSON-Object has no \'position\' property.")
315
- }
316
- }
317
-
318
- //lines undefined --> empty constructor
319
- if (typeof lines === 'undefined') {
320
-
321
- }
322
- //lines is a string --> wkb constructor
323
- else if (typeof lines === 'string') {
324
- textRep = lines;
325
- }
326
- //lines are described in (well known) text format with optional srid parameter
327
- else {
328
- if (!lines[0].coordinates) {
329
- lines = polygon(lines);
330
- }
331
-
332
- textRep = type + lines.map(function(points) {
333
- return '(' + (points.coordinates.map(function(points0) {
334
- return '(' +points0.map(function(p) {
335
- return p.join(" ");
336
- }).join(", ")+")";
337
- }).join(", "))+")";
338
- }).join(", ");
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
- var textRep;
346
-
347
- //GeoJson-Object as param
348
- if (Object.prototype.toString.call(points) === "[object Object]") {
349
- if(points.coordinates) {
350
- points = points.coordinates;
351
- }
352
- else {
353
- throw new Error("GeoJSON-Object has no \'position\' property.")
354
- }
355
- }
356
-
357
- //points undefined --> empty constructor
358
- if (typeof points === 'undefined') {
359
-
360
- }
361
- //points is a string --> wkb constructor
362
- else if (typeof points === 'string') {
363
- textRep = points;
364
- }
365
- //points are described in (well known) text format with optional srid parameter
366
- else {
367
- if (!points[0].coordinates) {
368
- points = jsonPoints(points);
369
- }
370
-
371
- textRep = "MultiPoint" + '(' + points.map(function(p) {
372
- return '('+p.coordinates.join(" ")+')';
373
- }).join(", ")+")";
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
- var textRep;
381
-
382
- //GeoJson-Object as param
383
- if (Object.prototype.toString.call(polygons) === "[object Object]") {
384
- if(polygons.coordinates) {
385
- polygons = polygons.coordinates;
386
- }
387
- else {
388
- throw new Error("GeoJSON-Object has no \'position\' property.")
389
- }
390
- }
391
-
392
- //polygons undefined --> empty constructor
393
- if (typeof polygons === 'undefined') {
394
-
395
- }
396
- //polygons is a string --> wkb constructor
397
- else if (typeof polygons === 'string') {
398
- textRep = polygons;
399
- }
400
- //polygons are described in (well known) text format with optional srid parameter
401
- else {
402
- textRep = "MultiPolygon" +'(' + polygons.map(function(lines) {
403
- if (!lines[0].coordinates) {
404
- lines = polygon(lines);
405
- }
406
-
407
- return (lines.map(function(points) {
408
- return '(' + (points.coordinates.map(function(points0) {
409
- return '(' +points0.map(function(p) {
410
- return p.join(" ");
411
- }).join(", ")+")";
412
- }).join(", "))+")";
413
- }).join(", "));
414
- }).join(", ")+")";
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
- var textRep;
422
-
423
- //GeoJson-Object as param
424
- if (Object.prototype.toString.call(geometries) === "[object Object]") {
425
- if(geometries.geometries) {
426
- geometries = geometries.geometries;
427
- }
428
- else {
429
- throw new Error("GeoJSON-Object has no \'position\' property.")
430
- }
431
-
432
- geometries = geometries.map(function(jsonGeom) {
433
- var geoConstr;
434
-
435
- switch(jsonGeom.type) {
436
- case "Point":
437
- geoConstr = stPoint(jsonGeom.coordinates);
438
- break;
439
- case "MultiPoint":
440
- geoConstr = stMultiPoint(jsonGeom.coordinates);
441
- break;
442
- case "LineString":
443
- geoConstr = stLineString(jsonGeom.coordinates);
444
- break;
445
- case "CircularString":
446
- geoConstr = stCircularString(jsonGeom.coordinates);
447
- break;
448
- case "MultiLineString":
449
- geoConstr = stMultiLineString(jsonGeom.coordinates);
450
- break;
451
- case "Polygon":
452
- geoConstr = stPolygon(jsonGeom.coordinates);
453
- break;
454
- case "MultiPolygon":
455
- geoConstr = stMultiPolygon(jsonGeom.coordinates);
456
- break;
457
- default:
458
- //TODO error
459
- break;
460
- }
461
-
462
- return geoConstr;
463
- })
464
- }
465
-
466
- //geometries undefined --> empty constructor
467
- if (typeof geometries === 'undefined') {
468
-
469
- }
470
- //geometries is a string --> wkb constructor
471
- else if (typeof geometries === 'string') {
472
- textRep = geometries;
473
- }
474
- //take representations of the geometries (in whatever format they are) as constructor parameters
475
- else {
476
- textRep = "GeometryCollection " + '(' + geometries.map(function(geo) {
477
- return geo._geoPreOp[1];
478
- }).join(', ') + ")"
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
+ }