QGIS API Documentation  2.13.0-Master
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 
31 #include <qgswkbtypes.h>
32 
36 class CORE_EXPORT QGis
37 {
38  public:
39  // Version constants
40  //
41  // Version string
42  static const char* QGIS_VERSION;
43  // Version number used for comparing versions using the "Check QGIS Version" function
44  static const int QGIS_VERSION_INT;
45  // Release name
46  static const char* QGIS_RELEASE_NAME;
47  // The development version
48  static const char* QGIS_DEV_VERSION;
49 
50  // Enumerations
51  //
52 
54  // Feature types
55  // @deprecated use QgsWKBTypes::Type
56  /* Q_DECL_DEPRECATED */
57  enum WkbType
58  {
59  WKBUnknown = 0,
60  WKBPoint = 1,
66  WKBNoGeometry = 100, //attributes only
67  WKBPoint25D = 0x80000001,
73  };
74 
76  // @deprecated use QgsWKBTypes::singleType
77  /* Q_DECL_DEPRECATED */
78  static WkbType singleType( WkbType type );
79 
81  // @deprecated use QgsWKBTypes::multiType
82  /* Q_DECL_DEPRECATED */
83  static WkbType multiType( WkbType type );
84 
86  // @deprecated use QgsWKBTypes::flatType
87  /* Q_DECL_DEPRECATED */
88  static WkbType flatType( WkbType type );
89 
91  // @deprecated use QgsWKBTypes::isSingleType
92  /* Q_DECL_DEPRECATED */
93  static bool isSingleType( WkbType type );
94 
96  // @deprecated use QgsWKBTypes::isMultiType
97  /* Q_DECL_DEPRECATED */
98  static bool isMultiType( WkbType type );
99 
100  // get dimension of points
101  // @deprecated use QgsWKBTypes::hasZ() and QgsWKBTypes::hasM()
102  /* Q_DECL_DEPRECATED */
103  static int wkbDimensions( WkbType type );
104 
106  static QgsWKBTypes::Type fromOldWkbType( QGis::WkbType type );
107 
109  static QGis::WkbType fromNewWkbType( QgsWKBTypes::Type type );
110 
112  {
117  NoGeometry
118  };
119 
121  static const char *vectorGeometryType( GeometryType type );
122 
124  static const char *featureType( WkbType type );
125 
129  enum DataType
130  { 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
147  };
148 
149 
154  //TODO QGIS 3.0 - clean up and move to QgsUnitTypes and rename to DistanceUnit
155  enum UnitType
156  {
157  Meters = 0,
158  Feet = 1,
159  Degrees = 2, //for 1.0 api backwards compatibility
160  UnknownUnit = 3,
161 
162  // for [1.4;1.8] api compatibility
163  DecimalDegrees = 2, // was 2
164  DegreesMinutesSeconds = 2, // was 4
165  DegreesDecimalMinutes = 2, // was 5
166  NauticalMiles = 7
167  };
168 
171  Q_DECL_DEPRECATED static QString toLiteral( QGis::UnitType unit );
172 
175  Q_DECL_DEPRECATED static UnitType fromLiteral( const QString& literal, QGis::UnitType defaultType = UnknownUnit );
176 
179  Q_DECL_DEPRECATED static QString tr( QGis::UnitType unit );
180 
183  Q_DECL_DEPRECATED static UnitType fromTr( const QString& literal, QGis::UnitType defaultType = UnknownUnit );
184 
187  Q_DECL_DEPRECATED static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
188 
197  static double permissiveToDouble( QString string, bool& ok );
198 
207  static int permissiveToInt( QString string, bool& ok );
208 
211  {
212  // These first two are useful for threads to alert their parent data providers
213 
215  ProviderExtentCalcEvent = ( QEvent::User + 1 ),
216 
218  ProviderCountCalcEvent
219  };
220 
223  Q_DECL_DEPRECATED static const double DEFAULT_IDENTIFY_RADIUS;
224 
227  static const double DEFAULT_SEARCH_RADIUS_MM;
228 
230  static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
231 
236 
240 
244 
245  private:
246  // String representation of unit types (set in qgis.cpp)
247  static const char *qgisUnitTypes[];
248 
249 };
250 
251 // hack to workaround warnings when casting void pointers
252 // retrieved from QLibrary::resolve to function pointers.
253 // It's assumed that this works on all systems supporting
254 // QLibrary
255 #if QT_VERSION >= 0x050000
256 #define cast_to_fptr(f) f
257 #else
258 inline void ( *cast_to_fptr( void *p ) )()
259 {
260  union
261  {
262  void *p;
263  void ( *f )();
264  } u;
265 
266  u.p = p;
267  return u.f;
268 }
269 #endif
270 
271 //
272 // return a string representation of a double
273 //
274 inline QString qgsDoubleToString( double a, int precision = 17 )
275 {
276  if ( precision )
277  return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
278  else
279  return QString::number( a, 'f', precision );
280 }
281 
282 //
283 // compare two doubles (but allow some difference)
284 //
285 inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
286 {
287  const double diff = a - b;
288  return diff > -epsilon && diff <= epsilon;
289 }
290 
291 //
292 // compare two doubles using specified number of significant digits
293 //
294 inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
295 {
296  // The most simple would be to print numbers as %.xe and compare as strings
297  // but that is probably too costly
298  // Then the fastest would be to set some bits directly, but little/big endian
299  // has to be considered (maybe TODO)
300  // Is there a better way?
301  int aexp, bexp;
302  double ar = frexp( a, &aexp );
303  double br = frexp( b, &bexp );
304 
305  return aexp == bexp &&
306  qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) );
307 }
308 
309 //
310 // a round function which returns a double to guard against overflows
311 //
312 inline double qgsRound( double x )
313 {
314  return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
315 }
316 
317 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
318 
319 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
320 
321 CORE_EXPORT QString qgsVsiPrefix( const QString& path );
322 
327 void CORE_EXPORT *qgsMalloc( size_t size );
328 
335 void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );
336 
340 void CORE_EXPORT qgsFree( void *ptr );
341 
345 extern CORE_EXPORT const QString GEOWKT;
346 extern CORE_EXPORT const QString PROJECT_SCALES;
347 
349 extern CORE_EXPORT const QString GEOPROJ4;
351 const long GEOSRID = 4326;
353 const long GEOCRS_ID = 3452;
355 const long GEO_EPSG_CRS_ID = 4326;
357 extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;
359 const int PROJ_PREFIX_LEN = 6;
361 const int ELLPS_PREFIX_LEN = 7;
363 const int LAT_PREFIX_LEN = 7;
366 const int USER_CRS_START_ID = 100000;
367 
369 extern CORE_EXPORT const QString GEO_NONE;
370 
371 //
372 // Constants for point symbols
373 //
374 
376 const double MINIMUM_POINT_SIZE = 0.1;
378 const double DEFAULT_POINT_SIZE = 2.0;
379 const double DEFAULT_LINE_WIDTH = 0.26;
380 
382 const double DEFAULT_SEGMENT_EPSILON = 1e-8;
383 
385 
392 typedef unsigned long long qgssize;
393 
394 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
395 #define Q_NOWARN_DEPRECATED_PUSH \
396  _Pragma("GCC diagnostic push") \
397  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
398 #define Q_NOWARN_DEPRECATED_POP \
399  _Pragma("GCC diagnostic pop");
400 #elif defined(_MSC_VER)
401 #define Q_NOWARN_DEPRECATED_PUSH \
402  __pragma(warning(push)) \
403  __pragma(warning(disable:4996))
404 #define Q_NOWARN_DEPRECATED_POP \
405  __pragma(warning(pop))
406 #else
407 #define Q_NOWARN_DEPRECATED_PUSH
408 #define Q_NOWARN_DEPRECATED_POP
409 #endif
410 
411 #ifndef QGISEXTERN
412 #ifdef Q_OS_WIN
413 # define QGISEXTERN extern "C" __declspec( dllexport )
414 # ifdef _MSC_VER
415 // do not warn about C bindings returing QString
416 # pragma warning(disable:4190)
417 # endif
418 #else
419 # if defined(__GNUC__) || defined(__clang__)
420 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
421 # else
422 # define QGISEXTERN extern "C"
423 # endif
424 #endif
425 #endif
426 #endif
427 
428 #if defined(__clang__)
429 #define FALLTHROUGH [[clang::fallthrough]]
430 #else
431 #define FALLTHROUGH
432 #endif
static const char * QGIS_VERSION
Definition: qgis.h:42
CORE_EXPORT QString qgsVsiPrefix(const QString &path)
Definition: qgis.cpp:293
static double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition: qgis.h:239
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition: qgis.h:235
GeometryType
Definition: qgis.h:111
WkbType
Used for symbology operations.
Definition: qgis.h:57
static Q_DECL_DEPRECATED const double DEFAULT_IDENTIFY_RADIUS
Old search radius in % of canvas width.
Definition: qgis.h:223
The QGis class provides global constants for use throughout the application.
Definition: qgis.h:36
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:241
QMap< QString, QString > QgsStringMap
Definition: qgis.h:384
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:285
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Definition: qgis.cpp:261
double qgsRound(double x)
Definition: qgis.h:312
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:76
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition: qgis.h:382
static const char * QGIS_DEV_VERSION
Definition: qgis.h:48
QString qgsDoubleToString(double a, int precision=17)
Definition: qgis.h:274
const int ELLPS_PREFIX_LEN
The length of the string "+ellps=".
Definition: qgis.h:361
static const float DEFAULT_MAPTOPIXEL_THRESHOLD
Default threshold between map coordinates and device coordinates for map2pixel simplification.
Definition: qgis.h:230
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:353
CORE_EXPORT const QString GEOPROJ4
PROJ4 string that represents a geographic coord sys.
Definition: qgis.cpp:54
void CORE_EXPORT qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
Definition: qgis.cpp:256
UserEvent
User defined event types.
Definition: qgis.h:210
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:392
static const double DEFAULT_SEARCH_RADIUS_MM
Identify search radius in mm.
Definition: qgis.h:227
static const char * QGIS_RELEASE_NAME
Definition: qgis.h:46
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:378
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/...
Definition: qgis.h:366
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
Definition: qgis.h:351
const double MINIMUM_POINT_SIZE
Magic number that determines the minimum allowable point size for point symbols.
Definition: qgis.h:376
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Definition: qgis.h:294
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:379
CORE_EXPORT const QString PROJECT_SCALES
Definition: qgis.cpp:70
DataType
Raster data types.
Definition: qgis.h:129
const int LAT_PREFIX_LEN
The length of the string "+lat_1=".
Definition: qgis.h:363
UnitType
Map units that qgis supports.
Definition: qgis.h:155
void(*)() cast_to_fptr(void *p)
Definition: qgis.h:258
const int PROJ_PREFIX_LEN
The length of the string "+proj=".
Definition: qgis.h:359
static const int QGIS_VERSION_INT
Definition: qgis.h:44
void CORE_EXPORT * qgsMalloc(size_t size)
Allocates size bytes and returns a pointer to the allocated memory.
Definition: qgis.cpp:226
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/outline minimum width in mm.
Definition: qgis.h:243
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Definition: qgis.cpp:288
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
Definition: qgis.h:355
CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:74
CORE_EXPORT const QString GEOWKT
Wkt string that represents a geographic coord sys.
Definition: qgis.cpp:57
#define tr(sourceText)