QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsunittypes.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsunittypes.cpp
3  --------------
4  begin : February 2016
5  copyright : (C) 2016 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgsunittypes.h"
18 #include "qgis.h"
19 
20 /***************************************************************************
21  * This class is considered CRITICAL and any change MUST be accompanied with
22  * full unit tests in test_qgsunittypes.py.
23  * See details in QEP #17
24  ****************************************************************************/
25 
27 {
28  switch ( type )
29  {
30  case TypeDistance:
31  return QStringLiteral( "distance" );
32 
33  case TypeArea:
34  return QStringLiteral( "area" );
35 
36  case TypeVolume:
37  return QStringLiteral( "volume" );
38 
39  case TypeTemporal:
40  return QStringLiteral( "temporal" );
41 
42  case TypeUnknown:
43  return QStringLiteral( "<unknown>" );
44 
45  }
46  return QString();
47 }
48 
49 QgsUnitTypes::UnitType QgsUnitTypes::decodeUnitType( const QString &string, bool *ok )
50 {
51  QString normalized = string.trimmed().toLower();
52 
53  if ( ok )
54  *ok = true;
55 
56  if ( normalized == encodeUnitType( TypeDistance ) )
57  return TypeDistance;
58  if ( normalized == encodeUnitType( TypeArea ) )
59  return TypeArea;
60  if ( normalized == encodeUnitType( TypeVolume ) )
61  return TypeVolume;
62  if ( normalized == encodeUnitType( TypeTemporal ) )
63  return TypeTemporal;
64  if ( normalized == encodeUnitType( TypeUnknown ) )
65  return TypeUnknown;
66 
67  if ( ok )
68  *ok = false;
69 
70  return TypeUnknown;
71 }
72 
74 {
75  switch ( unit )
76  {
77  case DistanceMeters:
78  case DistanceFeet:
80  case DistanceYards:
81  case DistanceMiles:
82  case DistanceKilometers:
85  return Standard;
86 
87  case DistanceDegrees:
88  return Geographic;
89 
91  return UnknownType;
92  }
93  return UnknownType;
94 }
95 
97 {
98  switch ( unit )
99  {
100  case AreaSquareMeters:
102  case AreaSquareFeet:
103  case AreaSquareYards:
104  case AreaSquareMiles:
105  case AreaHectares:
106  case AreaAcres:
110  return Standard;
111 
112  case AreaSquareDegrees:
113  return Geographic;
114 
115  case AreaUnknownUnit:
116  return UnknownType;
117  }
118 
119  return UnknownType;
120 }
121 
123 {
124  switch ( unit )
125  {
126  case DistanceMeters:
127  return QStringLiteral( "meters" );
128 
129  case DistanceKilometers:
130  return QStringLiteral( "km" );
131 
132  case DistanceFeet:
133  return QStringLiteral( "feet" );
134 
135  case DistanceYards:
136  return QStringLiteral( "yd" );
137 
138  case DistanceMiles:
139  return QStringLiteral( "mi" );
140 
141  case DistanceDegrees:
142  return QStringLiteral( "degrees" );
143 
144  case DistanceUnknownUnit:
145  return QStringLiteral( "<unknown>" );
146 
148  return QStringLiteral( "nautical miles" );
149 
150  case DistanceCentimeters:
151  return QStringLiteral( "cm" );
152 
153  case DistanceMillimeters:
154  return QStringLiteral( "mm" );
155  }
156  return QString();
157 }
158 
159 /***************************************************************************
160  * This class is considered CRITICAL and any change MUST be accompanied with
161  * full unit tests in test_qgsunittypes.py.
162  * See details in QEP #17
163  ****************************************************************************/
164 
166 {
167  QString normalized = string.trimmed().toLower();
168 
169  if ( ok )
170  *ok = true;
171 
172  if ( normalized == encodeUnit( DistanceMeters ) )
173  return DistanceMeters;
174  if ( normalized == encodeUnit( DistanceFeet ) )
175  return DistanceFeet;
176  if ( normalized == encodeUnit( DistanceDegrees ) )
177  return DistanceDegrees;
178  if ( normalized == encodeUnit( DistanceNauticalMiles ) )
179  return DistanceNauticalMiles;
180  if ( normalized == encodeUnit( DistanceKilometers ) )
181  return DistanceKilometers;
182  if ( normalized == encodeUnit( DistanceYards ) )
183  return DistanceYards;
184  if ( normalized == encodeUnit( DistanceMiles ) )
185  return DistanceMiles;
186  if ( normalized == encodeUnit( DistanceCentimeters ) )
187  return DistanceCentimeters;
188  if ( normalized == encodeUnit( DistanceMillimeters ) )
189  return DistanceMillimeters;
190  if ( normalized == encodeUnit( DistanceUnknownUnit ) )
191  return DistanceUnknownUnit;
192 
193  if ( ok )
194  *ok = false;
195 
196  return DistanceUnknownUnit;
197 }
198 
200 {
201  switch ( unit )
202  {
203  case DistanceMeters:
204  return QObject::tr( "meters", "distance" );
205 
206  case DistanceKilometers:
207  return QObject::tr( "kilometers", "distance" );
208 
209  case DistanceFeet:
210  return QObject::tr( "feet", "distance" );
211 
212  case DistanceYards:
213  return QObject::tr( "yards", "distance" );
214 
215  case DistanceMiles:
216  return QObject::tr( "miles", "distance" );
217 
218  case DistanceDegrees:
219  return QObject::tr( "degrees", "distance" );
220 
221  case DistanceCentimeters:
222  return QObject::tr( "centimeters", "distance" );
223 
224  case DistanceMillimeters:
225  return QObject::tr( "millimeters", "distance" );
226 
227  case DistanceUnknownUnit:
228  return QObject::tr( "<unknown>", "distance" );
229 
231  return QObject::tr( "nautical miles", "distance" );
232  }
233  return QString();
234 }
235 
237 {
238  switch ( unit )
239  {
240  case RenderMillimeters:
241  return QObject::tr( "mm", "render" );
242 
243  case RenderMapUnits:
244  return QObject::tr( "map units", "render" );
245 
246  case RenderPixels:
247  return QObject::tr( "px", "render" );
248 
249  case RenderPercentage:
250  return QObject::tr( "%", "render" );
251 
252  case RenderPoints:
253  return QObject::tr( "pt", "render" );
254 
255  case RenderInches:
256  return QObject::tr( "in", "render" );
257 
258  case RenderUnknownUnit:
259  return QObject::tr( "unknown", "render" );
260 
262  return QObject::tr( "m", "render" );
263 
264  }
265 
266  return QString();
267 }
268 
270 {
271  switch ( unit )
272  {
273  case DistanceMeters:
274  return QObject::tr( "m", "distance" );
275 
276  case DistanceKilometers:
277  return QObject::tr( "km", "distance" );
278 
279  case DistanceFeet:
280  return QObject::tr( "ft", "distance" );
281 
282  case DistanceYards:
283  return QObject::tr( "yd", "distance" );
284 
285  case DistanceMiles:
286  return QObject::tr( "mi", "distance" );
287 
288  case DistanceDegrees:
289  return QObject::tr( "deg", "distance" );
290 
291  case DistanceCentimeters:
292  return QObject::tr( "cm", "distance" );
293 
294  case DistanceMillimeters:
295  return QObject::tr( "mm", "distance" );
296 
297  case DistanceUnknownUnit:
298  return QString();
299 
301  return QObject::tr( "NM", "distance" );
302  }
303  return QString();
304 }
305 
306 /***************************************************************************
307  * This class is considered CRITICAL and any change MUST be accompanied with
308  * full unit tests in test_qgsunittypes.py.
309  * See details in QEP #17
310  ****************************************************************************/
311 
313 {
314  QString normalized = string.trimmed().toLower();
315 
316  if ( ok )
317  *ok = true;
318 
319  if ( normalized == toString( DistanceMeters ) )
320  return DistanceMeters;
321  if ( normalized == toString( DistanceKilometers ) )
322  return DistanceKilometers;
323  if ( normalized == toString( DistanceFeet ) )
324  return DistanceFeet;
325  if ( normalized == toString( DistanceYards ) )
326  return DistanceYards;
327  if ( normalized == toString( DistanceMiles ) )
328  return DistanceMiles;
329  if ( normalized == toString( DistanceDegrees ) )
330  return DistanceDegrees;
331  if ( normalized == toString( DistanceCentimeters ) )
332  return DistanceCentimeters;
333  if ( normalized == toString( DistanceMillimeters ) )
334  return DistanceMillimeters;
335  if ( normalized == toString( DistanceNauticalMiles ) )
336  return DistanceNauticalMiles;
337  if ( normalized == toString( DistanceUnknownUnit ) )
338  return DistanceUnknownUnit;
339 
340  if ( ok )
341  *ok = false;
342 
343  return DistanceUnknownUnit;
344 }
345 
346 /***************************************************************************
347  * This class is considered CRITICAL and any change MUST be accompanied with
348  * full unit tests in test_qgsunittypes.py.
349  * See details in QEP #17
350  ****************************************************************************/
351 
353 {
354 #define DEGREE_TO_METER 111319.49079327358
355 #define FEET_TO_METER 0.3048
356 #define NMILE_TO_METER 1852.0
357 #define KILOMETERS_TO_METER 1000.0
358 #define CENTIMETERS_TO_METER 0.01
359 #define MILLIMETERS_TO_METER 0.001
360 #define YARDS_TO_METER 0.9144
361 #define YARDS_TO_FEET 3.0
362 #define MILES_TO_METER 1609.344
363 
364  // Calculate the conversion factor between the specified units
365  switch ( fromUnit )
366  {
367  case DistanceMeters:
368  {
369  switch ( toUnit )
370  {
371  case DistanceMeters:
372  return 1.0;
373  case DistanceKilometers:
374  return 1.0 / KILOMETERS_TO_METER;
375  case DistanceMillimeters:
376  return 1.0 / MILLIMETERS_TO_METER;
377  case DistanceCentimeters:
378  return 1.0 / CENTIMETERS_TO_METER;
379  case DistanceFeet:
380  return 1.0 / FEET_TO_METER;
381  case DistanceYards:
382  return 1.0 / YARDS_TO_METER;
383  case DistanceMiles:
384  return 1.0 / MILES_TO_METER;
385  case DistanceDegrees:
386  return 1.0 / DEGREE_TO_METER;
388  return 1.0 / NMILE_TO_METER;
389  case DistanceUnknownUnit:
390  break;
391  }
392 
393  break;
394  }
395  case DistanceKilometers:
396  {
397  switch ( toUnit )
398  {
399  case DistanceMeters:
400  return KILOMETERS_TO_METER;
401  case DistanceKilometers:
402  return 1.0;
403  case DistanceCentimeters:
405  case DistanceMillimeters:
407  case DistanceFeet:
409  case DistanceYards:
411  case DistanceMiles:
413  case DistanceDegrees:
417  case DistanceUnknownUnit:
418  break;
419  }
420 
421  break;
422  }
423  case DistanceFeet:
424  {
425  switch ( toUnit )
426  {
427  case DistanceMeters:
428  return FEET_TO_METER;
429  case DistanceKilometers:
431  case DistanceCentimeters:
433  case DistanceMillimeters:
435  case DistanceFeet:
436  return 1.0;
437  case DistanceYards:
438  return 1.0 / YARDS_TO_FEET;
439  case DistanceMiles:
440  return FEET_TO_METER / MILES_TO_METER;
441  case DistanceDegrees:
444  return FEET_TO_METER / NMILE_TO_METER;
445  case DistanceUnknownUnit:
446  break;
447  }
448 
449  break;
450  }
451  case DistanceYards:
452  {
453  switch ( toUnit )
454  {
455  case DistanceMeters:
456  return YARDS_TO_METER;
457  case DistanceKilometers:
459  case DistanceCentimeters:
461  case DistanceMillimeters:
463  case DistanceFeet:
464  return YARDS_TO_FEET;
465  case DistanceYards:
466  return 1.0;
467  case DistanceMiles:
469  case DistanceDegrees:
473  case DistanceUnknownUnit:
474  break;
475  }
476 
477  break;
478  }
479  case DistanceMiles:
480  {
481  switch ( toUnit )
482  {
483  case DistanceMeters:
484  return MILES_TO_METER;
485  case DistanceKilometers:
487  case DistanceCentimeters:
489  case DistanceMillimeters:
491  case DistanceFeet:
492  return MILES_TO_METER / FEET_TO_METER;
493  case DistanceYards:
495  case DistanceMiles:
496  return 1.0;
497  case DistanceDegrees:
501  case DistanceUnknownUnit:
502  break;
503  }
504 
505  break;
506  }
507  case DistanceDegrees:
508  {
509  switch ( toUnit )
510  {
511  case DistanceMeters:
512  return DEGREE_TO_METER;
513  case DistanceKilometers:
515  case DistanceCentimeters:
517  case DistanceMillimeters:
519  case DistanceFeet:
521  case DistanceYards:
523  case DistanceMiles:
525  case DistanceDegrees:
526  return 1.0;
529  case DistanceUnknownUnit:
530  break;
531  }
532 
533  break;
534  }
536  {
537  switch ( toUnit )
538  {
539  case DistanceMeters:
540  return NMILE_TO_METER;
541  case DistanceKilometers:
543  case DistanceCentimeters:
545  case DistanceMillimeters:
547  case DistanceFeet:
548  return NMILE_TO_METER / FEET_TO_METER;
549  case DistanceYards:
551  case DistanceMiles:
553  case DistanceDegrees:
556  return 1.0;
557  case DistanceUnknownUnit:
558  break;
559  }
560 
561  break;
562  }
563  case DistanceCentimeters:
564  {
565  switch ( toUnit )
566  {
567  case DistanceMeters:
568  return CENTIMETERS_TO_METER;
569  case DistanceKilometers:
571  case DistanceCentimeters:
572  return 1.0;
573  case DistanceMillimeters:
575  case DistanceFeet:
577  case DistanceYards:
579  case DistanceMiles:
581  case DistanceDegrees:
585  case DistanceUnknownUnit:
586  break;
587  }
588 
589  break;
590  }
591  case DistanceMillimeters:
592  {
593  switch ( toUnit )
594  {
595  case DistanceMeters:
596  return MILLIMETERS_TO_METER;
597  case DistanceKilometers:
599  case DistanceCentimeters:
601  case DistanceMillimeters:
602  return 1.0;
603  case DistanceFeet:
605  case DistanceYards:
607  case DistanceMiles:
609  case DistanceDegrees:
613  case DistanceUnknownUnit:
614  break;
615  }
616 
617  break;
618  }
619  case DistanceUnknownUnit:
620  break;
621  }
622  return 1.0;
623 }
624 
626 {
627  switch ( unit )
628  {
629  case AreaSquareMeters:
630  return QStringLiteral( "m2" );
632  return QStringLiteral( "km2" );
633  case AreaSquareFeet:
634  return QStringLiteral( "ft2" );
635  case AreaSquareYards:
636  return QStringLiteral( "y2" );
637  case AreaSquareMiles:
638  return QStringLiteral( "mi2" );
639  case AreaHectares:
640  return QStringLiteral( "ha" );
641  case AreaAcres:
642  return QStringLiteral( "ac" );
644  return QStringLiteral( "nm2" );
645  case AreaSquareDegrees:
646  return QStringLiteral( "deg2" );
648  return QStringLiteral( "cm2" );
650  return QStringLiteral( "mm2" );
651  case AreaUnknownUnit:
652  return QStringLiteral( "<unknown>" );
653  }
654  return QString();
655 }
656 
657 QgsUnitTypes::AreaUnit QgsUnitTypes::decodeAreaUnit( const QString &string, bool *ok )
658 {
659  QString normalized = string.trimmed().toLower();
660 
661  if ( ok )
662  *ok = true;
663 
664  if ( normalized == encodeUnit( AreaSquareMeters ) )
665  return AreaSquareMeters;
666  if ( normalized == encodeUnit( AreaSquareKilometers ) )
667  return AreaSquareKilometers;
668  if ( normalized == encodeUnit( AreaSquareFeet ) )
669  return AreaSquareFeet;
670  if ( normalized == encodeUnit( AreaSquareYards ) )
671  return AreaSquareYards;
672  if ( normalized == encodeUnit( AreaSquareMiles ) )
673  return AreaSquareMiles;
674  if ( normalized == encodeUnit( AreaHectares ) )
675  return AreaHectares;
676  if ( normalized == encodeUnit( AreaAcres ) )
677  return AreaAcres;
678  if ( normalized == encodeUnit( AreaSquareNauticalMiles ) )
680  if ( normalized == encodeUnit( AreaSquareDegrees ) )
681  return AreaSquareDegrees;
682  if ( normalized == encodeUnit( AreaSquareCentimeters ) )
683  return AreaSquareCentimeters;
684  if ( normalized == encodeUnit( AreaSquareMillimeters ) )
685  return AreaSquareMillimeters;
686  if ( normalized == encodeUnit( AreaUnknownUnit ) )
687  return AreaUnknownUnit;
688 
689  if ( ok )
690  *ok = false;
691 
692  return AreaUnknownUnit;
693 }
694 
696 {
697  switch ( unit )
698  {
699  case AreaSquareMeters:
700  return QObject::tr( "square meters", "area" );
702  return QObject::tr( "square kilometers", "area" );
703  case AreaSquareFeet:
704  return QObject::tr( "square feet", "area" );
705  case AreaSquareYards:
706  return QObject::tr( "square yards", "area" );
707  case AreaSquareMiles:
708  return QObject::tr( "square miles", "area" );
709  case AreaHectares:
710  return QObject::tr( "hectares", "area" );
711  case AreaAcres:
712  return QObject::tr( "acres", "area" );
714  return QObject::tr( "square nautical miles", "area" );
715  case AreaSquareDegrees:
716  return QObject::tr( "square degrees", "area" );
718  return QObject::tr( "square millimeters", "area" );
720  return QObject::tr( "square centimeters", "area" );
721  case AreaUnknownUnit:
722  return QObject::tr( "<unknown>", "area" );
723  }
724  return QString();
725 }
726 
728 {
729  switch ( unit )
730  {
731  case AreaSquareMeters:
732  return QObject::tr( "m²", "area" );
734  return QObject::tr( "km²", "area" );
735  case AreaSquareFeet:
736  return QObject::tr( "ft²", "area" );
737  case AreaSquareYards:
738  return QObject::tr( "yd²", "area" );
739  case AreaSquareMiles:
740  return QObject::tr( "mi²", "area" );
741  case AreaHectares:
742  return QObject::tr( "ha", "area" );
743  case AreaAcres:
744  return QObject::tr( "ac", "area" );
746  return QObject::tr( "NM²", "area" );
747  case AreaSquareDegrees:
748  return QObject::tr( "deg²", "area" );
750  return QObject::tr( "cm²", "area" );
752  return QObject::tr( "mm²", "area" );
753  case AreaUnknownUnit:
754  return QString();
755  }
756  return QString();
757 }
758 
759 QgsUnitTypes::AreaUnit QgsUnitTypes::stringToAreaUnit( const QString &string, bool *ok )
760 {
761  QString normalized = string.trimmed().toLower();
762 
763  if ( ok )
764  *ok = true;
765 
766  if ( normalized == toString( AreaSquareMeters ) )
767  return AreaSquareMeters;
768  if ( normalized == toString( AreaSquareKilometers ) )
769  return AreaSquareKilometers;
770  if ( normalized == toString( AreaSquareFeet ) )
771  return AreaSquareFeet;
772  if ( normalized == toString( AreaSquareYards ) )
773  return AreaSquareYards;
774  if ( normalized == toString( AreaSquareMiles ) )
775  return AreaSquareMiles;
776  if ( normalized == toString( AreaHectares ) )
777  return AreaHectares;
778  if ( normalized == toString( AreaAcres ) )
779  return AreaAcres;
780  if ( normalized == toString( AreaSquareNauticalMiles ) )
782  if ( normalized == toString( AreaSquareDegrees ) )
783  return AreaSquareDegrees;
784  if ( normalized == toString( AreaSquareMillimeters ) )
785  return AreaSquareMillimeters;
786  if ( normalized == toString( AreaSquareCentimeters ) )
787  return AreaSquareCentimeters;
788  if ( normalized == toString( AreaUnknownUnit ) )
789  return AreaUnknownUnit;
790  if ( ok )
791  *ok = false;
792 
793  return AreaUnknownUnit;
794 }
795 
797 {
798 #define KM2_TO_M2 1000000.0
799 #define CM2_TO_M2 0.0001
800 #define MM2_TO_M2 0.000001
801 #define FT2_TO_M2 0.09290304
802 #define YD2_TO_M2 0.83612736
803 #define MI2_TO_M2 2589988.110336
804 #define HA_TO_M2 10000.0
805 #define AC_TO_FT2 43560.0
806 #define DEG2_TO_M2 12392029030.5
807 #define NM2_TO_M2 3429904.0
808 
809  // Calculate the conversion factor between the specified units
810  switch ( fromUnit )
811  {
812  case AreaSquareMeters:
813  {
814  switch ( toUnit )
815  {
816  case AreaSquareMeters:
817  return 1.0;
819  return 1.0 / KM2_TO_M2;
820  case AreaSquareFeet:
821  return 1.0 / FT2_TO_M2;
822  case AreaSquareYards:
823  return 1.0 / YD2_TO_M2;
824  case AreaSquareMiles:
825  return 1.0 / MI2_TO_M2;
826  case AreaHectares:
827  return 1.0 / HA_TO_M2;
828  case AreaAcres:
829  return 1.0 / AC_TO_FT2 / FT2_TO_M2;
831  return 1.0 / NM2_TO_M2;
832  case AreaSquareDegrees:
833  return 1.0 / DEG2_TO_M2;
835  return 1.0 / CM2_TO_M2;
837  return 1.0 / MM2_TO_M2;
838  case AreaUnknownUnit:
839  break;
840  }
841 
842  break;
843  }
845  {
846  switch ( toUnit )
847  {
848  case AreaSquareMeters:
849  return KM2_TO_M2;
851  return 1.0;
852  case AreaSquareFeet:
853  return KM2_TO_M2 / FT2_TO_M2;
854  case AreaSquareYards:
855  return KM2_TO_M2 / YD2_TO_M2;
856  case AreaSquareMiles:
857  return KM2_TO_M2 / MI2_TO_M2;
858  case AreaHectares:
859  return KM2_TO_M2 / HA_TO_M2;
860  case AreaAcres:
861  return KM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
863  return KM2_TO_M2 / NM2_TO_M2;
864  case AreaSquareDegrees:
865  return KM2_TO_M2 / DEG2_TO_M2;
867  return KM2_TO_M2 / CM2_TO_M2;
869  return KM2_TO_M2 / MM2_TO_M2;
870  case AreaUnknownUnit:
871  break;
872  }
873 
874  break;
875  }
876  case AreaSquareFeet:
877  {
878  switch ( toUnit )
879  {
880  case AreaSquareMeters:
881  return FT2_TO_M2;
883  return FT2_TO_M2 / KM2_TO_M2;
884  case AreaSquareFeet:
885  return 1.0;
886  case AreaSquareYards:
887  return FT2_TO_M2 / YD2_TO_M2;
888  case AreaSquareMiles:
889  return FT2_TO_M2 / MI2_TO_M2;
890  case AreaHectares:
891  return FT2_TO_M2 / HA_TO_M2;
892  case AreaAcres:
893  return 1.0 / AC_TO_FT2;
895  return FT2_TO_M2 / NM2_TO_M2;
896  case AreaSquareDegrees:
897  return FT2_TO_M2 / DEG2_TO_M2;
899  return FT2_TO_M2 / CM2_TO_M2;
901  return FT2_TO_M2 / MM2_TO_M2;
902  case AreaUnknownUnit:
903  break;
904  }
905 
906  break;
907  }
908 
909  case AreaSquareYards:
910  {
911  switch ( toUnit )
912  {
913  case AreaSquareMeters:
914  return YD2_TO_M2;
916  return YD2_TO_M2 / KM2_TO_M2;
917  case AreaSquareFeet:
918  return YD2_TO_M2 / FT2_TO_M2;
919  case AreaSquareYards:
920  return 1.0;
921  case AreaSquareMiles:
922  return YD2_TO_M2 / MI2_TO_M2;
923  case AreaHectares:
924  return YD2_TO_M2 / HA_TO_M2;
925  case AreaAcres:
926  return YD2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
928  return YD2_TO_M2 / NM2_TO_M2;
929  case AreaSquareDegrees:
930  return YD2_TO_M2 / DEG2_TO_M2;
932  return YD2_TO_M2 / CM2_TO_M2;
934  return YD2_TO_M2 / MM2_TO_M2;
935  case AreaUnknownUnit:
936  break;
937  }
938  break;
939  }
940 
941  case AreaSquareMiles:
942  {
943  switch ( toUnit )
944  {
945  case AreaSquareMeters:
946  return MI2_TO_M2;
948  return MI2_TO_M2 / KM2_TO_M2;
949  case AreaSquareFeet:
950  return MI2_TO_M2 / FT2_TO_M2;
951  case AreaSquareYards:
952  return MI2_TO_M2 / YD2_TO_M2;
953  case AreaSquareMiles:
954  return 1.0;
955  case AreaHectares:
956  return MI2_TO_M2 / HA_TO_M2;
957  case AreaAcres:
958  return MI2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
960  return MI2_TO_M2 / NM2_TO_M2;
961  case AreaSquareDegrees:
962  return MI2_TO_M2 / DEG2_TO_M2;
964  return MI2_TO_M2 / CM2_TO_M2;
966  return MI2_TO_M2 / MM2_TO_M2;
967  case AreaUnknownUnit:
968  break;
969  }
970 
971  break;
972  }
973 
974  case AreaHectares:
975  {
976  switch ( toUnit )
977  {
978  case AreaSquareMeters:
979  return HA_TO_M2;
981  return HA_TO_M2 / KM2_TO_M2;
982  case AreaSquareFeet:
983  return HA_TO_M2 / FT2_TO_M2;
984  case AreaSquareYards:
985  return HA_TO_M2 / YD2_TO_M2;
986  case AreaSquareMiles:
987  return HA_TO_M2 / MI2_TO_M2;
988  case AreaHectares:
989  return 1.0;
990  case AreaAcres:
991  return HA_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
993  return HA_TO_M2 / NM2_TO_M2;
994  case AreaSquareDegrees:
995  return HA_TO_M2 / DEG2_TO_M2;
997  return HA_TO_M2 / CM2_TO_M2;
999  return HA_TO_M2 / MM2_TO_M2;
1000  case AreaUnknownUnit:
1001  break;
1002  }
1003 
1004  break;
1005  }
1006 
1007  case AreaAcres:
1008  {
1009  switch ( toUnit )
1010  {
1011  case AreaSquareMeters:
1012  return AC_TO_FT2 * FT2_TO_M2;
1013  case AreaSquareKilometers:
1014  return AC_TO_FT2 * FT2_TO_M2 / KM2_TO_M2;
1015  case AreaSquareFeet:
1016  return AC_TO_FT2;
1017  case AreaSquareYards:
1018  return AC_TO_FT2 * FT2_TO_M2 / YD2_TO_M2;
1019  case AreaSquareMiles:
1020  return AC_TO_FT2 * FT2_TO_M2 / MI2_TO_M2;
1021  case AreaHectares:
1022  return AC_TO_FT2 * FT2_TO_M2 / HA_TO_M2;
1023  case AreaAcres:
1024  return 1.0;
1026  return AC_TO_FT2 * FT2_TO_M2 / NM2_TO_M2;
1027  case AreaSquareDegrees:
1028  return AC_TO_FT2 * FT2_TO_M2 / DEG2_TO_M2;
1029  case AreaSquareCentimeters:
1030  return AC_TO_FT2 * FT2_TO_M2 / CM2_TO_M2;
1031  case AreaSquareMillimeters:
1032  return AC_TO_FT2 * FT2_TO_M2 / MM2_TO_M2;
1033  case AreaUnknownUnit:
1034  break;
1035  }
1036 
1037  break;
1038  }
1039 
1041  {
1042  switch ( toUnit )
1043  {
1044  case AreaSquareMeters:
1045  return NM2_TO_M2;
1046  case AreaSquareKilometers:
1047  return NM2_TO_M2 / KM2_TO_M2;
1048  case AreaSquareFeet:
1049  return NM2_TO_M2 / FT2_TO_M2;
1050  case AreaSquareYards:
1051  return NM2_TO_M2 / YD2_TO_M2;
1052  case AreaSquareMiles:
1053  return NM2_TO_M2 / MI2_TO_M2;
1054  case AreaHectares:
1055  return NM2_TO_M2 / HA_TO_M2;
1056  case AreaAcres:
1057  return NM2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1059  return 1.0;
1060  case AreaSquareDegrees:
1061  return NM2_TO_M2 / DEG2_TO_M2;
1062  case AreaSquareCentimeters:
1063  return NM2_TO_M2 / CM2_TO_M2;
1064  case AreaSquareMillimeters:
1065  return NM2_TO_M2 / MM2_TO_M2;
1066  case AreaUnknownUnit:
1067  break;
1068  }
1069 
1070  break;
1071  }
1072 
1073  case AreaSquareDegrees:
1074  {
1075  switch ( toUnit )
1076  {
1077  case AreaSquareMeters:
1078  return DEG2_TO_M2;
1079  case AreaSquareKilometers:
1080  return DEG2_TO_M2 / KM2_TO_M2;
1081  case AreaSquareFeet:
1082  return DEG2_TO_M2 / FT2_TO_M2;
1083  case AreaSquareYards:
1084  return DEG2_TO_M2 / YD2_TO_M2;
1085  case AreaSquareMiles:
1086  return DEG2_TO_M2 / MI2_TO_M2;
1087  case AreaHectares:
1088  return DEG2_TO_M2 / HA_TO_M2;
1089  case AreaAcres:
1090  return DEG2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1092  return DEG2_TO_M2 / NM2_TO_M2;
1093  case AreaSquareDegrees:
1094  return 1.0;
1095  case AreaSquareCentimeters:
1096  return DEG2_TO_M2 / CM2_TO_M2;
1097  case AreaSquareMillimeters:
1098  return DEG2_TO_M2 / MM2_TO_M2;
1099  case AreaUnknownUnit:
1100  break;
1101  }
1102 
1103  break;
1104  }
1105 
1106  case AreaSquareMillimeters:
1107  {
1108  switch ( toUnit )
1109  {
1110  case AreaSquareMeters:
1111  return MM2_TO_M2;
1112  case AreaSquareKilometers:
1113  return MM2_TO_M2 / KM2_TO_M2;
1114  case AreaSquareFeet:
1115  return MM2_TO_M2 / FT2_TO_M2;
1116  case AreaSquareYards:
1117  return MM2_TO_M2 / YD2_TO_M2;
1118  case AreaSquareMiles:
1119  return MM2_TO_M2 / MI2_TO_M2;
1120  case AreaHectares:
1121  return MM2_TO_M2 / HA_TO_M2;
1122  case AreaAcres:
1123  return MM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1125  return MM2_TO_M2 / NM2_TO_M2;
1126  case AreaSquareDegrees:
1127  return MM2_TO_M2 / DEG2_TO_M2;
1128  case AreaSquareCentimeters:
1129  return MM2_TO_M2 / CM2_TO_M2;
1130  case AreaSquareMillimeters:
1131  return 1.0;
1132  case AreaUnknownUnit:
1133  break;
1134  }
1135 
1136  break;
1137  }
1138  case AreaSquareCentimeters:
1139  {
1140  switch ( toUnit )
1141  {
1142  case AreaSquareMeters:
1143  return CM2_TO_M2;
1144  case AreaSquareKilometers:
1145  return CM2_TO_M2 / KM2_TO_M2;
1146  case AreaSquareFeet:
1147  return CM2_TO_M2 / FT2_TO_M2;
1148  case AreaSquareYards:
1149  return CM2_TO_M2 / YD2_TO_M2;
1150  case AreaSquareMiles:
1151  return CM2_TO_M2 / MI2_TO_M2;
1152  case AreaHectares:
1153  return CM2_TO_M2 / HA_TO_M2;
1154  case AreaAcres:
1155  return CM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1157  return CM2_TO_M2 / NM2_TO_M2;
1158  case AreaSquareDegrees:
1159  return CM2_TO_M2 / DEG2_TO_M2;
1160  case AreaSquareCentimeters:
1161  return 1.0;
1162  case AreaSquareMillimeters:
1163  return CM2_TO_M2 / MM2_TO_M2;
1164  case AreaUnknownUnit:
1165  break;
1166  }
1167 
1168  break;
1169  }
1170  case AreaUnknownUnit:
1171  break;
1172  }
1173  return 1.0;
1174 }
1175 
1177 {
1178  switch ( distanceUnit )
1179  {
1180  case DistanceMeters:
1181  return AreaSquareMeters;
1182 
1183  case DistanceKilometers:
1184  return AreaSquareKilometers;
1185 
1186  case DistanceCentimeters:
1187  return AreaSquareCentimeters;
1188 
1189  case DistanceMillimeters:
1190  return AreaSquareMillimeters;
1191 
1192  case DistanceFeet:
1193  return AreaSquareFeet;
1194 
1195  case DistanceYards:
1196  return AreaSquareYards;
1197 
1198  case DistanceMiles:
1199  return AreaSquareMiles;
1200 
1201  case DistanceDegrees:
1202  return AreaSquareDegrees;
1203 
1204  case DistanceUnknownUnit:
1205  return AreaUnknownUnit;
1206 
1207  case DistanceNauticalMiles:
1208  return AreaSquareNauticalMiles;
1209  }
1210 
1211  return AreaUnknownUnit;
1212 }
1213 
1215 {
1216  switch ( areaUnit )
1217  {
1218  case AreaSquareMeters:
1219  case AreaHectares:
1220  return DistanceMeters;
1221 
1222  case AreaSquareKilometers:
1223  return DistanceKilometers;
1224 
1225  case AreaSquareCentimeters:
1226  return DistanceCentimeters;
1227 
1228  case AreaSquareMillimeters:
1229  return DistanceMillimeters;
1230 
1231  case AreaSquareFeet:
1232  return DistanceFeet;
1233 
1234  case AreaSquareYards:
1235  case AreaAcres:
1236  return DistanceYards;
1237 
1238  case AreaSquareMiles:
1239  return DistanceMiles;
1240 
1241  case AreaSquareDegrees:
1242  return DistanceDegrees;
1243 
1244  case AreaUnknownUnit:
1245  return DistanceUnknownUnit;
1246 
1248  return DistanceNauticalMiles;
1249  }
1250 
1251  return DistanceUnknownUnit;
1252 }
1253 
1255 {
1256  switch ( unit )
1257  {
1258  case TemporalSeconds:
1259  return QStringLiteral( "s" );
1260  case TemporalMilliseconds:
1261  return QStringLiteral( "ms" );
1262  case TemporalMinutes:
1263  return QStringLiteral( "min" );
1264  case TemporalHours:
1265  return QStringLiteral( "h" );
1266  case TemporalDays:
1267  return QStringLiteral( "d" );
1268  case TemporalWeeks:
1269  return QStringLiteral( "wk" );
1270  case TemporalMonths:
1271  return QStringLiteral( "mon" );
1272  case TemporalYears:
1273  return QStringLiteral( "y" );
1274  case TemporalDecades:
1275  return QStringLiteral( "dec" );
1276  case TemporalCenturies:
1277  return QStringLiteral( "c" );
1278  case TemporalUnknownUnit:
1279  return QStringLiteral( "<unknown>" );
1280  }
1281  return QString();
1282 }
1283 
1285 {
1286  QString normalized = string.trimmed().toLower();
1287 
1288  if ( ok )
1289  *ok = true;
1290 
1291  if ( normalized == encodeUnit( TemporalSeconds ) )
1292  return TemporalSeconds;
1293  if ( normalized == encodeUnit( TemporalMilliseconds ) )
1294  return TemporalMilliseconds;
1295  if ( normalized == encodeUnit( TemporalMinutes ) )
1296  return TemporalMinutes;
1297  if ( normalized == encodeUnit( TemporalHours ) )
1298  return TemporalHours;
1299  if ( normalized == encodeUnit( TemporalDays ) )
1300  return TemporalDays;
1301  if ( normalized == encodeUnit( TemporalWeeks ) )
1302  return TemporalWeeks;
1303  if ( normalized == encodeUnit( TemporalMonths ) )
1304  return TemporalMonths;
1305  if ( normalized == encodeUnit( TemporalYears ) )
1306  return TemporalYears;
1307  if ( normalized == encodeUnit( TemporalDecades ) )
1308  return TemporalDecades;
1309  if ( normalized == encodeUnit( TemporalCenturies ) )
1310  return TemporalCenturies;
1311  if ( normalized == encodeUnit( TemporalUnknownUnit ) )
1312  return TemporalUnknownUnit;
1313 
1314  if ( ok )
1315  *ok = false;
1316 
1317  return TemporalUnknownUnit;
1318 }
1319 
1321 {
1322  switch ( unit )
1323  {
1324  case TemporalSeconds:
1325  return QObject::tr( "seconds", "temporal" );
1326  case TemporalMilliseconds:
1327  return QObject::tr( "milliseconds", "temporal" );
1328  case TemporalMinutes:
1329  return QObject::tr( "minutes", "temporal" );
1330  case TemporalHours:
1331  return QObject::tr( "hours", "temporal" );
1332  case TemporalDays:
1333  return QObject::tr( "days", "temporal" );
1334  case TemporalWeeks:
1335  return QObject::tr( "weeks", "temporal" );
1336  case TemporalMonths:
1337  return QObject::tr( "months", "temporal" );
1338  case TemporalYears:
1339  return QObject::tr( "years", "temporal" );
1340  case TemporalDecades:
1341  return QObject::tr( "decades", "temporal" );
1342  case TemporalCenturies:
1343  return QObject::tr( "centuries", "temporal" );
1344  case TemporalUnknownUnit:
1345  return QObject::tr( "<unknown>", "temporal" );
1346  }
1347  return QString();
1348 }
1349 
1351 {
1352  switch ( unit )
1353  {
1354  case TemporalSeconds:
1355  return QObject::tr( "s", "temporal" );
1356  case TemporalMilliseconds:
1357  return QObject::tr( "ms", "temporal" );
1358  case TemporalMinutes:
1359  return QObject::tr( "min", "temporal" );
1360  case TemporalHours:
1361  return QObject::tr( "h", "temporal" );
1362  case TemporalDays:
1363  return QObject::tr( "d", "temporal" );
1364  case TemporalWeeks:
1365  return QObject::tr( "wk", "temporal" );
1366  case TemporalMonths:
1367  return QObject::tr( "mon", "temporal" );
1368  case TemporalYears:
1369  return QObject::tr( "y", "temporal" );
1370  case TemporalDecades:
1371  return QObject::tr( "dec", "temporal" );
1372  case TemporalCenturies:
1373  return QObject::tr( "cen", "temporal" );
1374  case TemporalUnknownUnit:
1375  return QObject::tr( "<unknown>", "temporal" );
1376  }
1377  return QString();
1378 }
1379 
1381 {
1382  QString normalized = string.trimmed().toLower();
1383 
1384  if ( ok )
1385  *ok = true;
1386 
1387  if ( normalized == toString( TemporalSeconds ) )
1388  return TemporalSeconds;
1389  if ( normalized == toString( TemporalMilliseconds ) )
1390  return TemporalMilliseconds;
1391  if ( normalized == toString( TemporalMinutes ) )
1392  return TemporalMinutes;
1393  if ( normalized == toString( TemporalHours ) )
1394  return TemporalHours;
1395  if ( normalized == toString( TemporalDays ) )
1396  return TemporalDays;
1397  if ( normalized == toString( TemporalWeeks ) )
1398  return TemporalWeeks;
1399  if ( normalized == toString( TemporalMonths ) )
1400  return TemporalMonths;
1401  if ( normalized == toString( TemporalYears ) )
1402  return TemporalYears;
1403  if ( normalized == toString( TemporalDecades ) )
1404  return TemporalDecades;
1405  if ( normalized == toString( TemporalCenturies ) )
1406  return TemporalCenturies;
1407  if ( normalized == toString( TemporalUnknownUnit ) )
1408  return TemporalUnknownUnit;
1409 
1410  if ( ok )
1411  *ok = false;
1412 
1413  return TemporalUnknownUnit;
1414 }
1415 
1417 {
1418  switch ( fromUnit )
1419  {
1420  case TemporalSeconds:
1421  {
1422  switch ( toUnit )
1423  {
1424  case TemporalSeconds:
1425  return 1.0;
1426  case TemporalMilliseconds:
1427  return 1000.0;
1428  case TemporalMinutes:
1429  return 1 / 60.0;
1430  case TemporalHours:
1431  return 1 / 3600.0;
1432  case TemporalDays:
1433  return 1 / 86400.0;
1434  case TemporalWeeks:
1435  return 1 / 604800.0;
1436  case TemporalMonths:
1437  return 1 / 2592000.0;
1438  case TemporalYears:
1439  return 1 / 31557600.0;
1440  case TemporalDecades:
1441  return 1 / 315576000.0;
1442  case TemporalCenturies:
1443  return 1 / 3155760000.0;
1444  case TemporalUnknownUnit:
1445  return 1.0;
1446  }
1447  break;
1448  }
1449  case TemporalMilliseconds:
1450  {
1451  switch ( toUnit )
1452  {
1453  case TemporalSeconds:
1454  return 1 / 1000.0;
1455  case TemporalMilliseconds:
1456  return 1.0;
1457  case TemporalMinutes:
1458  return 1 / 60000.0;
1459  case TemporalHours:
1460  return 1 / 3600000.0;
1461  case TemporalDays:
1462  return 1 / 86400000.0;
1463  case TemporalWeeks:
1464  return 1 / 60480000.0;
1465  case TemporalMonths:
1466  return 1 / 259200000.0;
1467  case TemporalYears:
1468  return 1 / 3155760000.0;
1469  case TemporalDecades:
1470  return 1 / 31557600000.0;
1471  case TemporalCenturies:
1472  return 1 / 315576000000.0;
1473  case TemporalUnknownUnit:
1474  return 1.0;
1475  }
1476  break;
1477  }
1478  case TemporalMinutes:
1479  {
1480  switch ( toUnit )
1481  {
1482  case TemporalSeconds:
1483  return 60.0;
1484  case TemporalMilliseconds:
1485  return 60000.0;
1486  case TemporalMinutes:
1487  return 1;
1488  case TemporalHours:
1489  return 1 / 60.0;
1490  case TemporalDays:
1491  return 1 / 1440.0;
1492  case TemporalWeeks:
1493  return 1 / 10080.0;
1494  case TemporalMonths:
1495  return 1 / 43200.0;
1496  case TemporalYears:
1497  return 1 / 525960.0;
1498  case TemporalDecades:
1499  return 1 / 5259600.0;
1500  case TemporalCenturies:
1501  return 1 / 52596000.0;
1502  case TemporalUnknownUnit:
1503  return 1.0;
1504  }
1505  break;
1506  }
1507  case TemporalHours:
1508  {
1509  switch ( toUnit )
1510  {
1511  case TemporalSeconds:
1512  return 3600.0;
1513  case TemporalMilliseconds:
1514  return 3600000.0;
1515  case TemporalMinutes:
1516  return 60;
1517  case TemporalHours:
1518  return 1;
1519  case TemporalDays:
1520  return 1 / 24.0;
1521  case TemporalWeeks:
1522  return 1 / 168.0;
1523  case TemporalMonths:
1524  return 1 / 720.0;
1525  case TemporalYears:
1526  return 1 / 8766.0;
1527  case TemporalDecades:
1528  return 1 / 87660.0;
1529  case TemporalCenturies:
1530  return 1 / 876600.0;
1531  case TemporalUnknownUnit:
1532  return 1.0;
1533  }
1534  break;
1535  }
1536  case TemporalDays:
1537  {
1538  switch ( toUnit )
1539  {
1540  case TemporalSeconds:
1541  return 86400.0;
1542  case TemporalMilliseconds:
1543  return 86400000.0;
1544  case TemporalMinutes:
1545  return 1440;
1546  case TemporalHours:
1547  return 24;
1548  case TemporalDays:
1549  return 1;
1550  case TemporalWeeks:
1551  return 1 / 7.0;
1552  case TemporalMonths:
1553  return 1 / 30.0;
1554  case TemporalYears:
1555  return 1 / 365.25;
1556  case TemporalDecades:
1557  return 1 / 3652.5;
1558  case TemporalCenturies:
1559  return 1 / 36525.0;
1560  case TemporalUnknownUnit:
1561  return 1.0;
1562  }
1563  break;
1564  }
1565  case TemporalWeeks:
1566  {
1567  switch ( toUnit )
1568  {
1569  case TemporalSeconds:
1570  return 604800.0;
1571  case TemporalMilliseconds:
1572  return 604800000.0;
1573  case TemporalMinutes:
1574  return 10080;
1575  case TemporalHours:
1576  return 168;
1577  case TemporalDays:
1578  return 7;
1579  case TemporalWeeks:
1580  return 1;
1581  case TemporalMonths:
1582  return 7 / 30.0;
1583  case TemporalYears:
1584  return 7 / 365.25;
1585  case TemporalDecades:
1586  return 7 / 3652.5;
1587  case TemporalCenturies:
1588  return 7 / 36525.0;
1589  case TemporalUnknownUnit:
1590  return 1.0;
1591  }
1592  break;
1593  }
1594  case TemporalMonths:
1595  {
1596  switch ( toUnit )
1597  {
1598  case TemporalSeconds:
1599  return 2592000.0;
1600  case TemporalMilliseconds:
1601  return 2592000000.0;
1602  case TemporalMinutes:
1603  return 43200;
1604  case TemporalHours:
1605  return 720;
1606  case TemporalDays:
1607  return 30;
1608  case TemporalWeeks:
1609  return 30 / 7.0;
1610  case TemporalMonths:
1611  return 1;
1612  case TemporalYears:
1613  return 30 / 365.25;
1614  case TemporalDecades:
1615  return 30 / 3652.5;
1616  case TemporalCenturies:
1617  return 30 / 36525.0;
1618  case TemporalUnknownUnit:
1619  return 1.0;
1620  }
1621  break;
1622  }
1623  case TemporalYears:
1624  {
1625  switch ( toUnit )
1626  {
1627  case TemporalSeconds:
1628  return 31557600.0;
1629  case TemporalMilliseconds:
1630  return 31557600000.0;
1631  case TemporalMinutes:
1632  return 525960.0;
1633  case TemporalHours:
1634  return 8766.0;
1635  case TemporalDays:
1636  return 365.25;
1637  case TemporalWeeks:
1638  return 365.25 / 7.0;
1639  case TemporalMonths:
1640  return 365.25 / 30.0;
1641  case TemporalYears:
1642  return 1;
1643  case TemporalDecades:
1644  return 0.1;
1645  case TemporalCenturies:
1646  return 0.01;
1647  case TemporalUnknownUnit:
1648  return 1.0;
1649  }
1650  break;
1651  }
1652  case TemporalDecades:
1653  {
1654  switch ( toUnit )
1655  {
1656  case TemporalSeconds:
1657  return 315576000.0;
1658  case TemporalMilliseconds:
1659  return 315576000000.0;
1660  case TemporalMinutes:
1661  return 5259600.0;
1662  case TemporalHours:
1663  return 87660.0;
1664  case TemporalDays:
1665  return 3652.5;
1666  case TemporalWeeks:
1667  return 3652.5 / 7.0;
1668  case TemporalMonths:
1669  return 3652.5 / 30.0;
1670  case TemporalYears:
1671  return 10;
1672  case TemporalDecades:
1673  return 1;
1674  case TemporalCenturies:
1675  return 0.1;
1676  case TemporalUnknownUnit:
1677  return 1.0;
1678  }
1679  break;
1680  }
1681 
1682  case TemporalCenturies:
1683  {
1684  switch ( toUnit )
1685  {
1686  case TemporalSeconds:
1687  return 3155760000.0;
1688  case TemporalMilliseconds:
1689  return 3155760000000.0;
1690  case TemporalMinutes:
1691  return 52596000.0;
1692  case TemporalHours:
1693  return 876600.0;
1694  case TemporalDays:
1695  return 36525;
1696  case TemporalWeeks:
1697  return 36525 / 7.0;
1698  case TemporalMonths:
1699  return 36525 / 30.0;
1700  case TemporalYears:
1701  return 100;
1702  case TemporalDecades:
1703  return 10;
1704  case TemporalCenturies:
1705  return 1;
1706  case TemporalUnknownUnit:
1707  return 1.0;
1708  }
1709  break;
1710  }
1711 
1712  case TemporalUnknownUnit:
1713  {
1714  return 1.0;
1715  }
1716  }
1717  return 1.0;
1718 }
1719 
1721 {
1722  QString normalized = string.trimmed().toLower();
1723 
1724  if ( ok )
1725  *ok = true;
1726 
1727  if ( normalized == encodeUnit( VolumeCubicMeters ) )
1728  return VolumeCubicMeters;
1729  if ( normalized == encodeUnit( VolumeCubicFeet ) )
1730  return VolumeCubicFeet;
1731  if ( normalized == encodeUnit( VolumeCubicYards ) )
1732  return VolumeCubicYards;
1733  if ( normalized == encodeUnit( VolumeBarrel ) )
1734  return VolumeBarrel;
1735  if ( normalized == encodeUnit( VolumeCubicDecimeter ) )
1736  return VolumeCubicDecimeter;
1737  if ( normalized == encodeUnit( VolumeLiters ) )
1738  return VolumeLiters;
1739  if ( normalized == encodeUnit( VolumeGallonUS ) )
1740  return VolumeGallonUS;
1741  if ( normalized == encodeUnit( VolumeCubicInch ) )
1742  return VolumeCubicInch;
1743  if ( normalized == encodeUnit( VolumeCubicCentimeter ) )
1744  return VolumeCubicCentimeter;
1745  if ( normalized == encodeUnit( VolumeCubicDegrees ) )
1746  return VolumeCubicDegrees;
1747  if ( normalized == encodeUnit( VolumeUnknownUnit ) )
1748  return VolumeUnknownUnit;
1749 
1750  if ( ok )
1751  *ok = false;
1752 
1753  return VolumeUnknownUnit;
1754 }
1755 
1757 {
1758  switch ( unit )
1759  {
1760  case VolumeCubicMeters:
1761  return QObject::tr( "cubic meters", "volume" );
1762  case VolumeCubicFeet:
1763  return QObject::tr( "cubic feet", "volume" );
1764  case VolumeCubicYards:
1765  return QObject::tr( "cubic yards", "volume" );
1766  case VolumeBarrel:
1767  return QObject::tr( "barrels", "volume" );
1768  case VolumeCubicDecimeter:
1769  return QObject::tr( "cubic decimeters", "volume" );
1770  case VolumeLiters:
1771  return QObject::tr( "liters", "volume" );
1772  case VolumeGallonUS:
1773  return QObject::tr( "gallons", "volume" );
1774  case VolumeCubicInch:
1775  return QObject::tr( "cubic inches", "volume" );
1776  case VolumeCubicCentimeter:
1777  return QObject::tr( "cubic centimeters", "volume" );
1778  case VolumeCubicDegrees:
1779  return QObject::tr( "cubic degrees", "volume" );
1780  case VolumeUnknownUnit:
1781  return QObject::tr( "<unknown>", "volume" );
1782  }
1783  return QString();
1784 }
1785 
1787 {
1788  switch ( unit )
1789  {
1790  case VolumeCubicMeters:
1791  return QObject::tr( "m³", "volume" );
1792  case VolumeCubicFeet:
1793  return QObject::tr( "ft³", "volume" );
1794  case VolumeCubicYards:
1795  return QObject::tr( "yds³", "volume" );
1796  case VolumeBarrel:
1797  return QObject::tr( "bbl", "volume" );
1798  case VolumeCubicDecimeter:
1799  return QObject::tr( "dm³", "volume" );
1800  case VolumeLiters:
1801  return QObject::tr( "l", "volume" );
1802  case VolumeGallonUS:
1803  return QObject::tr( "gal", "volume" );
1804  case VolumeCubicInch:
1805  return QObject::tr( "in³", "volume" );
1806  case VolumeCubicCentimeter:
1807  return QObject::tr( "cm³", "volume" );
1808  case VolumeCubicDegrees:
1809  return QObject::tr( "deg³", "volume" );
1810  case VolumeUnknownUnit:
1811  return QObject::tr( "<unknown>", "volume" );
1812  }
1813  return QString();
1814 
1815 }
1816 
1818 {
1819  QString normalized = string.trimmed().toLower();
1820 
1821  if ( ok )
1822  *ok = true;
1823 
1824  if ( normalized == toString( VolumeCubicMeters ) )
1825  return VolumeCubicMeters;
1826  if ( normalized == toString( VolumeCubicFeet ) )
1827  return VolumeCubicFeet;
1828  if ( normalized == toString( VolumeCubicYards ) )
1829  return VolumeCubicYards;
1830  if ( normalized == toString( VolumeBarrel ) )
1831  return VolumeBarrel;
1832  if ( normalized == toString( VolumeCubicDecimeter ) )
1833  return VolumeCubicDecimeter;
1834  if ( normalized == toString( VolumeLiters ) )
1835  return VolumeLiters;
1836  if ( normalized == toString( VolumeGallonUS ) )
1837  return VolumeGallonUS;
1838  if ( normalized == toString( VolumeCubicInch ) )
1839  return VolumeCubicInch;
1840  if ( normalized == toString( VolumeCubicCentimeter ) )
1841  return VolumeCubicCentimeter;
1842  if ( normalized == toString( VolumeCubicDegrees ) )
1843  return VolumeCubicDegrees;
1844  if ( normalized == toString( VolumeUnknownUnit ) )
1845  return VolumeUnknownUnit;
1846 
1847  if ( ok )
1848  *ok = false;
1849 
1850  return VolumeUnknownUnit;
1851 }
1852 
1853 #define DEG2_TO_M3 1379474361572186.2
1855 {
1856  switch ( fromUnit )
1857  {
1858  case VolumeCubicMeters:
1859  {
1860  switch ( toUnit )
1861  {
1862  case VolumeCubicMeters:
1863  return 1.0;
1864  case VolumeCubicFeet:
1865  return 35.314666572222;
1866  case VolumeCubicYards:
1867  return 1.307950613786;
1868  case VolumeBarrel:
1869  return 6.2898107438466;
1870  case VolumeCubicDecimeter:
1871  return 1000;
1872  case VolumeLiters:
1873  return 1000;
1874  case VolumeGallonUS:
1875  return 264.17205124156;
1876  case VolumeCubicInch:
1877  return 61023.7438368;
1878  case VolumeCubicCentimeter:
1879  return 1000000;
1880  case VolumeCubicDegrees:
1881  return 1 / DEG2_TO_M3; // basically meaningless!
1882  case VolumeUnknownUnit:
1883  return 1.0;
1884  }
1885  break;
1886  }
1887  case VolumeCubicFeet:
1888  {
1889  switch ( toUnit )
1890  {
1891  case VolumeCubicMeters:
1892  return 0.028316846592;
1893  case VolumeCubicFeet:
1894  return 1.0;
1895  case VolumeCubicYards:
1896  return 0.037037037;
1897  case VolumeBarrel:
1898  return 0.178107622;
1899  case VolumeCubicDecimeter:
1900  return 28.31685;
1901  case VolumeLiters:
1902  return 28.31685;
1903  case VolumeGallonUS:
1904  return 7.480519954;
1905  case VolumeCubicInch:
1906  return 1728.000629765;
1907  case VolumeCubicCentimeter:
1908  return 28316.85;
1909  case VolumeCubicDegrees:
1910  return 0.028316846592 / DEG2_TO_M3; // basically meaningless!
1911  case VolumeUnknownUnit:
1912  return 1.0;
1913  }
1914  break;
1915  }
1916  case VolumeCubicYards:
1917  {
1918  switch ( toUnit )
1919  {
1920  case VolumeCubicMeters:
1921  return 0.764554900;
1922  case VolumeCubicFeet:
1923  return 26.999998234;
1924  case VolumeCubicYards:
1925  return 1.0;
1926  case VolumeBarrel:
1927  return 4.808905491;
1928  case VolumeCubicDecimeter:
1929  return 764.5549;
1930  case VolumeLiters:
1931  return 764.5549;
1932  case VolumeGallonUS:
1933  return 201.974025549;
1934  case VolumeCubicInch:
1935  return 46656.013952472;
1936  case VolumeCubicCentimeter:
1937  return 764554.9;
1938  case VolumeCubicDegrees:
1939  return 0.764554900 / DEG2_TO_M3; // basically meaningless!
1940  case VolumeUnknownUnit:
1941  return 1.0;
1942  }
1943  break;
1944  }
1945  case VolumeBarrel:
1946  {
1947  switch ( toUnit )
1948  {
1949  case VolumeCubicMeters:
1950  return 0.158987300;
1951  case VolumeCubicFeet:
1952  return 5.614582837;
1953  case VolumeCubicYards:
1954  return 0.207947526;
1955  case VolumeBarrel:
1956  return 1.0;
1957  case VolumeCubicDecimeter:
1958  return 158.9873;
1959  case VolumeLiters:
1960  return 158.9873;
1961  case VolumeGallonUS:
1962  return 41.999998943;
1963  case VolumeCubicInch:
1964  return 9702.002677722;
1965  case VolumeCubicCentimeter:
1966  return 158987.3;
1967  case VolumeCubicDegrees:
1968  return 0.158987300 / DEG2_TO_M3; // basically meaningless!
1969  case VolumeUnknownUnit:
1970  return 1.0;
1971  }
1972  break;
1973  }
1974  case VolumeCubicDecimeter:
1975  case VolumeLiters:
1976  {
1977  switch ( toUnit )
1978  {
1979  case VolumeCubicMeters:
1980  return 0.001;
1981  case VolumeCubicFeet:
1982  return 0.035314662;
1983  case VolumeCubicYards:
1984  return 0.001307951;
1985  case VolumeBarrel:
1986  return 0.006289811;
1987  case VolumeCubicDecimeter:
1988  case VolumeLiters:
1989  return 1.0;
1990  case VolumeGallonUS:
1991  return 0.264172037;
1992  case VolumeCubicInch:
1993  return 61.023758990;
1994  case VolumeCubicCentimeter:
1995  return 1000;
1996  case VolumeCubicDegrees:
1997  return 0.001 / DEG2_TO_M3; // basically meaningless!
1998  case VolumeUnknownUnit:
1999  return 1.0;
2000  }
2001  break;
2002  }
2003  case VolumeGallonUS:
2004  {
2005  switch ( toUnit )
2006  {
2007  case VolumeCubicMeters:
2008  return 0.003785412;
2009  case VolumeCubicFeet:
2010  return 0.133680547;
2011  case VolumeCubicYards:
2012  return 0.004951132;
2013  case VolumeBarrel:
2014  return 0.023809524;
2015  case VolumeCubicDecimeter:
2016  case VolumeLiters:
2017  return 3.785412000;
2018  case VolumeGallonUS:
2019  return 1.0;
2020  case VolumeCubicInch:
2021  return 231.000069567;
2022  case VolumeCubicCentimeter:
2023  return 3785.412;
2024  case VolumeCubicDegrees:
2025  return 0.003785412 / DEG2_TO_M3; // basically meaningless!
2026  case VolumeUnknownUnit:
2027  return 1.0;
2028  }
2029  break;
2030  }
2031  case VolumeCubicInch:
2032  {
2033  switch ( toUnit )
2034  {
2035  case VolumeCubicMeters:
2036  return 0.000016387;
2037  case VolumeCubicFeet:
2038  return 0.000578703;
2039  case VolumeCubicYards:
2040  return 0.000021433;
2041  case VolumeBarrel:
2042  return 0.000103072;
2043  case VolumeCubicDecimeter:
2044  case VolumeLiters:
2045  return 0.016387060;
2046  case VolumeGallonUS:
2047  return 0.004329003;
2048  case VolumeCubicInch:
2049  return 1.0;
2050  case VolumeCubicCentimeter:
2051  return 16.387060000;
2052  case VolumeCubicDegrees:
2053  return 0.000016387 / DEG2_TO_M3; // basically meaningless!
2054  case VolumeUnknownUnit:
2055  return 1.0;
2056  }
2057  break;
2058  }
2059  case VolumeCubicCentimeter:
2060  {
2061  switch ( toUnit )
2062  {
2063  case VolumeCubicMeters:
2064  return 0.000001;
2065  case VolumeCubicFeet:
2066  return 0.000035315;
2067  case VolumeCubicYards:
2068  return 0.000001308;
2069  case VolumeBarrel:
2070  return 0.000006290;
2071  case VolumeCubicDecimeter:
2072  case VolumeLiters:
2073  return 0.001;
2074  case VolumeGallonUS:
2075  return 0.000264172 ;
2076  case VolumeCubicInch:
2077  return 0.061023759;
2078  case VolumeCubicCentimeter:
2079  return 1.0;
2080  case VolumeCubicDegrees:
2081  return 0.000001 / DEG2_TO_M3; // basically meaningless!
2082  case VolumeUnknownUnit:
2083  return 1.0;
2084  }
2085  break;
2086  }
2087  case VolumeCubicDegrees:
2088  if ( toUnit == VolumeUnknownUnit || toUnit == VolumeCubicDegrees )
2089  return 1.0;
2090  else
2092 
2093  case VolumeUnknownUnit:
2094  {
2095  return 1.0;
2096  }
2097  }
2098  return 1.0;
2099 }
2100 
2102 {
2103  switch ( distanceUnit )
2104  {
2105  case DistanceMeters:
2106  return VolumeCubicMeters;
2107 
2108  case DistanceKilometers:
2109  return VolumeCubicMeters;
2110 
2111  case DistanceCentimeters:
2112  return VolumeCubicCentimeter;
2113 
2114  case DistanceMillimeters:
2115  return VolumeCubicCentimeter;
2116 
2117  case DistanceFeet:
2118  return VolumeCubicFeet;
2119 
2120  case DistanceYards:
2121  return VolumeCubicYards;
2122 
2123  case DistanceMiles:
2124  return VolumeCubicFeet;
2125 
2126  case DistanceDegrees:
2127  return VolumeCubicDegrees;
2128 
2129  case DistanceUnknownUnit:
2130  return VolumeUnknownUnit;
2131 
2132  case DistanceNauticalMiles:
2133  return VolumeCubicFeet;
2134  }
2135 
2136  return VolumeUnknownUnit;
2137 }
2138 
2140 {
2141  switch ( volumeUnit )
2142  {
2143  case VolumeCubicMeters:
2144  return DistanceMeters;
2145  case VolumeCubicFeet:
2146  return DistanceFeet;
2147  case VolumeCubicYards:
2148  return DistanceYards;
2149  case VolumeBarrel:
2150  return DistanceFeet;
2151  case VolumeCubicDecimeter:
2152  return DistanceCentimeters;
2153  case VolumeLiters:
2154  return DistanceMeters;
2155  case VolumeGallonUS:
2156  return DistanceFeet;
2157  case VolumeCubicInch:
2158  return DistanceFeet;
2159  case VolumeCubicCentimeter:
2160  return DistanceCentimeters;
2161  case VolumeCubicDegrees:
2162  return DistanceDegrees;
2163  case VolumeUnknownUnit:
2164  return DistanceUnknownUnit;
2165  }
2166  return DistanceUnknownUnit;
2167 }
2168 
2170 {
2171  switch ( unit )
2172  {
2173  case VolumeCubicMeters:
2174  case VolumeCubicFeet:
2175  case VolumeCubicYards:
2176  case VolumeBarrel:
2177  case VolumeCubicDecimeter:
2178  case VolumeLiters:
2179  case VolumeGallonUS:
2180  case VolumeCubicInch:
2181  case VolumeCubicCentimeter:
2182  return Standard;
2183  case VolumeCubicDegrees:
2184  return Geographic;
2185  case VolumeUnknownUnit:
2186  return UnknownType;
2187  }
2188  return UnknownType;
2189 }
2190 
2192 {
2193  switch ( unit )
2194  {
2195  case VolumeCubicMeters:
2196  return QStringLiteral( "m3" );
2197  case VolumeCubicFeet:
2198  return QStringLiteral( "ft3" );
2199  case VolumeCubicYards:
2200  return QStringLiteral( "yd3" );
2201  case VolumeBarrel:
2202  return QStringLiteral( "bbl" );
2203  case VolumeCubicDecimeter:
2204  return QStringLiteral( "dm3" );
2205  case VolumeLiters:
2206  return QStringLiteral( "l" );
2207  case VolumeGallonUS:
2208  return QStringLiteral( "gal" );
2209  case VolumeCubicInch:
2210  return QStringLiteral( "in3" );
2211  case VolumeCubicCentimeter:
2212  return QStringLiteral( "cm3" );
2213  case VolumeCubicDegrees:
2214  return QStringLiteral( "deg3" );
2215  case VolumeUnknownUnit:
2216  return QStringLiteral( "<unknown>" );
2217  }
2218  return QString();
2219 }
2220 
2222 {
2223  switch ( unit )
2224  {
2225  case AngleDegrees:
2226  return QStringLiteral( "degrees" );
2227  case AngleRadians:
2228  return QStringLiteral( "radians" );
2229  case AngleGon:
2230  return QStringLiteral( "gon" );
2231  case AngleMinutesOfArc:
2232  return QStringLiteral( "moa" );
2233  case AngleSecondsOfArc:
2234  return QStringLiteral( "soa" );
2235  case AngleTurn:
2236  return QStringLiteral( "tr" );
2237  case AngleMilliradiansSI:
2238  return QStringLiteral( "milliradians" );
2239  case AngleMilNATO:
2240  return QStringLiteral( "mil" );
2241  case AngleUnknownUnit:
2242  return QStringLiteral( "<unknown>" );
2243  }
2244  return QString();
2245 }
2246 
2247 QgsUnitTypes::AngleUnit QgsUnitTypes::decodeAngleUnit( const QString &string, bool *ok )
2248 {
2249  QString normalized = string.trimmed().toLower();
2250 
2251  if ( ok )
2252  *ok = true;
2253 
2254  if ( normalized == encodeUnit( AngleDegrees ) )
2255  return AngleDegrees;
2256  if ( normalized == encodeUnit( AngleRadians ) )
2257  return AngleRadians;
2258  if ( normalized == encodeUnit( AngleGon ) )
2259  return AngleGon;
2260  if ( normalized == encodeUnit( AngleMinutesOfArc ) )
2261  return AngleMinutesOfArc;
2262  if ( normalized == encodeUnit( AngleSecondsOfArc ) )
2263  return AngleSecondsOfArc;
2264  if ( normalized == encodeUnit( AngleTurn ) )
2265  return AngleTurn;
2266  if ( normalized == encodeUnit( AngleMilliradiansSI ) )
2267  return AngleMilliradiansSI;
2268  if ( normalized == encodeUnit( AngleMilNATO ) )
2269  return AngleMilNATO;
2270  if ( normalized == encodeUnit( AngleUnknownUnit ) )
2271  return AngleUnknownUnit;
2272  if ( ok )
2273  *ok = false;
2274 
2275  return AngleUnknownUnit;
2276 }
2277 
2279 {
2280  switch ( unit )
2281  {
2282  case AngleDegrees:
2283  return QObject::tr( "degrees", "angle" );
2284  case AngleRadians:
2285  return QObject::tr( "radians", "angle" );
2286  case AngleGon:
2287  return QObject::tr( "gon", "angle" );
2288  case AngleMinutesOfArc:
2289  return QObject::tr( "minutes of arc", "angle" );
2290  case AngleSecondsOfArc:
2291  return QObject::tr( "seconds of arc", "angle" );
2292  case AngleTurn:
2293  return QObject::tr( "turns", "angle" );
2294  case AngleMilliradiansSI:
2295  return QObject::tr( "milliradians", "angle" );
2296  case AngleMilNATO:
2297  return QObject::tr( "mil", "angle" );
2298  case AngleUnknownUnit:
2299  return QObject::tr( "<unknown>", "angle" );
2300  }
2301  return QString();
2302 }
2303 
2305 {
2306  // Calculate the conversion factor between the specified units
2307  switch ( fromUnit )
2308  {
2309  case AngleDegrees:
2310  {
2311  switch ( toUnit )
2312  {
2313  case AngleDegrees:
2314  return 1.0;
2315  case AngleRadians:
2316  return M_PI / 180.0;
2317  case AngleGon:
2318  return 400.0 / 360.0;
2319  case AngleMinutesOfArc:
2320  return 60;
2321  case AngleSecondsOfArc:
2322  return 3600;
2323  case AngleTurn:
2324  return 1.0 / 360.0;
2325  case AngleMilliradiansSI:
2326  return M_PI / 180.0 * 1000;
2327  case AngleMilNATO:
2328  return 3200.0 / 180;
2329  case AngleUnknownUnit:
2330  break;
2331  }
2332  break;
2333  }
2334  case AngleRadians:
2335  {
2336  switch ( toUnit )
2337  {
2338  case AngleDegrees:
2339  return 180.0 / M_PI;
2340  case AngleRadians:
2341  return 1.0;
2342  case AngleGon:
2343  return 200.0 / M_PI;
2344  case AngleMinutesOfArc:
2345  return 60 * 180.0 / M_PI;
2346  case AngleSecondsOfArc:
2347  return 3600 * 180.0 / M_PI;
2348  case AngleTurn:
2349  return 0.5 / M_PI;
2350  case AngleMilliradiansSI:
2351  return 1000;
2352  case AngleMilNATO:
2353  return 3200.0 / M_PI;
2354  case AngleUnknownUnit:
2355  break;
2356  }
2357  break;
2358  }
2359  case AngleGon:
2360  {
2361  switch ( toUnit )
2362  {
2363  case AngleDegrees:
2364  return 360.0 / 400.0;
2365  case AngleRadians:
2366  return M_PI / 200.0;
2367  case AngleGon:
2368  return 1.0;
2369  case AngleMinutesOfArc:
2370  return 60 * 360.0 / 400.0;
2371  case AngleSecondsOfArc:
2372  return 3600 * 360.0 / 400.0;
2373  case AngleTurn:
2374  return 1.0 / 400.0;
2375  case AngleMilliradiansSI:
2376  return M_PI / 200.0 * 1000;
2377  case AngleMilNATO:
2378  return 3200.0 / 200.0;
2379  case AngleUnknownUnit:
2380  break;
2381  }
2382  break;
2383  }
2384  case AngleMinutesOfArc:
2385  {
2386  switch ( toUnit )
2387  {
2388  case AngleDegrees:
2389  return 1 / 60.0;
2390  case AngleRadians:
2391  return M_PI / 180.0 / 60.0;
2392  case AngleGon:
2393  return 400.0 / 360.0 / 60.0;
2394  case AngleMinutesOfArc:
2395  return 1.0;
2396  case AngleSecondsOfArc:
2397  return 60.0;
2398  case AngleTurn:
2399  return 1.0 / 360.0 / 60.0;
2400  case AngleMilliradiansSI:
2401  return M_PI / 180.0 / 60.0 * 1000;
2402  case AngleMilNATO:
2403  return 3200.0 / 180.0 / 60.0;
2404  case AngleUnknownUnit:
2405  break;
2406  }
2407  break;
2408  }
2409  case AngleSecondsOfArc:
2410  {
2411  switch ( toUnit )
2412  {
2413  case AngleDegrees:
2414  return 1 / 3600.0;
2415  case AngleRadians:
2416  return M_PI / 180.0 / 3600.0;
2417  case AngleGon:
2418  return 400.0 / 360.0 / 3600.0;
2419  case AngleMinutesOfArc:
2420  return 1.0 / 60.0;
2421  case AngleSecondsOfArc:
2422  return 1.0;
2423  case AngleTurn:
2424  return 1.0 / 360.0 / 3600.0;
2425  case AngleMilliradiansSI:
2426  return M_PI / 180.0 / 3600.0 * 1000;
2427  case AngleMilNATO:
2428  return 3200.0 / 180.0 / 3600.0;
2429  case AngleUnknownUnit:
2430  break;
2431  }
2432  break;
2433  }
2434  case AngleTurn:
2435  {
2436  switch ( toUnit )
2437  {
2438  case AngleDegrees:
2439  return 360.0;
2440  case AngleRadians:
2441  return 2 * M_PI;
2442  case AngleGon:
2443  return 400.0;
2444  case AngleMinutesOfArc:
2445  return 360.0 * 60.0;
2446  case AngleSecondsOfArc:
2447  return 360.0 * 3600.0;
2448  case AngleTurn:
2449  return 1.0;
2450  case AngleMilliradiansSI:
2451  return 2 * M_PI * 1000;
2452  case AngleMilNATO:
2453  return 2 * 3200;
2454  case AngleUnknownUnit:
2455  break;
2456  }
2457  break;
2458  }
2459  case AngleMilliradiansSI:
2460  {
2461  switch ( toUnit )
2462  {
2463  case AngleDegrees:
2464  return 180.0 / M_PI / 1000;
2465  case AngleRadians:
2466  return 0.001;
2467  case AngleGon:
2468  return 200.0 / M_PI / 1000;
2469  case AngleMinutesOfArc:
2470  return 180.0 * 60.0 / M_PI / 1000;
2471  case AngleSecondsOfArc:
2472  return 180.0 * 3600.0 / M_PI / 1000;
2473  case AngleTurn:
2474  return M_PI / 2 / 1000;
2475  case AngleMilliradiansSI:
2476  return 1.0;
2477  case AngleMilNATO:
2478  return 3200.0 / 1000.0 / M_PI;
2479  case AngleUnknownUnit:
2480  break;
2481  }
2482  break;
2483  }
2484 
2485  case AngleMilNATO:
2486  {
2487  switch ( toUnit )
2488  {
2489  case AngleDegrees:
2490  return 180.0 / 3200;
2491  case AngleRadians:
2492  return M_PI / 3200;
2493  case AngleGon:
2494  return 200.0 / 3200;
2495  case AngleMinutesOfArc:
2496  return 60 * 180.0 / 3200;
2497  case AngleSecondsOfArc:
2498  return 3600.0 * 180 / 3200;
2499  case AngleTurn:
2500  return 1.0 / ( 2 * 32000 );
2501  case AngleMilliradiansSI:
2502  return 1000.0 * M_PI / 3200.0;
2503  case AngleMilNATO:
2504  return 1.0;
2505  case AngleUnknownUnit:
2506  break;
2507  }
2508  break;
2509  }
2510 
2511  case AngleUnknownUnit:
2512  break;
2513  }
2514  return 1.0;
2515 }
2516 
2517 QString QgsUnitTypes::formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit )
2518 {
2519  QString unitLabel;
2520 
2521  switch ( unit )
2522  {
2523  case AngleDegrees:
2524  unitLabel = QObject::tr( "°", "angle" );
2525  break;
2526  case AngleRadians:
2527  unitLabel = QObject::tr( " rad", "angle" );
2528  break;
2529  case AngleGon:
2530  unitLabel = QObject::tr( " gon", "angle" );
2531  break;
2532  case AngleMinutesOfArc:
2533  unitLabel = QObject::tr( "′", "angle minutes" );
2534  break;
2535  case AngleSecondsOfArc:
2536  unitLabel = QObject::tr( "″", "angle seconds" );
2537  break;
2538  case AngleTurn:
2539  unitLabel = QObject::tr( " tr", "angle turn" );
2540  break;
2541  case AngleMilliradiansSI:
2542  unitLabel = QObject::tr( " millirad", "angular mil SI" );
2543  break;
2544  case AngleMilNATO:
2545  unitLabel = QObject::tr( " mil", "angular mil NATO" );
2546  break;
2547  case AngleUnknownUnit:
2548  break;
2549  }
2550 
2551  return QStringLiteral( "%L1%2" ).arg( angle, 0, 'f', decimals ).arg( unitLabel );
2552 }
2553 
2554 
2555 QgsUnitTypes::DistanceValue QgsUnitTypes::scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit )
2556 {
2557  DistanceValue result;
2558 
2559  switch ( unit )
2560  {
2561  case DistanceMeters:
2562  if ( keepBaseUnit )
2563  {
2564  result.value = qgsRound( distance, decimals );
2566  }
2567  else if ( std::fabs( distance ) > 1000.0 )
2568  {
2569  result.value = qgsRound( distance / 1000, decimals );
2571  }
2572  else if ( std::fabs( distance ) < 0.01 )
2573  {
2574  result.value = qgsRound( distance * 1000, decimals );
2576  }
2577  else if ( std::fabs( distance ) < 0.1 )
2578  {
2579 
2580  result.value = qgsRound( distance * 100, decimals );
2582  }
2583  else
2584  {
2585  result.value = qgsRound( distance, decimals );
2587  }
2588  break;
2589 
2590  case DistanceKilometers:
2591  if ( keepBaseUnit || std::fabs( distance ) >= 1.0 )
2592  {
2593  result.value = qgsRound( distance, decimals );
2595  }
2596  else
2597  {
2598  result.value = qgsRound( distance * 1000, decimals );
2600  }
2601  break;
2602 
2603  case DistanceFeet:
2604  if ( std::fabs( distance ) <= 5280.0 || keepBaseUnit )
2605  {
2606  result.value = qgsRound( distance, decimals );
2608  }
2609  else
2610  {
2611  result.value = qgsRound( distance / 5280.0, decimals );
2613  }
2614  break;
2615 
2616  case DistanceYards:
2617  if ( std::fabs( distance ) <= 1760.0 || keepBaseUnit )
2618  {
2619  result.value = qgsRound( distance, decimals );
2621  }
2622  else
2623  {
2624  result.value = qgsRound( distance / 1760.0, decimals );
2626  }
2627  break;
2628 
2629  case DistanceMiles:
2630  if ( std::fabs( distance ) >= 1.0 || keepBaseUnit )
2631  {
2632  result.value = qgsRound( distance, decimals );
2634  }
2635  else
2636  {
2637  result.value = qgsRound( distance * 5280.0, decimals );
2639  }
2640  break;
2641 
2642  case DistanceNauticalMiles:
2643  result.value = qgsRound( distance, decimals );
2645  break;
2646 
2647  case DistanceDegrees:
2648  result.value = qgsRound( distance, decimals );
2650  break;
2651 
2652  case DistanceUnknownUnit:
2653  result.value = qgsRound( distance, decimals );
2655  break;
2656 
2657  default:
2658  result.value = qgsRound( distance, decimals );
2659  result.unit = unit;
2660  break;
2661  }
2662 
2663  return result;
2664 }
2665 
2666 QgsUnitTypes::AreaValue QgsUnitTypes::scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit )
2667 {
2668  AreaValue result;
2669  result.value = -1.0;
2670  result.unit = AreaUnknownUnit;
2671 
2672  // If we are not forced to keep the base units, switch to meter calculation
2673  if ( unit == AreaSquareMillimeters )
2674  {
2675  if ( keepBaseUnit )
2676  {
2677  result.value = qgsRound( area, decimals );
2679  }
2680  else
2681  {
2682  area /= 1000000.0;
2684  }
2685  }
2686  else if ( unit == AreaSquareCentimeters )
2687  {
2688  if ( keepBaseUnit )
2689  {
2690  result.value = qgsRound( area, decimals );
2692  }
2693  else
2694  {
2695  area /= 10000.0;
2697  }
2698  }
2699 
2700  switch ( unit )
2701  {
2702  case AreaSquareCentimeters:
2703  // handled in the if above
2704  break;
2705  case AreaSquareMillimeters:
2706  // handled in the if above
2707  break;
2708  case AreaSquareMeters:
2709  {
2710  if ( keepBaseUnit )
2711  {
2712  result.value = qgsRound( area, decimals );
2714  }
2716  {
2719  }
2721  {
2724  }
2725  else
2726  {
2727  result.value = qgsRound( area, decimals );
2729  }
2730  break;
2731  }
2732 
2733  case AreaSquareKilometers:
2734  {
2735  result.value = qgsRound( area, decimals );
2737  break;
2738  }
2739 
2740  case AreaSquareFeet:
2741  {
2742  if ( keepBaseUnit )
2743  {
2744  result.value = qgsRound( area, decimals );
2746  }
2748  {
2751  }
2752  else
2753  {
2754  result.value = qgsRound( area, decimals );
2756  }
2757  break;
2758  }
2759 
2760  case AreaSquareYards:
2761  {
2762  if ( keepBaseUnit )
2763  {
2764  result.value = qgsRound( area, decimals );
2766  }
2768  {
2771  }
2772  else
2773  {
2774  result.value = qgsRound( area, decimals );
2776  }
2777  break;
2778  }
2779 
2780  case AreaSquareMiles:
2781  {
2782  result.value = qgsRound( area, decimals );
2784  break;
2785  }
2786 
2787  case AreaHectares:
2788  {
2789  if ( keepBaseUnit )
2790  {
2791  result.value = qgsRound( area, decimals );
2793  }
2795  {
2798  }
2799  else
2800  {
2801  result.value = qgsRound( area, decimals );
2803  }
2804  break;
2805  }
2806 
2807  case AreaAcres:
2808  {
2809  if ( keepBaseUnit )
2810  {
2811  result.value = qgsRound( area, decimals );
2812  result.unit = QgsUnitTypes::AreaAcres;
2813  }
2815  {
2818  }
2819  else
2820  {
2821  result.value = qgsRound( area, decimals );
2822  result.unit = QgsUnitTypes::AreaAcres;
2823  }
2824  break;
2825  }
2826 
2828  {
2829  result.value = qgsRound( area, decimals );
2831  break;
2832  }
2833 
2834  case AreaSquareDegrees:
2835  {
2836  result.value = qgsRound( area, decimals );
2838  break;
2839  }
2840 
2841  case AreaUnknownUnit:
2842  {
2843  result.value = qgsRound( area, decimals );
2845  break;
2846  }
2847  }
2848  return result;
2849 }
2850 
2851 
2852 QString QgsUnitTypes::formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit )
2853 {
2854  DistanceValue dist = scaledDistance( distance, unit, decimals, keepBaseUnit );
2855 
2856  QString unitText;
2857 
2858  if ( dist.unit != DistanceUnknownUnit )
2859  unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( dist.unit );
2860 
2861  return QStringLiteral( "%L1%2" ).arg( dist.value, 0, 'f', decimals ).arg( unitText );
2862 }
2863 
2864 QString QgsUnitTypes::formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit )
2865 {
2866  AreaValue areaValue = scaledArea( area, unit, decimals, keepBaseUnit );
2867 
2868  QString unitText;
2869 
2870  if ( areaValue.unit != AreaUnknownUnit )
2871  unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( areaValue.unit );
2872 
2873  return QStringLiteral( "%L1%2" ).arg( areaValue.value, 0, 'f', decimals ).arg( unitText );
2874 }
2875 
2877 {
2878  switch ( unit )
2879  {
2880  case RenderMillimeters:
2881  return QStringLiteral( "MM" );
2883  return QStringLiteral( "RenderMetersInMapUnits" );
2884  case RenderMapUnits:
2885  return QStringLiteral( "MapUnit" );
2886  case RenderPixels:
2887  return QStringLiteral( "Pixel" );
2888  case RenderPercentage:
2889  return QStringLiteral( "Percentage" );
2890  case RenderPoints:
2891  return QStringLiteral( "Point" );
2892  case RenderInches:
2893  return QStringLiteral( "Inch" );
2894  case RenderUnknownUnit:
2895  return QString();
2896  }
2897  return QString();
2898 }
2899 
2901 {
2902  QString normalized = string.trimmed().toLower();
2903 
2904  if ( ok )
2905  *ok = true;
2906 
2907  if ( normalized == encodeUnit( RenderMillimeters ).toLower() )
2908  return RenderMillimeters;
2909  if ( normalized == encodeUnit( RenderMetersInMapUnits ).toLower() )
2910  return RenderMetersInMapUnits;
2911  if ( normalized == QLatin1String( "meters" ) )
2912  return RenderMetersInMapUnits;
2913  if ( normalized == encodeUnit( RenderMapUnits ).toLower() )
2914  return RenderMapUnits;
2915  if ( normalized == QLatin1String( "mapunits" ) )
2916  return RenderMapUnits;
2917  if ( normalized == encodeUnit( RenderPixels ).toLower() )
2918  return RenderPixels;
2919  if ( normalized == encodeUnit( RenderPercentage ).toLower() )
2920  return RenderPercentage;
2921  if ( normalized == QLatin1String( "percent" ) )
2922  return RenderPercentage;
2923  if ( normalized == encodeUnit( RenderPoints ).toLower() )
2924  return RenderPoints;
2925  if ( normalized == QLatin1String( "points" ) )
2926  return RenderPoints;
2927  if ( normalized == encodeUnit( RenderInches ).toLower() )
2928  return RenderInches;
2929 
2930  if ( ok )
2931  *ok = false;
2932 
2933  // millimeters are default
2934  return RenderMillimeters;
2935 }
2936 
2938 {
2939  switch ( unit )
2940  {
2941  case RenderMillimeters:
2942  return QObject::tr( "millimeters", "render" );
2943 
2945  return QObject::tr( "meters at scale", "render" );
2946 
2947  case RenderMapUnits:
2948  return QObject::tr( "map units", "render" );
2949 
2950  case RenderPixels:
2951  return QObject::tr( "pixels", "render" );
2952 
2953  case RenderPercentage:
2954  return QObject::tr( "percent", "render" );
2955 
2956  case RenderPoints:
2957  return QObject::tr( "points", "render" );
2958 
2959  case RenderInches:
2960  return QObject::tr( "inches", "render" );
2961 
2962  case RenderUnknownUnit:
2963  return QObject::tr( "<unknown>", "render" );
2964 
2965  }
2966  return QString();
2967 }
2968 
2969 
2970 
2972 {
2973  switch ( unit )
2974  {
2975  case LayoutCentimeters:
2976  return QStringLiteral( "cm" );
2977  case LayoutMeters:
2978  return QStringLiteral( "m" );
2979  case LayoutInches:
2980  return QStringLiteral( "in" );
2981  case LayoutFeet:
2982  return QStringLiteral( "ft" );
2983  case LayoutPoints:
2984  return QStringLiteral( "pt" );
2985  case LayoutPicas:
2986  return QStringLiteral( "pi" );
2987  case LayoutPixels:
2988  return QStringLiteral( "px" );
2989  case LayoutMillimeters:
2990  return QStringLiteral( "mm" );
2991  }
2992  return QString();
2993 }
2994 
2996 {
2997  QString normalized = string.trimmed().toLower();
2998 
2999  if ( ok )
3000  *ok = true;
3001 
3002  if ( normalized == encodeUnit( LayoutMillimeters ).toLower() )
3003  return LayoutMillimeters;
3004  if ( normalized == encodeUnit( LayoutCentimeters ).toLower() )
3005  return LayoutCentimeters;
3006  if ( normalized == encodeUnit( LayoutMeters ).toLower() )
3007  return LayoutMeters;
3008  if ( normalized == encodeUnit( LayoutInches ).toLower() )
3009  return LayoutInches;
3010  if ( normalized == encodeUnit( LayoutFeet ).toLower() )
3011  return LayoutFeet;
3012  if ( normalized == encodeUnit( LayoutPoints ).toLower() )
3013  return LayoutPoints;
3014  if ( normalized == encodeUnit( LayoutPicas ).toLower() )
3015  return LayoutPicas;
3016  if ( normalized == encodeUnit( LayoutPixels ).toLower() )
3017  return LayoutPixels;
3018 
3019  if ( ok )
3020  *ok = false;
3021 
3022  // millimeters are default
3023  return LayoutMillimeters;
3024 }
3025 
3027 {
3028  switch ( units )
3029  {
3030  case LayoutPixels:
3031  return LayoutScreenUnits;
3032  case LayoutMillimeters:
3033  case LayoutCentimeters:
3034  case LayoutMeters:
3035  case LayoutInches:
3036  case LayoutFeet:
3037  case LayoutPoints:
3038  case LayoutPicas:
3039  return LayoutPaperUnits;
3040  }
3041 
3042  // avoid warnings
3043  return LayoutPaperUnits;
3044 }
3045 
3047 {
3048  switch ( unit )
3049  {
3050  case LayoutPixels:
3051  return QObject::tr( "px" );
3052  case LayoutMillimeters:
3053  return QObject::tr( "mm" );
3054  case LayoutCentimeters:
3055  return QObject::tr( "cm" );
3056  case LayoutMeters:
3057  return QObject::tr( "m" );
3058  case LayoutInches:
3059  return QObject::tr( "in", "unit inch" );
3060  case LayoutFeet:
3061  return QObject::tr( "ft" );
3062  case LayoutPoints:
3063  return QObject::tr( "pt" );
3064  case LayoutPicas:
3065  return QObject::tr( "pica" );
3066  }
3067  return QString(); // no warnings
3068 }
3069 
3071 {
3072  switch ( unit )
3073  {
3074  case LayoutPixels:
3075  return QObject::tr( "pixels" );
3076  case LayoutMillimeters:
3077  return QObject::tr( "millimeters" );
3078  case LayoutCentimeters:
3079  return QObject::tr( "centimeters" );
3080  case LayoutMeters:
3081  return QObject::tr( "meters" );
3082  case LayoutInches:
3083  return QObject::tr( "inches" );
3084  case LayoutFeet:
3085  return QObject::tr( "feet" );
3086  case LayoutPoints:
3087  return QObject::tr( "points" );
3088  case LayoutPicas:
3089  return QObject::tr( "picas" );
3090  }
3091  return QString(); // no warnings
3092 }
static Q_INVOKABLE QgsUnitTypes::VolumeUnit decodeVolumeUnit(const QString &string, bool *ok=nullptr)
Decodes a volume unit from a string.
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:68
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
LayoutUnit
Layout measurement units.
Definition: qgsunittypes.h:181
@ LayoutInches
Inches.
Definition: qgsunittypes.h:185
@ LayoutMillimeters
Millimeters.
Definition: qgsunittypes.h:182
@ LayoutFeet
Feet.
Definition: qgsunittypes.h:186
@ LayoutCentimeters
Centimeters.
Definition: qgsunittypes.h:183
@ LayoutPixels
Pixels.
Definition: qgsunittypes.h:189
@ LayoutPicas
Typographic picas.
Definition: qgsunittypes.h:188
@ LayoutPoints
Typographic points.
Definition: qgsunittypes.h:187
@ LayoutMeters
Meters.
Definition: qgsunittypes.h:184
static Q_INVOKABLE QgsUnitTypes::TemporalUnit stringToTemporalUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to a temporal unit.
AngleUnit
Units of angles.
Definition: qgsunittypes.h:132
@ AngleGon
Gon/gradian.
Definition: qgsunittypes.h:135
@ AngleRadians
Square kilometers.
Definition: qgsunittypes.h:134
@ AngleDegrees
Degrees.
Definition: qgsunittypes.h:133
@ AngleMilNATO
Angular mil (NATO definition, 6400 mil = 2PI radians)
Definition: qgsunittypes.h:140
@ AngleMilliradiansSI
Angular milliradians (SI definition, 1/1000 of radian)
Definition: qgsunittypes.h:139
@ AngleTurn
Turn/revolutions.
Definition: qgsunittypes.h:138
@ AngleUnknownUnit
Unknown angle unit.
Definition: qgsunittypes.h:141
@ AngleMinutesOfArc
Minutes of arc.
Definition: qgsunittypes.h:136
@ AngleSecondsOfArc
Seconds of arc.
Definition: qgsunittypes.h:137
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QgsUnitTypes::AreaUnit distanceToAreaUnit(QgsUnitTypes::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding area unit, e.g., meters to square meters.
static Q_INVOKABLE QgsUnitTypes::VolumeUnit stringToVolumeUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to a volume unit.
static Q_INVOKABLE QgsUnitTypes::AngleUnit decodeAngleUnit(const QString &string, bool *ok=nullptr)
Decodes an angular unit from a string.
VolumeUnit
Units of volume.
Definition: qgsunittypes.h:115
@ VolumeBarrel
Barrels.
Definition: qgsunittypes.h:119
@ VolumeCubicYards
Cubic yards.
Definition: qgsunittypes.h:118
@ VolumeCubicMeters
Cubic meters.
Definition: qgsunittypes.h:116
@ VolumeCubicDecimeter
Cubic decimeters.
Definition: qgsunittypes.h:120
@ VolumeCubicCentimeter
Cubic Centimeters.
Definition: qgsunittypes.h:124
@ VolumeCubicDegrees
Cubic degrees, for planar geographic CRS volume measurements.
Definition: qgsunittypes.h:125
@ VolumeCubicFeet
Cubic feet.
Definition: qgsunittypes.h:117
@ VolumeLiters
Litres.
Definition: qgsunittypes.h:121
@ VolumeCubicInch
Cubic inches.
Definition: qgsunittypes.h:123
@ VolumeUnknownUnit
Unknown volume unit.
Definition: qgsunittypes.h:126
@ VolumeGallonUS
US Gallons.
Definition: qgsunittypes.h:122
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit areaToDistanceUnit(QgsUnitTypes::AreaUnit areaUnit)
Converts an area unit to its corresponding distance unit, e.g., square meters to meters.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit stringToDistanceUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to a distance unit.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE QgsUnitTypes::AreaUnit stringToAreaUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to an areal unit.
static Q_INVOKABLE QgsUnitTypes::DistanceUnit volumeToDistanceUnit(QgsUnitTypes::VolumeUnit volumeUnit)
Converts a volume unit to its corresponding distance unit, e.g., cubic meters to meters.
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static Q_INVOKABLE QgsUnitTypes::DistanceUnitType unitType(QgsUnitTypes::DistanceUnit unit)
Returns the type for a distance unit.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QgsUnitTypes::AreaValue scaledArea(double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit=false)
Will convert an area with a given unit to an area value which is nice to display.
static Q_INVOKABLE QString formatArea(double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string.
static Q_INVOKABLE QgsUnitTypes::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
static Q_INVOKABLE QgsUnitTypes::AreaUnit decodeAreaUnit(const QString &string, bool *ok=nullptr)
Decodes an areal unit from a string.
DistanceUnitType
Types of distance units.
Definition: qgsunittypes.h:86
@ Geographic
Unit is a geographic (e.g., degree based) unit.
Definition: qgsunittypes.h:88
@ Standard
Unit is a standard measurement unit.
Definition: qgsunittypes.h:87
@ UnknownType
Unknown unit type.
Definition: qgsunittypes.h:89
UnitType
Unit types.
Definition: qgsunittypes.h:58
@ TypeDistance
Distance unit.
Definition: qgsunittypes.h:59
@ TypeTemporal
Temporal unit.
Definition: qgsunittypes.h:63
@ TypeArea
Area unit.
Definition: qgsunittypes.h:60
@ TypeVolume
Volume unit.
Definition: qgsunittypes.h:61
@ TypeUnknown
Unknown unit type.
Definition: qgsunittypes.h:62
static Q_INVOKABLE QgsUnitTypes::DistanceValue scaledDistance(double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit=false)
Will convert a distance with a given unit to a distance value which is nice to display.
static Q_INVOKABLE QgsUnitTypes::VolumeUnit distanceToVolumeUnit(QgsUnitTypes::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding volume unit, e.g., meters to cubic meters.
AreaUnit
Units of area.
Definition: qgsunittypes.h:94
@ AreaSquareNauticalMiles
Square nautical miles.
Definition: qgsunittypes.h:102
@ AreaSquareYards
Square yards.
Definition: qgsunittypes.h:98
@ AreaSquareFeet
Square feet.
Definition: qgsunittypes.h:97
@ AreaHectares
Hectares.
Definition: qgsunittypes.h:100
@ AreaUnknownUnit
Unknown areal unit.
Definition: qgsunittypes.h:106
@ AreaSquareMeters
Square meters.
Definition: qgsunittypes.h:95
@ AreaSquareMiles
Square miles.
Definition: qgsunittypes.h:99
@ AreaSquareCentimeters
Square centimeters.
Definition: qgsunittypes.h:104
@ AreaSquareKilometers
Square kilometers.
Definition: qgsunittypes.h:96
@ AreaSquareDegrees
Square degrees, for planar geographic CRS area measurements.
Definition: qgsunittypes.h:103
@ AreaAcres
Acres.
Definition: qgsunittypes.h:101
@ AreaSquareMillimeters
Square millimeters.
Definition: qgsunittypes.h:105
TemporalUnit
Temporal units.
Definition: qgsunittypes.h:150
@ TemporalMonths
Months.
Definition: qgsunittypes.h:157
@ TemporalUnknownUnit
Unknown time unit.
Definition: qgsunittypes.h:161
@ TemporalWeeks
Weeks.
Definition: qgsunittypes.h:156
@ TemporalMilliseconds
Milliseconds.
Definition: qgsunittypes.h:151
@ TemporalDays
Days.
Definition: qgsunittypes.h:155
@ TemporalDecades
Decades.
Definition: qgsunittypes.h:159
@ TemporalCenturies
Centuries.
Definition: qgsunittypes.h:160
@ TemporalSeconds
Seconds.
Definition: qgsunittypes.h:152
@ TemporalMinutes
Minutes.
Definition: qgsunittypes.h:153
@ TemporalYears
Years.
Definition: qgsunittypes.h:158
@ TemporalHours
Hours.
Definition: qgsunittypes.h:154
static Q_INVOKABLE QgsUnitTypes::TemporalUnit decodeTemporalUnit(const QString &string, bool *ok=nullptr)
Decodes a temporal unit from a string.
static Q_INVOKABLE QString formatDistance(double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit=false)
Returns an distance formatted as a friendly string.
static Q_INVOKABLE QgsUnitTypes::UnitType decodeUnitType(const QString &string, bool *ok=nullptr)
Decodes a unit type from a string.
static Q_INVOKABLE QString encodeUnitType(QgsUnitTypes::UnitType type)
Encodes a unit type to a string.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:174
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:175
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:171
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
@ RenderInches
Inches.
Definition: qgsunittypes.h:173
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
static Q_INVOKABLE QString formatAngle(double angle, int decimals, QgsUnitTypes::AngleUnit unit)
Returns an angle formatted as a friendly string.
LayoutUnitType
Types of layout units.
Definition: qgsunittypes.h:195
@ LayoutScreenUnits
Unit is a screen based measurement unit.
Definition: qgsunittypes.h:197
@ LayoutPaperUnits
Unit is a paper based measurement unit.
Definition: qgsunittypes.h:196
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
Definition: qgis.h:364
#define DEGREE_TO_METER
#define MILLIMETERS_TO_METER
#define KM2_TO_M2
#define CENTIMETERS_TO_METER
#define DEG2_TO_M3
#define MI2_TO_M2
#define AC_TO_FT2
#define NMILE_TO_METER
#define KILOMETERS_TO_METER
#define YARDS_TO_FEET
#define FEET_TO_METER
#define YD2_TO_M2
#define NM2_TO_M2
#define MM2_TO_M2
#define DEG2_TO_M2
#define CM2_TO_M2
#define FT2_TO_M2
#define MILES_TO_METER
#define YARDS_TO_METER
#define HA_TO_M2
A combination of area value and unit.
Definition: qgsunittypes.h:225
double value
The value part of the distance.
Definition: qgsunittypes.h:230
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:235
A combination of distance value and unit.
Definition: qgsunittypes.h:206
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:216
double value
The value part of the distance.
Definition: qgsunittypes.h:211