QGIS API Documentation  2.12.0-Lyon
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 */ enum WkbType
57  {
58  WKBUnknown = 0,
59  WKBPoint = 1,
65  WKBNoGeometry = 100, //attributes only
66  WKBPoint25D = 0x80000001,
72  };
73 
75  // @deprecated use QgsWKBTypes::singleType
76  /* Q_DECL_DEPRECATED */ static WkbType singleType( WkbType type );
77 
79  // @deprecated use QgsWKBTypes::multiType
80  /* Q_DECL_DEPRECATED */ static WkbType multiType( WkbType type );
81 
83  // @deprecated use QgsWKBTypes::flatType
84  /* Q_DECL_DEPRECATED */ static WkbType flatType( WkbType type );
85 
87  // @deprecated use QgsWKBTypes::isSingleType
88  /* Q_DECL_DEPRECATED */ static bool isSingleType( WkbType type );
89 
91  // @deprecated use QgsWKBTypes::isMultiType
92  /* Q_DECL_DEPRECATED */ static bool isMultiType( WkbType type );
93 
94  // get dimension of points
95  // @deprecated use QgsWKBTypes::hasZ() and QgsWKBTypes::hasM()
96  /* Q_DECL_DEPRECATED */ static int wkbDimensions( WkbType type );
97 
99  static QgsWKBTypes::Type fromOldWkbType( QGis::WkbType type );
100 
102  static QGis::WkbType fromNewWkbType( QgsWKBTypes::Type type );
103 
105  {
110  NoGeometry
111  };
112 
114  static const char *vectorGeometryType( GeometryType type );
115 
117  static const char *featureType( WkbType type );
118 
122  enum DataType
123  { 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
140  };
141 
142 
147  enum UnitType
148  {
149  Meters = 0,
150  Feet = 1,
151  Degrees = 2, //for 1.0 api backwards compatibility
152  UnknownUnit = 3,
153 
154  // for [1.4;1.8] api compatibility
155  DecimalDegrees = 2, // was 2
156  DegreesMinutesSeconds = 2, // was 4
157  DegreesDecimalMinutes = 2, // was 5
158  NauticalMiles = 7
159  };
160 
162  static QString toLiteral( QGis::UnitType unit );
164  static UnitType fromLiteral( const QString& literal, QGis::UnitType defaultType = UnknownUnit );
166  static QString tr( QGis::UnitType unit );
168  static UnitType fromTr( const QString& literal, QGis::UnitType defaultType = UnknownUnit );
170  static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
171 
180  static double permissiveToDouble( QString string, bool& ok );
181 
190  static int permissiveToInt( QString string, bool& ok );
191 
194  {
195  // These first two are useful for threads to alert their parent data providers
196 
198  ProviderExtentCalcEvent = ( QEvent::User + 1 ),
199 
201  ProviderCountCalcEvent
202  };
203 
206  static const double DEFAULT_IDENTIFY_RADIUS;
207 
210  static const double DEFAULT_SEARCH_RADIUS_MM;
211 
213  static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
214 
219 
223 
227 
228  private:
229  // String representation of unit types (set in qgis.cpp)
230  static const char *qgisUnitTypes[];
231 
232 };
233 
234 // hack to workaround warnings when casting void pointers
235 // retrieved from QLibrary::resolve to function pointers.
236 // It's assumed that this works on all systems supporting
237 // QLibrary
238 #if QT_VERSION >= 0x050000
239 #define cast_to_fptr(f) f
240 #else
241 inline void ( *cast_to_fptr( void *p ) )()
242 {
243  union
244  {
245  void *p;
246  void ( *f )();
247  } u;
248 
249  u.p = p;
250  return u.f;
251 }
252 #endif
253 
254 //
255 // return a string representation of a double
256 //
257 inline QString qgsDoubleToString( const double &a, const int &precision = 17 )
258 {
259  if ( precision )
260  return QString::number( a, 'f', precision ).remove( QRegExp( "\\.?0+$" ) );
261  else
262  return QString::number( a, 'f', precision );
263 }
264 
265 //
266 // compare two doubles (but allow some difference)
267 //
268 inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
269 {
270  const double diff = a - b;
271  return diff > -epsilon && diff <= epsilon;
272 }
273 
274 //
275 // compare two doubles using specified number of significant digits
276 //
277 inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
278 {
279  // The most simple would be to print numbers as %.xe and compare as strings
280  // but that is probably too costly
281  // Then the fastest would be to set some bits directly, but little/big endian
282  // has to be considered (maybe TODO)
283  // Is there a better way?
284  int aexp, bexp;
285  double ar = frexp( a, &aexp );
286  double br = frexp( b, &bexp );
287 
288  return aexp == bexp &&
289  qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) );
290 }
291 
292 //
293 // a round function which returns a double to guard against overflows
294 //
295 inline double qgsRound( double x )
296 {
297  return x < 0.0 ? std::ceil( x - 0.5 ) : std::floor( x + 0.5 );
298 }
299 
300 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
301 
302 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
303 
304 CORE_EXPORT QString qgsVsiPrefix( const QString& path );
305 
310 void CORE_EXPORT *qgsMalloc( size_t size );
311 
318 void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );
319 
323 void CORE_EXPORT qgsFree( void *ptr );
324 
328 extern CORE_EXPORT const QString GEOWKT;
329 extern CORE_EXPORT const QString PROJECT_SCALES;
330 
332 extern CORE_EXPORT const QString GEOPROJ4;
334 const long GEOSRID = 4326;
336 const long GEOCRS_ID = 3452;
338 const long GEO_EPSG_CRS_ID = 4326;
340 extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;
342 const int PROJ_PREFIX_LEN = 6;
344 const int ELLPS_PREFIX_LEN = 7;
346 const int LAT_PREFIX_LEN = 7;
349 const int USER_CRS_START_ID = 100000;
350 
352 extern CORE_EXPORT const QString GEO_NONE;
353 
354 //
355 // Constants for point symbols
356 //
357 
359 const double MINIMUM_POINT_SIZE = 0.1;
361 const double DEFAULT_POINT_SIZE = 2.0;
362 const double DEFAULT_LINE_WIDTH = 0.26;
363 
365 const double DEFAULT_SEGMENT_EPSILON = 1e-8;
366 
368 
375 typedef unsigned long long qgssize;
376 
377 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
378 #define Q_NOWARN_DEPRECATED_PUSH \
379  _Pragma("GCC diagnostic push") \
380  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"");
381 #define Q_NOWARN_DEPRECATED_POP \
382  _Pragma("GCC diagnostic pop");
383 #elif defined(_MSC_VER)
384 #define Q_NOWARN_DEPRECATED_PUSH \
385  __pragma(warning(push)) \
386  __pragma(warning(disable:4996))
387 #define Q_NOWARN_DEPRECATED_POP \
388  __pragma(warning(pop))
389 #else
390 #define Q_NOWARN_DEPRECATED_PUSH
391 #define Q_NOWARN_DEPRECATED_POP
392 #endif
393 
394 #ifndef QGISEXTERN
395 #ifdef Q_OS_WIN
396 # define QGISEXTERN extern "C" __declspec( dllexport )
397 # ifdef _MSC_VER
398 // do not warn about C bindings returing QString
399 # pragma warning(disable:4190)
400 # endif
401 #else
402 # if defined(__GNUC__) || defined(__clang__)
403 # define QGISEXTERN extern "C" __attribute__ ((visibility ("default")))
404 # else
405 # define QGISEXTERN extern "C"
406 # endif
407 #endif
408 #endif
409 #endif
static const char * QGIS_VERSION
Definition: qgis.h:42
CORE_EXPORT QString qgsVsiPrefix(const QString &path)
Definition: qgis.cpp:320
static double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition: qgis.h:222
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition: qgis.h:218
UnitType
Map units that qgis supports.
Definition: qgis.h:147
UserEvent
User defined event types.
Definition: qgis.h:193
static const double DEFAULT_IDENTIFY_RADIUS
Old search radius in % of canvas width.
Definition: qgis.h:206
GeometryType
Definition: qgis.h:104
The QGis class provides global constants for use throughout the application.
Definition: qgis.h:36
WkbType
Used for symbology operations.
Definition: qgis.h:56
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:268
QMap< QString, QString > QgsStringMap
Definition: qgis.h:367
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:268
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
Definition: qgis.cpp:288
double qgsRound(double x)
Definition: qgis.h:295
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:75
const double DEFAULT_SEGMENT_EPSILON
Default snapping tolerance for segments.
Definition: qgis.h:365
static const char * QGIS_DEV_VERSION
Definition: qgis.h:48
const int ELLPS_PREFIX_LEN
The length of the string "+ellps=".
Definition: qgis.h:344
static const float DEFAULT_MAPTOPIXEL_THRESHOLD
Default threshold between map coordinates and device coordinates for map2pixel simplification.
Definition: qgis.h:213
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:336
CORE_EXPORT const QString GEOPROJ4
PROJ4 string that represents a geographic coord sys.
Definition: qgis.cpp:53
DataType
Raster data types.
Definition: qgis.h:122
void CORE_EXPORT qgsFree(void *ptr)
Frees the memory space pointed to by ptr.
Definition: qgis.cpp:283
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:375
static const double DEFAULT_SEARCH_RADIUS_MM
Identify search radius in mm.
Definition: qgis.h:210
static const char * QGIS_RELEASE_NAME
Definition: qgis.h:46
QString qgsDoubleToString(const double &a, const int &precision=17)
Definition: qgis.h:257
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:361
const int USER_CRS_START_ID
Magick number that determines whether a projection crsid is a system (srs.db) or user (~/...
Definition: qgis.h:349
const long GEOSRID
Magic number for a geographic coord sys in POSTGIS SRID.
Definition: qgis.h:334
const double MINIMUM_POINT_SIZE
Magic number that determines the minimum allowable point size for point symbols.
Definition: qgis.h:359
bool qgsDoubleNearSig(double a, double b, int significantDigits=10)
Definition: qgis.h:277
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:362
CORE_EXPORT const QString PROJECT_SCALES
Definition: qgis.cpp:69
const int LAT_PREFIX_LEN
The length of the string "+lat_1=".
Definition: qgis.h:346
void(*)() cast_to_fptr(void *p)
Definition: qgis.h:241
const int PROJ_PREFIX_LEN
The length of the string "+proj=".
Definition: qgis.h:342
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:253
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/outline minimum width in mm.
Definition: qgis.h:226
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
Definition: qgis.cpp:315
const long GEO_EPSG_CRS_ID
Magic number for a geographic coord sys in EpsgCrsId ID format.
Definition: qgis.h:338
CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID
Geographic coord sys from EPSG authority.
Definition: qgis.cpp:73
CORE_EXPORT const QString GEOWKT
Wkt string that represents a geographic coord sys.
Definition: qgis.cpp:56
#define tr(sourceText)