-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeometryReader.ts
969 lines (864 loc) · 26.2 KB
/
GeometryReader.ts
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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
import {
CircularString,
CompoundCurve,
Curve,
CurvePolygon,
Geometry,
GeometryCollection,
GeometryFilter,
GeometryType,
LineString,
MultiLineString,
MultiPoint,
MultiPolygon,
Point,
Polygon,
PolyhedralSurface,
SFException,
Surface,
TIN,
Triangle
} from "@ngageoint/simple-features-js";
import { StringReader } from "./StringReader";
import {GeometryTypeInfo} from "./GeometryTypeInfo";
/**
* Well Known Text reader
*/
export class GeometryReader {
/**
* Text Reader
*/
private reader: StringReader;
public constructor(reader: StringReader);
public constructor(text: string);
/**
* Constructor
* @param args
*/
public constructor(...args) {
if (args.length === 1 && args[0] instanceof StringReader) {
this.reader = args[0];
} else if (args.length === 1 && typeof args[0] === 'string') {
this.reader = new StringReader(args[0]);
}
}
/**
* Read a geometry from the well-known text
* @param filter geometry filter
* @param containingType containing geometry type
* @return geometry
*/
public read(filter: GeometryFilter, containingType: GeometryType = undefined): Geometry {
let geometry = null;
// Read the geometry type
const geometryTypeInfo = this.readGeometryType();
if (geometryTypeInfo != null) {
const geometryType = geometryTypeInfo.geometryType;
const hasZ = geometryTypeInfo.hasZ;
const hasM = geometryTypeInfo.hasM;
switch (geometryType) {
case GeometryType.GEOMETRY:
throw new SFException("Unexpected Geometry Type of " + GeometryType.nameFromType(geometryType) + " which is abstract");
case GeometryType.POINT:
geometry = this.readPointText(hasZ, hasM);
break;
case GeometryType.LINESTRING:
geometry = this.readLineString(filter, hasZ, hasM);
break;
case GeometryType.POLYGON:
geometry = this.readPolygon(filter, hasZ, hasM);
break;
case GeometryType.MULTIPOINT:
geometry = this.readMultiPoint(filter, hasZ, hasM);
break;
case GeometryType.MULTILINESTRING:
geometry = this.readMultiLineString(filter, hasZ, hasM);
break;
case GeometryType.MULTIPOLYGON:
geometry = this.readMultiPolygon(filter, hasZ, hasM);
break;
case GeometryType.GEOMETRYCOLLECTION:
geometry = this.readGeometryCollection(filter, hasZ, hasM);
break;
case GeometryType.MULTICURVE:
geometry = this.readMultiCurve(filter, hasZ, hasM);
break;
case GeometryType.MULTISURFACE:
geometry = this.readMultiSurface(filter, hasZ, hasM);
break;
case GeometryType.CIRCULARSTRING:
geometry = this.readCircularString(filter, hasZ, hasM);
break;
case GeometryType.COMPOUNDCURVE:
geometry = this.readCompoundCurve(filter, hasZ, hasM);
break;
case GeometryType.CURVEPOLYGON:
geometry = this.readCurvePolygon(filter, hasZ, hasM);
break;
case GeometryType.CURVE:
throw new SFException("Unexpected Geometry Type of "
+ GeometryType.nameFromType(geometryType) + " which is abstract");
case GeometryType.SURFACE:
throw new SFException("Unexpected Geometry Type of "
+ GeometryType.nameFromType(geometryType) + " which is abstract");
case GeometryType.POLYHEDRALSURFACE:
geometry = this.readPolyhedralSurface(filter, hasZ, hasM);
break;
case GeometryType.TIN:
geometry = this.readTIN(filter, hasZ, hasM);
break;
case GeometryType.TRIANGLE:
geometry = this.readTriangle(filter, hasZ, hasM);
break;
default:
throw new SFException("Geometry Type not supported: " + geometryType);
}
if (!GeometryReader.filter(filter, containingType, geometry)) {
geometry = null;
}
}
return geometry;
}
/**
* Read the geometry type info
* @return geometry type info
*/
public readGeometryType(): GeometryTypeInfo {
let geometryInfo = null;
// Read the geometry type
let geometryTypeValue = this.reader.readToken();
if (geometryTypeValue != null && geometryTypeValue.toUpperCase() !== "EMPTY") {
let hasZ = false;
let hasM = false;
// Determine the geometry type
let geometryType = GeometryType.fromName(geometryTypeValue.toLocaleUpperCase('en-US'));
// If not found, check if the geometry type has Z and/or M suffix
if (geometryType == null) {
// Check if the Z and/or M is appended to the geometry type
let geomType = geometryTypeValue.toLocaleUpperCase('en-US');
if (geomType.endsWith("Z")) {
hasZ = true;
} else if (geomType.endsWith("M")) {
hasM = true;
if (geomType.endsWith("ZM")) {
hasZ = true;
}
}
let suffixSize = 0;
if (hasZ) {
suffixSize++;
}
if (hasM) {
suffixSize++;
}
if (suffixSize > 0) {
// Check for the geometry type without the suffix
geomType = geometryTypeValue.substring(0, geometryTypeValue.length - suffixSize);
geometryType = GeometryType.fromName(geomType.toLocaleUpperCase('en-US'));
}
if (geometryType == null) {
throw new SFException("Expected a valid geometry type, found: '" + geometryTypeValue + "'");
}
}
// Determine if the geometry has a z (3d) or m (linear referencing
// system) value
if (!hasZ && !hasM) {
// Peek at the next token without popping it off
let next = this.reader.peekToken();
switch (GeometryReader.toUpperCase(next)) {
case "Z":
hasZ = true;
break;
case "M":
hasM = true;
break;
case "ZM":
hasZ = true;
hasM = true;
break;
case "(":
case "EMPTY":
break;
default:
throw new SFException(
"Invalid value following geometry type: '"
+ geometryTypeValue + "', value: '" + next
+ "'");
}
if (hasZ || hasM) {
// Read off the Z and/or M token
this.reader.readToken();
}
}
geometryInfo = new GeometryTypeInfo(geometryType, hasZ, hasM);
}
return geometryInfo;
}
/**
* Read a Point
* @param hasZ has z flag
* @param hasM has m flag
* @return point
*/
public readPointText(hasZ: boolean, hasM: boolean): Point {
let point = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
point = this.readPoint(hasZ, hasM);
GeometryReader.rightParenthesis(this.reader);
}
return point;
}
/**
* Read a Point
* @param hasZ has z flag
* @param hasM has m flag
* @return point
*/
public readPoint(hasZ: boolean, hasM: boolean): Point {
const x = this.reader.readDouble();
const y = this.reader.readDouble();
const point = new Point(hasZ, hasM, x, y);
if (hasZ || hasM) {
if (hasZ) {
point.z = this.reader.readDouble();
}
if (hasM) {
point.m = this.reader.readDouble();
}
} else if (!GeometryReader.isCommaOrRightParenthesis(this.reader)) {
point.z = this.reader.readDouble();
if (!GeometryReader.isCommaOrRightParenthesis(this.reader)) {
point.m = this.reader.readDouble();
}
}
return point;
}
/**
* Read a Line String
*
* @param filter
* geometry filter
* @param hasZ
* has z flag
* @param hasM
* has m flag
* @return line string
*/
public readLineString(filter: GeometryFilter, hasZ: boolean, hasM: boolean): LineString {
let lineString = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
lineString = new LineString(hasZ, hasM);
do {
let point = this.readPoint(hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.LINESTRING, point)) {
lineString.addPoint(point);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return lineString;
}
/**
* Read a Polygon
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return polygon
*/
public readPolygon(filter: GeometryFilter, hasZ: boolean, hasM: boolean): Polygon {
let polygon = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
polygon = new Polygon(hasZ, hasM);
do {
let ring = this.readLineString(filter, hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.POLYGON, ring)) {
polygon.addRing(ring);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return polygon;
}
/**
* Read a Multi Point
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi point
*/
public readMultiPoint(filter: GeometryFilter, hasZ: boolean, hasM: boolean): MultiPoint {
let multiPoint = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
multiPoint = new MultiPoint(hasZ, hasM);
do {
let point = null;
if (GeometryReader.isLeftParenthesisOrEmpty(this.reader)) {
point = this.readPointText(hasZ, hasM);
} else {
point = this.readPoint(hasZ, hasM);
}
if (GeometryReader.filter(filter, GeometryType.MULTIPOINT, point)) {
multiPoint.addPoint(point);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return multiPoint;
}
/**
* Read a Multi Line String
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi line string
*/
public readMultiLineString(filter: GeometryFilter, hasZ: boolean, hasM: boolean): MultiLineString {
let multiLineString = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
multiLineString = new MultiLineString(hasZ, hasM);
do {
let lineString = this.readLineString(filter, hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.MULTILINESTRING, lineString)) {
multiLineString.addLineString(lineString);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return multiLineString;
}
/**
* Read a Multi Polygon
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi polygon
*/
public readMultiPolygon(filter: GeometryFilter, hasZ: boolean, hasM: boolean): MultiPolygon {
let multiPolygon = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
multiPolygon = new MultiPolygon(hasZ, hasM);
do {
let polygon = this.readPolygon(filter, hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.MULTIPOLYGON, polygon)) {
multiPolygon.addPolygon(polygon);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return multiPolygon;
}
/**
* Read a Geometry Collection
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return geometry collection
*/
public readGeometryCollection(filter: GeometryFilter, hasZ: boolean, hasM: boolean): GeometryCollection<Geometry> {
let geometryCollection = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
geometryCollection = new GeometryCollection<Geometry>(hasZ, hasM);
do {
let geometry = this.read(filter, GeometryType.GEOMETRYCOLLECTION);
if (geometry != null) {
geometryCollection.addGeometry(geometry);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return geometryCollection;
}
/**
* Read a Multi Curve
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi curve
*/
public readMultiCurve(filter: GeometryFilter, hasZ: boolean, hasM: boolean): GeometryCollection<Curve> {
let multiCurve = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
multiCurve = new GeometryCollection<Curve>(hasZ, hasM);
do {
let curve = null;
if (GeometryReader.isLeftParenthesisOrEmpty(this.reader)) {
curve = this.readLineString(filter, hasZ, hasM);
if (!GeometryReader.filter(filter, GeometryType.MULTICURVE, curve)) {
curve = null;
}
} else {
curve = this.read(filter, GeometryType.MULTICURVE);
}
if (curve != null) {
multiCurve.addGeometry(curve);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return multiCurve;
}
/**
* Read a Multi Surface
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi surface
*/
public readMultiSurface(filter: GeometryFilter, hasZ: boolean, hasM: boolean): GeometryCollection<Surface> {
let multiSurface = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
multiSurface = new GeometryCollection<Surface>(hasZ, hasM);
do {
let surface = null;
if (GeometryReader.isLeftParenthesisOrEmpty(this.reader)) {
surface = this.readPolygon(filter, hasZ, hasM);
if (!GeometryReader.filter(filter, GeometryType.MULTISURFACE, surface)) {
surface = null;
}
} else {
surface = this.read(filter, GeometryType.MULTISURFACE);
}
if (surface != null) {
multiSurface.addGeometry(surface);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return multiSurface;
}
/**
* Read a Circular String
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return circular string
*/
public readCircularString(filter: GeometryFilter, hasZ: boolean, hasM: boolean): CircularString {
let circularString = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
circularString = new CircularString(hasZ, hasM);
do {
let point = this.readPoint(hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.CIRCULARSTRING, point)) {
circularString.addPoint(point);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return circularString;
}
/**
* Read a Compound Curve
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return compound curve
*/
public readCompoundCurve(filter: GeometryFilter, hasZ: boolean, hasM: boolean): CompoundCurve {
let compoundCurve = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
compoundCurve = new CompoundCurve(hasZ, hasM);
do {
let lineString = null;
if (GeometryReader.isLeftParenthesisOrEmpty(this.reader)) {
lineString = this.readLineString(filter, hasZ, hasM);
if (!GeometryReader.filter(filter, GeometryType.COMPOUNDCURVE, lineString)) {
lineString = null;
}
} else {
lineString = this.read(filter, GeometryType.COMPOUNDCURVE);
}
if (lineString != null) {
compoundCurve.addLineString(lineString);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return compoundCurve;
}
/**
* Read a Curve Polygon
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return curve polygon
*/
public readCurvePolygon(filter: GeometryFilter, hasZ: boolean, hasM: boolean): CurvePolygon<Curve> {
let curvePolygon = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
curvePolygon = new CurvePolygon<Curve>(hasZ, hasM);
do {
let ring = null;
if (GeometryReader.isLeftParenthesisOrEmpty(this.reader)) {
ring = this.readLineString(filter, hasZ, hasM);
if (!GeometryReader.filter(filter, GeometryType.CURVEPOLYGON, ring)) {
ring = null;
}
} else {
ring = this.read(filter, GeometryType.CURVEPOLYGON);
}
if (ring != null) {
curvePolygon.addRing(ring);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return curvePolygon;
}
/**
* Read a Polyhedral Surface
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return polyhedral surface
*/
public readPolyhedralSurface(filter: GeometryFilter, hasZ: boolean, hasM: boolean): PolyhedralSurface {
let polyhedralSurface = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
polyhedralSurface = new PolyhedralSurface(hasZ, hasM);
do {
let polygon = this.readPolygon(filter, hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.POLYHEDRALSURFACE, polygon)) {
polyhedralSurface.addPolygon(polygon);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return polyhedralSurface;
}
/**
* Read a TIN
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return TIN
*/
public readTIN(filter: GeometryFilter, hasZ: boolean, hasM: boolean): TIN {
let tin = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
tin = new TIN(hasZ, hasM);
do {
let polygon = this.readPolygon(filter, hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.TIN, polygon)) {
tin.addPolygon(polygon);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return tin;
}
/**
* Read a Triangle
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return triangle
*/
public readTriangle(filter: GeometryFilter, hasZ: boolean, hasM: boolean): Triangle {
let triangle = null;
if (GeometryReader.leftParenthesisOrEmpty(this.reader)) {
triangle = new Triangle(hasZ, hasM);
do {
let ring = this.readLineString(filter, hasZ, hasM);
if (GeometryReader.filter(filter, GeometryType.TRIANGLE, ring)) {
triangle.addRing(ring);
}
} while (GeometryReader.commaOrRightParenthesis(this.reader));
}
return triangle;
}
/**
* Read a geometry from the well-known text
* @param reader text reader
* @param filter geometry filter
* @param containingType containing geometry type
* @return geometry
*/
public static readGeometry(reader: StringReader, filter: GeometryFilter = undefined, containingType: GeometryType = undefined): Geometry {
const geometryReader = new GeometryReader(reader);
return geometryReader.read(filter, containingType);
}
/**
* Read the geometry type info
*
* @param reader
* text reader
* @return geometry type info
*/
public static readGeometryType(reader: StringReader): GeometryTypeInfo {
const geometryReader = new GeometryReader(reader);
return geometryReader.readGeometryType();
}
/**
* Read a Point
* @param reader text reader
* @param hasZ has z flag
* @param hasM has m flag
* @return point
*/
public static readPointText(reader: StringReader, hasZ: boolean, hasM: boolean): Point {
const geometryReader = new GeometryReader(reader);
return geometryReader.readPointText(hasZ, hasM);
}
/**
* Read a Point
* @param reader text reader
* @param hasZ has z flag
* @param hasM has m flag
* @return point
*/
public static readPoint(reader: StringReader, hasZ: boolean, hasM: boolean): Point {
const geometryReader = new GeometryReader(reader);
return geometryReader.readPoint(hasZ, hasM);
}
/**
* Read a Line String
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return line string
*/
public static readLineString(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): LineString {
const geometryReader = new GeometryReader(reader);
return geometryReader.readLineString(filter, hasZ, hasM);
}
/**
* Read a Polygon
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return polygon
*/
public static readPolygon(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): Polygon {
const geometryReader = new GeometryReader(reader);
return geometryReader.readPolygon(filter, hasZ, hasM);
}
/**
* Read a Multi Point
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi point
*/
public static readMultiPoint(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): MultiPoint {
const geometryReader = new GeometryReader(reader);
return geometryReader.readMultiPoint(filter, hasZ, hasM);
}
/**
* Read a Multi Line String
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi line string
*/
public static readMultiLineString(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): MultiLineString {
const geometryReader = new GeometryReader(reader);
return geometryReader.readMultiLineString(filter, hasZ, hasM);
}
/**
* Read a Multi Polygon
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi polygon
*/
public static readMultiPolygon(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): MultiPolygon {
const geometryReader = new GeometryReader(reader);
return geometryReader.readMultiPolygon(filter, hasZ, hasM);
}
/**
* Read a Geometry Collection
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return geometry collection
*/
public static readGeometryCollection(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): GeometryCollection<Geometry> {
const geometryReader = new GeometryReader(reader);
return geometryReader.readGeometryCollection(filter, hasZ, hasM);
}
/**
* Read a Multi Surface
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return multi surface
*/
public static readMultiSurface(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): GeometryCollection<Surface> {
const geometryReader = new GeometryReader(reader);
return geometryReader.readMultiSurface(filter, hasZ, hasM);
}
/**
* Read a Circular String
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return circular string
*/
public static readCircularString(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): CircularString {
const geometryReader = new GeometryReader(reader);
return geometryReader.readCircularString(filter, hasZ, hasM);
}
/**
* Read a Compound Curve
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return compound curve
*/
public static readCompoundCurve(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): CompoundCurve {
const geometryReader = new GeometryReader(reader);
return geometryReader.readCompoundCurve(filter, hasZ, hasM);
}
/**
* Read a Curve Polygon
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return curve polygon
*/
public static readCurvePolygon(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): CurvePolygon<Curve> {
const geometryReader = new GeometryReader(reader);
return geometryReader.readCurvePolygon(filter, hasZ, hasM);
}
/**
* Read a Polyhedral Surface
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return polyhedral surface
*/
public static readPolyhedralSurface(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): PolyhedralSurface {
const geometryReader = new GeometryReader(reader);
return geometryReader.readPolyhedralSurface(filter, hasZ, hasM);
}
/**
* Read a TIN
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return TIN
*/
public static readTIN(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): TIN {
const geometryReader = new GeometryReader(reader);
return geometryReader.readTIN(filter, hasZ, hasM);
}
/**
* Read a Triangle
* @param reader text reader
* @param filter geometry filter
* @param hasZ has z flag
* @param hasM has m flag
* @return triangle
*/
public static readTriangle(reader: StringReader, filter: GeometryFilter, hasZ: boolean, hasM: boolean): Triangle {
const geometryReader = new GeometryReader(reader);
return geometryReader.readTriangle(filter, hasZ, hasM);
}
/**
* Read a left parenthesis or empty set
* @param reader text reader
* @return true if not empty
*/
private static leftParenthesisOrEmpty(reader: StringReader): boolean {
let nonEmpty;
const token = reader.readToken();
switch (GeometryReader.toUpperCase(token)) {
case "EMPTY":
nonEmpty = false;
break;
case "(":
nonEmpty = true;
break;
default:
throw new SFException("Invalid token, expected 'EMPTY' or '('. found: '" + token + "'");
}
return nonEmpty;
}
/**
* Read a comma or right parenthesis
* @param reader text reader
* @return true if a comma
*/
private static commaOrRightParenthesis(reader: StringReader): boolean {
let comma;
const token = reader.readToken();
switch (GeometryReader.toUpperCase(token)) {
case ",":
comma = true;
break;
case ")":
comma = false;
break;
default:
throw new SFException("Invalid token, expected ',' or ')'. found: '"
+ token + "'");
}
return comma;
}
/**
* Read a right parenthesis
*
* @param reader
* text reader
*/
private static rightParenthesis(reader: StringReader): void {
let token = reader.readToken();
if (token !== ")") {
throw new SFException("Invalid token, expected ')'. found: '" + token + "'");
}
}
/**
* Determine if the next token is either a left parenthesis or empty
*
* @param reader
* text reader
* @return true if a left parenthesis or empty
*/
private static isLeftParenthesisOrEmpty(reader: StringReader): boolean {
let is = false;
const token = reader.peekToken();
switch (GeometryReader.toUpperCase(token)) {
case "EMPTY":
case "(":
is = true;
break;
default:
}
return is;
}
/**
* Determine if the next token is either a comma or right parenthesis
* @param reader text reader
* @return true if a comma
*/
private static isCommaOrRightParenthesis(reader: StringReader): boolean {
let is = false;
const token = reader.peekToken();
switch (token) {
case ",":
case ")":
is = true;
break;
default:
}
return is;
}
/**
* Filter the geometry
* @param filter geometry filter or null
* @param containingType containing geometry type
* @param geometry geometry or null
* @return true if passes filter
*/
private static filter(filter: GeometryFilter, containingType: GeometryType, geometry: Geometry): boolean {
return filter == null || geometry == null || filter.filter(containingType, geometry);
}
/**
* To upper case helper with null handling for switch statements
* @param value string value
* @return upper case value or empty string
*/
private static toUpperCase(value: string): string {
return value != null ? value.toLocaleUpperCase('en-US') : "";
}
}