QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgis.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgis.h - QGIS namespace
3  -------------------
4  begin : Sat Jun 30 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.com
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 #ifndef QGIS_H
19 #define QGIS_H
20 
21 #include <QEvent>
22 #include <QString>
23 #include <QRegExp>
24 #include <QMetaType>
25 #include <QVariant>
26 #include <stdlib.h>
27 #include <cfloat>
28 #include <cmath>
29 #include <qnumeric.h>
30 
34 class CORE_EXPORT QGis
35 {
36  public:
37  // Version constants
38  //
39  // Version string
40  static const char* QGIS_VERSION;
41  // Version number used for comparing versions using the "Check QGIS Version" function
42  static const int QGIS_VERSION_INT;
43  // Release name
44  static const char* QGIS_RELEASE_NAME;
45  // The development version
46  static const char* QGIS_DEV_VERSION;
47 
48  // Enumerations
49  //
50 
52  // Feature types
53  enum WkbType
54  {
55  WKBUnknown = 0,
56  WKBPoint = 1,
62  WKBNoGeometry = 100, //attributes only
63  WKBPoint25D = 0x80000001,
69  };
70 
71  static WkbType singleType( WkbType type )
72  {
73  switch ( type )
74  {
75  case WKBMultiPoint: return WKBPoint;
76  case WKBMultiLineString: return WKBLineString;
77  case WKBMultiPolygon: return WKBPolygon;
78  case WKBMultiPoint25D: return WKBPoint25D;
79  case WKBMultiLineString25D: return WKBLineString25D;
80  case WKBMultiPolygon25D: return WKBPolygon25D;
81  default: return type;
82  }
83  }
84 
85  static WkbType flatType( WkbType type )
86  {
87  switch ( type )
88  {
89  case WKBPoint25D: return WKBPoint;
90  case WKBLineString25D: return WKBLineString;
91  case WKBPolygon25D: return WKBPolygon;
92  case WKBMultiPoint25D: return WKBMultiPoint;
93  case WKBMultiLineString25D: return WKBMultiLineString;
94  case WKBMultiPolygon25D: return WKBMultiPolygon;
95  default: return type;
96  }
97  }
98 
99  static int wkbDimensions( WkbType type )
100  {
101  switch ( type )
102  {
103  case WKBUnknown: return 0;
104  case WKBNoGeometry: return 0;
105  case WKBPoint25D: return 3;
106  case WKBLineString25D: return 3;
107  case WKBPolygon25D: return 3;
108  case WKBMultiPoint25D: return 3;
109  case WKBMultiLineString25D: return 3;
110  case WKBMultiPolygon25D: return 3;
111  default: return 2;
112  }
113  }
114 
116  {
121  NoGeometry
122  };
123 
125  static const char *vectorGeometryType( GeometryType type )
126  {
127  switch ( type )
128  {
129  case Point: return "Point";
130  case Line: return "Line";
131  case Polygon: return "Polygon";
132  case UnknownGeometry: return "Unknown geometry";
133  case NoGeometry: return "No geometry";
134  default: return "Invalid type";
135  }
136  }
137 
139  static const char *featureType( WkbType type )
140  {
141  switch ( type )
142  {
143  case WKBUnknown: return "WKBUnknown";
144  case WKBPoint: return "WKBPoint";
145  case WKBLineString: return "WKBLineString";
146  case WKBPolygon: return "WKBPolygon";
147  case WKBMultiPoint: return "WKBMultiLineString";
148  case WKBMultiPolygon: return "WKBMultiPolygon";
149  case WKBNoGeometry: return "WKBNoGeometry";
150  case WKBPoint25D: return "WKBPoint25D";
151  case WKBLineString25D: return "WKBLineString25D";
152  case WKBPolygon25D: return "WKBPolygon25D";
153  case WKBMultiPoint25D: return "WKBMultiPoint25D";
154  case WKBMultiLineString25D: return "WKBMultiLineString25D";
155  case WKBMultiPolygon25D: return "WKBMultiPolygon25D";
156  default: return "invalid wkbtype";
157  }
158  }
159 
163  enum DataType
164  { UnknownDataType = 0, Byte = 1, UInt16 = 2, Int16 = 3, UInt32 = 4, Int32 = 5, Float32 = 6, Float64 = 7, CInt16 = 8, CInt32 = 9, CFloat32 = 10, CFloat64 = 11, ARGB32 = 12, ARGB32_Premultiplied = 13
181  };
182 
183 
188  enum UnitType
189  {
190  Meters = 0,
191  Feet = 1,
192  Degrees = 2, //for 1.0 api backwards compatibility
193  UnknownUnit = 3,
194 
195  // for [1.4;1.8] api compatibility
196  DecimalDegrees = 2, // was 2
197  DegreesMinutesSeconds = 2, // was 4
198  DegreesDecimalMinutes = 2, // was 5
199  };
200 
202  // Added in version 2.0
203  static QString toLiteral( QGis::UnitType unit );
205  // Added in version 2.0
206  static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
208  // Added in version 2.0
209  static QString tr( QGis::UnitType unit );
210 
213  {
214  // These first two are useful for threads to alert their parent data providers
215 
217  ProviderExtentCalcEvent = ( QEvent::User + 1 ),
218 
220  ProviderCountCalcEvent
221  };
222 
223  static const double DEFAULT_IDENTIFY_RADIUS;
224 
225  private:
226  // String representation of unit types (set in qgis.cpp)
227  static const char *qgisUnitTypes[];
228 
229 };
230 
231 // hack to workaround warnings when casting void pointers
232 // retrieved from QLibrary::resolve to function pointers.
233 // It's assumed that this works on all systems supporting
234 // QLibrary
235 inline void ( *cast_to_fptr( void *p ) )()
236 {
237  union
238  {
239  void *p;
240  void ( *f )();
241  } u;
242 
243  u.p = p;
244  return u.f;
245 }
246 
247 //
248 // return a string representation of a double
249 //
250 inline QString qgsDoubleToString( const double &a )
251 {
252  return QString::number( a, 'f', 17 ).remove( QRegExp( "\\.?0+$" ) );
253 }
254 
255 //
256 // compare two doubles (but allow some difference)
257 //
258 inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
259 {
260  const double diff = a - b;
261  return diff > -epsilon && diff <= epsilon;
262 }
263 
264 //
265 // compare two doubles using specified number of significant digits
266 //
267 inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
268 {
269  // The most simple would be to print numbers as %.xe and compare as strings
270  // but that is probably too costly
271  // Then the fastest would be to set some bits directly, but little/big endian
272  // has to be considered (maybe TODO)
273  // Is there a better way?
274  int aexp, bexp;
275  double ar = frexp( a, &aexp );
276  double br = frexp( b, &bexp );
277 
278  return aexp == bexp &&
279  qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) ) ;
280 }
281 
282 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
283 
284 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
285 
290 void CORE_EXPORT *qgsMalloc( size_t size );
291 
298 void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );
299 
303 void CORE_EXPORT qgsFree( void *ptr );
304 
308 extern CORE_EXPORT const QString GEOWKT;
309 extern CORE_EXPORT const QString PROJECT_SCALES;
310 
312 extern CORE_EXPORT const QString GEOPROJ4;
314 const long GEOSRID = 4326;
316 const long GEOCRS_ID = 3452;
318 const long GEO_EPSG_CRS_ID = 4326;
320 extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;
322 const int PROJ_PREFIX_LEN = 6;
324 const int ELLPS_PREFIX_LEN = 7;
326 const int LAT_PREFIX_LEN = 7;
329 const int USER_CRS_START_ID = 100000;
330 
332 // Added in version 2.0
333 extern CORE_EXPORT const QString GEO_NONE;
334 
335 //
336 // Constants for point symbols
337 //
338 
340 const double MINIMUM_POINT_SIZE = 0.1;
342 const double DEFAULT_POINT_SIZE = 2.0;
343 const double DEFAULT_LINE_WIDTH = 0.26;
344 
346 const double DEFAULT_SEGMENT_EPSILON = 1e-8;
347 
348 typedef QMap<QString, QString> QgsStringMap;
349 
350 // FIXME: also in qgisinterface.h
351 #ifndef QGISEXTERN
352 #ifdef WIN32
353 # define QGISEXTERN extern "C" __declspec( dllexport )
354 # ifdef _MSC_VER
355 // do not warn about C bindings returing QString
356 # pragma warning(disable:4190)
357 # endif
358 #else
359 # define QGISEXTERN extern "C"
360 #endif
361 #endif
362 
363 #endif