/
qgswkbtypes.cpp
253 lines (234 loc) · 12.7 KB
/
qgswkbtypes.cpp
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
/***************************************************************************
qgswkbtypes.cpp
---------------
begin : January 2015
copyright : (C) 2015 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgswkbtypes.h"
QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry>* QgsWKBTypes::entries()
{
static QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry> entries = registerTypes();
return &entries;
}
QgsWKBTypes::Type QgsWKBTypes::singleType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() || it.key() == Unknown )
{
return Unknown;
}
return ( it->mSingleType );
}
QgsWKBTypes::Type QgsWKBTypes::multiType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() || it.key() == Unknown )
{
return Unknown;
}
return it->mMultiType;
}
QgsWKBTypes::Type QgsWKBTypes::flatType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() || it.key() == Unknown )
{
return Unknown;
}
return it->mFlatType;
}
QgsWKBTypes::Type QgsWKBTypes::parseType( const QString &wktStr )
{
QString typestr = wktStr.left( wktStr.indexOf( '(' ) ).simplified().replace( " ", "" );
Q_FOREACH ( const Type& type, entries()->keys() )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it != entries()->constEnd() && it.value().mName.compare( typestr, Qt::CaseInsensitive ) == 0 )
{
return type;
}
}
return Unknown;
}
bool QgsWKBTypes::isSingleType( Type type )
{
return ( type != Unknown && !isMultiType( type ) );
}
bool QgsWKBTypes::isMultiType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() )
{
return Unknown;
}
return it->mIsMultiType;
}
int QgsWKBTypes::wkbDimensions( Type type )
{
GeometryType gtype = geometryType( type );
switch ( gtype )
{
case LineGeometry:
return 1;
case PolygonGeometry:
return 2;
default: //point, no geometry, unknown geometry
return 0;
}
}
QgsWKBTypes::GeometryType QgsWKBTypes::geometryType( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() )
{
return UnknownGeometry;
}
return it->mGeometryType;
}
QString QgsWKBTypes::displayString( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() )
{
return QString::null;
}
return it->mName;
}
bool QgsWKBTypes::hasZ( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() )
{
return false;
}
return it->mHasZ;
}
bool QgsWKBTypes::hasM( Type type )
{
QMap< Type, wkbEntry >::const_iterator it = entries()->find( type );
if ( it == entries()->constEnd() )
{
return false;
}
return it->mHasM;
}
QgsWKBTypes::Type QgsWKBTypes::addZ( QgsWKBTypes::Type type )
{
if ( hasZ( type ) )
return type;
else if ( type == Unknown )
return Unknown;
else if ( type == NoGeometry )
return NoGeometry;
//upgrade with z dimension
Type flat = flatType( type );
if ( hasM( type ) )
return ( QgsWKBTypes::Type )( flat + 3000 );
else
return ( QgsWKBTypes::Type )( flat + 1000 );
}
QgsWKBTypes::Type QgsWKBTypes::addM( QgsWKBTypes::Type type )
{
if ( hasM( type ) )
return type;
else if ( type == Unknown )
return Unknown;
else if ( type == NoGeometry )
return NoGeometry;
else if ( type == Point25D ||
type == LineString25D ||
type == Polygon25D ||
type == MultiPoint25D ||
type == MultiLineString25D ||
type == MultiPolygon25D )
return type; //can't add M dimension to these types
//upgrade with m dimension
Type flat = flatType( type );
if ( hasZ( type ) )
return ( QgsWKBTypes::Type )( flat + 3000 );
else
return ( QgsWKBTypes::Type )( flat + 2000 );
}
QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry> QgsWKBTypes::registerTypes()
{
QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry> entries;
//register the known wkb types
entries.insert( Unknown, wkbEntry( "Unknown", false, Unknown, Unknown, Unknown, UnknownGeometry, false, false ) );
entries.insert( NoGeometry, wkbEntry( "NoGeometry", false, NoGeometry, NoGeometry, NoGeometry, NullGeometry, false, false ) );
//point
entries.insert( Point, wkbEntry( "Point", false, MultiPoint, Point, Point, PointGeometry, false, false ) );
entries.insert( PointZ, wkbEntry( "PointZ", false, MultiPointZ, PointZ, Point, PointGeometry, true, false ) );
entries.insert( PointM, wkbEntry( "PointM", false, MultiPointM, PointM, Point, PointGeometry, false, true ) );
entries.insert( PointZM, wkbEntry( "PointZM", false, MultiPointZM, PointZM, Point, PointGeometry, true, true ) );
entries.insert( Point25D, wkbEntry( "Point25D", false, MultiPoint25D, Point25D, Point, PointGeometry, true, false ) );
//linestring
entries.insert( LineString, wkbEntry( "LineString", false, MultiLineString, LineString, LineString, LineGeometry, false, false ) );
entries.insert( LineStringZ, wkbEntry( "LineStringZ", false, MultiLineStringZ, LineStringZ, LineString, LineGeometry, true, false ) );
entries.insert( LineStringM, wkbEntry( "LineStringM", false, MultiLineStringM, LineStringM, LineString, LineGeometry, false, true ) );
entries.insert( LineStringZM, wkbEntry( "LineStringZM", false, MultiLineStringZM, LineStringZM, LineString, LineGeometry, true, true ) );
entries.insert( LineString25D, wkbEntry( "LineString25D", false, MultiLineString25D, LineString25D, LineString, LineGeometry, true, false ) );
//circularstring
entries.insert( CircularString, wkbEntry( "CircularString", false, MultiCurve, CircularString, CircularString, LineGeometry, false, false ) );
entries.insert( CircularStringZ, wkbEntry( "CircularStringZ", false, MultiCurveZ, CircularStringZ, CircularString, LineGeometry, true, false ) );
entries.insert( CircularStringM, wkbEntry( "CircularStringM", false, MultiCurveM, CircularStringM, CircularString, LineGeometry, false, true ) );
entries.insert( CircularStringZM, wkbEntry( "CircularStringZM", false, MultiCurveZM, CircularStringZM, CircularString, LineGeometry, true, true ) );
//compoundcurve
entries.insert( CompoundCurve, wkbEntry( "CompoundCurve", false, MultiCurve, CompoundCurve, CompoundCurve, LineGeometry, false, false ) );
entries.insert( CompoundCurveZ, wkbEntry( "CompoundCurveZ", false, MultiCurveZ, CompoundCurveZ, CompoundCurve, LineGeometry, true, false ) );
entries.insert( CompoundCurveM, wkbEntry( "CompoundCurveM", false, MultiCurveM, CompoundCurveM, CompoundCurve, LineGeometry, false, true ) );
entries.insert( CompoundCurveZM, wkbEntry( "CompoundCurveZM", false, MultiCurveZM, CompoundCurveZM, CompoundCurve, LineGeometry, true, true ) );
//polygon
entries.insert( Polygon, wkbEntry( "Polygon", false, MultiPolygon, Polygon, Polygon, PolygonGeometry, false, false ) );
entries.insert( PolygonZ, wkbEntry( "PolygonZ", false, MultiPolygonZ, PolygonZ, Polygon, PolygonGeometry, true, false ) );
entries.insert( PolygonM, wkbEntry( "PolygonM", false, MultiPolygonM, PolygonM, Polygon, PolygonGeometry, false, true ) );
entries.insert( PolygonZM, wkbEntry( "PolygonZM", false, MultiPolygonZM, PolygonZM, Polygon, PolygonGeometry, true, true ) );
entries.insert( Polygon25D, wkbEntry( "Polygon25D", false, MultiPolygon25D, Polygon25D, Polygon, PolygonGeometry, true, false ) );
//curvepolygon
entries.insert( CurvePolygon, wkbEntry( "CurvePolygon", false, MultiSurface, CurvePolygon, CurvePolygon, PolygonGeometry, false, false ) );
entries.insert( CurvePolygonZ, wkbEntry( "CurvePolygonZ", false, MultiSurfaceZ, CurvePolygonZ, CurvePolygon, PolygonGeometry, true, false ) );
entries.insert( CurvePolygonM, wkbEntry( "CurvePolygonM", false, MultiSurfaceM, CurvePolygonM, CurvePolygon, PolygonGeometry, false, true ) );
entries.insert( CurvePolygonZM, wkbEntry( "CurvePolygonZM", false, MultiSurfaceZM, CurvePolygonZM, CurvePolygon, PolygonGeometry, true, true ) );
//multipoint
entries.insert( MultiPoint, wkbEntry( "MultiPoint", true, MultiPoint, Point, MultiPoint, PointGeometry, false, false ) );
entries.insert( MultiPointZ, wkbEntry( "MultiPointZ", true, MultiPointZ, PointZ, MultiPoint, PointGeometry, true, false ) );
entries.insert( MultiPointM, wkbEntry( "MultiPointM", true, MultiPointM, PointM, MultiPoint, PointGeometry, false, true ) );
entries.insert( MultiPointZM, wkbEntry( "MultiPointZM", true, MultiPointZM, PointZM, MultiPoint, PointGeometry, true, true ) );
entries.insert( MultiPoint25D, wkbEntry( "MultiPoint25D", true, MultiPoint25D, Point25D, MultiPoint, PointGeometry, true, false ) );
//multiline
entries.insert( MultiLineString, wkbEntry( "MultiLineString", true, MultiLineString, LineString, MultiLineString, LineGeometry, false, false ) );
entries.insert( MultiLineStringZ, wkbEntry( "MultiLineStringZ", true, MultiLineStringZ, LineStringZ, MultiLineString, LineGeometry, true, false ) );
entries.insert( MultiLineStringM, wkbEntry( "MultiLineStringM", true, MultiLineStringM, LineStringM, MultiLineString, LineGeometry, false, true ) );
entries.insert( MultiLineStringZM, wkbEntry( "MultiLineStringZM", true, MultiLineStringZM, LineStringZM, MultiLineString, LineGeometry, true, true ) );
entries.insert( MultiLineString25D, wkbEntry( "MultiLineString25D", true, MultiLineString25D, LineString25D, MultiLineString, LineGeometry, true, false ) );
//multicurve
entries.insert( MultiCurve, wkbEntry( "MultiCurve", true, MultiCurve, CompoundCurve, MultiCurve, LineGeometry, false, false ) );
entries.insert( MultiCurveZ, wkbEntry( "MultiCurveZ", true, MultiCurveZ, CompoundCurveZ, MultiCurve, LineGeometry, true, false ) );
entries.insert( MultiCurveM, wkbEntry( "MultiCurveM", true, MultiCurveM, CompoundCurveM, MultiCurve, LineGeometry, false, true ) );
entries.insert( MultiCurveZM, wkbEntry( "MultiCurveZM", true, MultiCurveZM, CompoundCurveZM, MultiCurve, LineGeometry, true, true ) );
//multipolygon
entries.insert( MultiPolygon, wkbEntry( "MultiPolygon", true, MultiPolygon, Polygon, MultiPolygon, PolygonGeometry, false, false ) );
entries.insert( MultiPolygonZ, wkbEntry( "MultiPolygonZ", true, MultiPolygonZ, PolygonZ, MultiPolygon, PolygonGeometry, true, false ) );
entries.insert( MultiPolygonM, wkbEntry( "MultiPolygonM", true, MultiPolygonM, PolygonM, MultiPolygon, PolygonGeometry, false, true ) );
entries.insert( MultiPolygonZM, wkbEntry( "MultiPolygonZM", true, MultiPolygonZM, PolygonZM, MultiPolygon, PolygonGeometry, true, true ) );
entries.insert( MultiPolygon25D, wkbEntry( "MultiPolygon25D", true, MultiPolygon25D, Polygon25D, MultiPolygon, PolygonGeometry, true, false ) );
//multisurface
entries.insert( MultiSurface, wkbEntry( "MultiSurface", true, MultiSurface, CurvePolygon, MultiSurface, PolygonGeometry, false, false ) );
entries.insert( MultiSurfaceZ, wkbEntry( "MultiSurfaceZ", true, MultiSurfaceZ, CurvePolygonZ, MultiSurface, PolygonGeometry, true, false ) );
entries.insert( MultiSurfaceM, wkbEntry( "MultiSurfaceM", true, MultiSurfaceM, CurvePolygonM, MultiSurface, PolygonGeometry, false, true ) );
entries.insert( MultiSurfaceZM, wkbEntry( "MultiSurfaceZM", true, MultiSurfaceZM, CurvePolygonZM, MultiSurface, PolygonGeometry, true, true ) );
//geometrycollection
entries.insert( GeometryCollection, wkbEntry( "GeometryCollection", true, GeometryCollection, Unknown, GeometryCollection, UnknownGeometry, false, false ) );
entries.insert( GeometryCollectionZ, wkbEntry( "GeometryCollectionZ", true, GeometryCollectionZ, Unknown, GeometryCollection, UnknownGeometry, true, false ) );
entries.insert( GeometryCollectionM, wkbEntry( "GeometryCollectionM", true, GeometryCollectionM, Unknown, GeometryCollection, UnknownGeometry, false, true ) );
entries.insert( GeometryCollectionZM, wkbEntry( "GeometryCollectionZM", true, GeometryCollectionZM, Unknown, GeometryCollection, UnknownGeometry, true, true ) );
return entries;
}