Skip to content

Commit ac033cf

Browse files
committedJan 24, 2016
Refactor and optimise certain QgsWKBTypes functions
Given how frequently these functions are called throughout QGIS, it makes sense for them to be written in a way that makes it easy for the compiler to optimise them/inline them.
1 parent ba530a0 commit ac033cf

File tree

2 files changed

+637
-229
lines changed

2 files changed

+637
-229
lines changed
 

‎src/core/geometry/qgswkbtypes.cpp

Lines changed: 0 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,6 @@ QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry>* QgsWKBTypes::entries()
2929
return &entries;
3030
}
3131

32-
QgsWKBTypes::Type QgsWKBTypes::singleType( Type type )
33-
{
34-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
35-
if ( it == entries()->constEnd() || it.key() == Unknown )
36-
{
37-
return Unknown;
38-
}
39-
return ( it->mSingleType );
40-
}
41-
42-
QgsWKBTypes::Type QgsWKBTypes::multiType( Type type )
43-
{
44-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
45-
if ( it == entries()->constEnd() || it.key() == Unknown )
46-
{
47-
return Unknown;
48-
}
49-
return it->mMultiType;
50-
}
51-
52-
QgsWKBTypes::Type QgsWKBTypes::flatType( Type type )
53-
{
54-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
55-
if ( it == entries()->constEnd() || it.key() == Unknown )
56-
{
57-
return Unknown;
58-
}
59-
return it->mFlatType;
60-
}
61-
62-
/***************************************************************************
63-
* This class is considered CRITICAL and any change MUST be accompanied with
64-
* full unit tests.
65-
* See details in QEP #17
66-
****************************************************************************/
67-
6832
QgsWKBTypes::Type QgsWKBTypes::parseType( const QString &wktStr )
6933
{
7034
QString typestr = wktStr.left( wktStr.indexOf( '(' ) ).simplified().remove( ' ' );
@@ -79,82 +43,6 @@ QgsWKBTypes::Type QgsWKBTypes::parseType( const QString &wktStr )
7943
return Unknown;
8044
}
8145

82-
bool QgsWKBTypes::isSingleType( Type type )
83-
{
84-
return ( type != Unknown && !isMultiType( type ) );
85-
}
86-
87-
bool QgsWKBTypes::isMultiType( Type type )
88-
{
89-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
90-
if ( it == entries()->constEnd() )
91-
{
92-
return Unknown;
93-
}
94-
return it->mIsMultiType;
95-
}
96-
97-
bool QgsWKBTypes::isCurvedType( QgsWKBTypes::Type type )
98-
{
99-
switch ( flatType( type ) )
100-
{
101-
case CircularString:
102-
case CompoundCurve:
103-
case CurvePolygon:
104-
case MultiCurve:
105-
case MultiSurface:
106-
return true;
107-
108-
default:
109-
return false;
110-
}
111-
112-
return false;
113-
}
114-
115-
/***************************************************************************
116-
* This class is considered CRITICAL and any change MUST be accompanied with
117-
* full unit tests.
118-
* See details in QEP #17
119-
****************************************************************************/
120-
121-
int QgsWKBTypes::wkbDimensions( Type type )
122-
{
123-
GeometryType gtype = geometryType( type );
124-
switch ( gtype )
125-
{
126-
case LineGeometry:
127-
return 1;
128-
case PolygonGeometry:
129-
return 2;
130-
default: //point, no geometry, unknown geometry
131-
return 0;
132-
}
133-
}
134-
135-
int QgsWKBTypes::coordDimensions( QgsWKBTypes::Type type )
136-
{
137-
if ( type == Unknown || type == NoGeometry )
138-
return 0;
139-
140-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
141-
if ( it == entries()->constEnd() )
142-
{
143-
return 0;
144-
}
145-
return 2 + it->mHasZ + it->mHasM;
146-
}
147-
148-
QgsWKBTypes::GeometryType QgsWKBTypes::geometryType( Type type )
149-
{
150-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
151-
if ( it == entries()->constEnd() )
152-
{
153-
return UnknownGeometry;
154-
}
155-
return it->mGeometryType;
156-
}
157-
15846
QString QgsWKBTypes::displayString( Type type )
15947
{
16048
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
@@ -165,107 +53,6 @@ QString QgsWKBTypes::displayString( Type type )
16553
return it->mName;
16654
}
16755

168-
/***************************************************************************
169-
* This class is considered CRITICAL and any change MUST be accompanied with
170-
* full unit tests.
171-
* See details in QEP #17
172-
****************************************************************************/
173-
174-
bool QgsWKBTypes::hasZ( Type type )
175-
{
176-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
177-
if ( it == entries()->constEnd() )
178-
{
179-
return false;
180-
}
181-
return it->mHasZ;
182-
}
183-
184-
bool QgsWKBTypes::hasM( Type type )
185-
{
186-
QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
187-
if ( it == entries()->constEnd() )
188-
{
189-
return false;
190-
}
191-
return it->mHasM;
192-
}
193-
194-
QgsWKBTypes::Type QgsWKBTypes::addZ( QgsWKBTypes::Type type )
195-
{
196-
if ( hasZ( type ) )
197-
return type;
198-
else if ( type == Unknown )
199-
return Unknown;
200-
else if ( type == NoGeometry )
201-
return NoGeometry;
202-
203-
//upgrade with z dimension
204-
Type flat = flatType( type );
205-
if ( hasM( type ) )
206-
return static_cast< QgsWKBTypes::Type >( flat + 3000 );
207-
else
208-
return static_cast< QgsWKBTypes::Type >( flat + 1000 );
209-
}
210-
211-
QgsWKBTypes::Type QgsWKBTypes::addM( QgsWKBTypes::Type type )
212-
{
213-
if ( hasM( type ) )
214-
return type;
215-
else if ( type == Unknown )
216-
return Unknown;
217-
else if ( type == NoGeometry )
218-
return NoGeometry;
219-
else if ( type == Point25D ||
220-
type == LineString25D ||
221-
type == Polygon25D ||
222-
type == MultiPoint25D ||
223-
type == MultiLineString25D ||
224-
type == MultiPolygon25D )
225-
return type; //can't add M dimension to these types
226-
227-
//upgrade with m dimension
228-
Type flat = flatType( type );
229-
if ( hasZ( type ) )
230-
return static_cast< QgsWKBTypes::Type >( flat + 3000 );
231-
else
232-
return static_cast< QgsWKBTypes::Type >( flat + 2000 );
233-
}
234-
235-
QgsWKBTypes::Type QgsWKBTypes::dropZ( QgsWKBTypes::Type type )
236-
{
237-
if ( !hasZ( type ) )
238-
return type;
239-
240-
QgsWKBTypes::Type returnType = flatType( type );
241-
if ( hasM( type ) )
242-
returnType = addM( returnType );
243-
return returnType;
244-
}
245-
246-
QgsWKBTypes::Type QgsWKBTypes::dropM( QgsWKBTypes::Type type )
247-
{
248-
if ( !hasM( type ) )
249-
return type;
250-
251-
QgsWKBTypes::Type returnType = flatType( type );
252-
if ( hasZ( type ) )
253-
returnType = addZ( returnType );
254-
return returnType;
255-
}
256-
257-
QgsWKBTypes::Type QgsWKBTypes::to25D( QgsWKBTypes::Type type )
258-
{
259-
QgsWKBTypes::Type flat = flatType( type );
260-
261-
if ( flat >= Point && flat <= MultiPolygon )
262-
return static_cast< QgsWKBTypes::Type >( flat + 0x80000000 );
263-
else if ( type == QgsWKBTypes::NoGeometry )
264-
return QgsWKBTypes::NoGeometry;
265-
else
266-
return Unknown;
267-
}
268-
26956
/***************************************************************************
27057
* This class is considered CRITICAL and any change MUST be accompanied with
27158
* full unit tests.

‎src/core/geometry/qgswkbtypes.h

Lines changed: 637 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,349 @@ class CORE_EXPORT QgsWKBTypes
111111
* @see multiType()
112112
* @see flatType()
113113
*/
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+
}
115234

116235
/** Returns the multi type for a WKB type. Eg, for Polygon WKB types the multi type would be MultiPolygon.
117236
* @see isMultiType()
118237
* @see singleType()
119238
* @see flatType()
120239
*/
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+
}
122360

123361
/** Returns the flat type for a WKB type. This is the WKB type minus any Z or M dimensions.
124362
* Eg, for PolygonZM WKB types the single type would be Polygon.
125363
* @see singleType()
126364
* @see multiType()
127365
*/
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+
}
129457

130458
/** Attempts to extract the WKB type from a WKT string.
131459
* @param wktStr a valid WKT string
@@ -136,39 +464,189 @@ class CORE_EXPORT QgsWKBTypes
136464
* @see isMultiType()
137465
* @see singleType()
138466
*/
139-
static bool isSingleType( Type type );
467+
static bool isSingleType( Type type )
468+
{
469+
return ( type != Unknown && !isMultiType( type ) );
470+
}
140471

141472
/** Returns true if the WKB type is a multi type.
142473
* @see isSingleType()
143474
* @see multiType()
144475
*/
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+
}
146518

147519
/** Returns true if the WKB type is a curved type or can contain curved geometries.
148520
* @note added in QGIS 2.14
149521
*/
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+
}
151539

152540
/** Returns the inherent dimension of the geometry type as an integer. Returned value will
153541
* always be less than or equal to the coordinate dimension.
154542
* @returns 0 for point geometries, 1 for line geometries, 2 for polygon geometries
155543
* Invalid geometry types will return a dimension of 0.
156544
* @see coordDimensions()
157545
*/
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+
}
159559

160560
/** Returns the coordinate dimension of the geometry type as an integer. Returned value will
161561
* be between 2-4, depending on whether the geometry type contains the Z or M dimensions.
162562
* Invalid geometry types will return a dimension of 0.
163563
* @note added in QGIS 2.14
164564
* @see wkbDimensions()
165565
*/
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+
}
167573

168574
/** Returns the geometry type for a WKB type, eg both MultiPolygon and CurvePolygon would have a
169575
* PolygonGeometry geometry type.
170576
*/
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+
}
172650

173651
/** Returns a display string type for a WKB type, eg the geometry name used in WKT geometry representations.
174652
*/
@@ -179,14 +657,91 @@ class CORE_EXPORT QgsWKBTypes
179657
* @see addZ()
180658
* @see hasM()
181659
*/
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+
}
183703

184704
/** Tests whether a WKB type contains m values.
185705
* @returns true if type has m values
186706
* @see addM()
187707
* @see hasZ()
188708
*/
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+
}
190745

191746
/** Adds the z dimension to a WKB type and returns the new type
192747
* @param type original type
@@ -195,7 +750,22 @@ class CORE_EXPORT QgsWKBTypes
195750
* @see dropZ()
196751
* @see hasZ()
197752
*/
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+
}
199769

200770
/** Adds the m dimension to a WKB type and returns the new type
201771
* @param type original type
@@ -204,30 +774,81 @@ class CORE_EXPORT QgsWKBTypes
204774
* @see dropM()
205775
* @see hasM()
206776
*/
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+
}
208800

209801
/** Drops the z dimension (if present) for a WKB type and returns the new type.
210802
* @param type original type
211803
* @note added in QGIS 2.14
212804
* @see dropM()
213805
* @see addZ()
214806
*/
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+
}
216817

217818
/** Drops the m dimension (if present) for a WKB type and returns the new type.
218819
* @param type original type
219820
* @note added in QGIS 2.14
220821
* @see dropZ()
221822
* @see addM()
222823
*/
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+
}
224834

225835
/**
226836
* Will convert the 25D version of the flat type if supported or Unknown if not supported.
227837
* @param type The type to convert
228838
* @return the 25D version of the type or Unknown
229839
*/
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+
231852
private:
232853

233854
struct wkbEntry

0 commit comments

Comments
 (0)
Please sign in to comment.