Quantum GIS API Documentation  master-693a1fe
src/core/qgis.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgis.h - QGIS namespace
00003                              -------------------
00004     begin                : Sat Jun 30 2002
00005     copyright            : (C) 2002 by Gary E.Sherman
00006     email                : sherman at mrcc.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef QGIS_H
00019 #define QGIS_H
00020 
00021 #include <QEvent>
00022 #include <QString>
00023 #include <QMetaType>
00024 #include <QVariant>
00025 #include <stdlib.h>
00026 #include <cfloat>
00027 #include <cmath>
00028 #include <qnumeric.h>
00029 
00033 class CORE_EXPORT QGis
00034 {
00035   public:
00036     // Version constants
00037     //
00038     // Version string
00039     static const char* QGIS_VERSION;
00040     // Version number used for comparing versions using the "Check QGIS Version" function
00041     static const int QGIS_VERSION_INT;
00042     // Release name
00043     static const char* QGIS_RELEASE_NAME;
00044     // The development version
00045     static const char* QGIS_DEV_VERSION;
00046 
00047     // Enumerations
00048     //
00049 
00051     // Feature types
00052     enum WkbType
00053     {
00054       WKBUnknown = 0,
00055       WKBPoint = 1,
00056       WKBLineString,
00057       WKBPolygon,
00058       WKBMultiPoint,
00059       WKBMultiLineString,
00060       WKBMultiPolygon,
00061       WKBNoGeometry = 100, //attributes only
00062       WKBPoint25D = 0x80000001,
00063       WKBLineString25D,
00064       WKBPolygon25D,
00065       WKBMultiPoint25D,
00066       WKBMultiLineString25D,
00067       WKBMultiPolygon25D,
00068     };
00069 
00070     static WkbType singleType( WkbType type )
00071     {
00072       switch ( type )
00073       {
00074         case WKBMultiPoint:         return WKBPoint;
00075         case WKBMultiLineString:    return WKBLineString;
00076         case WKBMultiPolygon:       return WKBPolygon;
00077         case WKBMultiPoint25D:      return WKBPoint25D;
00078         case WKBMultiLineString25D: return WKBLineString25D;
00079         case WKBMultiPolygon25D:    return WKBPolygon25D;
00080         default:                    return type;
00081       }
00082     }
00083 
00084     static WkbType flatType( WkbType type )
00085     {
00086       switch ( type )
00087       {
00088         case WKBPoint25D:           return WKBPoint;
00089         case WKBLineString25D:      return WKBLineString;
00090         case WKBPolygon25D:         return WKBPolygon;
00091         case WKBMultiPoint25D:      return WKBMultiPoint;
00092         case WKBMultiLineString25D: return WKBMultiLineString;
00093         case WKBMultiPolygon25D:    return WKBMultiPolygon;
00094         default:                    return type;
00095       }
00096     }
00097 
00098     static int wkbDimensions( WkbType type )
00099     {
00100       switch ( type )
00101       {
00102         case WKBUnknown:            return 0;
00103         case WKBNoGeometry:         return 0;
00104         case WKBPoint25D:           return 3;
00105         case WKBLineString25D:      return 3;
00106         case WKBPolygon25D:         return 3;
00107         case WKBMultiPoint25D:      return 3;
00108         case WKBMultiLineString25D: return 3;
00109         case WKBMultiPolygon25D:    return 3;
00110         default:                    return 2;
00111       }
00112     }
00113 
00114     enum GeometryType
00115     {
00116       Point,
00117       Line,
00118       Polygon,
00119       UnknownGeometry,
00120       NoGeometry
00121     };
00122 
00124     static const char *vectorGeometryType( GeometryType type )
00125     {
00126       switch ( type )
00127       {
00128         case Point:           return "Point";
00129         case Line:            return "Line";
00130         case Polygon:         return "Polygon";
00131         case UnknownGeometry: return "Unknown geometry";
00132         case NoGeometry:      return "No geometry";
00133         default:              return "Invalid type";
00134       }
00135     }
00136 
00138     static const char *featureType( WkbType type )
00139     {
00140       switch ( type )
00141       {
00142         case WKBUnknown:            return "WKBUnknown";
00143         case WKBPoint:              return "WKBPoint";
00144         case WKBLineString:         return "WKBLineString";
00145         case WKBPolygon:            return "WKBPolygon";
00146         case WKBMultiPoint:         return "WKBMultiLineString";
00147         case WKBMultiPolygon:       return "WKBMultiPolygon";
00148         case WKBNoGeometry:         return "WKBNoGeometry";
00149         case WKBPoint25D:           return "WKBPoint25D";
00150         case WKBLineString25D:      return "WKBLineString25D";
00151         case WKBPolygon25D:         return "WKBPolygon25D";
00152         case WKBMultiPoint25D:      return "WKBMultiPoint25D";
00153         case WKBMultiLineString25D: return "WKBMultiLineString25D";
00154         case WKBMultiPolygon25D:    return "WKBMultiPolygon25D";
00155         default:                    return "invalid wkbtype";
00156       }
00157     }
00158 
00162     enum DataType
00163     {                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
00180     };
00181 
00182 
00187     enum UnitType
00188     {
00189       Meters = 0,
00190       Feet = 1,
00191       Degrees = 2, //for 1.0 api backwards compatibility
00192       UnknownUnit = 3,
00193 
00194       // for [1.4;1.8] api compatibility
00195       DecimalDegrees = 2,         // was 2
00196       DegreesMinutesSeconds = 2,  // was 4
00197       DegreesDecimalMinutes = 2,  // was 5
00198     };
00199 
00201     // Added in version 2.0
00202     static QString toLiteral( QGis::UnitType unit );
00204     // Added in version 2.0
00205     static UnitType fromLiteral( QString  literal, QGis::UnitType defaultType = UnknownUnit );
00207     // Added in version 2.0
00208     static QString tr( QGis::UnitType unit );
00209 
00211     enum UserEvent
00212     {
00213       // These first two are useful for threads to alert their parent data providers
00214 
00216       ProviderExtentCalcEvent = ( QEvent::User + 1 ),
00217 
00219       ProviderCountCalcEvent
00220     };
00221 
00222     static const double DEFAULT_IDENTIFY_RADIUS;
00223 
00224   private:
00225     // String representation of unit types (set in qgis.cpp)
00226     static const char *qgisUnitTypes[];
00227 
00228 };
00229 
00230 // hack to workaround warnings when casting void pointers
00231 // retrieved from QLibrary::resolve to function pointers.
00232 // It's assumed that this works on all systems supporting
00233 // QLibrary
00234 inline void ( *cast_to_fptr( void *p ) )()
00235 {
00236   union
00237   {
00238     void *p;
00239     void ( *f )();
00240   } u;
00241 
00242   u.p = p;
00243   return u.f;
00244 }
00245 
00246 //
00247 // compare two doubles (but allow some difference)
00248 //
00249 inline bool qgsDoubleNear( double a, double b, double epsilon = 4 * DBL_EPSILON )
00250 {
00251   const double diff = a - b;
00252   return diff > -epsilon && diff <= epsilon;
00253 }
00254 
00255 //
00256 // compare two doubles using specified number of significant digits
00257 //
00258 inline bool qgsDoubleNearSig( double a, double b, int significantDigits = 10 )
00259 {
00260   // The most simple would be to print numbers as %.xe and compare as strings
00261   // but that is probably too costly
00262   // Then the fastest would be to set some bits directly, but little/big endian
00263   // has to be considered (maybe TODO)
00264   // Is there a better way?
00265   int aexp, bexp;
00266   double ar = frexp( a, &aexp );
00267   double br = frexp( b, &bexp );
00268 
00269   return aexp == bexp &&
00270          qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) ) ;
00271 }
00272 
00273 bool qgsVariantLessThan( const QVariant& lhs, const QVariant& rhs );
00274 
00275 bool qgsVariantGreaterThan( const QVariant& lhs, const QVariant& rhs );
00276 
00281 void CORE_EXPORT *qgsMalloc( size_t size );
00282 
00289 void CORE_EXPORT *qgsCalloc( size_t nmemb, size_t size );
00290 
00294 void CORE_EXPORT qgsFree( void *ptr );
00295 
00299 extern CORE_EXPORT const QString GEOWKT;
00300 extern CORE_EXPORT const QString PROJECT_SCALES;
00301 
00303 extern CORE_EXPORT const QString GEOPROJ4;
00305 const long GEOSRID = 4326;
00307 const long GEOCRS_ID = 3452;
00309 const long GEO_EPSG_CRS_ID = 4326;
00311 extern CORE_EXPORT const QString GEO_EPSG_CRS_AUTHID;
00313 const int PROJ_PREFIX_LEN = 6;
00315 const int ELLPS_PREFIX_LEN = 7;
00317 const int LAT_PREFIX_LEN = 7;
00320 const int USER_CRS_START_ID = 100000;
00321 
00323 // Added in version 2.0
00324 extern CORE_EXPORT const QString GEO_NONE;
00325 
00326 //
00327 // Constants for point symbols
00328 //
00329 
00331 const double MINIMUM_POINT_SIZE = 0.1;
00333 const double DEFAULT_POINT_SIZE = 2.0;
00334 const double DEFAULT_LINE_WIDTH = 0.26;
00335 
00337 const double DEFAULT_SEGMENT_EPSILON = 1e-8;
00338 
00339 typedef QMap<QString, QString> QgsStringMap;
00340 
00341 // FIXME: also in qgisinterface.h
00342 #ifndef QGISEXTERN
00343 #ifdef WIN32
00344 #  define QGISEXTERN extern "C" __declspec( dllexport )
00345 #  ifdef _MSC_VER
00346 // do not warn about C bindings returing QString
00347 #    pragma warning(disable:4190)
00348 #  endif
00349 #else
00350 #  define QGISEXTERN extern "C"
00351 #endif
00352 #endif
00353 
00354 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines