QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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 "moc_qgsunittypes.cpp"
19#include "qgis.h"
20
21/***************************************************************************
22 * This class is considered CRITICAL and any change MUST be accompanied with
23 * full unit tests in test_qgsunittypes.py.
24 * See details in QEP #17
25 ****************************************************************************/
26
28{
29 switch ( type )
30 {
32 return QStringLiteral( "distance" );
33
35 return QStringLiteral( "area" );
36
38 return QStringLiteral( "volume" );
39
41 return QStringLiteral( "temporal" );
42
44 return QStringLiteral( "<unknown>" );
45
46 }
47 return QString();
48}
49
50Qgis::UnitType QgsUnitTypes::decodeUnitType( const QString &string, bool *ok )
51{
52 const QString normalized = string.trimmed().toLower();
53
54 if ( ok )
55 *ok = true;
56
57 if ( normalized == encodeUnitType( Qgis::UnitType::Distance ) )
59 if ( normalized == encodeUnitType( Qgis::UnitType::Area ) )
61 if ( normalized == encodeUnitType( Qgis::UnitType::Volume ) )
63 if ( normalized == encodeUnitType( Qgis::UnitType::Temporal ) )
65 if ( normalized == encodeUnitType( Qgis::UnitType::Unknown ) )
67
68 if ( ok )
69 *ok = false;
70
72}
73
75{
76 switch ( unit )
77 {
127
130
133 }
135}
136
163
165{
166 switch ( unit )
167 {
169 return QStringLiteral( "meters" );
170
172 return QStringLiteral( "km" );
173
175 return QStringLiteral( "feet" );
176
178 return QStringLiteral( "yd" );
179
181 return QStringLiteral( "mi" );
182
184 return QStringLiteral( "degrees" );
185
187 return QStringLiteral( "<unknown>" );
188
190 return QStringLiteral( "nautical miles" );
191
193 return QStringLiteral( "cm" );
194
196 return QStringLiteral( "mm" );
197
199 return QStringLiteral( "in" );
200
202 return QStringLiteral( "chain" );
203
205 return QStringLiteral( "chain british benoit b1895a" );
206
208 return QStringLiteral( "chain british benoit b1895b" );
209
211 return QStringLiteral( "chain british sears 1922 truncated" );
212
214 return QStringLiteral( "chain british sears 1922" );
215
217 return QStringLiteral( "chain clarkes" );
218
220 return QStringLiteral( "chain us survey" );
221
223 return QStringLiteral( "feet british 1865" );
224
226 return QStringLiteral( "feet british 1936" );
227
229 return QStringLiteral( "feet british benoit 1895a" );
230
232 return QStringLiteral( "feet british benoit 1895b" );
233
235 return QStringLiteral( "feet british sears 1922 truncated" );
236
238 return QStringLiteral( "feet british sears 1922" );
239
241 return QStringLiteral( "feet clarkes" );
242
244 return QStringLiteral( "feet gold coast" );
245
247 return QStringLiteral( "feet indian" );
249 return QStringLiteral( "feet indian 1937" );
250
252 return QStringLiteral( "feet indian 1962" );
253
255 return QStringLiteral( "feet indian 1975" );
256
258 return QStringLiteral( "feet us survey" );
259
261 return QStringLiteral( "links" );
262
264 return QStringLiteral( "links british benoit 1895a" );
265
267 return QStringLiteral( "links british benoit 1895b" );
268
270 return QStringLiteral( "links british sears 1922 truncated" );
271
273 return QStringLiteral( "links british sears 1922" );
274
276 return QStringLiteral( "links clarkes" );
277
279 return QStringLiteral( "links us survey" );
280
282 return QStringLiteral( "yards british benoit 1895a" );
283
285 return QStringLiteral( "yards british benoit 1895b" );
286
288 return QStringLiteral( "yards british sears 1922 truncated" );
289
291 return QStringLiteral( "yards british sears 1922" );
292
294 return QStringLiteral( "yards clarkes" );
295
297 return QStringLiteral( "yards indian" );
298
300 return QStringLiteral( "yards indian 1937" );
301
303 return QStringLiteral( "yards indian 1962" );
304
306 return QStringLiteral( "yards indian 1975" );
307
309 return QStringLiteral( "miles us survey" );
310
312 return QStringLiteral( "yards fathom" );
313
315 return QStringLiteral( "german legal meters" );
316 }
317 return QString();
318}
319
320/***************************************************************************
321 * This class is considered CRITICAL and any change MUST be accompanied with
322 * full unit tests in test_qgsunittypes.py.
323 * See details in QEP #17
324 ****************************************************************************/
325
326Qgis::DistanceUnit QgsUnitTypes::decodeDistanceUnit( const QString &string, bool *ok )
327{
328 const QString normalized = string.trimmed().toLower();
329
330 if ( ok )
331 *ok = true;
332
333 for ( const Qgis::DistanceUnit unit :
334 {
346
386 } )
387 {
388 if ( normalized == encodeUnit( unit ) )
389 return unit;
390 }
391 if ( ok )
392 *ok = false;
393
395}
396
398{
399 switch ( unit )
400 {
402 return QObject::tr( "meters", "distance" );
403
405 return QObject::tr( "kilometers", "distance" );
406
408 return QObject::tr( "feet", "distance" );
409
411 return QObject::tr( "yards", "distance" );
412
414 return QObject::tr( "miles", "distance" );
415
417 return QObject::tr( "degrees", "distance" );
418
420 return QObject::tr( "centimeters", "distance" );
421
423 return QObject::tr( "millimeters", "distance" );
424
426 return QObject::tr( "inches", "distance" );
427
429 return QObject::tr( "<unknown>", "distance" );
430
432 return QObject::tr( "nautical miles", "distance" );
433
435 return QObject::tr( "chains (international)", "distance" );
436
438 return QObject::tr( "chains (British, Benoit 1895 A)", "distance" );
439
441 return QObject::tr( "chains (British, Benoit 1895 B)", "distance" );
442
444 return QObject::tr( "chains (British, Sears 1922 truncated)", "distance" );
445
447 return QObject::tr( "chains (British, Sears 1922)", "distance" );
448
450 return QObject::tr( "chains (Clarke's)", "distance" );
451
453 return QObject::tr( "chains (US survey)", "distance" );
454
456 return QObject::tr( "feet (British, 1865)", "distance" );
457
459 return QObject::tr( "feet (British, 1936)", "distance" );
460
462 return QObject::tr( "feet (British, Benoit 1895 A)", "distance" );
463
465 return QObject::tr( "feet (British, Benoit 1895 B)", "distance" );
466
468 return QObject::tr( "feet (British, Sears 1922 truncated)", "distance" );
469
471 return QObject::tr( "feet (British, Sears 1922)", "distance" );
472
474 return QObject::tr( "feet (Clarke's)", "distance" );
475
477 return QObject::tr( "feet (Gold Coast)", "distance" );
478
480 return QObject::tr( "feet (Indian)", "distance" );
481
483 return QObject::tr( "feet (Indian 1937)", "distance" );
484
486 return QObject::tr( "feet (Indian 1962)", "distance" );
487
489 return QObject::tr( "feet (Indian 1975)", "distance" );
490
492 return QObject::tr( "feet (US survey)", "distance" );
493
495 return QObject::tr( "links", "distance" );
496
498 return QObject::tr( "links (British, Benoit 1895 A)", "distance" );
499
501 return QObject::tr( "links (British, Benoit 1895 B)", "distance" );
502
504 return QObject::tr( "links (British, Sears 1922 truncated)", "distance" );
505
507 return QObject::tr( "links (British, Sears 1922)", "distance" );
508
510 return QObject::tr( "links (Clarke's)", "distance" );
511
513 return QObject::tr( "links (US survey)", "distance" );
514
516 return QObject::tr( "yards (British, Benoit 1895 A)", "distance" );
517
519 return QObject::tr( "yards (British, Benoit 1895 B)", "distance" );
520
522 return QObject::tr( "yards (British, Sears 1922 truncated)", "distance" );
523
525 return QObject::tr( "yards (British, Sears 1922)", "distance" );
526
528 return QObject::tr( "yards (Clarke's)", "distance" );
529
531 return QObject::tr( "yards (Indian)", "distance" );
532
534 return QObject::tr( "yards (Indian 1937)", "distance" );
535
537 return QObject::tr( "yards (Indian 1962)", "distance" );
538
540 return QObject::tr( "yards (Indian 1975)", "distance" );
541
543 return QObject::tr( "miles (US survey)", "distance" );
544
546 return QObject::tr( "fathoms", "distance" );
547
549 return QObject::tr( "meters (German legal)", "distance" );
550 }
551 return QString();
552}
553
555{
556 switch ( unit )
557 {
559 return QObject::tr( "mm", "render" );
560
562 return QObject::tr( "map units", "render" );
563
565 return QObject::tr( "px", "render" );
566
568 return QObject::tr( "%", "render" );
569
571 return QObject::tr( "pt", "render" );
572
574 return QObject::tr( "in", "render" );
575
577 return QObject::tr( "unknown", "render" );
578
580 return QObject::tr( "m", "render" );
581
582 }
583
584 return QString();
585}
586
588{
589 switch ( unit )
590 {
592 return QObject::tr( "m", "distance" );
593
595 return QObject::tr( "km", "distance" );
596
611 return QObject::tr( "ft", "distance" );
612
623 return QObject::tr( "yd", "distance" );
624
627 return QObject::tr( "mi", "distance" );
628
630 return QObject::tr( "deg", "distance" );
631
633 return QObject::tr( "cm", "distance" );
634
636 return QObject::tr( "mm", "distance" );
637
639 return QObject::tr( "in", "distance" );
640
642 return QString();
643
645 return QObject::tr( "NM", "distance" );
646
654 return QObject::tr( "ch", "distance" );
655
663 return QObject::tr( "lk", "distance" );
664
666 return QObject::tr( "f", "distance" );
667
669 return QObject::tr( "glm", "distance" );
670
671 }
672 return QString();
673}
674
675/***************************************************************************
676 * This class is considered CRITICAL and any change MUST be accompanied with
677 * full unit tests in test_qgsunittypes.py.
678 * See details in QEP #17
679 ****************************************************************************/
680
682{
683 const QString normalized = string.trimmed().toLower();
684
685 if ( ok )
686 *ok = true;
687
688 for ( const Qgis::DistanceUnit unit :
689 {
740 } )
741 {
742 if ( normalized.compare( toString( unit ), Qt::CaseInsensitive ) == 0 )
743 return unit;
744 }
745
746 if ( ok )
747 *ok = false;
748
750}
751
752/***************************************************************************
753 * This class is considered CRITICAL and any change MUST be accompanied with
754 * full unit tests in test_qgsunittypes.py.
755 * See details in QEP #17
756 ****************************************************************************/
757
759{
760 // values are from the EPSG units database:
761 switch ( unit )
762 {
764 return 1.0;
766 return 1000.0;
768 return 0.3048;
770 return 1852.0;
772 return 0.9144;
774 return 1609.344;
776 return 111319.49079327358;
778 return 0.01;
780 return 0.001;
782 return 0.0254;
784 return 20.1168;
786 return 20.1167824;
788 return 20.116782494376;
790 return 20.116756;
792 return 20.116765121553;
794 return 20.1166195164;
796 return 20.11684023368;
798 return 0.30480083333333;
800 return 0.3048007491;
802 return 0.30479973333333;
804 return 0.30479973476327;
806 return 0.30479933333333;
808 return 0.30479947153868;
810 return 0.3047972654;
812 return 0.30479971018151;
814 return 0.30479951024815;
816 return 0.30479841;
818 return 0.3047996;
820 return 0.3047995;
822 return 0.30480060960122;
824 return 0.201168;
826 return 0.201167824;
828 return 0.20116782494376;
830 return 0.20116756;
832 return 0.20116765121553;
834 return 0.201166195164;
836 return 0.2011684023368;
838 return 0.9143992;
840 return 0.91439920428981;
842 return 0.914398;
844 return 0.91439841461603;
846 return 0.9143917962;
848 return 0.91439853074444;
850 return 0.91439523;
852 return 0.9143988;
854 return 0.9143985;
856 return 1609.3472186944;
858 return 1.8288;
860 return 1;
862 return 1.0000135965;
863 }
864 return 1;
865}
866
868{
869 if ( fromUnit == toUnit || fromUnit == Qgis::DistanceUnit::Unknown || toUnit == Qgis::DistanceUnit::Unknown )
870 return 1.0;
871
872 constexpr double FEET_TO_INCHES = 12;
873 constexpr double YARDS_TO_FEET = 3.0;
874
875 // Calculate the conversion factor between the specified units
876
877 // special cases, where we don't go through meters as an intermediate unit:
878 switch ( fromUnit )
879 {
881 {
882 switch ( toUnit )
883 {
885 return FEET_TO_INCHES;
887 return 1.0 / YARDS_TO_FEET;
888 default:
889 break;
890 }
891
892 break;
893 }
895 {
896 switch ( toUnit )
897 {
899 return YARDS_TO_FEET;
901 return YARDS_TO_FEET * FEET_TO_INCHES;
902 default:
903 break;
904 }
905
906 break;
907 }
908
910 {
911 switch ( toUnit )
912 {
914 return 1.0 / FEET_TO_INCHES;
916 return 1.0 / ( YARDS_TO_FEET * FEET_TO_INCHES );
917 default:
918 break;
919 }
920
921 break;
922 }
923
924 default:
925 break;
926 }
927
928 return distanceUnitToMeter( fromUnit ) / distanceUnitToMeter( toUnit );
929}
930
932{
933 switch ( unit )
934 {
936 return QStringLiteral( "m2" );
938 return QStringLiteral( "km2" );
940 return QStringLiteral( "ft2" );
942 return QStringLiteral( "y2" );
944 return QStringLiteral( "mi2" );
946 return QStringLiteral( "ha" );
948 return QStringLiteral( "ac" );
950 return QStringLiteral( "nm2" );
952 return QStringLiteral( "deg2" );
954 return QStringLiteral( "cm2" );
956 return QStringLiteral( "mm2" );
958 return QStringLiteral( "in2" );
960 return QStringLiteral( "<unknown>" );
961 }
962 return QString();
963}
964
965Qgis::AreaUnit QgsUnitTypes::decodeAreaUnit( const QString &string, bool *ok )
966{
967 const QString normalized = string.trimmed().toLower();
968
969 if ( ok )
970 *ok = true;
971
972 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareMeters ) )
974 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareKilometers ) )
976 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareFeet ) )
978 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareYards ) )
980 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareMiles ) )
982 if ( normalized == encodeUnit( Qgis::AreaUnit::Hectares ) )
984 if ( normalized == encodeUnit( Qgis::AreaUnit::Acres ) )
986 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareNauticalMiles ) )
988 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareDegrees ) )
990 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareCentimeters ) )
992 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareMillimeters ) )
994 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareInches ) )
996 if ( normalized == encodeUnit( Qgis::AreaUnit::Unknown ) )
998
999 if ( ok )
1000 *ok = false;
1001
1003}
1004
1006{
1007 switch ( unit )
1008 {
1010 return QObject::tr( "square meters", "area" );
1012 return QObject::tr( "square kilometers", "area" );
1014 return QObject::tr( "square feet", "area" );
1016 return QObject::tr( "square yards", "area" );
1018 return QObject::tr( "square miles", "area" );
1020 return QObject::tr( "hectares", "area" );
1022 return QObject::tr( "acres", "area" );
1024 return QObject::tr( "square nautical miles", "area" );
1026 return QObject::tr( "square degrees", "area" );
1028 return QObject::tr( "square millimeters", "area" );
1030 return QObject::tr( "square centimeters", "area" );
1032 return QObject::tr( "square inches", "area" );
1034 return QObject::tr( "<unknown>", "area" );
1035 }
1036 return QString();
1037}
1038
1040{
1041 switch ( unit )
1042 {
1044 return QObject::tr( "m²", "area" );
1046 return QObject::tr( "km²", "area" );
1048 return QObject::tr( "ft²", "area" );
1050 return QObject::tr( "yd²", "area" );
1052 return QObject::tr( "mi²", "area" );
1054 return QObject::tr( "ha", "area" );
1056 return QObject::tr( "ac", "area" );
1058 return QObject::tr( "NM²", "area" );
1060 return QObject::tr( "deg²", "area" );
1062 return QObject::tr( "cm²", "area" );
1064 return QObject::tr( "mm²", "area" );
1066 return QObject::tr( "in²", "area" );
1068 return QString();
1069 }
1070 return QString();
1071}
1072
1073Qgis::AreaUnit QgsUnitTypes::stringToAreaUnit( const QString &string, bool *ok )
1074{
1075 const QString normalized = string.trimmed().toLower();
1076
1077 if ( ok )
1078 *ok = true;
1079
1080 if ( normalized == toString( Qgis::AreaUnit::SquareMeters ) )
1082 if ( normalized == toString( Qgis::AreaUnit::SquareKilometers ) )
1084 if ( normalized == toString( Qgis::AreaUnit::SquareFeet ) )
1086 if ( normalized == toString( Qgis::AreaUnit::SquareYards ) )
1088 if ( normalized == toString( Qgis::AreaUnit::SquareMiles ) )
1090 if ( normalized == toString( Qgis::AreaUnit::Hectares ) )
1092 if ( normalized == toString( Qgis::AreaUnit::Acres ) )
1093 return Qgis::AreaUnit::Acres;
1094 if ( normalized == toString( Qgis::AreaUnit::SquareNauticalMiles ) )
1096 if ( normalized == toString( Qgis::AreaUnit::SquareDegrees ) )
1098 if ( normalized == toString( Qgis::AreaUnit::SquareMillimeters ) )
1100 if ( normalized == toString( Qgis::AreaUnit::SquareCentimeters ) )
1102 if ( normalized == toString( Qgis::AreaUnit::SquareInches ) )
1104 if ( normalized == toString( Qgis::AreaUnit::Unknown ) )
1106 if ( ok )
1107 *ok = false;
1108
1110}
1111
1113{
1114#define KM2_TO_M2 1000000.0
1115#define CM2_TO_M2 0.0001
1116#define MM2_TO_M2 0.000001
1117#define FT2_TO_M2 0.09290304
1118#define IN2_TO_M2 0.00064516
1119#define YD2_TO_M2 0.83612736
1120#define MI2_TO_M2 2589988.110336
1121#define HA_TO_M2 10000.0
1122#define AC_TO_FT2 43560.0
1123#define DEG2_TO_M2 12392029030.5
1124#define NM2_TO_M2 3429904.0
1125
1126 // Calculate the conversion factor between the specified units
1127 switch ( fromUnit )
1128 {
1130 {
1131 switch ( toUnit )
1132 {
1134 return 1.0;
1136 return 1.0 / KM2_TO_M2;
1138 return 1.0 / FT2_TO_M2;
1140 return 1.0 / YD2_TO_M2;
1142 return 1.0 / MI2_TO_M2;
1144 return 1.0 / HA_TO_M2;
1146 return 1.0 / AC_TO_FT2 / FT2_TO_M2;
1148 return 1.0 / NM2_TO_M2;
1150 return 1.0 / DEG2_TO_M2;
1152 return 1.0 / CM2_TO_M2;
1154 return 1.0 / MM2_TO_M2;
1156 return 1.0 / IN2_TO_M2;
1158 break;
1159 }
1160
1161 break;
1162 }
1164 {
1165 switch ( toUnit )
1166 {
1168 return KM2_TO_M2;
1170 return 1.0;
1172 return KM2_TO_M2 / FT2_TO_M2;
1174 return KM2_TO_M2 / YD2_TO_M2;
1176 return KM2_TO_M2 / MI2_TO_M2;
1178 return KM2_TO_M2 / HA_TO_M2;
1180 return KM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1182 return KM2_TO_M2 / NM2_TO_M2;
1184 return KM2_TO_M2 / DEG2_TO_M2;
1186 return KM2_TO_M2 / CM2_TO_M2;
1188 return KM2_TO_M2 / MM2_TO_M2;
1190 return KM2_TO_M2 / IN2_TO_M2;
1192 break;
1193 }
1194
1195 break;
1196 }
1198 {
1199 switch ( toUnit )
1200 {
1202 return FT2_TO_M2;
1204 return FT2_TO_M2 / KM2_TO_M2;
1206 return 1.0;
1208 return FT2_TO_M2 / YD2_TO_M2;
1210 return FT2_TO_M2 / MI2_TO_M2;
1212 return FT2_TO_M2 / HA_TO_M2;
1214 return 1.0 / AC_TO_FT2;
1216 return FT2_TO_M2 / NM2_TO_M2;
1218 return FT2_TO_M2 / DEG2_TO_M2;
1220 return FT2_TO_M2 / CM2_TO_M2;
1222 return FT2_TO_M2 / MM2_TO_M2;
1224 return FT2_TO_M2 / IN2_TO_M2;
1226 break;
1227 }
1228
1229 break;
1230 }
1231
1233 {
1234 switch ( toUnit )
1235 {
1237 return YD2_TO_M2;
1239 return YD2_TO_M2 / KM2_TO_M2;
1241 return YD2_TO_M2 / FT2_TO_M2;
1243 return 1.0;
1245 return YD2_TO_M2 / MI2_TO_M2;
1247 return YD2_TO_M2 / HA_TO_M2;
1249 return YD2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1251 return YD2_TO_M2 / NM2_TO_M2;
1253 return YD2_TO_M2 / DEG2_TO_M2;
1255 return YD2_TO_M2 / CM2_TO_M2;
1257 return YD2_TO_M2 / MM2_TO_M2;
1259 return YD2_TO_M2 / IN2_TO_M2;
1261 break;
1262 }
1263 break;
1264 }
1265
1267 {
1268 switch ( toUnit )
1269 {
1271 return MI2_TO_M2;
1273 return MI2_TO_M2 / KM2_TO_M2;
1275 return MI2_TO_M2 / FT2_TO_M2;
1277 return MI2_TO_M2 / YD2_TO_M2;
1279 return 1.0;
1281 return MI2_TO_M2 / HA_TO_M2;
1283 return MI2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1285 return MI2_TO_M2 / NM2_TO_M2;
1287 return MI2_TO_M2 / DEG2_TO_M2;
1289 return MI2_TO_M2 / CM2_TO_M2;
1291 return MI2_TO_M2 / MM2_TO_M2;
1293 return MI2_TO_M2 / IN2_TO_M2;
1295 break;
1296 }
1297
1298 break;
1299 }
1300
1302 {
1303 switch ( toUnit )
1304 {
1306 return HA_TO_M2;
1308 return HA_TO_M2 / KM2_TO_M2;
1310 return HA_TO_M2 / FT2_TO_M2;
1312 return HA_TO_M2 / YD2_TO_M2;
1314 return HA_TO_M2 / MI2_TO_M2;
1316 return 1.0;
1318 return HA_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1320 return HA_TO_M2 / NM2_TO_M2;
1322 return HA_TO_M2 / DEG2_TO_M2;
1324 return HA_TO_M2 / CM2_TO_M2;
1326 return HA_TO_M2 / MM2_TO_M2;
1328 return HA_TO_M2 / IN2_TO_M2;
1330 break;
1331 }
1332
1333 break;
1334 }
1335
1337 {
1338 switch ( toUnit )
1339 {
1341 return AC_TO_FT2 * FT2_TO_M2;
1343 return AC_TO_FT2 * FT2_TO_M2 / KM2_TO_M2;
1345 return AC_TO_FT2;
1347 return AC_TO_FT2 * FT2_TO_M2 / YD2_TO_M2;
1349 return AC_TO_FT2 * FT2_TO_M2 / MI2_TO_M2;
1351 return AC_TO_FT2 * FT2_TO_M2 / HA_TO_M2;
1353 return 1.0;
1355 return AC_TO_FT2 * FT2_TO_M2 / NM2_TO_M2;
1357 return AC_TO_FT2 * FT2_TO_M2 / DEG2_TO_M2;
1359 return AC_TO_FT2 * FT2_TO_M2 / CM2_TO_M2;
1361 return AC_TO_FT2 * FT2_TO_M2 / MM2_TO_M2;
1363 return AC_TO_FT2 * FT2_TO_M2 / IN2_TO_M2;
1365 break;
1366 }
1367
1368 break;
1369 }
1370
1372 {
1373 switch ( toUnit )
1374 {
1376 return NM2_TO_M2;
1378 return NM2_TO_M2 / KM2_TO_M2;
1380 return NM2_TO_M2 / FT2_TO_M2;
1382 return NM2_TO_M2 / YD2_TO_M2;
1384 return NM2_TO_M2 / MI2_TO_M2;
1386 return NM2_TO_M2 / HA_TO_M2;
1388 return NM2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1390 return 1.0;
1392 return NM2_TO_M2 / DEG2_TO_M2;
1394 return NM2_TO_M2 / CM2_TO_M2;
1396 return NM2_TO_M2 / MM2_TO_M2;
1398 return NM2_TO_M2 / IN2_TO_M2;
1400 break;
1401 }
1402
1403 break;
1404 }
1405
1407 {
1408 switch ( toUnit )
1409 {
1411 return DEG2_TO_M2;
1413 return DEG2_TO_M2 / KM2_TO_M2;
1415 return DEG2_TO_M2 / FT2_TO_M2;
1417 return DEG2_TO_M2 / YD2_TO_M2;
1419 return DEG2_TO_M2 / MI2_TO_M2;
1421 return DEG2_TO_M2 / HA_TO_M2;
1423 return DEG2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1425 return DEG2_TO_M2 / NM2_TO_M2;
1427 return 1.0;
1429 return DEG2_TO_M2 / CM2_TO_M2;
1431 return DEG2_TO_M2 / MM2_TO_M2;
1433 return DEG2_TO_M2 / IN2_TO_M2;
1435 break;
1436 }
1437
1438 break;
1439 }
1440
1442 {
1443 switch ( toUnit )
1444 {
1446 return MM2_TO_M2;
1448 return MM2_TO_M2 / KM2_TO_M2;
1450 return MM2_TO_M2 / FT2_TO_M2;
1452 return MM2_TO_M2 / YD2_TO_M2;
1454 return MM2_TO_M2 / MI2_TO_M2;
1456 return MM2_TO_M2 / HA_TO_M2;
1458 return MM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1460 return MM2_TO_M2 / NM2_TO_M2;
1462 return MM2_TO_M2 / DEG2_TO_M2;
1464 return MM2_TO_M2 / CM2_TO_M2;
1466 return 1.0;
1468 return MM2_TO_M2 / IN2_TO_M2;
1470 break;
1471 }
1472
1473 break;
1474 }
1476 {
1477 switch ( toUnit )
1478 {
1480 return CM2_TO_M2;
1482 return CM2_TO_M2 / KM2_TO_M2;
1484 return CM2_TO_M2 / FT2_TO_M2;
1486 return CM2_TO_M2 / YD2_TO_M2;
1488 return CM2_TO_M2 / MI2_TO_M2;
1490 return CM2_TO_M2 / HA_TO_M2;
1492 return CM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1494 return CM2_TO_M2 / NM2_TO_M2;
1496 return CM2_TO_M2 / DEG2_TO_M2;
1498 return 1.0;
1500 return CM2_TO_M2 / MM2_TO_M2;
1502 return CM2_TO_M2 / IN2_TO_M2;
1504 break;
1505 }
1506
1507 break;
1508 }
1510 {
1511 switch ( toUnit )
1512 {
1514 return IN2_TO_M2;
1516 return IN2_TO_M2 / KM2_TO_M2;
1518 return IN2_TO_M2 / FT2_TO_M2;
1520 return IN2_TO_M2 / YD2_TO_M2;
1522 return IN2_TO_M2 / MI2_TO_M2;
1524 return IN2_TO_M2 / HA_TO_M2;
1526 return IN2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1528 return IN2_TO_M2 / NM2_TO_M2;
1530 return IN2_TO_M2 / DEG2_TO_M2;
1532 return IN2_TO_M2 / CM2_TO_M2;
1534 return IN2_TO_M2 / MM2_TO_M2;
1536 return 1;
1538 break;
1539 }
1540
1541 break;
1542 }
1544 break;
1545 }
1546 return 1.0;
1547}
1548
1550{
1551 switch ( distanceUnit )
1552 {
1556
1559
1562
1565
1605
1608
1612
1615
1618
1621
1624 }
1625
1627}
1628
1671
1673{
1674 switch ( unit )
1675 {
1677 return QStringLiteral( "s" );
1679 return QStringLiteral( "ms" );
1681 return QStringLiteral( "min" );
1683 return QStringLiteral( "h" );
1685 return QStringLiteral( "d" );
1687 return QStringLiteral( "wk" );
1689 return QStringLiteral( "mon" );
1691 return QStringLiteral( "y" );
1693 return QStringLiteral( "dec" );
1695 return QStringLiteral( "c" );
1697 return QStringLiteral( "xxx" );
1699 return QStringLiteral( "<unknown>" );
1700 }
1701 return QString();
1702}
1703
1705{
1706 const QString normalized = string.trimmed().toLower();
1707
1708 if ( ok )
1709 *ok = true;
1710
1711 if ( normalized == encodeUnit( Qgis::TemporalUnit::Seconds ) )
1713 if ( normalized == encodeUnit( Qgis::TemporalUnit::Milliseconds ) )
1715 if ( normalized == encodeUnit( Qgis::TemporalUnit::Minutes ) )
1717 if ( normalized == encodeUnit( Qgis::TemporalUnit::Hours ) )
1719 if ( normalized == encodeUnit( Qgis::TemporalUnit::Days ) )
1721 if ( normalized == encodeUnit( Qgis::TemporalUnit::Weeks ) )
1723 if ( normalized == encodeUnit( Qgis::TemporalUnit::Months ) )
1725 if ( normalized == encodeUnit( Qgis::TemporalUnit::Years ) )
1727 if ( normalized == encodeUnit( Qgis::TemporalUnit::Decades ) )
1729 if ( normalized == encodeUnit( Qgis::TemporalUnit::Centuries ) )
1731 if ( normalized == encodeUnit( Qgis::TemporalUnit::IrregularStep ) )
1733 if ( normalized == encodeUnit( Qgis::TemporalUnit::Unknown ) )
1735
1736 if ( ok )
1737 *ok = false;
1738
1740}
1741
1743{
1744 switch ( unit )
1745 {
1747 return QObject::tr( "seconds", "temporal" );
1749 return QObject::tr( "milliseconds", "temporal" );
1751 return QObject::tr( "minutes", "temporal" );
1753 return QObject::tr( "hours", "temporal" );
1755 return QObject::tr( "days", "temporal" );
1757 return QObject::tr( "weeks", "temporal" );
1759 return QObject::tr( "months", "temporal" );
1761 return QObject::tr( "years", "temporal" );
1763 return QObject::tr( "decades", "temporal" );
1765 return QObject::tr( "centuries", "temporal" );
1767 return QObject::tr( "steps", "temporal" );
1769 return QObject::tr( "<unknown>", "temporal" );
1770 }
1771 return QString();
1772}
1773
1775{
1776 switch ( unit )
1777 {
1779 return QObject::tr( "s", "temporal" );
1781 return QObject::tr( "ms", "temporal" );
1783 return QObject::tr( "min", "temporal" );
1785 return QObject::tr( "h", "temporal" );
1787 return QObject::tr( "d", "temporal" );
1789 return QObject::tr( "wk", "temporal" );
1791 return QObject::tr( "mon", "temporal" );
1793 return QObject::tr( "y", "temporal" );
1795 return QObject::tr( "dec", "temporal" );
1797 return QObject::tr( "cen", "temporal" );
1799 return QObject::tr( "steps", "temporal" );
1801 return QObject::tr( "<unknown>", "temporal" );
1802 }
1803 return QString();
1804}
1805
1807{
1808 const QString normalized = string.trimmed().toLower();
1809
1810 if ( ok )
1811 *ok = true;
1812
1813 if ( normalized == toString( Qgis::TemporalUnit::Seconds ) )
1815 if ( normalized == toString( Qgis::TemporalUnit::Milliseconds ) )
1817 if ( normalized == toString( Qgis::TemporalUnit::Minutes ) )
1819 if ( normalized == toString( Qgis::TemporalUnit::Hours ) )
1821 if ( normalized == toString( Qgis::TemporalUnit::Days ) )
1823 if ( normalized == toString( Qgis::TemporalUnit::Weeks ) )
1825 if ( normalized == toString( Qgis::TemporalUnit::Months ) )
1827 if ( normalized == toString( Qgis::TemporalUnit::Years ) )
1829 if ( normalized == toString( Qgis::TemporalUnit::Decades ) )
1831 if ( normalized == toString( Qgis::TemporalUnit::Centuries ) )
1833 if ( normalized == toString( Qgis::TemporalUnit::IrregularStep ) )
1835 if ( normalized == toString( Qgis::TemporalUnit::Unknown ) )
1837
1838 if ( ok )
1839 *ok = false;
1840
1842}
1843
1845{
1846 switch ( fromUnit )
1847 {
1849 {
1850 switch ( toUnit )
1851 {
1853 return 1.0;
1855 return 1000.0;
1857 return 1 / 60.0;
1859 return 1 / 3600.0;
1861 return 1 / 86400.0;
1863 return 1 / 604800.0;
1865 return 1 / 2592000.0;
1867 return 1 / 31557600.0;
1869 return 1 / 315576000.0;
1871 return 1 / 3155760000.0;
1874 return 1.0;
1875 }
1876 break;
1877 }
1879 {
1880 switch ( toUnit )
1881 {
1883 return 1 / 1000.0;
1885 return 1.0;
1887 return 1 / 60000.0;
1889 return 1 / 3600000.0;
1891 return 1 / 86400000.0;
1893 return 1 / 604800000.0;
1895 return 1 / 2592000000.0;
1897 return 1 / 31557600000.0;
1899 return 1 / 315576000000.0;
1901 return 1 / 3155760000000.0;
1904 return 1.0;
1905 }
1906 break;
1907 }
1909 {
1910 switch ( toUnit )
1911 {
1913 return 60.0;
1915 return 60000.0;
1917 return 1;
1919 return 1 / 60.0;
1921 return 1 / 1440.0;
1923 return 1 / 10080.0;
1925 return 1 / 43200.0;
1927 return 1 / 525960.0;
1929 return 1 / 5259600.0;
1931 return 1 / 52596000.0;
1934 return 1.0;
1935 }
1936 break;
1937 }
1939 {
1940 switch ( toUnit )
1941 {
1943 return 3600.0;
1945 return 3600000.0;
1947 return 60;
1949 return 1;
1951 return 1 / 24.0;
1953 return 1 / 168.0;
1955 return 1 / 720.0;
1957 return 1 / 8766.0;
1959 return 1 / 87660.0;
1961 return 1 / 876600.0;
1964 return 1.0;
1965 }
1966 break;
1967 }
1969 {
1970 switch ( toUnit )
1971 {
1973 return 86400.0;
1975 return 86400000.0;
1977 return 1440;
1979 return 24;
1981 return 1;
1983 return 1 / 7.0;
1985 return 1 / 30.0;
1987 return 1 / 365.25;
1989 return 1 / 3652.5;
1991 return 1 / 36525.0;
1994 return 1.0;
1995 }
1996 break;
1997 }
1999 {
2000 switch ( toUnit )
2001 {
2003 return 604800.0;
2005 return 604800000.0;
2007 return 10080;
2009 return 168;
2011 return 7;
2013 return 1;
2015 return 7 / 30.0;
2017 return 7 / 365.25;
2019 return 7 / 3652.5;
2021 return 7 / 36525.0;
2024 return 1.0;
2025 }
2026 break;
2027 }
2029 {
2030 switch ( toUnit )
2031 {
2033 return 2592000.0;
2035 return 2592000000.0;
2037 return 43200;
2039 return 720;
2041 return 30;
2043 return 30 / 7.0;
2045 return 1;
2047 return 30 / 365.25;
2049 return 30 / 3652.5;
2051 return 30 / 36525.0;
2054 return 1.0;
2055 }
2056 break;
2057 }
2059 {
2060 switch ( toUnit )
2061 {
2063 return 31557600.0;
2065 return 31557600000.0;
2067 return 525960.0;
2069 return 8766.0;
2071 return 365.25;
2073 return 365.25 / 7.0;
2075 return 365.25 / 30.0;
2077 return 1;
2079 return 0.1;
2081 return 0.01;
2084 return 1.0;
2085 }
2086 break;
2087 }
2089 {
2090 switch ( toUnit )
2091 {
2093 return 315576000.0;
2095 return 315576000000.0;
2097 return 5259600.0;
2099 return 87660.0;
2101 return 3652.5;
2103 return 3652.5 / 7.0;
2105 return 3652.5 / 30.0;
2107 return 10;
2109 return 1;
2111 return 0.1;
2114 return 1.0;
2115 }
2116 break;
2117 }
2118
2120 {
2121 switch ( toUnit )
2122 {
2124 return 3155760000.0;
2126 return 3155760000000.0;
2128 return 52596000.0;
2130 return 876600.0;
2132 return 36525;
2134 return 36525 / 7.0;
2136 return 36525 / 30.0;
2138 return 100;
2140 return 10;
2142 return 1;
2145 return 1.0;
2146 }
2147 break;
2148 }
2149
2152 {
2153 return 1.0;
2154 }
2155 }
2156 return 1.0;
2157}
2158
2159Qgis::VolumeUnit QgsUnitTypes::decodeVolumeUnit( const QString &string, bool *ok )
2160{
2161 const QString normalized = string.trimmed().toLower();
2162
2163 if ( ok )
2164 *ok = true;
2165
2166 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicMeters ) )
2168 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicFeet ) )
2170 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicYards ) )
2172 if ( normalized == encodeUnit( Qgis::VolumeUnit::Barrel ) )
2174 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicDecimeter ) )
2176 if ( normalized == encodeUnit( Qgis::VolumeUnit::Liters ) )
2178 if ( normalized == encodeUnit( Qgis::VolumeUnit::GallonUS ) )
2180 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicInch ) )
2182 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicCentimeter ) )
2184 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicDegrees ) )
2186 if ( normalized == encodeUnit( Qgis::VolumeUnit::Unknown ) )
2188
2189 if ( ok )
2190 *ok = false;
2191
2193}
2194
2196{
2197 switch ( unit )
2198 {
2200 return QObject::tr( "cubic meters", "volume" );
2202 return QObject::tr( "cubic feet", "volume" );
2204 return QObject::tr( "cubic yards", "volume" );
2206 return QObject::tr( "barrels", "volume" );
2208 return QObject::tr( "cubic decimeters", "volume" );
2210 return QObject::tr( "liters", "volume" );
2212 return QObject::tr( "gallons", "volume" );
2214 return QObject::tr( "cubic inches", "volume" );
2216 return QObject::tr( "cubic centimeters", "volume" );
2218 return QObject::tr( "cubic degrees", "volume" );
2220 return QObject::tr( "<unknown>", "volume" );
2221 }
2222 return QString();
2223}
2224
2226{
2227 switch ( unit )
2228 {
2230 return QObject::tr( "m³", "volume" );
2232 return QObject::tr( "ft³", "volume" );
2234 return QObject::tr( "yds³", "volume" );
2236 return QObject::tr( "bbl", "volume" );
2238 return QObject::tr( "dm³", "volume" );
2240 return QObject::tr( "l", "volume" );
2242 return QObject::tr( "gal", "volume" );
2244 return QObject::tr( "in³", "volume" );
2246 return QObject::tr( "cm³", "volume" );
2248 return QObject::tr( "deg³", "volume" );
2250 return QObject::tr( "<unknown>", "volume" );
2251 }
2252 return QString();
2253
2254}
2255
2256Qgis::VolumeUnit QgsUnitTypes::stringToVolumeUnit( const QString &string, bool *ok )
2257{
2258 const QString normalized = string.trimmed().toLower();
2259
2260 if ( ok )
2261 *ok = true;
2262
2263 if ( normalized == toString( Qgis::VolumeUnit::CubicMeters ) )
2265 if ( normalized == toString( Qgis::VolumeUnit::CubicFeet ) )
2267 if ( normalized == toString( Qgis::VolumeUnit::CubicYards ) )
2269 if ( normalized == toString( Qgis::VolumeUnit::Barrel ) )
2271 if ( normalized == toString( Qgis::VolumeUnit::CubicDecimeter ) )
2273 if ( normalized == toString( Qgis::VolumeUnit::Liters ) )
2275 if ( normalized == toString( Qgis::VolumeUnit::GallonUS ) )
2277 if ( normalized == toString( Qgis::VolumeUnit::CubicInch ) )
2279 if ( normalized == toString( Qgis::VolumeUnit::CubicCentimeter ) )
2281 if ( normalized == toString( Qgis::VolumeUnit::CubicDegrees ) )
2283 if ( normalized == toString( Qgis::VolumeUnit::Unknown ) )
2285
2286 if ( ok )
2287 *ok = false;
2288
2290}
2291
2292#define DEG2_TO_M3 1379474361572186.2
2294{
2295 // cloned branches are intentional here for improved readability
2296 // NOLINTBEGIN(bugprone-branch-clone)
2297 switch ( fromUnit )
2298 {
2300 {
2301 switch ( toUnit )
2302 {
2304 return 1.0;
2306 return 35.314666572222;
2308 return 1.307950613786;
2310 return 6.2898107438466;
2312 return 1000;
2314 return 1000;
2316 return 264.17205124156;
2318 return 61023.7438368;
2320 return 1000000;
2322 return 1 / DEG2_TO_M3; // basically meaningless!
2324 return 1.0;
2325 }
2326 break;
2327 }
2329 {
2330 switch ( toUnit )
2331 {
2333 return 0.028316846592;
2335 return 1.0;
2337 return 0.037037037;
2339 return 0.178107622;
2341 return 28.31685;
2343 return 28.31685;
2345 return 7.480519954;
2347 return 1728.000629765;
2349 return 28316.85;
2351 return 0.028316846592 / DEG2_TO_M3; // basically meaningless!
2353 return 1.0;
2354 }
2355 break;
2356 }
2358 {
2359 switch ( toUnit )
2360 {
2362 return 0.764554900;
2364 return 26.999998234;
2366 return 1.0;
2368 return 4.808905491;
2370 return 764.5549;
2372 return 764.5549;
2374 return 201.974025549;
2376 return 46656.013952472;
2378 return 764554.9;
2380 return 0.764554900 / DEG2_TO_M3; // basically meaningless!
2382 return 1.0;
2383 }
2384 break;
2385 }
2387 {
2388 switch ( toUnit )
2389 {
2391 return 0.158987300;
2393 return 5.614582837;
2395 return 0.207947526;
2397 return 1.0;
2399 return 158.9873;
2401 return 158.9873;
2403 return 41.999998943;
2405 return 9702.002677722;
2407 return 158987.3;
2409 return 0.158987300 / DEG2_TO_M3; // basically meaningless!
2411 return 1.0;
2412 }
2413 break;
2414 }
2417 {
2418 switch ( toUnit )
2419 {
2421 return 0.001;
2423 return 0.035314662;
2425 return 0.001307951;
2427 return 0.006289811;
2430 return 1.0;
2432 return 0.264172037;
2434 return 61.023758990;
2436 return 1000;
2438 return 0.001 / DEG2_TO_M3; // basically meaningless!
2440 return 1.0;
2441 }
2442 break;
2443 }
2445 {
2446 switch ( toUnit )
2447 {
2449 return 0.003785412;
2451 return 0.133680547;
2453 return 0.004951132;
2455 return 0.023809524;
2458 return 3.785412000;
2460 return 1.0;
2462 return 231.000069567;
2464 return 3785.412;
2466 return 0.003785412 / DEG2_TO_M3; // basically meaningless!
2468 return 1.0;
2469 }
2470 break;
2471 }
2473 {
2474 switch ( toUnit )
2475 {
2477 return 0.000016387;
2479 return 0.000578703;
2481 return 0.000021433;
2483 return 0.000103072;
2486 return 0.016387060;
2488 return 0.004329003;
2490 return 1.0;
2492 return 16.387060000;
2494 return 0.000016387 / DEG2_TO_M3; // basically meaningless!
2496 return 1.0;
2497 }
2498 break;
2499 }
2501 {
2502 switch ( toUnit )
2503 {
2505 return 0.000001;
2507 return 0.000035315;
2509 return 0.000001308;
2511 return 0.000006290;
2514 return 0.001;
2516 return 0.000264172 ;
2518 return 0.061023759;
2520 return 1.0;
2522 return 0.000001 / DEG2_TO_M3; // basically meaningless!
2524 return 1.0;
2525 }
2526 break;
2527 }
2529 if ( toUnit == Qgis::VolumeUnit::Unknown || toUnit == Qgis::VolumeUnit::CubicDegrees )
2530 return 1.0;
2531 else
2533
2535 {
2536 return 1.0;
2537 }
2538 }
2539 // NOLINTEND(bugprone-branch-clone)
2540 return 1.0;
2541}
2542
2544{
2545 // cloned branches are intentional here for improved readability
2546 // NOLINTBEGIN(bugprone-branch-clone)
2547 switch ( distanceUnit )
2548 {
2552
2555
2558
2561
2577
2589
2608
2611
2614
2617
2620 }
2621 // NOLINTEND(bugprone-branch-clone)
2622
2624}
2625
2655
2677
2679{
2680 switch ( unit )
2681 {
2683 return QStringLiteral( "m3" );
2685 return QStringLiteral( "ft3" );
2687 return QStringLiteral( "yd3" );
2689 return QStringLiteral( "bbl" );
2691 return QStringLiteral( "dm3" );
2693 return QStringLiteral( "l" );
2695 return QStringLiteral( "gal" );
2697 return QStringLiteral( "in3" );
2699 return QStringLiteral( "cm3" );
2701 return QStringLiteral( "deg3" );
2703 return QStringLiteral( "<unknown>" );
2704 }
2705 return QString();
2706}
2707
2709{
2710 switch ( unit )
2711 {
2713 return QStringLiteral( "degrees" );
2715 return QStringLiteral( "radians" );
2717 return QStringLiteral( "gon" );
2719 return QStringLiteral( "moa" );
2721 return QStringLiteral( "soa" );
2723 return QStringLiteral( "tr" );
2725 return QStringLiteral( "milliradians" );
2727 return QStringLiteral( "mil" );
2729 return QStringLiteral( "<unknown>" );
2730 }
2731 return QString();
2732}
2733
2734Qgis::AngleUnit QgsUnitTypes::decodeAngleUnit( const QString &string, bool *ok )
2735{
2736 const QString normalized = string.trimmed().toLower();
2737
2738 if ( ok )
2739 *ok = true;
2740
2741 if ( normalized == encodeUnit( Qgis::AngleUnit::Degrees ) )
2743 if ( normalized == encodeUnit( Qgis::AngleUnit::Radians ) )
2745 if ( normalized == encodeUnit( Qgis::AngleUnit::Gon ) )
2746 return Qgis::AngleUnit::Gon;
2747 if ( normalized == encodeUnit( Qgis::AngleUnit::MinutesOfArc ) )
2749 if ( normalized == encodeUnit( Qgis::AngleUnit::SecondsOfArc ) )
2751 if ( normalized == encodeUnit( Qgis::AngleUnit::Turn ) )
2752 return Qgis::AngleUnit::Turn;
2753 if ( normalized == encodeUnit( Qgis::AngleUnit::MilliradiansSI ) )
2755 if ( normalized == encodeUnit( Qgis::AngleUnit::MilNATO ) )
2757 if ( normalized == encodeUnit( Qgis::AngleUnit::Unknown ) )
2759 if ( ok )
2760 *ok = false;
2761
2763}
2764
2766{
2767 switch ( unit )
2768 {
2770 return QObject::tr( "degrees", "angle" );
2772 return QObject::tr( "radians", "angle" );
2774 return QObject::tr( "gon", "angle" );
2776 return QObject::tr( "minutes of arc", "angle" );
2778 return QObject::tr( "seconds of arc", "angle" );
2780 return QObject::tr( "turns", "angle" );
2782 return QObject::tr( "milliradians", "angle" );
2784 return QObject::tr( "mil", "angle" );
2786 return QObject::tr( "<unknown>", "angle" );
2787 }
2788 return QString();
2789}
2790
2792{
2793 // Calculate the conversion factor between the specified units
2794 switch ( fromUnit )
2795 {
2797 {
2798 switch ( toUnit )
2799 {
2801 return 1.0;
2803 return M_PI / 180.0;
2805 return 400.0 / 360.0;
2807 return 60;
2809 return 3600;
2811 return 1.0 / 360.0;
2813 return M_PI / 180.0 * 1000;
2815 return 3200.0 / 180;
2817 break;
2818 }
2819 break;
2820 }
2822 {
2823 switch ( toUnit )
2824 {
2826 return 180.0 / M_PI;
2828 return 1.0;
2830 return 200.0 / M_PI;
2832 return 60 * 180.0 / M_PI;
2834 return 3600 * 180.0 / M_PI;
2836 return 0.5 / M_PI;
2838 return 1000;
2840 return 3200.0 / M_PI;
2842 break;
2843 }
2844 break;
2845 }
2847 {
2848 switch ( toUnit )
2849 {
2851 return 360.0 / 400.0;
2853 return M_PI / 200.0;
2855 return 1.0;
2857 return 60 * 360.0 / 400.0;
2859 return 3600 * 360.0 / 400.0;
2861 return 1.0 / 400.0;
2863 return M_PI / 200.0 * 1000;
2865 return 3200.0 / 200.0;
2867 break;
2868 }
2869 break;
2870 }
2872 {
2873 switch ( toUnit )
2874 {
2876 return 1 / 60.0;
2878 return M_PI / 180.0 / 60.0;
2880 return 400.0 / 360.0 / 60.0;
2882 return 1.0;
2884 return 60.0;
2886 return 1.0 / 360.0 / 60.0;
2888 return M_PI / 180.0 / 60.0 * 1000;
2890 return 3200.0 / 180.0 / 60.0;
2892 break;
2893 }
2894 break;
2895 }
2897 {
2898 switch ( toUnit )
2899 {
2901 return 1 / 3600.0;
2903 return M_PI / 180.0 / 3600.0;
2905 return 400.0 / 360.0 / 3600.0;
2907 return 1.0 / 60.0;
2909 return 1.0;
2911 return 1.0 / 360.0 / 3600.0;
2913 return M_PI / 180.0 / 3600.0 * 1000;
2915 return 3200.0 / 180.0 / 3600.0;
2917 break;
2918 }
2919 break;
2920 }
2922 {
2923 switch ( toUnit )
2924 {
2926 return 360.0;
2928 return 2 * M_PI;
2930 return 400.0;
2932 return 360.0 * 60.0;
2934 return 360.0 * 3600.0;
2936 return 1.0;
2938 return 2 * M_PI * 1000;
2940 return 2 * 3200;
2942 break;
2943 }
2944 break;
2945 }
2947 {
2948 switch ( toUnit )
2949 {
2951 return 180.0 / M_PI / 1000;
2953 return 0.001;
2955 return 200.0 / M_PI / 1000;
2957 return 180.0 * 60.0 / M_PI / 1000;
2959 return 180.0 * 3600.0 / M_PI / 1000;
2961 return M_PI / 2 / 1000;
2963 return 1.0;
2965 return 3200.0 / 1000.0 / M_PI;
2967 break;
2968 }
2969 break;
2970 }
2971
2973 {
2974 switch ( toUnit )
2975 {
2977 return 180.0 / 3200;
2979 return M_PI / 3200;
2981 return 200.0 / 3200;
2983 return 60 * 180.0 / 3200;
2985 return 3600.0 * 180 / 3200;
2987 return 1.0 / ( 2 * 32000 );
2989 return 1000.0 * M_PI / 3200.0;
2991 return 1.0;
2993 break;
2994 }
2995 break;
2996 }
2997
2999 break;
3000 }
3001 return 1.0;
3002}
3003
3004QString QgsUnitTypes::formatAngle( double angle, int decimals, Qgis::AngleUnit unit )
3005{
3006 QString unitLabel;
3007 int decimalPlaces = 2;
3008
3009 switch ( unit )
3010 {
3012 unitLabel = QObject::tr( "°", "angle" );
3013 decimalPlaces = 0;
3014 break;
3016 unitLabel = QObject::tr( " rad", "angle" );
3017 decimalPlaces = 2;
3018 break;
3020 unitLabel = QObject::tr( " gon", "angle" );
3021 decimalPlaces = 0;
3022 break;
3024 unitLabel = QObject::tr( "′", "angle minutes" );
3025 decimalPlaces = 0;
3026 break;
3028 unitLabel = QObject::tr( "″", "angle seconds" );
3029 decimalPlaces = 0;
3030 break;
3032 unitLabel = QObject::tr( " tr", "angle turn" );
3033 decimalPlaces = 3;
3034 break;
3036 unitLabel = QObject::tr( " millirad", "angular mil SI" );
3037 decimalPlaces = 0;
3038 break;
3040 unitLabel = QObject::tr( " mil", "angular mil NATO" );
3041 decimalPlaces = 0;
3042 break;
3044 break;
3045 }
3046
3047 if ( decimals >= 0 )
3048 decimalPlaces = decimals;
3049
3050 return QStringLiteral( "%L1%2" ).arg( angle, 0, 'f', decimalPlaces ).arg( unitLabel );
3051}
3052
3053QgsUnitTypes::DistanceValue QgsUnitTypes::scaledDistance( double distance, Qgis::DistanceUnit unit, int decimals, bool keepBaseUnit )
3054{
3055 DistanceValue result;
3056
3057 // cloned branches are intentional here for improved readability
3058 // NOLINTBEGIN(bugprone-branch-clone)
3059 switch ( unit )
3060 {
3062 if ( keepBaseUnit )
3063 {
3064 result.value = qgsRound( distance, decimals );
3066 }
3067 else if ( std::fabs( distance ) > 1000.0 )
3068 {
3069 result.value = qgsRound( distance / 1000, decimals );
3071 }
3072 else if ( std::fabs( distance ) < 0.01 )
3073 {
3074 result.value = qgsRound( distance * 1000, decimals );
3076 }
3077 else if ( std::fabs( distance ) < 0.1 )
3078 {
3079
3080 result.value = qgsRound( distance * 100, decimals );
3082 }
3083 else
3084 {
3085 result.value = qgsRound( distance, decimals );
3087 }
3088 break;
3089
3091 if ( keepBaseUnit || std::fabs( distance ) >= 1.0 )
3092 {
3093 result.value = qgsRound( distance, decimals );
3095 }
3096 else
3097 {
3098 result.value = qgsRound( distance * 1000, decimals );
3100 }
3101 break;
3102
3104 if ( std::fabs( distance ) <= 5280.0 || keepBaseUnit )
3105 {
3106 result.value = qgsRound( distance, decimals );
3108 }
3109 else
3110 {
3111 result.value = qgsRound( distance / 5280.0, decimals );
3113 }
3114 break;
3115
3117 if ( std::fabs( distance ) <= 1760.0 || keepBaseUnit )
3118 {
3119 result.value = qgsRound( distance, decimals );
3121 }
3122 else
3123 {
3124 result.value = qgsRound( distance / 1760.0, decimals );
3126 }
3127 break;
3128
3130 if ( std::fabs( distance ) >= 1.0 || keepBaseUnit )
3131 {
3132 result.value = qgsRound( distance, decimals );
3134 }
3135 else
3136 {
3137 result.value = qgsRound( distance * 5280.0, decimals );
3139 }
3140 break;
3141
3143 result.value = qgsRound( distance, decimals );
3145 break;
3146
3148 result.value = qgsRound( distance, decimals );
3150 break;
3151
3153 result.value = qgsRound( distance, decimals );
3155 break;
3156
3157 default:
3158 result.value = qgsRound( distance, decimals );
3159 result.unit = unit;
3160 break;
3161 }
3162 // NOLINTEND(bugprone-branch-clone)
3163
3164 return result;
3165}
3166
3167QgsUnitTypes::AreaValue QgsUnitTypes::scaledArea( double area, Qgis::AreaUnit unit, int decimals, bool keepBaseUnit )
3168{
3170 result.value = -1.0;
3172
3173 // If we are not forced to keep the base units, switch to meter calculation
3175 {
3176 if ( keepBaseUnit )
3177 {
3178 result.value = qgsRound( area, decimals );
3180 }
3181 else
3182 {
3183 area /= 1000000.0;
3185 }
3186 }
3187 else if ( unit == Qgis::AreaUnit::SquareCentimeters )
3188 {
3189 if ( keepBaseUnit )
3190 {
3191 result.value = qgsRound( area, decimals );
3193 }
3194 else
3195 {
3196 area /= 10000.0;
3198 }
3199 }
3200
3201 // cloned branches are intentional here for improved readability
3202 // NOLINTBEGIN(bugprone-branch-clone)
3203 switch ( unit )
3204 {
3206 // handled in the if above
3207 break;
3209 // handled in the if above
3210 break;
3212 {
3213 if ( keepBaseUnit )
3214 {
3215 result.value = qgsRound( area, decimals );
3217 }
3219 {
3222 }
3224 {
3227 }
3228 else
3229 {
3230 result.value = qgsRound( area, decimals );
3232 }
3233 break;
3234 }
3235
3237 {
3238 result.value = qgsRound( area, decimals );
3240 break;
3241 }
3242
3244 {
3245 result.value = qgsRound( area, decimals );
3247 break;
3248 }
3249
3251 {
3252 if ( keepBaseUnit )
3253 {
3254 result.value = qgsRound( area, decimals );
3256 }
3258 {
3261 }
3262 else
3263 {
3264 result.value = qgsRound( area, decimals );
3266 }
3267 break;
3268 }
3269
3271 {
3272 if ( keepBaseUnit )
3273 {
3274 result.value = qgsRound( area, decimals );
3276 }
3278 {
3281 }
3282 else
3283 {
3284 result.value = qgsRound( area, decimals );
3286 }
3287 break;
3288 }
3289
3291 {
3292 result.value = qgsRound( area, decimals );
3294 break;
3295 }
3296
3298 {
3299 if ( keepBaseUnit )
3300 {
3301 result.value = qgsRound( area, decimals );
3303 }
3305 {
3308 }
3309 else
3310 {
3311 result.value = qgsRound( area, decimals );
3313 }
3314 break;
3315 }
3316
3318 {
3319 if ( keepBaseUnit )
3320 {
3321 result.value = qgsRound( area, decimals );
3322 result.unit = Qgis::AreaUnit::Acres;
3323 }
3325 {
3328 }
3329 else
3330 {
3331 result.value = qgsRound( area, decimals );
3332 result.unit = Qgis::AreaUnit::Acres;
3333 }
3334 break;
3335 }
3336
3338 {
3339 result.value = qgsRound( area, decimals );
3341 break;
3342 }
3343
3345 {
3346 result.value = qgsRound( area, decimals );
3348 break;
3349 }
3350
3352 {
3353 result.value = qgsRound( area, decimals );
3355 break;
3356 }
3357 }
3358 // NOLINTEND(bugprone-branch-clone)
3359 return result;
3360}
3361
3362
3363QString QgsUnitTypes::formatDistance( double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit )
3364{
3365 const DistanceValue dist = scaledDistance( distance, unit, decimals, keepBaseUnit );
3366
3367 QString unitText;
3368
3369 if ( dist.unit != Qgis::DistanceUnit::Unknown )
3370 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( dist.unit );
3371
3372 if ( qgsDoubleNear( dist.value, 0 ) )
3373 {
3374 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( unit );
3375 return QStringLiteral( "%L1%2" ).arg( distance, 0, 'e', decimals ).arg( unitText );
3376 }
3377 else
3378 {
3379 return QStringLiteral( "%L1%2" ).arg( dist.value, 0, 'f', decimals ).arg( unitText );
3380 }
3381}
3382
3383QString QgsUnitTypes::formatArea( double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit )
3384{
3385 const QgsUnitTypes::AreaValue areaValue = scaledArea( area, unit, decimals, keepBaseUnit );
3386
3387 QString unitText;
3388
3389 if ( areaValue.unit != Qgis::AreaUnit::Unknown )
3390 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( areaValue.unit );
3391
3392 if ( qgsDoubleNear( areaValue.value, 0 ) )
3393 {
3394 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( unit );
3395 return QStringLiteral( "%L1%2" ).arg( area, 0, 'e', decimals ).arg( unitText );
3396 }
3397 else
3398 {
3399 return QStringLiteral( "%L1%2" ).arg( areaValue.value, 0, 'f', decimals ).arg( unitText );
3400 }
3401}
3402
3404{
3405 switch ( unit )
3406 {
3408 return QStringLiteral( "MM" );
3410 return QStringLiteral( "RenderMetersInMapUnits" );
3412 return QStringLiteral( "MapUnit" );
3414 return QStringLiteral( "Pixel" );
3416 return QStringLiteral( "Percentage" );
3418 return QStringLiteral( "Point" );
3420 return QStringLiteral( "Inch" );
3422 return QString();
3423 }
3424 return QString();
3425}
3426
3427Qgis::RenderUnit QgsUnitTypes::decodeRenderUnit( const QString &string, bool *ok )
3428{
3429 const QString normalized = string.trimmed().toLower();
3430
3431 if ( ok )
3432 *ok = true;
3433
3434 if ( normalized == encodeUnit( Qgis::RenderUnit::Millimeters ).toLower() )
3436 if ( normalized == encodeUnit( Qgis::RenderUnit::MetersInMapUnits ).toLower() )
3438 if ( normalized == QLatin1String( "meters" ) )
3440 if ( normalized == encodeUnit( Qgis::RenderUnit::MapUnits ).toLower() )
3442 if ( normalized == QLatin1String( "mapunits" ) )
3444 if ( normalized == encodeUnit( Qgis::RenderUnit::Pixels ).toLower() )
3446 if ( normalized == encodeUnit( Qgis::RenderUnit::Percentage ).toLower() )
3448 if ( normalized == QLatin1String( "percent" ) )
3450 if ( normalized == encodeUnit( Qgis::RenderUnit::Points ).toLower() )
3452 if ( normalized == QLatin1String( "points" ) )
3454 if ( normalized == encodeUnit( Qgis::RenderUnit::Inches ).toLower() )
3456
3457 if ( ok )
3458 *ok = false;
3459
3460 // millimeters are default
3462}
3463
3465{
3466 switch ( unit )
3467 {
3469 return QObject::tr( "millimeters", "render" );
3470
3472 return QObject::tr( "meters at scale", "render" );
3473
3475 return QObject::tr( "map units", "render" );
3476
3478 return QObject::tr( "pixels", "render" );
3479
3481 return QObject::tr( "percent", "render" );
3482
3484 return QObject::tr( "points", "render" );
3485
3487 return QObject::tr( "inches", "render" );
3488
3490 return QObject::tr( "<unknown>", "render" );
3491
3492 }
3493 return QString();
3494}
3495
3496
3497
3499{
3500 switch ( unit )
3501 {
3503 return QStringLiteral( "cm" );
3505 return QStringLiteral( "m" );
3507 return QStringLiteral( "in" );
3509 return QStringLiteral( "ft" );
3511 return QStringLiteral( "pt" );
3513 return QStringLiteral( "pi" );
3515 return QStringLiteral( "px" );
3517 return QStringLiteral( "mm" );
3518 }
3519 return QString();
3520}
3521
3522Qgis::LayoutUnit QgsUnitTypes::decodeLayoutUnit( const QString &string, bool *ok )
3523{
3524 const QString normalized = string.trimmed().toLower();
3525
3526 if ( ok )
3527 *ok = true;
3528
3529 if ( normalized == encodeUnit( Qgis::LayoutUnit::Millimeters ).toLower() )
3531 if ( normalized == encodeUnit( Qgis::LayoutUnit::Centimeters ).toLower() )
3533 if ( normalized == encodeUnit( Qgis::LayoutUnit::Meters ).toLower() )
3535 if ( normalized == encodeUnit( Qgis::LayoutUnit::Inches ).toLower() )
3537 if ( normalized == encodeUnit( Qgis::LayoutUnit::Feet ).toLower() )
3539 if ( normalized == encodeUnit( Qgis::LayoutUnit::Points ).toLower() )
3541 if ( normalized == encodeUnit( Qgis::LayoutUnit::Picas ).toLower() )
3543 if ( normalized == encodeUnit( Qgis::LayoutUnit::Pixels ).toLower() )
3545
3546 if ( ok )
3547 *ok = false;
3548
3549 // millimeters are default
3551}
3552
3572
3574{
3575 switch ( unit )
3576 {
3578 return QObject::tr( "px" );
3580 return QObject::tr( "mm" );
3582 return QObject::tr( "cm" );
3584 return QObject::tr( "m" );
3586 return QObject::tr( "in", "unit inch" );
3588 return QObject::tr( "ft" );
3590 return QObject::tr( "pt" );
3592 return QObject::tr( "pica" );
3593 }
3594 return QString(); // no warnings
3595}
3596
3598{
3599 switch ( unit )
3600 {
3602 return QObject::tr( "pixels" );
3604 return QObject::tr( "millimeters" );
3606 return QObject::tr( "centimeters" );
3608 return QObject::tr( "meters" );
3610 return QObject::tr( "inches" );
3612 return QObject::tr( "feet" );
3614 return QObject::tr( "points" );
3616 return QObject::tr( "picas" );
3617 }
3618 return QString(); // no warnings
3619}
DistanceUnitType
Types of distance units.
Definition qgis.h:4731
@ Geographic
Unit is a geographic (e.g., degree based) unit.
@ Unknown
Unknown unit type.
@ Standard
Unit is a standard measurement unit.
UnitType
Unit types.
Definition qgis.h:4652
@ Distance
Distance unit.
@ Temporal
Temporal unit.
@ Unknown
Unknown unit type.
@ Volume
Volume unit.
@ Area
Area unit.
LayoutUnit
Layout measurement units.
Definition qgis.h:4859
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Points
Typographic points.
@ Picas
Typographic picas.
AngleUnit
Units of angles.
Definition qgis.h:4794
@ SecondsOfArc
Seconds of arc.
@ Radians
Square kilometers.
@ Turn
Turn/revolutions.
@ MinutesOfArc
Minutes of arc.
@ Unknown
Unknown angle unit.
@ MilliradiansSI
Angular milliradians (SI definition, 1/1000 of radian)
@ Degrees
Degrees.
@ Gon
Gon/gradian.
@ MilNATO
Angular mil (NATO definition, 6400 mil = 2PI radians)
DistanceUnit
Units of distance.
Definition qgis.h:4669
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated)
@ Feet
Imperial feet.
@ MilesUSSurvey
US Survey miles.
@ LinksBritishSears1922
British links (Sears 1922)
@ YardsBritishBenoit1895A
British yards (Benoit 1895 A)
@ LinksBritishBenoit1895A
British links (Benoit 1895 A)
@ Centimeters
Centimeters.
@ YardsIndian1975
Indian yards (1975)
@ FeetUSSurvey
US Survey feet.
@ Millimeters
Millimeters.
@ FeetBritishSears1922
British feet (Sears 1922)
@ YardsClarkes
Clarke's yards.
@ YardsIndian
Indian yards.
@ FeetBritishBenoit1895B
British feet (Benoit 1895 B)
@ Miles
Terrestrial miles.
@ LinksUSSurvey
US Survey links.
@ ChainsUSSurvey
US Survey chains.
@ FeetClarkes
Clarke's feet.
@ Unknown
Unknown distance unit.
@ Yards
Imperial yards.
@ FeetBritish1936
British feet (1936)
@ FeetIndian1962
Indian feet (1962)
@ YardsBritishSears1922
British yards (Sears 1922)
@ FeetIndian1937
Indian feet (1937)
@ YardsIndian1937
Indian yards (1937)
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ ChainsBritishBenoit1895B
British chains (Benoit 1895 B)
@ LinksBritishSears1922Truncated
British links (Sears 1922 truncated)
@ ChainsBritishBenoit1895A
British chains (Benoit 1895 A)
@ YardsBritishBenoit1895B
British yards (Benoit 1895 B)
@ FeetBritish1865
British feet (1865)
@ YardsIndian1962
Indian yards (1962)
@ FeetBritishSears1922Truncated
British feet (Sears 1922 truncated)
@ MetersGermanLegal
German legal meter.
@ LinksBritishBenoit1895B
British links (Benoit 1895 B)
@ ChainsInternational
International chains.
@ LinksInternational
International links.
@ ChainsBritishSears1922Truncated
British chains (Sears 1922 truncated)
@ FeetIndian
Indian (geodetic) feet.
@ NauticalMiles
Nautical miles.
@ ChainsClarkes
Clarke's chains.
@ LinksClarkes
Clarke's links.
@ ChainsBritishSears1922
British chains (Sears 1922)
@ Kilometers
Kilometers.
@ FeetIndian1975
Indian feet (1975)
@ FeetGoldCoast
Gold Coast feet.
@ FeetBritishBenoit1895A
British feet (Benoit 1895 A)
AreaUnit
Units of area.
Definition qgis.h:4746
@ SquareFeet
Square feet.
@ SquareCentimeters
Square centimeters.
@ SquareInches
Square inches.
@ SquareNauticalMiles
Square nautical miles.
@ SquareMillimeters
Square millimeters.
@ SquareYards
Square yards.
@ Hectares
Hectares.
@ SquareKilometers
Square kilometers.
@ SquareMeters
Square meters.
@ Unknown
Unknown areal unit.
@ SquareDegrees
Square degrees, for planar geographic CRS area measurements.
@ SquareMiles
Square miles.
TemporalUnit
Temporal units.
Definition qgis.h:4815
@ IrregularStep
Special 'irregular step' time unit, used for temporal data which uses irregular, non-real-world unit ...
@ Milliseconds
Milliseconds.
@ Unknown
Unknown time unit.
@ Centuries
Centuries.
RenderUnit
Rendering size units.
Definition qgis.h:4839
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size)
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ Unknown
Mixed or unknown units.
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
LayoutUnitType
Types of layout units.
Definition qgis.h:4879
@ PaperUnits
Unit is a paper based measurement unit.
@ ScreenUnits
Unit is a screen based measurement unit.
VolumeUnit
Units of volume.
Definition qgis.h:4771
@ CubicMeters
Cubic meters.
@ Barrel
Barrels.
@ CubicYards
Cubic yards.
@ CubicFeet
Cubic feet.
@ CubicDegrees
Cubic degrees, for planar geographic CRS volume measurements.
@ CubicDecimeter
Cubic decimeters.
@ Unknown
Unknown volume unit.
@ CubicInch
Cubic inches.
@ GallonUS
US Gallons.
@ CubicCentimeter
Cubic Centimeters.
static Q_INVOKABLE Qgis::VolumeUnit decodeVolumeUnit(const QString &string, bool *ok=nullptr)
Decodes a volume unit from a string.
static Q_INVOKABLE Qgis::DistanceUnit stringToDistanceUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to a distance unit.
static Q_INVOKABLE QgsUnitTypes::AreaValue scaledArea(double area, Qgis::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 QgsUnitTypes::DistanceValue scaledDistance(double distance, Qgis::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 QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
static Q_INVOKABLE QString formatArea(double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit=false)
Returns an area formatted as a friendly string.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static Q_INVOKABLE Qgis::VolumeUnit stringToVolumeUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to a volume unit.
static Q_INVOKABLE QString formatDistance(double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit=false)
Returns an distance formatted as a friendly string.
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
static Q_INVOKABLE Qgis::DistanceUnitType unitType(Qgis::DistanceUnit unit)
Returns the type for a distance unit.
static Q_INVOKABLE Qgis::UnitType decodeUnitType(const QString &string, bool *ok=nullptr)
Decodes a unit type from a string.
static Q_INVOKABLE Qgis::AreaUnit decodeAreaUnit(const QString &string, bool *ok=nullptr)
Decodes an areal unit from a string.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE Qgis::TemporalUnit stringToTemporalUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to a temporal unit.
static Q_INVOKABLE Qgis::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
static Q_INVOKABLE Qgis::AreaUnit stringToAreaUnit(const QString &string, bool *ok=nullptr)
Converts a translated string to an areal unit.
static Q_INVOKABLE Qgis::AreaUnit distanceToAreaUnit(Qgis::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding area unit, e.g., meters to square meters.
static Q_INVOKABLE Qgis::TemporalUnit decodeTemporalUnit(const QString &string, bool *ok=nullptr)
Decodes a temporal unit from a string.
static Q_INVOKABLE Qgis::AngleUnit decodeAngleUnit(const QString &string, bool *ok=nullptr)
Decodes an angular unit from a string.
static Q_INVOKABLE Qgis::DistanceUnit areaToDistanceUnit(Qgis::AreaUnit areaUnit)
Converts an area unit to its corresponding distance unit, e.g., square meters to meters.
static Q_INVOKABLE Qgis::DistanceUnit volumeToDistanceUnit(Qgis::VolumeUnit volumeUnit)
Converts a volume unit to its corresponding distance unit, e.g., cubic meters to meters.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static Q_INVOKABLE QString encodeUnitType(Qgis::UnitType type)
Encodes a unit type to a string.
static Q_INVOKABLE QString formatAngle(double angle, int decimals, Qgis::AngleUnit unit)
Returns an angle formatted as a friendly string.
static Q_INVOKABLE Qgis::VolumeUnit distanceToVolumeUnit(Qgis::DistanceUnit distanceUnit)
Converts a distance unit to its corresponding volume unit, e.g., meters to cubic meters.
static Q_INVOKABLE Qgis::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=nullptr)
Decodes a distance unit from a string.
double qgsRound(double number, int places)
Returns a double number, rounded (as close as possible) to the specified number of places.
Definition qgis.h:5958
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5917
#define KM2_TO_M2
#define DEG2_TO_M3
#define MI2_TO_M2
#define AC_TO_FT2
#define YD2_TO_M2
#define NM2_TO_M2
#define IN2_TO_M2
#define MM2_TO_M2
#define DEG2_TO_M2
#define CM2_TO_M2
#define FT2_TO_M2
constexpr double distanceUnitToMeter(Qgis::DistanceUnit unit)
#define HA_TO_M2
A combination of area value and unit.
double value
The value part of the distance.
Qgis::AreaUnit unit
The value part of the distance.
A combination of distance value and unit.
double value
The value part of the distance.
Qgis::DistanceUnit unit
The value part of the distance.