QGIS API Documentation  2.12.0-Lyon
qgswkbtypes.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswkbtypes.cpp
3  ---------------
4  begin : January 2015
5  copyright : (C) 2015 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgswkbtypes.h"
19 
21 {
22  static QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry> entries = registerTypes();
23  return &entries;
24 }
25 
27 {
28  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
29  if ( it == entries()->constEnd() || it.key() == Unknown )
30  {
31  return Unknown;
32  }
33  return ( it->mSingleType );
34 }
35 
37 {
38  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
39  if ( it == entries()->constEnd() || it.key() == Unknown )
40  {
41  return Unknown;
42  }
43  return it->mMultiType;
44 }
45 
47 {
48  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
49  if ( it == entries()->constEnd() || it.key() == Unknown )
50  {
51  return Unknown;
52  }
53  return it->mFlatType;
54 }
55 
57 {
58  QString typestr = wktStr.left( wktStr.indexOf( '(' ) ).simplified().replace( " ", "" );
59  Q_FOREACH ( const Type& type, entries()->keys() )
60  {
61  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
62  if ( it != entries()->constEnd() && it.value().mName.compare( typestr, Qt::CaseInsensitive ) == 0 )
63  {
64  return type;
65  }
66  }
67  return Unknown;
68 }
69 
71 {
72  return ( type != Unknown && !isMultiType( type ) );
73 }
74 
76 {
77  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
78  if ( it == entries()->constEnd() )
79  {
80  return Unknown;
81  }
82  return it->mIsMultiType;
83 }
84 
86 {
87  GeometryType gtype = geometryType( type );
88  switch ( gtype )
89  {
90  case LineGeometry:
91  return 1;
92  case PolygonGeometry:
93  return 2;
94  default: //point, no geometry, unknown geometry
95  return 0;
96  }
97 }
98 
100 {
101  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
102  if ( it == entries()->constEnd() )
103  {
104  return UnknownGeometry;
105  }
106  return it->mGeometryType;
107 }
108 
110 {
111  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
112  if ( it == entries()->constEnd() )
113  {
114  return QString::null;
115  }
116  return it->mName;
117 }
118 
120 {
121  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
122  if ( it == entries()->constEnd() )
123  {
124  return false;
125  }
126  return it->mHasZ;
127 }
128 
130 {
131  QMap< Type, wkbEntry >::const_iterator it = entries()->constFind( type );
132  if ( it == entries()->constEnd() )
133  {
134  return false;
135  }
136  return it->mHasM;
137 }
138 
140 {
141  if ( hasZ( type ) )
142  return type;
143  else if ( type == Unknown )
144  return Unknown;
145  else if ( type == NoGeometry )
146  return NoGeometry;
147 
148  //upgrade with z dimension
149  Type flat = flatType( type );
150  if ( hasM( type ) )
151  return ( QgsWKBTypes::Type )( flat + 3000 );
152  else
153  return ( QgsWKBTypes::Type )( flat + 1000 );
154 }
155 
157 {
158  if ( hasM( type ) )
159  return type;
160  else if ( type == Unknown )
161  return Unknown;
162  else if ( type == NoGeometry )
163  return NoGeometry;
164  else if ( type == Point25D ||
165  type == LineString25D ||
166  type == Polygon25D ||
167  type == MultiPoint25D ||
168  type == MultiLineString25D ||
169  type == MultiPolygon25D )
170  return type; //can't add M dimension to these types
171 
172  //upgrade with m dimension
173  Type flat = flatType( type );
174  if ( hasZ( type ) )
175  return ( QgsWKBTypes::Type )( flat + 3000 );
176  else
177  return ( QgsWKBTypes::Type )( flat + 2000 );
178 }
179 
180 QMap<QgsWKBTypes::Type, QgsWKBTypes::wkbEntry> QgsWKBTypes::registerTypes()
181 {
183  //register the known wkb types
184  entries.insert( Unknown, wkbEntry( "Unknown", false, Unknown, Unknown, Unknown, UnknownGeometry, false, false ) );
185  entries.insert( NoGeometry, wkbEntry( "NoGeometry", false, NoGeometry, NoGeometry, NoGeometry, NullGeometry, false, false ) );
186  //point
187  entries.insert( Point, wkbEntry( "Point", false, MultiPoint, Point, Point, PointGeometry, false, false ) );
188  entries.insert( PointZ, wkbEntry( "PointZ", false, MultiPointZ, PointZ, Point, PointGeometry, true, false ) );
189  entries.insert( PointM, wkbEntry( "PointM", false, MultiPointM, PointM, Point, PointGeometry, false, true ) );
190  entries.insert( PointZM, wkbEntry( "PointZM", false, MultiPointZM, PointZM, Point, PointGeometry, true, true ) );
191  entries.insert( Point25D, wkbEntry( "Point25D", false, MultiPoint25D, Point25D, Point, PointGeometry, true, false ) );
192  //linestring
193  entries.insert( LineString, wkbEntry( "LineString", false, MultiLineString, LineString, LineString, LineGeometry, false, false ) );
194  entries.insert( LineStringZ, wkbEntry( "LineStringZ", false, MultiLineStringZ, LineStringZ, LineString, LineGeometry, true, false ) );
195  entries.insert( LineStringM, wkbEntry( "LineStringM", false, MultiLineStringM, LineStringM, LineString, LineGeometry, false, true ) );
196  entries.insert( LineStringZM, wkbEntry( "LineStringZM", false, MultiLineStringZM, LineStringZM, LineString, LineGeometry, true, true ) );
197  entries.insert( LineString25D, wkbEntry( "LineString25D", false, MultiLineString25D, LineString25D, LineString, LineGeometry, true, false ) );
198  //circularstring
199  entries.insert( CircularString, wkbEntry( "CircularString", false, MultiCurve, CircularString, CircularString, LineGeometry, false, false ) );
200  entries.insert( CircularStringZ, wkbEntry( "CircularStringZ", false, MultiCurveZ, CircularStringZ, CircularString, LineGeometry, true, false ) );
201  entries.insert( CircularStringM, wkbEntry( "CircularStringM", false, MultiCurveM, CircularStringM, CircularString, LineGeometry, false, true ) );
202  entries.insert( CircularStringZM, wkbEntry( "CircularStringZM", false, MultiCurveZM, CircularStringZM, CircularString, LineGeometry, true, true ) );
203  //compoundcurve
204  entries.insert( CompoundCurve, wkbEntry( "CompoundCurve", false, MultiCurve, CompoundCurve, CompoundCurve, LineGeometry, false, false ) );
205  entries.insert( CompoundCurveZ, wkbEntry( "CompoundCurveZ", false, MultiCurveZ, CompoundCurveZ, CompoundCurve, LineGeometry, true, false ) );
206  entries.insert( CompoundCurveM, wkbEntry( "CompoundCurveM", false, MultiCurveM, CompoundCurveM, CompoundCurve, LineGeometry, false, true ) );
207  entries.insert( CompoundCurveZM, wkbEntry( "CompoundCurveZM", false, MultiCurveZM, CompoundCurveZM, CompoundCurve, LineGeometry, true, true ) );
208  //polygon
209  entries.insert( Polygon, wkbEntry( "Polygon", false, MultiPolygon, Polygon, Polygon, PolygonGeometry, false, false ) );
210  entries.insert( PolygonZ, wkbEntry( "PolygonZ", false, MultiPolygonZ, PolygonZ, Polygon, PolygonGeometry, true, false ) );
211  entries.insert( PolygonM, wkbEntry( "PolygonM", false, MultiPolygonM, PolygonM, Polygon, PolygonGeometry, false, true ) );
212  entries.insert( PolygonZM, wkbEntry( "PolygonZM", false, MultiPolygonZM, PolygonZM, Polygon, PolygonGeometry, true, true ) );
213  entries.insert( Polygon25D, wkbEntry( "Polygon25D", false, MultiPolygon25D, Polygon25D, Polygon, PolygonGeometry, true, false ) );
214  //curvepolygon
215  entries.insert( CurvePolygon, wkbEntry( "CurvePolygon", false, MultiSurface, CurvePolygon, CurvePolygon, PolygonGeometry, false, false ) );
216  entries.insert( CurvePolygonZ, wkbEntry( "CurvePolygonZ", false, MultiSurfaceZ, CurvePolygonZ, CurvePolygon, PolygonGeometry, true, false ) );
217  entries.insert( CurvePolygonM, wkbEntry( "CurvePolygonM", false, MultiSurfaceM, CurvePolygonM, CurvePolygon, PolygonGeometry, false, true ) );
218  entries.insert( CurvePolygonZM, wkbEntry( "CurvePolygonZM", false, MultiSurfaceZM, CurvePolygonZM, CurvePolygon, PolygonGeometry, true, true ) );
219  //multipoint
220  entries.insert( MultiPoint, wkbEntry( "MultiPoint", true, MultiPoint, Point, MultiPoint, PointGeometry, false, false ) );
221  entries.insert( MultiPointZ, wkbEntry( "MultiPointZ", true, MultiPointZ, PointZ, MultiPoint, PointGeometry, true, false ) );
222  entries.insert( MultiPointM, wkbEntry( "MultiPointM", true, MultiPointM, PointM, MultiPoint, PointGeometry, false, true ) );
223  entries.insert( MultiPointZM, wkbEntry( "MultiPointZM", true, MultiPointZM, PointZM, MultiPoint, PointGeometry, true, true ) );
224  entries.insert( MultiPoint25D, wkbEntry( "MultiPoint25D", true, MultiPoint25D, Point25D, MultiPoint, PointGeometry, true, false ) );
225  //multiline
226  entries.insert( MultiLineString, wkbEntry( "MultiLineString", true, MultiLineString, LineString, MultiLineString, LineGeometry, false, false ) );
227  entries.insert( MultiLineStringZ, wkbEntry( "MultiLineStringZ", true, MultiLineStringZ, LineStringZ, MultiLineString, LineGeometry, true, false ) );
228  entries.insert( MultiLineStringM, wkbEntry( "MultiLineStringM", true, MultiLineStringM, LineStringM, MultiLineString, LineGeometry, false, true ) );
229  entries.insert( MultiLineStringZM, wkbEntry( "MultiLineStringZM", true, MultiLineStringZM, LineStringZM, MultiLineString, LineGeometry, true, true ) );
230  entries.insert( MultiLineString25D, wkbEntry( "MultiLineString25D", true, MultiLineString25D, LineString25D, MultiLineString, LineGeometry, true, false ) );
231  //multicurve
232  entries.insert( MultiCurve, wkbEntry( "MultiCurve", true, MultiCurve, CompoundCurve, MultiCurve, LineGeometry, false, false ) );
233  entries.insert( MultiCurveZ, wkbEntry( "MultiCurveZ", true, MultiCurveZ, CompoundCurveZ, MultiCurve, LineGeometry, true, false ) );
234  entries.insert( MultiCurveM, wkbEntry( "MultiCurveM", true, MultiCurveM, CompoundCurveM, MultiCurve, LineGeometry, false, true ) );
235  entries.insert( MultiCurveZM, wkbEntry( "MultiCurveZM", true, MultiCurveZM, CompoundCurveZM, MultiCurve, LineGeometry, true, true ) );
236  //multipolygon
237  entries.insert( MultiPolygon, wkbEntry( "MultiPolygon", true, MultiPolygon, Polygon, MultiPolygon, PolygonGeometry, false, false ) );
238  entries.insert( MultiPolygonZ, wkbEntry( "MultiPolygonZ", true, MultiPolygonZ, PolygonZ, MultiPolygon, PolygonGeometry, true, false ) );
239  entries.insert( MultiPolygonM, wkbEntry( "MultiPolygonM", true, MultiPolygonM, PolygonM, MultiPolygon, PolygonGeometry, false, true ) );
240  entries.insert( MultiPolygonZM, wkbEntry( "MultiPolygonZM", true, MultiPolygonZM, PolygonZM, MultiPolygon, PolygonGeometry, true, true ) );
241  entries.insert( MultiPolygon25D, wkbEntry( "MultiPolygon25D", true, MultiPolygon25D, Polygon25D, MultiPolygon, PolygonGeometry, true, false ) );
242  //multisurface
243  entries.insert( MultiSurface, wkbEntry( "MultiSurface", true, MultiSurface, CurvePolygon, MultiSurface, PolygonGeometry, false, false ) );
244  entries.insert( MultiSurfaceZ, wkbEntry( "MultiSurfaceZ", true, MultiSurfaceZ, CurvePolygonZ, MultiSurface, PolygonGeometry, true, false ) );
245  entries.insert( MultiSurfaceM, wkbEntry( "MultiSurfaceM", true, MultiSurfaceM, CurvePolygonM, MultiSurface, PolygonGeometry, false, true ) );
246  entries.insert( MultiSurfaceZM, wkbEntry( "MultiSurfaceZM", true, MultiSurfaceZM, CurvePolygonZM, MultiSurface, PolygonGeometry, true, true ) );
247  //geometrycollection
248  entries.insert( GeometryCollection, wkbEntry( "GeometryCollection", true, GeometryCollection, Unknown, GeometryCollection, UnknownGeometry, false, false ) );
249  entries.insert( GeometryCollectionZ, wkbEntry( "GeometryCollectionZ", true, GeometryCollectionZ, Unknown, GeometryCollection, UnknownGeometry, true, false ) );
250  entries.insert( GeometryCollectionM, wkbEntry( "GeometryCollectionM", true, GeometryCollectionM, Unknown, GeometryCollection, UnknownGeometry, false, true ) );
251  entries.insert( GeometryCollectionZM, wkbEntry( "GeometryCollectionZM", true, GeometryCollectionZM, Unknown, GeometryCollection, UnknownGeometry, true, true ) );
252  return entries;
253 }
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static bool isMultiType(Type type)
Definition: qgswkbtypes.cpp:75
static Type multiType(Type type)
Definition: qgswkbtypes.cpp:36
static Type singleType(Type type)
Definition: qgswkbtypes.cpp:26
static Type flatType(Type type)
Definition: qgswkbtypes.cpp:46
static int wkbDimensions(Type type)
Definition: qgswkbtypes.cpp:85
static bool hasM(Type type)
Tests whether a WKB type contains m values.
const Key & key() const
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
static GeometryType geometryType(Type type)
Definition: qgswkbtypes.cpp:99
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
const T & value() const
QString & replace(int position, int n, QChar after)
static bool isSingleType(Type type)
Definition: qgswkbtypes.cpp:70
QString left(int n) const
iterator insert(const Key &key, const T &value)
static Type parseType(const QString &wktStr)
Definition: qgswkbtypes.cpp:56
static QString displayString(Type type)
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.