QGIS API Documentation  2.10.1-Pisa
 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 multiType( WkbType type )
86  {
87  switch ( type )
88  {
89  case WKBPoint: return WKBMultiPoint;
90  case WKBLineString: return WKBMultiLineString;
91  case WKBPolygon: return WKBMultiPolygon;
92  case WKBPoint25D: return WKBMultiPoint25D;
93  case WKBLineString25D: return WKBMultiLineString25D;
94  case WKBPolygon25D: return WKBMultiPolygon25D;
95  default: return type;
96  }
97  }
98 
99  static WkbType flatType( WkbType type )
100  {
101  switch ( type )
102  {
103  case WKBPoint25D: return WKBPoint;
104  case WKBLineString25D: return WKBLineString;
105  case WKBPolygon25D: return WKBPolygon;
106  case WKBMultiPoint25D: return WKBMultiPoint;
107  case WKBMultiLineString25D: return WKBMultiLineString;
108  case WKBMultiPolygon25D: return WKBMultiPolygon;
109  default: return type;
110  }
111  }
112 
113  static bool isSingleType( WkbType type )
114  {
115  switch ( flatType( type ) )
116  {
117  case WKBPoint:
118  case WKBLineString:
119  case WKBPolygon:
120  return true;
121  default:
122  return false;
123  }
124  }
125 
126  static bool isMultiType( WkbType type )
127  {
128  switch ( flatType( type ) )
129  {
130  case WKBMultiPoint:
131  case WKBMultiLineString:
132  case WKBMultiPolygon:
133  return true;
134  default:
135  return false;
136  }
137  }
138 
139  static int wkbDimensions( WkbType type )
140  {
141  switch ( type )
142  {
143  case WKBUnknown: return 0;
144  case WKBNoGeometry: return 0;
145  case WKBPoint25D: return 3;
146  case WKBLineString25D: return 3;
147  case WKBPolygon25D: return 3;
148  case WKBMultiPoint25D: return 3;
149  case WKBMultiLineString25D: return 3;
150  case WKBMultiPolygon25D: return 3;
151  default: return 2;
152  }
153  }
154 
156  {
161  NoGeometry
162  };
163 
165  static const char *vectorGeometryType( GeometryType type )
166  {
167  switch ( type )
168  {
169  case Point: return "Point";
170  case Line: return "Line";
171  case Polygon: return "Polygon";
172  case UnknownGeometry: return "Unknown geometry";
173  case NoGeometry: return "No geometry";
174  default: return "Invalid type";
175  }
176  }
177 
179  static const char *featureType( WkbType type )
180  {
181  switch ( type )
182  {
183  case WKBUnknown: return "WKBUnknown";
184  case WKBPoint: return "WKBPoint";
185  case WKBLineString: return "WKBLineString";
186  case WKBPolygon: return "WKBPolygon";
187  case WKBMultiPoint: return "WKBMultiPoint";
188  case WKBMultiLineString: return "WKBMultiLineString";
189  case WKBMultiPolygon: return "WKBMultiPolygon";
190  case WKBNoGeometry: return "WKBNoGeometry";
191  case WKBPoint25D: return "WKBPoint25D";
192  case WKBLineString25D: return "WKBLineString25D";
193  case WKBPolygon25D: return "WKBPolygon25D";
194  case WKBMultiPoint25D: return "WKBMultiPoint25D";
195  case WKBMultiLineString25D: return "WKBMultiLineString25D";
196  case WKBMultiPolygon25D: return "WKBMultiPolygon25D";
197  default: return "invalid wkbtype";
198  }
199  }
200 
204  enum DataType
205  { 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
222  };
223 
224 
229  enum UnitType
230  {
231  Meters = 0,
232  Feet = 1,
233  Degrees = 2, //for 1.0 api backwards compatibility
234  UnknownUnit = 3,
235 
236  // for [1.4;1.8] api compatibility
237  DecimalDegrees = 2, // was 2
238  DegreesMinutesSeconds = 2, // was 4
239  DegreesDecimalMinutes = 2, // was 5
240  NauticalMiles = 7
241  };
242 
244  static QString toLiteral( QGis::UnitType unit );
246  static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
248  static QString tr( QGis::UnitType unit );
250  static UnitType fromTr( QString literal, QGis::UnitType defaultType = UnknownUnit );
252  static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
253 
262  static double permissiveToDouble( QString string, bool& ok );
263 
272  static int permissiveToInt( QString string, bool& ok );
273 
276  {
277  // These first two are useful for threads to alert their parent data providers
278 
280  ProviderExtentCalcEvent = ( QEvent::User + 1 ),
281 
283  ProviderCountCalcEvent
284  };
285 
288  static const double DEFAULT_IDENTIFY_RADIUS;
289 
292  static const double DEFAULT_SEARCH_RADIUS_MM;
293 
295  static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
296 
301 
305 
309 
310  private:
311  // String representation of unit types (set in qgis.cpp)
312  static const char *qgisUnitTypes[];
313 
314 };
315 
316 // hack to workaround warnings when casting void pointers
317 // retrieved from QLibrary::resolve to function pointers.
318 // It's assumed that this works on all systems supporting
319 // QLibrary
320 #if QT_VERSION >= 0x050000
321 #define cast_to_fptr(f) f
322 #else
323 inline void ( *cast_to_fptr( void *p ) )()
324 {
325  union
326  {
327  void *p;
328  void ( *f )();
329  } u;
330 
331  u.p = p;
332  return u.f;
333 }
334 #endif
335 
336 //
337 // return a string representation of a double
338 //
339 inline QString qgsDoubleToString( const double &a, const int &precision = 17 )
340 {
341  if ( precision )
342  return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
343  else
344  return QString::number( a, 'f', precision );
345 }
346 
347 //
348 // compare two doubles (but allow some difference)
349 //
350 inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
351 {
352  const double diff = a - b;
353  return diff > -epsilon && diff <= epsilon;
354 }
355 
356 //
357 // compare two doubles using specified number of significant digits
358 //
359 inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
360 {
361  // The most simple would be to print numbers as %.xe and compare as strings
362  // but that is probably too costly
363  // Then the fastest would be to set some bits directly, but little/big endian
364  // has to be considered (maybe TODO)
365  // Is there a better way?
366  int aexp, bexp;
367  double ar = frexp( a, &aexp );
368  double br = frexp( b, &bexp );
369 
370  return aexp == bexp &&
371  qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) );
372 }
373 
374 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
375 
376 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
377 
378 CORE_EXPORT QString qgsVsiPrefix( QString path );
379 
384 void CORE_EXPORT *qgsMalloc( size_t size );
385 
392 void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );
393 
397 void CORE_EXPORT qgsFree( void *ptr );
398 
402 extern CORE_EXPORT const QString GEOWKT;
403 extern CORE_EXPORT const QString PROJECT_SCALES;
404 
406 extern CORE_EXPORT const QString GEOPROJ4;
408 const long GEOSRID = 4326;
410 const long GEOCRS_ID = 3452;
412 const long GEO_EPSG_CRS_ID = 4326;
414 extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;
416 const int PROJ_PREFIX_LEN = 6;
418 const int ELLPS_PREFIX_LEN = 7;
420 const int LAT_PREFIX_LEN = 7;
423 const int USER_CRS_START_ID = 100000;
424 
426 extern CORE_EXPORT const QString GEO_NONE;
427 
428 //
429 // Constants for point symbols
430 //
431 
433 const double MINIMUM_POINT_SIZE = 0.1;
435 const double DEFAULT_POINT_SIZE = 2.0;
436 const double DEFAULT_LINE_WIDTH = 0.26;
437 
439 const double DEFAULT_SEGMENT_EPSILON = 1e-8;
440 
442 
449 typedef unsigned long long qgssize;
450 
451 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
452 #define Q_NOWARN_DEPRECATED_PUSH \
453  _Pragma("GCC diagnostic push") \
454  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
455 #define Q_NOWARN_DEPRECATED_POP \
456  _Pragma("GCC diagnostic pop");
457 #elif defined(_MSC_VER)
458 #define Q_NOWARN_DEPRECATED_PUSH \
459  __pragma(warning(push)) \
460  __pragma(warning(disable:4996))
461 #define Q_NOWARN_DEPRECATED_POP \
462  __pragma(warning(pop))
463 #else
464 #define Q_NOWARN_DEPRECATED_PUSH
465 #define Q_NOWARN_DEPRECATED_POP
466 #endif
467 
468 #ifndef QGISEXTERN
469 #ifdef WIN32
470 # define QGISEXTERN extern "C" __declspec( dllexport )
471 # ifdef _MSC_VER
472 // do not warn about C bindings returing QString
473 # pragma warning(disable:4190)
474 # endif
475 #else
476 # if defined(__GNUC__) || defined(__clang__)
477 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
478 # else
479 # define QGISEXTERN extern "C"
480 # endif
481 #endif
482 #endif
483 #endif
static WkbType singleType(WkbType type)
Definition: qgis.h:71
static const char * QGIS_VERSION
Definition: qgis.h:40
static double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition: qgis.h:304
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition: qgis.h:300
GeometryType
Definition: qgis.h:155
CORE_EXPORT QString qgsVsiPrefix(QString path)
Definition: qgis.cpp:269
static const char * vectorGeometryType(GeometryType type)
description strings for geometry types
Definition: qgis.h:165
WkbType
Used for symbology operations.
Definition: qgis.h:53
static const double DEFAULT_IDENTIFY_RADIUS
Old search radius in % of canvas width.
Definition: qgis.h:288
The QGis class provides global constants for use throughout the application.
Definition: qgis.h:34
QString & remove(int position, int n)
void CORE_EXPORT * qgsCalloc(size_t nmemb, size_t size)
Allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the alloc...
Definition: qgis.cpp:217
QMap< QString, QString > QgsStringMap
Definition: qgis.h:441
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:350
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Definition: qgis.cpp:237
static WkbType flatType(WkbType type)
Definition: qgis.h:99
static bool isSingleType(WkbType type)
Definition: qgis.h:113
QString number(int n, int base)
CORE_EXPORT const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:74
const double DEFAULT_SEGMENT_EPSILON
default snapping tolerance for segments
Definition: qgis.h:439
static const char * QGIS_DEV_VERSION
Definition: qgis.h:46
const int ELLPS_PREFIX_LEN
The length of the string "+ellps=".
Definition: qgis.h:418
static const float DEFAULT_MAPTOPIXEL_THRESHOLD
Default threshold between map coordinates and device coordinates for map2pixel simplification.
Definition: qgis.h:295
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:410
CORE_EXPORT const QString GEOPROJ4
PROJ4 string that represents a geographic coord sys.
Definition: qgis.cpp:52
void CORE_EXPORT qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
Definition: qgis.cpp:232
UserEvent
User defined event types.
Definition: qgis.h:275
unsigned long long qgssize
qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
Definition: qgis.h:449
static const double DEFAULT_SEARCH_RADIUS_MM
Identify search radius in mm.
Definition: qgis.h:292
static const char * QGIS_RELEASE_NAME
Definition: qgis.h:44
QString qgsDoubleToString(const double &a, const int &precision=17)
Definition: qgis.h:339
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:435
static bool isMultiType(WkbType type)
Definition: qgis.h:126
static int wkbDimensions(WkbType type)
Definition: qgis.h:139
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/...
Definition: qgis.h:423
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
Definition: qgis.h:408
const double MINIMUM_POINT_SIZE
Magic number that determines the minimum allowable point size for point symbols.
Definition: qgis.h:433
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Definition: qgis.h:359
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:436
CORE_EXPORT const QString PROJECT_SCALES
Definition: qgis.cpp:68
DataType
Raster data types.
Definition: qgis.h:204
const int LAT_PREFIX_LEN
The length of the string "+lat_1=".
Definition: qgis.h:420
UnitType
Map units that qgis supports.
Definition: qgis.h:229
void(*)() cast_to_fptr(void *p)
Definition: qgis.h:323
const int PROJ_PREFIX_LEN
The length of the string "+proj=".
Definition: qgis.h:416
static const int QGIS_VERSION_INT
Definition: qgis.h:42
void CORE_EXPORT * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
Definition: qgis.cpp:202
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/outline minimum width in mm.
Definition: qgis.h:308
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Definition: qgis.cpp:264
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
Definition: qgis.h:412
CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:72
static WkbType multiType(WkbType type)
Definition: qgis.h:85
CORE_EXPORT const QString GEOWKT
Wkt string that represents a geographic coord sys.
Definition: qgis.cpp:55
static const char * featureType(WkbType type)
description strings for feature types
Definition: qgis.h:179
#define tr(sourceText)