QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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  const 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  const 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  const 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  const 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  const 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 TemporalIrregularStep:
1279  return QStringLiteral( "xxx" );
1280  case TemporalUnknownUnit:
1281  return QStringLiteral( "<unknown>" );
1282  }
1283  return QString();
1284 }
1285 
1287 {
1288  const QString normalized = string.trimmed().toLower();
1289 
1290  if ( ok )
1291  *ok = true;
1292 
1293  if ( normalized == encodeUnit( TemporalSeconds ) )
1294  return TemporalSeconds;
1295  if ( normalized == encodeUnit( TemporalMilliseconds ) )
1296  return TemporalMilliseconds;
1297  if ( normalized == encodeUnit( TemporalMinutes ) )
1298  return TemporalMinutes;
1299  if ( normalized == encodeUnit( TemporalHours ) )
1300  return TemporalHours;
1301  if ( normalized == encodeUnit( TemporalDays ) )
1302  return TemporalDays;
1303  if ( normalized == encodeUnit( TemporalWeeks ) )
1304  return TemporalWeeks;
1305  if ( normalized == encodeUnit( TemporalMonths ) )
1306  return TemporalMonths;
1307  if ( normalized == encodeUnit( TemporalYears ) )
1308  return TemporalYears;
1309  if ( normalized == encodeUnit( TemporalDecades ) )
1310  return TemporalDecades;
1311  if ( normalized == encodeUnit( TemporalCenturies ) )
1312  return TemporalCenturies;
1313  if ( normalized == encodeUnit( TemporalIrregularStep ) )
1314  return TemporalIrregularStep;
1315  if ( normalized == encodeUnit( TemporalUnknownUnit ) )
1316  return TemporalUnknownUnit;
1317 
1318  if ( ok )
1319  *ok = false;
1320 
1321  return TemporalUnknownUnit;
1322 }
1323 
1325 {
1326  switch ( unit )
1327  {
1328  case TemporalSeconds:
1329  return QObject::tr( "seconds", "temporal" );
1330  case TemporalMilliseconds:
1331  return QObject::tr( "milliseconds", "temporal" );
1332  case TemporalMinutes:
1333  return QObject::tr( "minutes", "temporal" );
1334  case TemporalHours:
1335  return QObject::tr( "hours", "temporal" );
1336  case TemporalDays:
1337  return QObject::tr( "days", "temporal" );
1338  case TemporalWeeks:
1339  return QObject::tr( "weeks", "temporal" );
1340  case TemporalMonths:
1341  return QObject::tr( "months", "temporal" );
1342  case TemporalYears:
1343  return QObject::tr( "years", "temporal" );
1344  case TemporalDecades:
1345  return QObject::tr( "decades", "temporal" );
1346  case TemporalCenturies:
1347  return QObject::tr( "centuries", "temporal" );
1348  case TemporalIrregularStep:
1349  return QObject::tr( "steps", "temporal" );
1350  case TemporalUnknownUnit:
1351  return QObject::tr( "<unknown>", "temporal" );
1352  }
1353  return QString();
1354 }
1355 
1357 {
1358  switch ( unit )
1359  {
1360  case TemporalSeconds:
1361  return QObject::tr( "s", "temporal" );
1362  case TemporalMilliseconds:
1363  return QObject::tr( "ms", "temporal" );
1364  case TemporalMinutes:
1365  return QObject::tr( "min", "temporal" );
1366  case TemporalHours:
1367  return QObject::tr( "h", "temporal" );
1368  case TemporalDays:
1369  return QObject::tr( "d", "temporal" );
1370  case TemporalWeeks:
1371  return QObject::tr( "wk", "temporal" );
1372  case TemporalMonths:
1373  return QObject::tr( "mon", "temporal" );
1374  case TemporalYears:
1375  return QObject::tr( "y", "temporal" );
1376  case TemporalDecades:
1377  return QObject::tr( "dec", "temporal" );
1378  case TemporalCenturies:
1379  return QObject::tr( "cen", "temporal" );
1380  case TemporalIrregularStep:
1381  return QObject::tr( "steps", "temporal" );
1382  case TemporalUnknownUnit:
1383  return QObject::tr( "<unknown>", "temporal" );
1384  }
1385  return QString();
1386 }
1387 
1389 {
1390  const QString normalized = string.trimmed().toLower();
1391 
1392  if ( ok )
1393  *ok = true;
1394 
1395  if ( normalized == toString( TemporalSeconds ) )
1396  return TemporalSeconds;
1397  if ( normalized == toString( TemporalMilliseconds ) )
1398  return TemporalMilliseconds;
1399  if ( normalized == toString( TemporalMinutes ) )
1400  return TemporalMinutes;
1401  if ( normalized == toString( TemporalHours ) )
1402  return TemporalHours;
1403  if ( normalized == toString( TemporalDays ) )
1404  return TemporalDays;
1405  if ( normalized == toString( TemporalWeeks ) )
1406  return TemporalWeeks;
1407  if ( normalized == toString( TemporalMonths ) )
1408  return TemporalMonths;
1409  if ( normalized == toString( TemporalYears ) )
1410  return TemporalYears;
1411  if ( normalized == toString( TemporalDecades ) )
1412  return TemporalDecades;
1413  if ( normalized == toString( TemporalCenturies ) )
1414  return TemporalCenturies;
1415  if ( normalized == toString( TemporalIrregularStep ) )
1416  return TemporalIrregularStep;
1417  if ( normalized == toString( TemporalUnknownUnit ) )
1418  return TemporalUnknownUnit;
1419 
1420  if ( ok )
1421  *ok = false;
1422 
1423  return TemporalUnknownUnit;
1424 }
1425 
1427 {
1428  switch ( fromUnit )
1429  {
1430  case TemporalSeconds:
1431  {
1432  switch ( toUnit )
1433  {
1434  case TemporalSeconds:
1435  return 1.0;
1436  case TemporalMilliseconds:
1437  return 1000.0;
1438  case TemporalMinutes:
1439  return 1 / 60.0;
1440  case TemporalHours:
1441  return 1 / 3600.0;
1442  case TemporalDays:
1443  return 1 / 86400.0;
1444  case TemporalWeeks:
1445  return 1 / 604800.0;
1446  case TemporalMonths:
1447  return 1 / 2592000.0;
1448  case TemporalYears:
1449  return 1 / 31557600.0;
1450  case TemporalDecades:
1451  return 1 / 315576000.0;
1452  case TemporalCenturies:
1453  return 1 / 3155760000.0;
1454  case TemporalUnknownUnit:
1455  case TemporalIrregularStep:
1456  return 1.0;
1457  }
1458  break;
1459  }
1460  case TemporalMilliseconds:
1461  {
1462  switch ( toUnit )
1463  {
1464  case TemporalSeconds:
1465  return 1 / 1000.0;
1466  case TemporalMilliseconds:
1467  return 1.0;
1468  case TemporalMinutes:
1469  return 1 / 60000.0;
1470  case TemporalHours:
1471  return 1 / 3600000.0;
1472  case TemporalDays:
1473  return 1 / 86400000.0;
1474  case TemporalWeeks:
1475  return 1 / 60480000.0;
1476  case TemporalMonths:
1477  return 1 / 259200000.0;
1478  case TemporalYears:
1479  return 1 / 3155760000.0;
1480  case TemporalDecades:
1481  return 1 / 31557600000.0;
1482  case TemporalCenturies:
1483  return 1 / 315576000000.0;
1484  case TemporalUnknownUnit:
1485  case TemporalIrregularStep:
1486  return 1.0;
1487  }
1488  break;
1489  }
1490  case TemporalMinutes:
1491  {
1492  switch ( toUnit )
1493  {
1494  case TemporalSeconds:
1495  return 60.0;
1496  case TemporalMilliseconds:
1497  return 60000.0;
1498  case TemporalMinutes:
1499  return 1;
1500  case TemporalHours:
1501  return 1 / 60.0;
1502  case TemporalDays:
1503  return 1 / 1440.0;
1504  case TemporalWeeks:
1505  return 1 / 10080.0;
1506  case TemporalMonths:
1507  return 1 / 43200.0;
1508  case TemporalYears:
1509  return 1 / 525960.0;
1510  case TemporalDecades:
1511  return 1 / 5259600.0;
1512  case TemporalCenturies:
1513  return 1 / 52596000.0;
1514  case TemporalUnknownUnit:
1515  case TemporalIrregularStep:
1516  return 1.0;
1517  }
1518  break;
1519  }
1520  case TemporalHours:
1521  {
1522  switch ( toUnit )
1523  {
1524  case TemporalSeconds:
1525  return 3600.0;
1526  case TemporalMilliseconds:
1527  return 3600000.0;
1528  case TemporalMinutes:
1529  return 60;
1530  case TemporalHours:
1531  return 1;
1532  case TemporalDays:
1533  return 1 / 24.0;
1534  case TemporalWeeks:
1535  return 1 / 168.0;
1536  case TemporalMonths:
1537  return 1 / 720.0;
1538  case TemporalYears:
1539  return 1 / 8766.0;
1540  case TemporalDecades:
1541  return 1 / 87660.0;
1542  case TemporalCenturies:
1543  return 1 / 876600.0;
1544  case TemporalUnknownUnit:
1545  case TemporalIrregularStep:
1546  return 1.0;
1547  }
1548  break;
1549  }
1550  case TemporalDays:
1551  {
1552  switch ( toUnit )
1553  {
1554  case TemporalSeconds:
1555  return 86400.0;
1556  case TemporalMilliseconds:
1557  return 86400000.0;
1558  case TemporalMinutes:
1559  return 1440;
1560  case TemporalHours:
1561  return 24;
1562  case TemporalDays:
1563  return 1;
1564  case TemporalWeeks:
1565  return 1 / 7.0;
1566  case TemporalMonths:
1567  return 1 / 30.0;
1568  case TemporalYears:
1569  return 1 / 365.25;
1570  case TemporalDecades:
1571  return 1 / 3652.5;
1572  case TemporalCenturies:
1573  return 1 / 36525.0;
1574  case TemporalUnknownUnit:
1575  case TemporalIrregularStep:
1576  return 1.0;
1577  }
1578  break;
1579  }
1580  case TemporalWeeks:
1581  {
1582  switch ( toUnit )
1583  {
1584  case TemporalSeconds:
1585  return 604800.0;
1586  case TemporalMilliseconds:
1587  return 604800000.0;
1588  case TemporalMinutes:
1589  return 10080;
1590  case TemporalHours:
1591  return 168;
1592  case TemporalDays:
1593  return 7;
1594  case TemporalWeeks:
1595  return 1;
1596  case TemporalMonths:
1597  return 7 / 30.0;
1598  case TemporalYears:
1599  return 7 / 365.25;
1600  case TemporalDecades:
1601  return 7 / 3652.5;
1602  case TemporalCenturies:
1603  return 7 / 36525.0;
1604  case TemporalUnknownUnit:
1605  case TemporalIrregularStep:
1606  return 1.0;
1607  }
1608  break;
1609  }
1610  case TemporalMonths:
1611  {
1612  switch ( toUnit )
1613  {
1614  case TemporalSeconds:
1615  return 2592000.0;
1616  case TemporalMilliseconds:
1617  return 2592000000.0;
1618  case TemporalMinutes:
1619  return 43200;
1620  case TemporalHours:
1621  return 720;
1622  case TemporalDays:
1623  return 30;
1624  case TemporalWeeks:
1625  return 30 / 7.0;
1626  case TemporalMonths:
1627  return 1;
1628  case TemporalYears:
1629  return 30 / 365.25;
1630  case TemporalDecades:
1631  return 30 / 3652.5;
1632  case TemporalCenturies:
1633  return 30 / 36525.0;
1634  case TemporalUnknownUnit:
1635  case TemporalIrregularStep:
1636  return 1.0;
1637  }
1638  break;
1639  }
1640  case TemporalYears:
1641  {
1642  switch ( toUnit )
1643  {
1644  case TemporalSeconds:
1645  return 31557600.0;
1646  case TemporalMilliseconds:
1647  return 31557600000.0;
1648  case TemporalMinutes:
1649  return 525960.0;
1650  case TemporalHours:
1651  return 8766.0;
1652  case TemporalDays:
1653  return 365.25;
1654  case TemporalWeeks:
1655  return 365.25 / 7.0;
1656  case TemporalMonths:
1657  return 365.25 / 30.0;
1658  case TemporalYears:
1659  return 1;
1660  case TemporalDecades:
1661  return 0.1;
1662  case TemporalCenturies:
1663  return 0.01;
1664  case TemporalUnknownUnit:
1665  case TemporalIrregularStep:
1666  return 1.0;
1667  }
1668  break;
1669  }
1670  case TemporalDecades:
1671  {
1672  switch ( toUnit )
1673  {
1674  case TemporalSeconds:
1675  return 315576000.0;
1676  case TemporalMilliseconds:
1677  return 315576000000.0;
1678  case TemporalMinutes:
1679  return 5259600.0;
1680  case TemporalHours:
1681  return 87660.0;
1682  case TemporalDays:
1683  return 3652.5;
1684  case TemporalWeeks:
1685  return 3652.5 / 7.0;
1686  case TemporalMonths:
1687  return 3652.5 / 30.0;
1688  case TemporalYears:
1689  return 10;
1690  case TemporalDecades:
1691  return 1;
1692  case TemporalCenturies:
1693  return 0.1;
1694  case TemporalUnknownUnit:
1695  case TemporalIrregularStep:
1696  return 1.0;
1697  }
1698  break;
1699  }
1700 
1701  case TemporalCenturies:
1702  {
1703  switch ( toUnit )
1704  {
1705  case TemporalSeconds:
1706  return 3155760000.0;
1707  case TemporalMilliseconds:
1708  return 3155760000000.0;
1709  case TemporalMinutes:
1710  return 52596000.0;
1711  case TemporalHours:
1712  return 876600.0;
1713  case TemporalDays:
1714  return 36525;
1715  case TemporalWeeks:
1716  return 36525 / 7.0;
1717  case TemporalMonths:
1718  return 36525 / 30.0;
1719  case TemporalYears:
1720  return 100;
1721  case TemporalDecades:
1722  return 10;
1723  case TemporalCenturies:
1724  return 1;
1725  case TemporalUnknownUnit:
1726  case TemporalIrregularStep:
1727  return 1.0;
1728  }
1729  break;
1730  }
1731 
1732  case TemporalUnknownUnit:
1733  case TemporalIrregularStep:
1734  {
1735  return 1.0;
1736  }
1737  }
1738  return 1.0;
1739 }
1740 
1742 {
1743  const QString normalized = string.trimmed().toLower();
1744 
1745  if ( ok )
1746  *ok = true;
1747 
1748  if ( normalized == encodeUnit( VolumeCubicMeters ) )
1749  return VolumeCubicMeters;
1750  if ( normalized == encodeUnit( VolumeCubicFeet ) )
1751  return VolumeCubicFeet;
1752  if ( normalized == encodeUnit( VolumeCubicYards ) )
1753  return VolumeCubicYards;
1754  if ( normalized == encodeUnit( VolumeBarrel ) )
1755  return VolumeBarrel;
1756  if ( normalized == encodeUnit( VolumeCubicDecimeter ) )
1757  return VolumeCubicDecimeter;
1758  if ( normalized == encodeUnit( VolumeLiters ) )
1759  return VolumeLiters;
1760  if ( normalized == encodeUnit( VolumeGallonUS ) )
1761  return VolumeGallonUS;
1762  if ( normalized == encodeUnit( VolumeCubicInch ) )
1763  return VolumeCubicInch;
1764  if ( normalized == encodeUnit( VolumeCubicCentimeter ) )
1765  return VolumeCubicCentimeter;
1766  if ( normalized == encodeUnit( VolumeCubicDegrees ) )
1767  return VolumeCubicDegrees;
1768  if ( normalized == encodeUnit( VolumeUnknownUnit ) )
1769  return VolumeUnknownUnit;
1770 
1771  if ( ok )
1772  *ok = false;
1773 
1774  return VolumeUnknownUnit;
1775 }
1776 
1778 {
1779  switch ( unit )
1780  {
1781  case VolumeCubicMeters:
1782  return QObject::tr( "cubic meters", "volume" );
1783  case VolumeCubicFeet:
1784  return QObject::tr( "cubic feet", "volume" );
1785  case VolumeCubicYards:
1786  return QObject::tr( "cubic yards", "volume" );
1787  case VolumeBarrel:
1788  return QObject::tr( "barrels", "volume" );
1789  case VolumeCubicDecimeter:
1790  return QObject::tr( "cubic decimeters", "volume" );
1791  case VolumeLiters:
1792  return QObject::tr( "liters", "volume" );
1793  case VolumeGallonUS:
1794  return QObject::tr( "gallons", "volume" );
1795  case VolumeCubicInch:
1796  return QObject::tr( "cubic inches", "volume" );
1797  case VolumeCubicCentimeter:
1798  return QObject::tr( "cubic centimeters", "volume" );
1799  case VolumeCubicDegrees:
1800  return QObject::tr( "cubic degrees", "volume" );
1801  case VolumeUnknownUnit:
1802  return QObject::tr( "<unknown>", "volume" );
1803  }
1804  return QString();
1805 }
1806 
1808 {
1809  switch ( unit )
1810  {
1811  case VolumeCubicMeters:
1812  return QObject::tr( "m³", "volume" );
1813  case VolumeCubicFeet:
1814  return QObject::tr( "ft³", "volume" );
1815  case VolumeCubicYards:
1816  return QObject::tr( "yds³", "volume" );
1817  case VolumeBarrel:
1818  return QObject::tr( "bbl", "volume" );
1819  case VolumeCubicDecimeter:
1820  return QObject::tr( "dm³", "volume" );
1821  case VolumeLiters:
1822  return QObject::tr( "l", "volume" );
1823  case VolumeGallonUS:
1824  return QObject::tr( "gal", "volume" );
1825  case VolumeCubicInch:
1826  return QObject::tr( "in³", "volume" );
1827  case VolumeCubicCentimeter:
1828  return QObject::tr( "cm³", "volume" );
1829  case VolumeCubicDegrees:
1830  return QObject::tr( "deg³", "volume" );
1831  case VolumeUnknownUnit:
1832  return QObject::tr( "<unknown>", "volume" );
1833  }
1834  return QString();
1835 
1836 }
1837 
1839 {
1840  const QString normalized = string.trimmed().toLower();
1841 
1842  if ( ok )
1843  *ok = true;
1844 
1845  if ( normalized == toString( VolumeCubicMeters ) )
1846  return VolumeCubicMeters;
1847  if ( normalized == toString( VolumeCubicFeet ) )
1848  return VolumeCubicFeet;
1849  if ( normalized == toString( VolumeCubicYards ) )
1850  return VolumeCubicYards;
1851  if ( normalized == toString( VolumeBarrel ) )
1852  return VolumeBarrel;
1853  if ( normalized == toString( VolumeCubicDecimeter ) )
1854  return VolumeCubicDecimeter;
1855  if ( normalized == toString( VolumeLiters ) )
1856  return VolumeLiters;
1857  if ( normalized == toString( VolumeGallonUS ) )
1858  return VolumeGallonUS;
1859  if ( normalized == toString( VolumeCubicInch ) )
1860  return VolumeCubicInch;
1861  if ( normalized == toString( VolumeCubicCentimeter ) )
1862  return VolumeCubicCentimeter;
1863  if ( normalized == toString( VolumeCubicDegrees ) )
1864  return VolumeCubicDegrees;
1865  if ( normalized == toString( VolumeUnknownUnit ) )
1866  return VolumeUnknownUnit;
1867 
1868  if ( ok )
1869  *ok = false;
1870 
1871  return VolumeUnknownUnit;
1872 }
1873 
1874 #define DEG2_TO_M3 1379474361572186.2
1876 {
1877  switch ( fromUnit )
1878  {
1879  case VolumeCubicMeters:
1880  {
1881  switch ( toUnit )
1882  {
1883  case VolumeCubicMeters:
1884  return 1.0;
1885  case VolumeCubicFeet:
1886  return 35.314666572222;
1887  case VolumeCubicYards:
1888  return 1.307950613786;
1889  case VolumeBarrel:
1890  return 6.2898107438466;
1891  case VolumeCubicDecimeter:
1892  return 1000;
1893  case VolumeLiters:
1894  return 1000;
1895  case VolumeGallonUS:
1896  return 264.17205124156;
1897  case VolumeCubicInch:
1898  return 61023.7438368;
1899  case VolumeCubicCentimeter:
1900  return 1000000;
1901  case VolumeCubicDegrees:
1902  return 1 / DEG2_TO_M3; // basically meaningless!
1903  case VolumeUnknownUnit:
1904  return 1.0;
1905  }
1906  break;
1907  }
1908  case VolumeCubicFeet:
1909  {
1910  switch ( toUnit )
1911  {
1912  case VolumeCubicMeters:
1913  return 0.028316846592;
1914  case VolumeCubicFeet:
1915  return 1.0;
1916  case VolumeCubicYards:
1917  return 0.037037037;
1918  case VolumeBarrel:
1919  return 0.178107622;
1920  case VolumeCubicDecimeter:
1921  return 28.31685;
1922  case VolumeLiters:
1923  return 28.31685;
1924  case VolumeGallonUS:
1925  return 7.480519954;
1926  case VolumeCubicInch:
1927  return 1728.000629765;
1928  case VolumeCubicCentimeter:
1929  return 28316.85;
1930  case VolumeCubicDegrees:
1931  return 0.028316846592 / DEG2_TO_M3; // basically meaningless!
1932  case VolumeUnknownUnit:
1933  return 1.0;
1934  }
1935  break;
1936  }
1937  case VolumeCubicYards:
1938  {
1939  switch ( toUnit )
1940  {
1941  case VolumeCubicMeters:
1942  return 0.764554900;
1943  case VolumeCubicFeet:
1944  return 26.999998234;
1945  case VolumeCubicYards:
1946  return 1.0;
1947  case VolumeBarrel:
1948  return 4.808905491;
1949  case VolumeCubicDecimeter:
1950  return 764.5549;
1951  case VolumeLiters:
1952  return 764.5549;
1953  case VolumeGallonUS:
1954  return 201.974025549;
1955  case VolumeCubicInch:
1956  return 46656.013952472;
1957  case VolumeCubicCentimeter:
1958  return 764554.9;
1959  case VolumeCubicDegrees:
1960  return 0.764554900 / DEG2_TO_M3; // basically meaningless!
1961  case VolumeUnknownUnit:
1962  return 1.0;
1963  }
1964  break;
1965  }
1966  case VolumeBarrel:
1967  {
1968  switch ( toUnit )
1969  {
1970  case VolumeCubicMeters:
1971  return 0.158987300;
1972  case VolumeCubicFeet:
1973  return 5.614582837;
1974  case VolumeCubicYards:
1975  return 0.207947526;
1976  case VolumeBarrel:
1977  return 1.0;
1978  case VolumeCubicDecimeter:
1979  return 158.9873;
1980  case VolumeLiters:
1981  return 158.9873;
1982  case VolumeGallonUS:
1983  return 41.999998943;
1984  case VolumeCubicInch:
1985  return 9702.002677722;
1986  case VolumeCubicCentimeter:
1987  return 158987.3;
1988  case VolumeCubicDegrees:
1989  return 0.158987300 / DEG2_TO_M3; // basically meaningless!
1990  case VolumeUnknownUnit:
1991  return 1.0;
1992  }
1993  break;
1994  }
1995  case VolumeCubicDecimeter:
1996  case VolumeLiters:
1997  {
1998  switch ( toUnit )
1999  {
2000  case VolumeCubicMeters:
2001  return 0.001;
2002  case VolumeCubicFeet:
2003  return 0.035314662;
2004  case VolumeCubicYards:
2005  return 0.001307951;
2006  case VolumeBarrel:
2007  return 0.006289811;
2008  case VolumeCubicDecimeter:
2009  case VolumeLiters:
2010  return 1.0;
2011  case VolumeGallonUS:
2012  return 0.264172037;
2013  case VolumeCubicInch:
2014  return 61.023758990;
2015  case VolumeCubicCentimeter:
2016  return 1000;
2017  case VolumeCubicDegrees:
2018  return 0.001 / DEG2_TO_M3; // basically meaningless!
2019  case VolumeUnknownUnit:
2020  return 1.0;
2021  }
2022  break;
2023  }
2024  case VolumeGallonUS:
2025  {
2026  switch ( toUnit )
2027  {
2028  case VolumeCubicMeters:
2029  return 0.003785412;
2030  case VolumeCubicFeet:
2031  return 0.133680547;
2032  case VolumeCubicYards:
2033  return 0.004951132;
2034  case VolumeBarrel:
2035  return 0.023809524;
2036  case VolumeCubicDecimeter:
2037  case VolumeLiters:
2038  return 3.785412000;
2039  case VolumeGallonUS:
2040  return 1.0;
2041  case VolumeCubicInch:
2042  return 231.000069567;
2043  case VolumeCubicCentimeter:
2044  return 3785.412;
2045  case VolumeCubicDegrees:
2046  return 0.003785412 / DEG2_TO_M3; // basically meaningless!
2047  case VolumeUnknownUnit:
2048  return 1.0;
2049  }
2050  break;
2051  }
2052  case VolumeCubicInch:
2053  {
2054  switch ( toUnit )
2055  {
2056  case VolumeCubicMeters:
2057  return 0.000016387;
2058  case VolumeCubicFeet:
2059  return 0.000578703;
2060  case VolumeCubicYards:
2061  return 0.000021433;
2062  case VolumeBarrel:
2063  return 0.000103072;
2064  case VolumeCubicDecimeter:
2065  case VolumeLiters:
2066  return 0.016387060;
2067  case VolumeGallonUS:
2068  return 0.004329003;
2069  case VolumeCubicInch:
2070  return 1.0;
2071  case VolumeCubicCentimeter:
2072  return 16.387060000;
2073  case VolumeCubicDegrees:
2074  return 0.000016387 / DEG2_TO_M3; // basically meaningless!
2075  case VolumeUnknownUnit:
2076  return 1.0;
2077  }
2078  break;
2079  }
2080  case VolumeCubicCentimeter:
2081  {
2082  switch ( toUnit )
2083  {
2084  case VolumeCubicMeters:
2085  return 0.000001;
2086  case VolumeCubicFeet:
2087  return 0.000035315;
2088  case VolumeCubicYards:
2089  return 0.000001308;
2090  case VolumeBarrel:
2091  return 0.000006290;
2092  case VolumeCubicDecimeter:
2093  case VolumeLiters:
2094  return 0.001;
2095  case VolumeGallonUS:
2096  return 0.000264172 ;
2097  case VolumeCubicInch:
2098  return 0.061023759;
2099  case VolumeCubicCentimeter:
2100  return 1.0;
2101  case VolumeCubicDegrees:
2102  return 0.000001 / DEG2_TO_M3; // basically meaningless!
2103  case VolumeUnknownUnit:
2104  return 1.0;
2105  }
2106  break;
2107  }
2108  case VolumeCubicDegrees:
2109  if ( toUnit == VolumeUnknownUnit || toUnit == VolumeCubicDegrees )
2110  return 1.0;
2111  else
2113 
2114  case VolumeUnknownUnit:
2115  {
2116  return 1.0;
2117  }
2118  }
2119  return 1.0;
2120 }
2121 
2123 {
2124  switch ( distanceUnit )
2125  {
2126  case DistanceMeters:
2127  return VolumeCubicMeters;
2128 
2129  case DistanceKilometers:
2130  return VolumeCubicMeters;
2131 
2132  case DistanceCentimeters:
2133  return VolumeCubicCentimeter;
2134 
2135  case DistanceMillimeters:
2136  return VolumeCubicCentimeter;
2137 
2138  case DistanceFeet:
2139  return VolumeCubicFeet;
2140 
2141  case DistanceYards:
2142  return VolumeCubicYards;
2143 
2144  case DistanceMiles:
2145  return VolumeCubicFeet;
2146 
2147  case DistanceDegrees:
2148  return VolumeCubicDegrees;
2149 
2150  case DistanceUnknownUnit:
2151  return VolumeUnknownUnit;
2152 
2153  case DistanceNauticalMiles:
2154  return VolumeCubicFeet;
2155  }
2156 
2157  return VolumeUnknownUnit;
2158 }
2159 
2161 {
2162  switch ( volumeUnit )
2163  {
2164  case VolumeCubicMeters:
2165  return DistanceMeters;
2166  case VolumeCubicFeet:
2167  return DistanceFeet;
2168  case VolumeCubicYards:
2169  return DistanceYards;
2170  case VolumeBarrel:
2171  return DistanceFeet;
2172  case VolumeCubicDecimeter:
2173  return DistanceCentimeters;
2174  case VolumeLiters:
2175  return DistanceMeters;
2176  case VolumeGallonUS:
2177  return DistanceFeet;
2178  case VolumeCubicInch:
2179  return DistanceFeet;
2180  case VolumeCubicCentimeter:
2181  return DistanceCentimeters;
2182  case VolumeCubicDegrees:
2183  return DistanceDegrees;
2184  case VolumeUnknownUnit:
2185  return DistanceUnknownUnit;
2186  }
2187  return DistanceUnknownUnit;
2188 }
2189 
2191 {
2192  switch ( unit )
2193  {
2194  case VolumeCubicMeters:
2195  case VolumeCubicFeet:
2196  case VolumeCubicYards:
2197  case VolumeBarrel:
2198  case VolumeCubicDecimeter:
2199  case VolumeLiters:
2200  case VolumeGallonUS:
2201  case VolumeCubicInch:
2202  case VolumeCubicCentimeter:
2203  return Standard;
2204  case VolumeCubicDegrees:
2205  return Geographic;
2206  case VolumeUnknownUnit:
2207  return UnknownType;
2208  }
2209  return UnknownType;
2210 }
2211 
2213 {
2214  switch ( unit )
2215  {
2216  case VolumeCubicMeters:
2217  return QStringLiteral( "m3" );
2218  case VolumeCubicFeet:
2219  return QStringLiteral( "ft3" );
2220  case VolumeCubicYards:
2221  return QStringLiteral( "yd3" );
2222  case VolumeBarrel:
2223  return QStringLiteral( "bbl" );
2224  case VolumeCubicDecimeter:
2225  return QStringLiteral( "dm3" );
2226  case VolumeLiters:
2227  return QStringLiteral( "l" );
2228  case VolumeGallonUS:
2229  return QStringLiteral( "gal" );
2230  case VolumeCubicInch:
2231  return QStringLiteral( "in3" );
2232  case VolumeCubicCentimeter:
2233  return QStringLiteral( "cm3" );
2234  case VolumeCubicDegrees:
2235  return QStringLiteral( "deg3" );
2236  case VolumeUnknownUnit:
2237  return QStringLiteral( "<unknown>" );
2238  }
2239  return QString();
2240 }
2241 
2243 {
2244  switch ( unit )
2245  {
2246  case AngleDegrees:
2247  return QStringLiteral( "degrees" );
2248  case AngleRadians:
2249  return QStringLiteral( "radians" );
2250  case AngleGon:
2251  return QStringLiteral( "gon" );
2252  case AngleMinutesOfArc:
2253  return QStringLiteral( "moa" );
2254  case AngleSecondsOfArc:
2255  return QStringLiteral( "soa" );
2256  case AngleTurn:
2257  return QStringLiteral( "tr" );
2258  case AngleMilliradiansSI:
2259  return QStringLiteral( "milliradians" );
2260  case AngleMilNATO:
2261  return QStringLiteral( "mil" );
2262  case AngleUnknownUnit:
2263  return QStringLiteral( "<unknown>" );
2264  }
2265  return QString();
2266 }
2267 
2268 QgsUnitTypes::AngleUnit QgsUnitTypes::decodeAngleUnit( const QString &string, bool *ok )
2269 {
2270  const QString normalized = string.trimmed().toLower();
2271 
2272  if ( ok )
2273  *ok = true;
2274 
2275  if ( normalized == encodeUnit( AngleDegrees ) )
2276  return AngleDegrees;
2277  if ( normalized == encodeUnit( AngleRadians ) )
2278  return AngleRadians;
2279  if ( normalized == encodeUnit( AngleGon ) )
2280  return AngleGon;
2281  if ( normalized == encodeUnit( AngleMinutesOfArc ) )
2282  return AngleMinutesOfArc;
2283  if ( normalized == encodeUnit( AngleSecondsOfArc ) )
2284  return AngleSecondsOfArc;
2285  if ( normalized == encodeUnit( AngleTurn ) )
2286  return AngleTurn;
2287  if ( normalized == encodeUnit( AngleMilliradiansSI ) )
2288  return AngleMilliradiansSI;
2289  if ( normalized == encodeUnit( AngleMilNATO ) )
2290  return AngleMilNATO;
2291  if ( normalized == encodeUnit( AngleUnknownUnit ) )
2292  return AngleUnknownUnit;
2293  if ( ok )
2294  *ok = false;
2295 
2296  return AngleUnknownUnit;
2297 }
2298 
2300 {
2301  switch ( unit )
2302  {
2303  case AngleDegrees:
2304  return QObject::tr( "degrees", "angle" );
2305  case AngleRadians:
2306  return QObject::tr( "radians", "angle" );
2307  case AngleGon:
2308  return QObject::tr( "gon", "angle" );
2309  case AngleMinutesOfArc:
2310  return QObject::tr( "minutes of arc", "angle" );
2311  case AngleSecondsOfArc:
2312  return QObject::tr( "seconds of arc", "angle" );
2313  case AngleTurn:
2314  return QObject::tr( "turns", "angle" );
2315  case AngleMilliradiansSI:
2316  return QObject::tr( "milliradians", "angle" );
2317  case AngleMilNATO:
2318  return QObject::tr( "mil", "angle" );
2319  case AngleUnknownUnit:
2320  return QObject::tr( "<unknown>", "angle" );
2321  }
2322  return QString();
2323 }
2324 
2326 {
2327  // Calculate the conversion factor between the specified units
2328  switch ( fromUnit )
2329  {
2330  case AngleDegrees:
2331  {
2332  switch ( toUnit )
2333  {
2334  case AngleDegrees:
2335  return 1.0;
2336  case AngleRadians:
2337  return M_PI / 180.0;
2338  case AngleGon:
2339  return 400.0 / 360.0;
2340  case AngleMinutesOfArc:
2341  return 60;
2342  case AngleSecondsOfArc:
2343  return 3600;
2344  case AngleTurn:
2345  return 1.0 / 360.0;
2346  case AngleMilliradiansSI:
2347  return M_PI / 180.0 * 1000;
2348  case AngleMilNATO:
2349  return 3200.0 / 180;
2350  case AngleUnknownUnit:
2351  break;
2352  }
2353  break;
2354  }
2355  case AngleRadians:
2356  {
2357  switch ( toUnit )
2358  {
2359  case AngleDegrees:
2360  return 180.0 / M_PI;
2361  case AngleRadians:
2362  return 1.0;
2363  case AngleGon:
2364  return 200.0 / M_PI;
2365  case AngleMinutesOfArc:
2366  return 60 * 180.0 / M_PI;
2367  case AngleSecondsOfArc:
2368  return 3600 * 180.0 / M_PI;
2369  case AngleTurn:
2370  return 0.5 / M_PI;
2371  case AngleMilliradiansSI:
2372  return 1000;
2373  case AngleMilNATO:
2374  return 3200.0 / M_PI;
2375  case AngleUnknownUnit:
2376  break;
2377  }
2378  break;
2379  }
2380  case AngleGon:
2381  {
2382  switch ( toUnit )
2383  {
2384  case AngleDegrees:
2385  return 360.0 / 400.0;
2386  case AngleRadians:
2387  return M_PI / 200.0;
2388  case AngleGon:
2389  return 1.0;
2390  case AngleMinutesOfArc:
2391  return 60 * 360.0 / 400.0;
2392  case AngleSecondsOfArc:
2393  return 3600 * 360.0 / 400.0;
2394  case AngleTurn:
2395  return 1.0 / 400.0;
2396  case AngleMilliradiansSI:
2397  return M_PI / 200.0 * 1000;
2398  case AngleMilNATO:
2399  return 3200.0 / 200.0;
2400  case AngleUnknownUnit:
2401  break;
2402  }
2403  break;
2404  }
2405  case AngleMinutesOfArc:
2406  {
2407  switch ( toUnit )
2408  {
2409  case AngleDegrees:
2410  return 1 / 60.0;
2411  case AngleRadians:
2412  return M_PI / 180.0 / 60.0;
2413  case AngleGon:
2414  return 400.0 / 360.0 / 60.0;
2415  case AngleMinutesOfArc:
2416  return 1.0;
2417  case AngleSecondsOfArc:
2418  return 60.0;
2419  case AngleTurn:
2420  return 1.0 / 360.0 / 60.0;
2421  case AngleMilliradiansSI:
2422  return M_PI / 180.0 / 60.0 * 1000;
2423  case AngleMilNATO:
2424  return 3200.0 / 180.0 / 60.0;
2425  case AngleUnknownUnit:
2426  break;
2427  }
2428  break;
2429  }
2430  case AngleSecondsOfArc:
2431  {
2432  switch ( toUnit )
2433  {
2434  case AngleDegrees:
2435  return 1 / 3600.0;
2436  case AngleRadians:
2437  return M_PI / 180.0 / 3600.0;
2438  case AngleGon:
2439  return 400.0 / 360.0 / 3600.0;
2440  case AngleMinutesOfArc:
2441  return 1.0 / 60.0;
2442  case AngleSecondsOfArc:
2443  return 1.0;
2444  case AngleTurn:
2445  return 1.0 / 360.0 / 3600.0;
2446  case AngleMilliradiansSI:
2447  return M_PI / 180.0 / 3600.0 * 1000;
2448  case AngleMilNATO:
2449  return 3200.0 / 180.0 / 3600.0;
2450  case AngleUnknownUnit:
2451  break;
2452  }
2453  break;
2454  }
2455  case AngleTurn:
2456  {
2457  switch ( toUnit )
2458  {
2459  case AngleDegrees:
2460  return 360.0;
2461  case AngleRadians:
2462  return 2 * M_PI;
2463  case AngleGon:
2464  return 400.0;
2465  case AngleMinutesOfArc:
2466  return 360.0 * 60.0;
2467  case AngleSecondsOfArc:
2468  return 360.0 * 3600.0;
2469  case AngleTurn:
2470  return 1.0;
2471  case AngleMilliradiansSI:
2472  return 2 * M_PI * 1000;
2473  case AngleMilNATO:
2474  return 2 * 3200;
2475  case AngleUnknownUnit:
2476  break;
2477  }
2478  break;
2479  }
2480  case AngleMilliradiansSI:
2481  {
2482  switch ( toUnit )
2483  {
2484  case AngleDegrees:
2485  return 180.0 / M_PI / 1000;
2486  case AngleRadians:
2487  return 0.001;
2488  case AngleGon:
2489  return 200.0 / M_PI / 1000;
2490  case AngleMinutesOfArc:
2491  return 180.0 * 60.0 / M_PI / 1000;
2492  case AngleSecondsOfArc:
2493  return 180.0 * 3600.0 / M_PI / 1000;
2494  case AngleTurn:
2495  return M_PI / 2 / 1000;
2496  case AngleMilliradiansSI:
2497  return 1.0;
2498  case AngleMilNATO:
2499  return 3200.0 / 1000.0 / M_PI;
2500  case AngleUnknownUnit:
2501  break;
2502  }
2503  break;
2504  }
2505 
2506  case AngleMilNATO:
2507  {
2508  switch ( toUnit )
2509  {
2510  case AngleDegrees:
2511  return 180.0 / 3200;
2512  case AngleRadians:
2513  return M_PI / 3200;
2514  case AngleGon:
2515  return 200.0 / 3200;
2516  case AngleMinutesOfArc:
2517  return 60 * 180.0 / 3200;
2518  case AngleSecondsOfArc:
2519  return 3600.0 * 180 / 3200;
2520  case AngleTurn:
2521  return 1.0 / ( 2 * 32000 );
2522  case AngleMilliradiansSI:
2523  return 1000.0 * M_PI / 3200.0;
2524  case AngleMilNATO:
2525  return 1.0;
2526  case AngleUnknownUnit:
2527  break;
2528  }
2529  break;
2530  }
2531 
2532  case AngleUnknownUnit:
2533  break;
2534  }
2535  return 1.0;
2536 }
2537 
2538 QString QgsUnitTypes::formatAngle( double angle, int decimals, QgsUnitTypes::AngleUnit unit )
2539 {
2540  QString unitLabel;
2541  int decimalPlaces = 2;
2542 
2543  switch ( unit )
2544  {
2545  case AngleDegrees:
2546  unitLabel = QObject::tr( "°", "angle" );
2547  decimalPlaces = 0;
2548  break;
2549  case AngleRadians:
2550  unitLabel = QObject::tr( " rad", "angle" );
2551  decimalPlaces = 2;
2552  break;
2553  case AngleGon:
2554  unitLabel = QObject::tr( " gon", "angle" );
2555  decimalPlaces = 0;
2556  break;
2557  case AngleMinutesOfArc:
2558  unitLabel = QObject::tr( "′", "angle minutes" );
2559  decimalPlaces = 0;
2560  break;
2561  case AngleSecondsOfArc:
2562  unitLabel = QObject::tr( "″", "angle seconds" );
2563  decimalPlaces = 0;
2564  break;
2565  case AngleTurn:
2566  unitLabel = QObject::tr( " tr", "angle turn" );
2567  decimalPlaces = 3;
2568  break;
2569  case AngleMilliradiansSI:
2570  unitLabel = QObject::tr( " millirad", "angular mil SI" );
2571  decimalPlaces = 0;
2572  break;
2573  case AngleMilNATO:
2574  unitLabel = QObject::tr( " mil", "angular mil NATO" );
2575  decimalPlaces = 0;
2576  break;
2577  case AngleUnknownUnit:
2578  break;
2579  }
2580 
2581  if ( decimals >= 0 )
2582  decimalPlaces = decimals;
2583 
2584  return QStringLiteral( "%L1%2" ).arg( angle, 0, 'f', decimalPlaces ).arg( unitLabel );
2585 }
2586 
2587 QgsUnitTypes::DistanceValue QgsUnitTypes::scaledDistance( double distance, QgsUnitTypes::DistanceUnit unit, int decimals, bool keepBaseUnit )
2588 {
2589  DistanceValue result;
2590 
2591  switch ( unit )
2592  {
2593  case DistanceMeters:
2594  if ( keepBaseUnit )
2595  {
2596  result.value = qgsRound( distance, decimals );
2598  }
2599  else if ( std::fabs( distance ) > 1000.0 )
2600  {
2601  result.value = qgsRound( distance / 1000, decimals );
2603  }
2604  else if ( std::fabs( distance ) < 0.01 )
2605  {
2606  result.value = qgsRound( distance * 1000, decimals );
2608  }
2609  else if ( std::fabs( distance ) < 0.1 )
2610  {
2611 
2612  result.value = qgsRound( distance * 100, decimals );
2614  }
2615  else
2616  {
2617  result.value = qgsRound( distance, decimals );
2619  }
2620  break;
2621 
2622  case DistanceKilometers:
2623  if ( keepBaseUnit || std::fabs( distance ) >= 1.0 )
2624  {
2625  result.value = qgsRound( distance, decimals );
2627  }
2628  else
2629  {
2630  result.value = qgsRound( distance * 1000, decimals );
2632  }
2633  break;
2634 
2635  case DistanceFeet:
2636  if ( std::fabs( distance ) <= 5280.0 || keepBaseUnit )
2637  {
2638  result.value = qgsRound( distance, decimals );
2640  }
2641  else
2642  {
2643  result.value = qgsRound( distance / 5280.0, decimals );
2645  }
2646  break;
2647 
2648  case DistanceYards:
2649  if ( std::fabs( distance ) <= 1760.0 || keepBaseUnit )
2650  {
2651  result.value = qgsRound( distance, decimals );
2653  }
2654  else
2655  {
2656  result.value = qgsRound( distance / 1760.0, decimals );
2658  }
2659  break;
2660 
2661  case DistanceMiles:
2662  if ( std::fabs( distance ) >= 1.0 || keepBaseUnit )
2663  {
2664  result.value = qgsRound( distance, decimals );
2666  }
2667  else
2668  {
2669  result.value = qgsRound( distance * 5280.0, decimals );
2671  }
2672  break;
2673 
2674  case DistanceNauticalMiles:
2675  result.value = qgsRound( distance, decimals );
2677  break;
2678 
2679  case DistanceDegrees:
2680  result.value = qgsRound( distance, decimals );
2682  break;
2683 
2684  case DistanceUnknownUnit:
2685  result.value = qgsRound( distance, decimals );
2687  break;
2688 
2689  default:
2690  result.value = qgsRound( distance, decimals );
2691  result.unit = unit;
2692  break;
2693  }
2694 
2695  return result;
2696 }
2697 
2698 QgsUnitTypes::AreaValue QgsUnitTypes::scaledArea( double area, QgsUnitTypes::AreaUnit unit, int decimals, bool keepBaseUnit )
2699 {
2700  AreaValue result;
2701  result.value = -1.0;
2702  result.unit = AreaUnknownUnit;
2703 
2704  // If we are not forced to keep the base units, switch to meter calculation
2705  if ( unit == AreaSquareMillimeters )
2706  {
2707  if ( keepBaseUnit )
2708  {
2709  result.value = qgsRound( area, decimals );
2711  }
2712  else
2713  {
2714  area /= 1000000.0;
2716  }
2717  }
2718  else if ( unit == AreaSquareCentimeters )
2719  {
2720  if ( keepBaseUnit )
2721  {
2722  result.value = qgsRound( area, decimals );
2724  }
2725  else
2726  {
2727  area /= 10000.0;
2729  }
2730  }
2731 
2732  switch ( unit )
2733  {
2734  case AreaSquareCentimeters:
2735  // handled in the if above
2736  break;
2737  case AreaSquareMillimeters:
2738  // handled in the if above
2739  break;
2740  case AreaSquareMeters:
2741  {
2742  if ( keepBaseUnit )
2743  {
2744  result.value = qgsRound( area, decimals );
2746  }
2748  {
2751  }
2753  {
2756  }
2757  else
2758  {
2759  result.value = qgsRound( area, decimals );
2761  }
2762  break;
2763  }
2764 
2765  case AreaSquareKilometers:
2766  {
2767  result.value = qgsRound( area, decimals );
2769  break;
2770  }
2771 
2772  case AreaSquareFeet:
2773  {
2774  if ( keepBaseUnit )
2775  {
2776  result.value = qgsRound( area, decimals );
2778  }
2780  {
2783  }
2784  else
2785  {
2786  result.value = qgsRound( area, decimals );
2788  }
2789  break;
2790  }
2791 
2792  case AreaSquareYards:
2793  {
2794  if ( keepBaseUnit )
2795  {
2796  result.value = qgsRound( area, decimals );
2798  }
2800  {
2803  }
2804  else
2805  {
2806  result.value = qgsRound( area, decimals );
2808  }
2809  break;
2810  }
2811 
2812  case AreaSquareMiles:
2813  {
2814  result.value = qgsRound( area, decimals );
2816  break;
2817  }
2818 
2819  case AreaHectares:
2820  {
2821  if ( keepBaseUnit )
2822  {
2823  result.value = qgsRound( area, decimals );
2825  }
2827  {
2830  }
2831  else
2832  {
2833  result.value = qgsRound( area, decimals );
2835  }
2836  break;
2837  }
2838 
2839  case AreaAcres:
2840  {
2841  if ( keepBaseUnit )
2842  {
2843  result.value = qgsRound( area, decimals );
2844  result.unit = QgsUnitTypes::AreaAcres;
2845  }
2847  {
2850  }
2851  else
2852  {
2853  result.value = qgsRound( area, decimals );
2854  result.unit = QgsUnitTypes::AreaAcres;
2855  }
2856  break;
2857  }
2858 
2860  {
2861  result.value = qgsRound( area, decimals );
2863  break;
2864  }
2865 
2866  case AreaSquareDegrees:
2867  {
2868  result.value = qgsRound( area, decimals );
2870  break;
2871  }
2872 
2873  case AreaUnknownUnit:
2874  {
2875  result.value = qgsRound( area, decimals );
2877  break;
2878  }
2879  }
2880  return result;
2881 }
2882 
2883 
2884 QString QgsUnitTypes::formatDistance( double distance, int decimals, QgsUnitTypes::DistanceUnit unit, bool keepBaseUnit )
2885 {
2886  const DistanceValue dist = scaledDistance( distance, unit, decimals, keepBaseUnit );
2887 
2888  QString unitText;
2889 
2890  if ( dist.unit != DistanceUnknownUnit )
2891  unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( dist.unit );
2892 
2893  return QStringLiteral( "%L1%2" ).arg( dist.value, 0, 'f', decimals ).arg( unitText );
2894 }
2895 
2896 QString QgsUnitTypes::formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit )
2897 {
2898  const AreaValue areaValue = scaledArea( area, unit, decimals, keepBaseUnit );
2899 
2900  QString unitText;
2901 
2902  if ( areaValue.unit != AreaUnknownUnit )
2903  unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( areaValue.unit );
2904 
2905  return QStringLiteral( "%L1%2" ).arg( areaValue.value, 0, 'f', decimals ).arg( unitText );
2906 }
2907 
2909 {
2910  switch ( unit )
2911  {
2912  case RenderMillimeters:
2913  return QStringLiteral( "MM" );
2915  return QStringLiteral( "RenderMetersInMapUnits" );
2916  case RenderMapUnits:
2917  return QStringLiteral( "MapUnit" );
2918  case RenderPixels:
2919  return QStringLiteral( "Pixel" );
2920  case RenderPercentage:
2921  return QStringLiteral( "Percentage" );
2922  case RenderPoints:
2923  return QStringLiteral( "Point" );
2924  case RenderInches:
2925  return QStringLiteral( "Inch" );
2926  case RenderUnknownUnit:
2927  return QString();
2928  }
2929  return QString();
2930 }
2931 
2933 {
2934  const QString normalized = string.trimmed().toLower();
2935 
2936  if ( ok )
2937  *ok = true;
2938 
2939  if ( normalized == encodeUnit( RenderMillimeters ).toLower() )
2940  return RenderMillimeters;
2941  if ( normalized == encodeUnit( RenderMetersInMapUnits ).toLower() )
2942  return RenderMetersInMapUnits;
2943  if ( normalized == QLatin1String( "meters" ) )
2944  return RenderMetersInMapUnits;
2945  if ( normalized == encodeUnit( RenderMapUnits ).toLower() )
2946  return RenderMapUnits;
2947  if ( normalized == QLatin1String( "mapunits" ) )
2948  return RenderMapUnits;
2949  if ( normalized == encodeUnit( RenderPixels ).toLower() )
2950  return RenderPixels;
2951  if ( normalized == encodeUnit( RenderPercentage ).toLower() )
2952  return RenderPercentage;
2953  if ( normalized == QLatin1String( "percent" ) )
2954  return RenderPercentage;
2955  if ( normalized == encodeUnit( RenderPoints ).toLower() )
2956  return RenderPoints;
2957  if ( normalized == QLatin1String( "points" ) )
2958  return RenderPoints;
2959  if ( normalized == encodeUnit( RenderInches ).toLower() )
2960  return RenderInches;
2961 
2962  if ( ok )
2963  *ok = false;
2964 
2965  // millimeters are default
2966  return RenderMillimeters;
2967 }
2968 
2970 {
2971  switch ( unit )
2972  {
2973  case RenderMillimeters:
2974  return QObject::tr( "millimeters", "render" );
2975 
2977  return QObject::tr( "meters at scale", "render" );
2978 
2979  case RenderMapUnits:
2980  return QObject::tr( "map units", "render" );
2981 
2982  case RenderPixels:
2983  return QObject::tr( "pixels", "render" );
2984 
2985  case RenderPercentage:
2986  return QObject::tr( "percent", "render" );
2987 
2988  case RenderPoints:
2989  return QObject::tr( "points", "render" );
2990 
2991  case RenderInches:
2992  return QObject::tr( "inches", "render" );
2993 
2994  case RenderUnknownUnit:
2995  return QObject::tr( "<unknown>", "render" );
2996 
2997  }
2998  return QString();
2999 }
3000 
3001 
3002 
3004 {
3005  switch ( unit )
3006  {
3007  case LayoutCentimeters:
3008  return QStringLiteral( "cm" );
3009  case LayoutMeters:
3010  return QStringLiteral( "m" );
3011  case LayoutInches:
3012  return QStringLiteral( "in" );
3013  case LayoutFeet:
3014  return QStringLiteral( "ft" );
3015  case LayoutPoints:
3016  return QStringLiteral( "pt" );
3017  case LayoutPicas:
3018  return QStringLiteral( "pi" );
3019  case LayoutPixels:
3020  return QStringLiteral( "px" );
3021  case LayoutMillimeters:
3022  return QStringLiteral( "mm" );
3023  }
3024  return QString();
3025 }
3026 
3028 {
3029  const QString normalized = string.trimmed().toLower();
3030 
3031  if ( ok )
3032  *ok = true;
3033 
3034  if ( normalized == encodeUnit( LayoutMillimeters ).toLower() )
3035  return LayoutMillimeters;
3036  if ( normalized == encodeUnit( LayoutCentimeters ).toLower() )
3037  return LayoutCentimeters;
3038  if ( normalized == encodeUnit( LayoutMeters ).toLower() )
3039  return LayoutMeters;
3040  if ( normalized == encodeUnit( LayoutInches ).toLower() )
3041  return LayoutInches;
3042  if ( normalized == encodeUnit( LayoutFeet ).toLower() )
3043  return LayoutFeet;
3044  if ( normalized == encodeUnit( LayoutPoints ).toLower() )
3045  return LayoutPoints;
3046  if ( normalized == encodeUnit( LayoutPicas ).toLower() )
3047  return LayoutPicas;
3048  if ( normalized == encodeUnit( LayoutPixels ).toLower() )
3049  return LayoutPixels;
3050 
3051  if ( ok )
3052  *ok = false;
3053 
3054  // millimeters are default
3055  return LayoutMillimeters;
3056 }
3057 
3059 {
3060  switch ( units )
3061  {
3062  case LayoutPixels:
3063  return LayoutScreenUnits;
3064  case LayoutMillimeters:
3065  case LayoutCentimeters:
3066  case LayoutMeters:
3067  case LayoutInches:
3068  case LayoutFeet:
3069  case LayoutPoints:
3070  case LayoutPicas:
3071  return LayoutPaperUnits;
3072  }
3073 
3074  // avoid warnings
3075  return LayoutPaperUnits;
3076 }
3077 
3079 {
3080  switch ( unit )
3081  {
3082  case LayoutPixels:
3083  return QObject::tr( "px" );
3084  case LayoutMillimeters:
3085  return QObject::tr( "mm" );
3086  case LayoutCentimeters:
3087  return QObject::tr( "cm" );
3088  case LayoutMeters:
3089  return QObject::tr( "m" );
3090  case LayoutInches:
3091  return QObject::tr( "in", "unit inch" );
3092  case LayoutFeet:
3093  return QObject::tr( "ft" );
3094  case LayoutPoints:
3095  return QObject::tr( "pt" );
3096  case LayoutPicas:
3097  return QObject::tr( "pica" );
3098  }
3099  return QString(); // no warnings
3100 }
3101 
3103 {
3104  switch ( unit )
3105  {
3106  case LayoutPixels:
3107  return QObject::tr( "pixels" );
3108  case LayoutMillimeters:
3109  return QObject::tr( "millimeters" );
3110  case LayoutCentimeters:
3111  return QObject::tr( "centimeters" );
3112  case LayoutMeters:
3113  return QObject::tr( "meters" );
3114  case LayoutInches:
3115  return QObject::tr( "inches" );
3116  case LayoutFeet:
3117  return QObject::tr( "feet" );
3118  case LayoutPoints:
3119  return QObject::tr( "points" );
3120  case LayoutPicas:
3121  return QObject::tr( "picas" );
3122  }
3123  return QString(); // no warnings
3124 }
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:182
@ LayoutInches
Inches.
Definition: qgsunittypes.h:186
@ LayoutMillimeters
Millimeters.
Definition: qgsunittypes.h:183
@ LayoutFeet
Feet.
Definition: qgsunittypes.h:187
@ LayoutCentimeters
Centimeters.
Definition: qgsunittypes.h:184
@ LayoutPixels
Pixels.
Definition: qgsunittypes.h:190
@ LayoutPicas
Typographic picas.
Definition: qgsunittypes.h:189
@ LayoutPoints
Typographic points.
Definition: qgsunittypes.h:188
@ LayoutMeters
Meters.
Definition: qgsunittypes.h:185
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:162
@ TemporalWeeks
Weeks.
Definition: qgsunittypes.h:156
@ TemporalMilliseconds
Milliseconds.
Definition: qgsunittypes.h:151
@ TemporalIrregularStep
Special "irregular step" time unit, used for temporal data which uses irregular, non-real-world unit ...
Definition: qgsunittypes.h:161
@ 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:168
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:175
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:172
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
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:196
@ LayoutScreenUnits
Unit is a screen based measurement unit.
Definition: qgsunittypes.h:198
@ LayoutPaperUnits
Unit is a paper based measurement unit.
Definition: qgsunittypes.h:197
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:1300
#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:226
double value
The value part of the distance.
Definition: qgsunittypes.h:231
QgsUnitTypes::AreaUnit unit
The value part of the distance.
Definition: qgsunittypes.h:236
A combination of distance value and unit.
Definition: qgsunittypes.h:207
QgsUnitTypes::DistanceUnit unit
The value part of the distance.
Definition: qgsunittypes.h:217
double value
The value part of the distance.
Definition: qgsunittypes.h:212