@@ -111,21 +111,349 @@ class CORE_EXPORT QgsWKBTypes
111
111
* @see multiType()
112
112
* @see flatType()
113
113
*/
114
- static Type singleType ( Type type );
114
+ static Type singleType ( Type type )
115
+ {
116
+ switch ( type )
117
+ {
118
+ case Unknown:
119
+ case GeometryCollection:
120
+ case GeometryCollectionZ:
121
+ case GeometryCollectionM:
122
+ case GeometryCollectionZM:
123
+ return Unknown;
124
+
125
+ case Point:
126
+ case MultiPoint:
127
+ return Point;
128
+
129
+ case PointZ:
130
+ case MultiPointZ:
131
+ return PointZ;
132
+
133
+ case PointM:
134
+ case MultiPointM:
135
+ return PointM;
136
+
137
+ case PointZM:
138
+ case MultiPointZM:
139
+ return PointZM;
140
+
141
+ case LineString:
142
+ case MultiLineString:
143
+ return LineString;
144
+
145
+ case LineStringZ:
146
+ case MultiLineStringZ:
147
+ return LineStringZ;
148
+
149
+ case LineStringM:
150
+ case MultiLineStringM:
151
+ return LineStringM;
152
+
153
+ case LineStringZM:
154
+ case MultiLineStringZM:
155
+ return LineStringZM;
156
+
157
+ case Polygon:
158
+ case MultiPolygon:
159
+ return Polygon;
160
+
161
+ case PolygonZ:
162
+ case MultiPolygonZ:
163
+ return PolygonZ;
164
+
165
+ case PolygonM:
166
+ case MultiPolygonM:
167
+ return PolygonM;
168
+
169
+ case PolygonZM:
170
+ case MultiPolygonZM:
171
+ return PolygonZM;
172
+
173
+ case CircularString:
174
+ return CircularString;
175
+
176
+ case CircularStringZ:
177
+ return CircularStringZ;
178
+
179
+ case CircularStringM:
180
+ return CircularStringM;
181
+
182
+ case CircularStringZM:
183
+ return CircularStringZM;
184
+
185
+ case CompoundCurve:
186
+ case MultiCurve:
187
+ return CompoundCurve;
188
+
189
+ case CompoundCurveZ:
190
+ case MultiCurveZ:
191
+ return CompoundCurveZ;
192
+
193
+ case CompoundCurveM:
194
+ case MultiCurveM:
195
+ return CompoundCurveM;
196
+
197
+ case CompoundCurveZM:
198
+ case MultiCurveZM:
199
+ return CompoundCurveZM;
200
+
201
+ case CurvePolygon:
202
+ case MultiSurface:
203
+ return CurvePolygon;
204
+
205
+ case CurvePolygonZ:
206
+ case MultiSurfaceZ:
207
+ return CurvePolygonZ;
208
+
209
+ case CurvePolygonM:
210
+ case MultiSurfaceM:
211
+ return CurvePolygonM;
212
+
213
+ case CurvePolygonZM:
214
+ case MultiSurfaceZM:
215
+ return CurvePolygonZM;
216
+
217
+ case NoGeometry:
218
+ return NoGeometry;
219
+
220
+ case Point25D:
221
+ case MultiPoint25D:
222
+ return Point25D;
223
+
224
+ case LineString25D:
225
+ case MultiLineString25D:
226
+ return LineString25D;
227
+
228
+ case Polygon25D:
229
+ case MultiPolygon25D:
230
+ return Polygon25D;
231
+ }
232
+ return Unknown;
233
+ }
115
234
116
235
/* * Returns the multi type for a WKB type. Eg, for Polygon WKB types the multi type would be MultiPolygon.
117
236
* @see isMultiType()
118
237
* @see singleType()
119
238
* @see flatType()
120
239
*/
121
- static Type multiType ( Type type );
240
+ static Type multiType ( Type type )
241
+ {
242
+ switch ( type )
243
+ {
244
+ case Unknown:
245
+ return Unknown;
246
+
247
+ case GeometryCollection:
248
+ return GeometryCollection;
249
+
250
+ case GeometryCollectionZ:
251
+ return GeometryCollectionZ;
252
+
253
+ case GeometryCollectionM:
254
+ return GeometryCollectionM;
255
+
256
+ case GeometryCollectionZM:
257
+ return GeometryCollectionZM;
258
+
259
+ case Point:
260
+ case MultiPoint:
261
+ return MultiPoint;
262
+
263
+ case PointZ:
264
+ case MultiPointZ:
265
+ return MultiPointZ;
266
+
267
+ case PointM:
268
+ case MultiPointM:
269
+ return MultiPointM;
270
+
271
+ case PointZM:
272
+ case MultiPointZM:
273
+ return MultiPointZM;
274
+
275
+ case LineString:
276
+ case MultiLineString:
277
+ return MultiLineString;
278
+
279
+ case LineStringZ:
280
+ case MultiLineStringZ:
281
+ return MultiLineStringZ;
282
+
283
+ case LineStringM:
284
+ case MultiLineStringM:
285
+ return MultiLineStringM;
286
+
287
+ case LineStringZM:
288
+ case MultiLineStringZM:
289
+ return MultiLineStringZM;
290
+
291
+ case Polygon:
292
+ case MultiPolygon:
293
+ return MultiPolygon;
294
+
295
+ case PolygonZ:
296
+ case MultiPolygonZ:
297
+ return MultiPolygonZ;
298
+
299
+ case PolygonM:
300
+ case MultiPolygonM:
301
+ return MultiPolygonM;
302
+
303
+ case PolygonZM:
304
+ case MultiPolygonZM:
305
+ return MultiPolygonZM;
306
+
307
+ case CompoundCurve:
308
+ case CircularString:
309
+ case MultiCurve:
310
+ return MultiCurve;
311
+
312
+ case CompoundCurveZ:
313
+ case CircularStringZ:
314
+ case MultiCurveZ:
315
+ return MultiCurveZ;
316
+
317
+ case CompoundCurveM:
318
+ case CircularStringM:
319
+ case MultiCurveM:
320
+ return MultiCurveM;
321
+
322
+ case CompoundCurveZM:
323
+ case CircularStringZM:
324
+ case MultiCurveZM:
325
+ return MultiCurveZM;
326
+
327
+ case CurvePolygon:
328
+ case MultiSurface:
329
+ return MultiSurface;
330
+
331
+ case CurvePolygonZ:
332
+ case MultiSurfaceZ:
333
+ return MultiSurfaceZ;
334
+
335
+ case CurvePolygonM:
336
+ case MultiSurfaceM:
337
+ return MultiSurfaceM;
338
+
339
+ case CurvePolygonZM:
340
+ case MultiSurfaceZM:
341
+ return MultiSurfaceZM;
342
+
343
+ case NoGeometry:
344
+ return NoGeometry;
345
+
346
+ case Point25D:
347
+ case MultiPoint25D:
348
+ return MultiPoint25D;
349
+
350
+ case LineString25D:
351
+ case MultiLineString25D:
352
+ return MultiLineString25D;
353
+
354
+ case Polygon25D:
355
+ case MultiPolygon25D:
356
+ return MultiPolygon25D;
357
+ }
358
+ return Unknown;
359
+ }
122
360
123
361
/* * Returns the flat type for a WKB type. This is the WKB type minus any Z or M dimensions.
124
362
* Eg, for PolygonZM WKB types the single type would be Polygon.
125
363
* @see singleType()
126
364
* @see multiType()
127
365
*/
128
- static Type flatType ( Type type );
366
+ static Type flatType ( Type type )
367
+ {
368
+ switch ( type )
369
+ {
370
+ case Unknown:
371
+ return Unknown;
372
+
373
+ case Point:
374
+ case PointZ:
375
+ case PointM:
376
+ case PointZM:
377
+ case Point25D:
378
+ return Point;
379
+
380
+ case LineString:
381
+ case LineStringZ:
382
+ case LineStringM:
383
+ case LineStringZM:
384
+ case LineString25D:
385
+ return LineString;
386
+
387
+ case Polygon:
388
+ case PolygonZ:
389
+ case PolygonM:
390
+ case PolygonZM:
391
+ case Polygon25D:
392
+ return Polygon;
393
+
394
+ case MultiPoint:
395
+ case MultiPointZ:
396
+ case MultiPointM:
397
+ case MultiPointZM:
398
+ case MultiPoint25D:
399
+ return MultiPoint;
400
+
401
+ case MultiLineString:
402
+ case MultiLineStringZ:
403
+ case MultiLineStringM:
404
+ case MultiLineStringZM:
405
+ case MultiLineString25D:
406
+ return MultiLineString;
407
+
408
+ case MultiPolygon:
409
+ case MultiPolygonZ:
410
+ case MultiPolygonM:
411
+ case MultiPolygonZM:
412
+ case MultiPolygon25D:
413
+ return MultiPolygon;
414
+
415
+ case GeometryCollection:
416
+ case GeometryCollectionZ:
417
+ case GeometryCollectionM:
418
+ case GeometryCollectionZM:
419
+ return GeometryCollection;
420
+
421
+ case CircularString:
422
+ case CircularStringZ:
423
+ case CircularStringM:
424
+ case CircularStringZM:
425
+ return CircularString;
426
+
427
+ case CompoundCurve:
428
+ case CompoundCurveZ:
429
+ case CompoundCurveM:
430
+ case CompoundCurveZM:
431
+ return CompoundCurve;
432
+
433
+ case MultiCurve:
434
+ case MultiCurveZ:
435
+ case MultiCurveM:
436
+ case MultiCurveZM:
437
+ return MultiCurve;
438
+
439
+ case CurvePolygon:
440
+ case CurvePolygonZ:
441
+ case CurvePolygonM:
442
+ case CurvePolygonZM:
443
+ return CurvePolygon;
444
+
445
+ case MultiSurface:
446
+ case MultiSurfaceZ:
447
+ case MultiSurfaceM:
448
+ case MultiSurfaceZM:
449
+ return MultiSurface;
450
+
451
+ case NoGeometry:
452
+ return NoGeometry;
453
+
454
+ }
455
+ return Unknown;
456
+ }
129
457
130
458
/* * Attempts to extract the WKB type from a WKT string.
131
459
* @param wktStr a valid WKT string
@@ -136,39 +464,189 @@ class CORE_EXPORT QgsWKBTypes
136
464
* @see isMultiType()
137
465
* @see singleType()
138
466
*/
139
- static bool isSingleType ( Type type );
467
+ static bool isSingleType ( Type type )
468
+ {
469
+ return ( type != Unknown && !isMultiType ( type ) );
470
+ }
140
471
141
472
/* * Returns true if the WKB type is a multi type.
142
473
* @see isSingleType()
143
474
* @see multiType()
144
475
*/
145
- static bool isMultiType ( Type type );
476
+ static bool isMultiType ( Type type )
477
+ {
478
+ switch ( type )
479
+ {
480
+ case Unknown:
481
+ case Point:
482
+ case LineString:
483
+ case Polygon:
484
+ case CircularString:
485
+ case CompoundCurve:
486
+ case CurvePolygon:
487
+ case NoGeometry:
488
+ case PointZ:
489
+ case LineStringZ:
490
+ case PolygonZ:
491
+ case CircularStringZ:
492
+ case CompoundCurveZ:
493
+ case CurvePolygonZ:
494
+ case PointM:
495
+ case LineStringM:
496
+ case PolygonM:
497
+ case CircularStringM:
498
+ case CompoundCurveM:
499
+ case CurvePolygonM:
500
+ case PointZM:
501
+ case LineStringZM:
502
+ case PolygonZM:
503
+ case CircularStringZM:
504
+ case CompoundCurveZM:
505
+ case CurvePolygonZM:
506
+ case Point25D:
507
+ case LineString25D:
508
+ case Polygon25D:
509
+ return false ;
510
+
511
+ default :
512
+ return true ;
513
+
514
+ }
515
+
516
+ return false ;
517
+ }
146
518
147
519
/* * Returns true if the WKB type is a curved type or can contain curved geometries.
148
520
* @note added in QGIS 2.14
149
521
*/
150
- static bool isCurvedType ( Type type );
522
+ static bool isCurvedType ( Type type )
523
+ {
524
+ switch ( flatType ( type ) )
525
+ {
526
+ case CircularString:
527
+ case CompoundCurve:
528
+ case CurvePolygon:
529
+ case MultiCurve:
530
+ case MultiSurface:
531
+ return true ;
532
+
533
+ default :
534
+ return false ;
535
+ }
536
+
537
+ return false ;
538
+ }
151
539
152
540
/* * Returns the inherent dimension of the geometry type as an integer. Returned value will
153
541
* always be less than or equal to the coordinate dimension.
154
542
* @returns 0 for point geometries, 1 for line geometries, 2 for polygon geometries
155
543
* Invalid geometry types will return a dimension of 0.
156
544
* @see coordDimensions()
157
545
*/
158
- static int wkbDimensions ( Type type );
546
+ static int wkbDimensions ( Type type )
547
+ {
548
+ GeometryType gtype = geometryType ( type );
549
+ switch ( gtype )
550
+ {
551
+ case LineGeometry:
552
+ return 1 ;
553
+ case PolygonGeometry:
554
+ return 2 ;
555
+ default : // point, no geometry, unknown geometry
556
+ return 0 ;
557
+ }
558
+ }
159
559
160
560
/* * Returns the coordinate dimension of the geometry type as an integer. Returned value will
161
561
* be between 2-4, depending on whether the geometry type contains the Z or M dimensions.
162
562
* Invalid geometry types will return a dimension of 0.
163
563
* @note added in QGIS 2.14
164
564
* @see wkbDimensions()
165
565
*/
166
- static int coordDimensions ( Type type );
566
+ static int coordDimensions ( Type type )
567
+ {
568
+ if ( type == Unknown || type == NoGeometry )
569
+ return 0 ;
570
+
571
+ return 2 + hasZ ( type ) + hasM ( type );
572
+ }
167
573
168
574
/* * Returns the geometry type for a WKB type, eg both MultiPolygon and CurvePolygon would have a
169
575
* PolygonGeometry geometry type.
170
576
*/
171
- static GeometryType geometryType ( Type type );
577
+ static GeometryType geometryType ( Type type )
578
+ {
579
+ switch ( type )
580
+ {
581
+ case Unknown:
582
+ case GeometryCollection:
583
+ case GeometryCollectionZ:
584
+ case GeometryCollectionM:
585
+ case GeometryCollectionZM:
586
+ return UnknownGeometry;
587
+
588
+ case Point:
589
+ case MultiPoint:
590
+ case PointZ:
591
+ case MultiPointZ:
592
+ case PointM:
593
+ case MultiPointM:
594
+ case PointZM:
595
+ case MultiPointZM:
596
+ case Point25D:
597
+ case MultiPoint25D:
598
+ return PointGeometry;
599
+
600
+ case LineString:
601
+ case MultiLineString:
602
+ case LineStringZ:
603
+ case MultiLineStringZ:
604
+ case LineStringM:
605
+ case MultiLineStringM:
606
+ case LineStringZM:
607
+ case MultiLineStringZM:
608
+ case LineString25D:
609
+ case MultiLineString25D:
610
+ case CircularString:
611
+ case CompoundCurve:
612
+ case MultiCurve:
613
+ case CircularStringZ:
614
+ case CompoundCurveZ:
615
+ case MultiCurveZ:
616
+ case CircularStringM:
617
+ case CompoundCurveM:
618
+ case MultiCurveM:
619
+ case CircularStringZM:
620
+ case CompoundCurveZM:
621
+ case MultiCurveZM:
622
+ return LineGeometry;
623
+
624
+ case Polygon:
625
+ case MultiPolygon:
626
+ case PolygonZ:
627
+ case MultiPolygonZ:
628
+ case PolygonM:
629
+ case MultiPolygonM:
630
+ case PolygonZM:
631
+ case MultiPolygonZM:
632
+ case Polygon25D:
633
+ case MultiPolygon25D:
634
+ case CurvePolygon:
635
+ case MultiSurface:
636
+ case CurvePolygonZ:
637
+ case MultiSurfaceZ:
638
+ case CurvePolygonM:
639
+ case MultiSurfaceM:
640
+ case CurvePolygonZM:
641
+ case MultiSurfaceZM:
642
+ return PolygonGeometry;
643
+
644
+ case NoGeometry:
645
+ return NullGeometry;
646
+ }
647
+
648
+ return UnknownGeometry;
649
+ }
172
650
173
651
/* * Returns a display string type for a WKB type, eg the geometry name used in WKT geometry representations.
174
652
*/
@@ -179,14 +657,91 @@ class CORE_EXPORT QgsWKBTypes
179
657
* @see addZ()
180
658
* @see hasM()
181
659
*/
182
- static bool hasZ ( Type type );
660
+ static bool hasZ ( Type type )
661
+ {
662
+ switch ( type )
663
+ {
664
+ case PointZ:
665
+ case LineStringZ:
666
+ case PolygonZ:
667
+ case MultiPointZ:
668
+ case MultiLineStringZ:
669
+ case MultiPolygonZ:
670
+ case GeometryCollectionZ:
671
+ case CircularStringZ:
672
+ case CompoundCurveZ:
673
+ case CurvePolygonZ:
674
+ case MultiCurveZ:
675
+ case MultiSurfaceZ:
676
+ case PointZM:
677
+ case LineStringZM:
678
+ case PolygonZM:
679
+ case MultiPointZM:
680
+ case MultiLineStringZM:
681
+ case MultiPolygonZM:
682
+ case GeometryCollectionZM:
683
+ case CircularStringZM:
684
+ case CompoundCurveZM:
685
+ case CurvePolygonZM:
686
+ case MultiCurveZM:
687
+ case MultiSurfaceZM:
688
+ case Point25D:
689
+ case LineString25D:
690
+ case Polygon25D:
691
+ case MultiPoint25D:
692
+ case MultiLineString25D:
693
+ case MultiPolygon25D:
694
+ return true ;
695
+
696
+ default :
697
+ return false ;
698
+
699
+ }
700
+ return false ;
701
+
702
+ }
183
703
184
704
/* * Tests whether a WKB type contains m values.
185
705
* @returns true if type has m values
186
706
* @see addM()
187
707
* @see hasZ()
188
708
*/
189
- static bool hasM ( Type type );
709
+ static bool hasM ( Type type )
710
+ {
711
+ switch ( type )
712
+ {
713
+ case PointM:
714
+ case LineStringM:
715
+ case PolygonM:
716
+ case MultiPointM:
717
+ case MultiLineStringM:
718
+ case MultiPolygonM:
719
+ case GeometryCollectionM:
720
+ case CircularStringM:
721
+ case CompoundCurveM:
722
+ case CurvePolygonM:
723
+ case MultiCurveM:
724
+ case MultiSurfaceM:
725
+ case PointZM:
726
+ case LineStringZM:
727
+ case PolygonZM:
728
+ case MultiPointZM:
729
+ case MultiLineStringZM:
730
+ case MultiPolygonZM:
731
+ case GeometryCollectionZM:
732
+ case CircularStringZM:
733
+ case CompoundCurveZM:
734
+ case CurvePolygonZM:
735
+ case MultiCurveZM:
736
+ case MultiSurfaceZM:
737
+ return true ;
738
+
739
+ default :
740
+ return false ;
741
+
742
+ }
743
+ return false ;
744
+ }
190
745
191
746
/* * Adds the z dimension to a WKB type and returns the new type
192
747
* @param type original type
@@ -195,7 +750,22 @@ class CORE_EXPORT QgsWKBTypes
195
750
* @see dropZ()
196
751
* @see hasZ()
197
752
*/
198
- static Type addZ ( Type type );
753
+ static Type addZ ( Type type )
754
+ {
755
+ if ( hasZ ( type ) )
756
+ return type;
757
+ else if ( type == Unknown )
758
+ return Unknown;
759
+ else if ( type == NoGeometry )
760
+ return NoGeometry;
761
+
762
+ // upgrade with z dimension
763
+ Type flat = flatType ( type );
764
+ if ( hasM ( type ) )
765
+ return static_cast < QgsWKBTypes::Type >( flat + 3000 );
766
+ else
767
+ return static_cast < QgsWKBTypes::Type >( flat + 1000 );
768
+ }
199
769
200
770
/* * Adds the m dimension to a WKB type and returns the new type
201
771
* @param type original type
@@ -204,30 +774,81 @@ class CORE_EXPORT QgsWKBTypes
204
774
* @see dropM()
205
775
* @see hasM()
206
776
*/
207
- static Type addM ( Type type );
777
+ static Type addM ( Type type )
778
+ {
779
+ if ( hasM ( type ) )
780
+ return type;
781
+ else if ( type == Unknown )
782
+ return Unknown;
783
+ else if ( type == NoGeometry )
784
+ return NoGeometry;
785
+ else if ( type == Point25D ||
786
+ type == LineString25D ||
787
+ type == Polygon25D ||
788
+ type == MultiPoint25D ||
789
+ type == MultiLineString25D ||
790
+ type == MultiPolygon25D )
791
+ return type; // can't add M dimension to these types
792
+
793
+ // upgrade with m dimension
794
+ Type flat = flatType ( type );
795
+ if ( hasZ ( type ) )
796
+ return static_cast < QgsWKBTypes::Type >( flat + 3000 );
797
+ else
798
+ return static_cast < QgsWKBTypes::Type >( flat + 2000 );
799
+ }
208
800
209
801
/* * Drops the z dimension (if present) for a WKB type and returns the new type.
210
802
* @param type original type
211
803
* @note added in QGIS 2.14
212
804
* @see dropM()
213
805
* @see addZ()
214
806
*/
215
- static Type dropZ ( Type type );
807
+ static Type dropZ ( Type type )
808
+ {
809
+ if ( !hasZ ( type ) )
810
+ return type;
811
+
812
+ QgsWKBTypes::Type returnType = flatType ( type );
813
+ if ( hasM ( type ) )
814
+ returnType = addM ( returnType );
815
+ return returnType;
816
+ }
216
817
217
818
/* * Drops the m dimension (if present) for a WKB type and returns the new type.
218
819
* @param type original type
219
820
* @note added in QGIS 2.14
220
821
* @see dropZ()
221
822
* @see addM()
222
823
*/
223
- static Type dropM ( Type type );
824
+ static Type dropM ( Type type )
825
+ {
826
+ if ( !hasM ( type ) )
827
+ return type;
828
+
829
+ QgsWKBTypes::Type returnType = flatType ( type );
830
+ if ( hasZ ( type ) )
831
+ returnType = addZ ( returnType );
832
+ return returnType;
833
+ }
224
834
225
835
/* *
226
836
* Will convert the 25D version of the flat type if supported or Unknown if not supported.
227
837
* @param type The type to convert
228
838
* @return the 25D version of the type or Unknown
229
839
*/
230
- static Type to25D ( Type type );
840
+ static Type to25D ( Type type )
841
+ {
842
+ QgsWKBTypes::Type flat = flatType ( type );
843
+
844
+ if ( flat >= Point && flat <= MultiPolygon )
845
+ return static_cast < QgsWKBTypes::Type >( flat + 0x80000000 );
846
+ else if ( type == QgsWKBTypes::NoGeometry )
847
+ return QgsWKBTypes::NoGeometry;
848
+ else
849
+ return Unknown;
850
+ }
851
+
231
852
private:
232
853
233
854
struct wkbEntry
0 commit comments