QGIS API Documentation 3.39.0-Master (d85f3c2a281)
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 "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 {
31 return QStringLiteral( "distance" );
32
34 return QStringLiteral( "area" );
35
37 return QStringLiteral( "volume" );
38
40 return QStringLiteral( "temporal" );
41
43 return QStringLiteral( "<unknown>" );
44
45 }
46 return QString();
47}
48
49Qgis::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( Qgis::UnitType::Distance ) )
58 if ( normalized == encodeUnitType( Qgis::UnitType::Area ) )
60 if ( normalized == encodeUnitType( Qgis::UnitType::Volume ) )
62 if ( normalized == encodeUnitType( Qgis::UnitType::Temporal ) )
64 if ( normalized == encodeUnitType( Qgis::UnitType::Unknown ) )
66
67 if ( ok )
68 *ok = false;
69
71}
72
74{
75 switch ( unit )
76 {
126
129
132 }
134}
135
162
164{
165 switch ( unit )
166 {
168 return QStringLiteral( "meters" );
169
171 return QStringLiteral( "km" );
172
174 return QStringLiteral( "feet" );
175
177 return QStringLiteral( "yd" );
178
180 return QStringLiteral( "mi" );
181
183 return QStringLiteral( "degrees" );
184
186 return QStringLiteral( "<unknown>" );
187
189 return QStringLiteral( "nautical miles" );
190
192 return QStringLiteral( "cm" );
193
195 return QStringLiteral( "mm" );
196
198 return QStringLiteral( "in" );
199
201 return QStringLiteral( "chain" );
202
204 return QStringLiteral( "chain british benoit b1895a" );
205
207 return QStringLiteral( "chain british benoit b1895b" );
208
210 return QStringLiteral( "chain british sears 1922 truncated" );
211
213 return QStringLiteral( "chain british sears 1922" );
214
216 return QStringLiteral( "chain clarkes" );
217
219 return QStringLiteral( "chain us survey" );
220
222 return QStringLiteral( "feet british 1865" );
223
225 return QStringLiteral( "feet british 1936" );
226
228 return QStringLiteral( "feet british benoit 1895a" );
229
231 return QStringLiteral( "feet british benoit 1895b" );
232
234 return QStringLiteral( "feet british sears 1922 truncated" );
235
237 return QStringLiteral( "feet british sears 1922" );
238
240 return QStringLiteral( "feet clarkes" );
241
243 return QStringLiteral( "feet gold coast" );
244
246 return QStringLiteral( "feet indian" );
248 return QStringLiteral( "feet indian 1937" );
249
251 return QStringLiteral( "feet indian 1962" );
252
254 return QStringLiteral( "feet indian 1975" );
255
257 return QStringLiteral( "feet us survey" );
258
260 return QStringLiteral( "links" );
261
263 return QStringLiteral( "links british benoit 1895a" );
264
266 return QStringLiteral( "links british benoit 1895b" );
267
269 return QStringLiteral( "links british sears 1922 truncated" );
270
272 return QStringLiteral( "links british sears 1922" );
273
275 return QStringLiteral( "links clarkes" );
276
278 return QStringLiteral( "links us survey" );
279
281 return QStringLiteral( "yards british benoit 1895a" );
282
284 return QStringLiteral( "yards british benoit 1895b" );
285
287 return QStringLiteral( "yards british sears 1922 truncated" );
288
290 return QStringLiteral( "yards british sears 1922" );
291
293 return QStringLiteral( "yards clarkes" );
294
296 return QStringLiteral( "yards indian" );
297
299 return QStringLiteral( "yards indian 1937" );
300
302 return QStringLiteral( "yards indian 1962" );
303
305 return QStringLiteral( "yards indian 1975" );
306
308 return QStringLiteral( "miles us survey" );
309
311 return QStringLiteral( "yards fathom" );
312
314 return QStringLiteral( "german legal meters" );
315 }
316 return QString();
317}
318
319/***************************************************************************
320 * This class is considered CRITICAL and any change MUST be accompanied with
321 * full unit tests in test_qgsunittypes.py.
322 * See details in QEP #17
323 ****************************************************************************/
324
325Qgis::DistanceUnit QgsUnitTypes::decodeDistanceUnit( const QString &string, bool *ok )
326{
327 const QString normalized = string.trimmed().toLower();
328
329 if ( ok )
330 *ok = true;
331
332 for ( const Qgis::DistanceUnit unit :
333 {
345
385 } )
386 {
387 if ( normalized == encodeUnit( unit ) )
388 return unit;
389 }
390 if ( ok )
391 *ok = false;
392
394}
395
397{
398 switch ( unit )
399 {
401 return QObject::tr( "meters", "distance" );
402
404 return QObject::tr( "kilometers", "distance" );
405
407 return QObject::tr( "feet", "distance" );
408
410 return QObject::tr( "yards", "distance" );
411
413 return QObject::tr( "miles", "distance" );
414
416 return QObject::tr( "degrees", "distance" );
417
419 return QObject::tr( "centimeters", "distance" );
420
422 return QObject::tr( "millimeters", "distance" );
423
425 return QObject::tr( "inches", "distance" );
426
428 return QObject::tr( "<unknown>", "distance" );
429
431 return QObject::tr( "nautical miles", "distance" );
432
434 return QObject::tr( "chains (international)", "distance" );
435
437 return QObject::tr( "chains (British, Benoit 1895 A)", "distance" );
438
440 return QObject::tr( "chains (British, Benoit 1895 B)", "distance" );
441
443 return QObject::tr( "chains (British, Sears 1922 truncated)", "distance" );
444
446 return QObject::tr( "chains (British, Sears 1922)", "distance" );
447
449 return QObject::tr( "chains (Clarke's)", "distance" );
450
452 return QObject::tr( "chains (US surver)", "distance" );
453
455 return QObject::tr( "feet (British, 1865)", "distance" );
456
458 return QObject::tr( "feet (British, 1936)", "distance" );
459
461 return QObject::tr( "feet (British, Benoit 1895 A)", "distance" );
462
464 return QObject::tr( "feet (British, Benoit 1895 B)", "distance" );
465
467 return QObject::tr( "feet (British, Sears 1922 truncated)", "distance" );
468
470 return QObject::tr( "feet (British, Sears 1922)", "distance" );
471
473 return QObject::tr( "feet (Clarke's)", "distance" );
474
476 return QObject::tr( "feet (Gold Coast)", "distance" );
477
479 return QObject::tr( "feet (Indian)", "distance" );
480
482 return QObject::tr( "feet (Indian 1937)", "distance" );
483
485 return QObject::tr( "feet (Indian 1962)", "distance" );
486
488 return QObject::tr( "feet (Indian 1975)", "distance" );
489
491 return QObject::tr( "feet (US survey)", "distance" );
492
494 return QObject::tr( "links", "distance" );
495
497 return QObject::tr( "links (British, Benoit 1895 A)", "distance" );
498
500 return QObject::tr( "links (British, Benoit 1895 B)", "distance" );
501
503 return QObject::tr( "links (British, Sears 1922 truncated)", "distance" );
504
506 return QObject::tr( "links (British, Sears 1922)", "distance" );
507
509 return QObject::tr( "links (Clarke's)", "distance" );
510
512 return QObject::tr( "links (US survey)", "distance" );
513
515 return QObject::tr( "yards (British, Benoit 1895 A)", "distance" );
516
518 return QObject::tr( "yards (British, Benoit 1895 B)", "distance" );
519
521 return QObject::tr( "yards (British, Sears 1922 truncated)", "distance" );
522
524 return QObject::tr( "yards (British, Sears 1922)", "distance" );
525
527 return QObject::tr( "yards (Clarke's)", "distance" );
528
530 return QObject::tr( "yards (Indian)", "distance" );
531
533 return QObject::tr( "yards (Indian 1937)", "distance" );
534
536 return QObject::tr( "yards (Indian 1962)", "distance" );
537
539 return QObject::tr( "yards (Indian 1975)", "distance" );
540
542 return QObject::tr( "miles (US survey)", "distance" );
543
545 return QObject::tr( "fathoms", "distance" );
546
548 return QObject::tr( "meters (German legal)", "distance" );
549 }
550 return QString();
551}
552
554{
555 switch ( unit )
556 {
558 return QObject::tr( "mm", "render" );
559
561 return QObject::tr( "map units", "render" );
562
564 return QObject::tr( "px", "render" );
565
567 return QObject::tr( "%", "render" );
568
570 return QObject::tr( "pt", "render" );
571
573 return QObject::tr( "in", "render" );
574
576 return QObject::tr( "unknown", "render" );
577
579 return QObject::tr( "m", "render" );
580
581 }
582
583 return QString();
584}
585
587{
588 switch ( unit )
589 {
591 return QObject::tr( "m", "distance" );
592
594 return QObject::tr( "km", "distance" );
595
610 return QObject::tr( "ft", "distance" );
611
622 return QObject::tr( "yd", "distance" );
623
626 return QObject::tr( "mi", "distance" );
627
629 return QObject::tr( "deg", "distance" );
630
632 return QObject::tr( "cm", "distance" );
633
635 return QObject::tr( "mm", "distance" );
636
638 return QObject::tr( "in", "distance" );
639
641 return QString();
642
644 return QObject::tr( "NM", "distance" );
645
653 return QObject::tr( "ch", "distance" );
654
662 return QObject::tr( "lk", "distance" );
663
665 return QObject::tr( "f", "distance" );
666
668 return QObject::tr( "glm", "distance" );
669
670 }
671 return QString();
672}
673
674/***************************************************************************
675 * This class is considered CRITICAL and any change MUST be accompanied with
676 * full unit tests in test_qgsunittypes.py.
677 * See details in QEP #17
678 ****************************************************************************/
679
681{
682 const QString normalized = string.trimmed().toLower();
683
684 if ( ok )
685 *ok = true;
686
687 for ( const Qgis::DistanceUnit unit :
688 {
739 } )
740 {
741 if ( normalized.compare( toString( unit ), Qt::CaseInsensitive ) == 0 )
742 return unit;
743 }
744
745 if ( ok )
746 *ok = false;
747
749}
750
751/***************************************************************************
752 * This class is considered CRITICAL and any change MUST be accompanied with
753 * full unit tests in test_qgsunittypes.py.
754 * See details in QEP #17
755 ****************************************************************************/
756
758{
759 // values are from the EPSG units database:
760 switch ( unit )
761 {
763 return 1.0;
765 return 1000.0;
767 return 0.3048;
769 return 1852.0;
771 return 0.9144;
773 return 1609.344;
775 return 111319.49079327358;
777 return 0.01;
779 return 0.001;
781 return 0.0254;
783 return 20.1168;
785 return 20.1167824;
787 return 20.116782494376;
789 return 20.116756;
791 return 20.116765121553;
793 return 20.1166195164;
795 return 20.11684023368;
797 return 0.30480083333333;
799 return 0.3048007491;
801 return 0.30479973333333;
803 return 0.30479973476327;
805 return 0.30479933333333;
807 return 0.30479947153868;
809 return 0.3047972654;
811 return 0.30479971018151;
813 return 0.30479951024815;
815 return 0.30479841;
817 return 0.3047996;
819 return 0.3047995;
821 return 0.30480060960122;
823 return 0.201168;
825 return 0.201167824;
827 return 0.20116782494376;
829 return 0.20116756;
831 return 0.20116765121553;
833 return 0.201166195164;
835 return 0.2011684023368;
837 return 0.9143992;
839 return 0.91439920428981;
841 return 0.914398;
843 return 0.91439841461603;
845 return 0.9143917962;
847 return 0.91439853074444;
849 return 0.91439523;
851 return 0.9143988;
853 return 0.9143985;
855 return 1609.3472186944;
857 return 1.8288;
859 return 1;
861 return 1.0000135965;
862 }
863 return 1;
864}
865
867{
868 if ( fromUnit == toUnit || fromUnit == Qgis::DistanceUnit::Unknown || toUnit == Qgis::DistanceUnit::Unknown )
869 return 1.0;
870
871 constexpr double FEET_TO_INCHES = 12;
872 constexpr double YARDS_TO_FEET = 3.0;
873
874 // Calculate the conversion factor between the specified units
875
876 // special cases, where we don't go through meters as an intermediate unit:
877 switch ( fromUnit )
878 {
880 {
881 switch ( toUnit )
882 {
884 return FEET_TO_INCHES;
886 return 1.0 / YARDS_TO_FEET;
887 default:
888 break;
889 }
890
891 break;
892 }
894 {
895 switch ( toUnit )
896 {
898 return YARDS_TO_FEET;
900 return YARDS_TO_FEET * FEET_TO_INCHES;
901 default:
902 break;
903 }
904
905 break;
906 }
907
909 {
910 switch ( toUnit )
911 {
913 return 1.0 / FEET_TO_INCHES;
915 return 1.0 / ( YARDS_TO_FEET * FEET_TO_INCHES );
916 default:
917 break;
918 }
919
920 break;
921 }
922
923 default:
924 break;
925 }
926
927 return distanceUnitToMeter( fromUnit ) / distanceUnitToMeter( toUnit );
928}
929
931{
932 switch ( unit )
933 {
935 return QStringLiteral( "m2" );
937 return QStringLiteral( "km2" );
939 return QStringLiteral( "ft2" );
941 return QStringLiteral( "y2" );
943 return QStringLiteral( "mi2" );
945 return QStringLiteral( "ha" );
947 return QStringLiteral( "ac" );
949 return QStringLiteral( "nm2" );
951 return QStringLiteral( "deg2" );
953 return QStringLiteral( "cm2" );
955 return QStringLiteral( "mm2" );
957 return QStringLiteral( "in2" );
959 return QStringLiteral( "<unknown>" );
960 }
961 return QString();
962}
963
964Qgis::AreaUnit QgsUnitTypes::decodeAreaUnit( const QString &string, bool *ok )
965{
966 const QString normalized = string.trimmed().toLower();
967
968 if ( ok )
969 *ok = true;
970
971 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareMeters ) )
973 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareKilometers ) )
975 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareFeet ) )
977 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareYards ) )
979 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareMiles ) )
981 if ( normalized == encodeUnit( Qgis::AreaUnit::Hectares ) )
983 if ( normalized == encodeUnit( Qgis::AreaUnit::Acres ) )
985 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareNauticalMiles ) )
987 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareDegrees ) )
989 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareCentimeters ) )
991 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareMillimeters ) )
993 if ( normalized == encodeUnit( Qgis::AreaUnit::SquareInches ) )
995 if ( normalized == encodeUnit( Qgis::AreaUnit::Unknown ) )
997
998 if ( ok )
999 *ok = false;
1000
1002}
1003
1005{
1006 switch ( unit )
1007 {
1009 return QObject::tr( "square meters", "area" );
1011 return QObject::tr( "square kilometers", "area" );
1013 return QObject::tr( "square feet", "area" );
1015 return QObject::tr( "square yards", "area" );
1017 return QObject::tr( "square miles", "area" );
1019 return QObject::tr( "hectares", "area" );
1021 return QObject::tr( "acres", "area" );
1023 return QObject::tr( "square nautical miles", "area" );
1025 return QObject::tr( "square degrees", "area" );
1027 return QObject::tr( "square millimeters", "area" );
1029 return QObject::tr( "square centimeters", "area" );
1031 return QObject::tr( "square inches", "area" );
1033 return QObject::tr( "<unknown>", "area" );
1034 }
1035 return QString();
1036}
1037
1039{
1040 switch ( unit )
1041 {
1043 return QObject::tr( "m²", "area" );
1045 return QObject::tr( "km²", "area" );
1047 return QObject::tr( "ft²", "area" );
1049 return QObject::tr( "yd²", "area" );
1051 return QObject::tr( "mi²", "area" );
1053 return QObject::tr( "ha", "area" );
1055 return QObject::tr( "ac", "area" );
1057 return QObject::tr( "NM²", "area" );
1059 return QObject::tr( "deg²", "area" );
1061 return QObject::tr( "cm²", "area" );
1063 return QObject::tr( "mm²", "area" );
1065 return QObject::tr( "in²", "area" );
1067 return QString();
1068 }
1069 return QString();
1070}
1071
1072Qgis::AreaUnit QgsUnitTypes::stringToAreaUnit( const QString &string, bool *ok )
1073{
1074 const QString normalized = string.trimmed().toLower();
1075
1076 if ( ok )
1077 *ok = true;
1078
1079 if ( normalized == toString( Qgis::AreaUnit::SquareMeters ) )
1081 if ( normalized == toString( Qgis::AreaUnit::SquareKilometers ) )
1083 if ( normalized == toString( Qgis::AreaUnit::SquareFeet ) )
1085 if ( normalized == toString( Qgis::AreaUnit::SquareYards ) )
1087 if ( normalized == toString( Qgis::AreaUnit::SquareMiles ) )
1089 if ( normalized == toString( Qgis::AreaUnit::Hectares ) )
1091 if ( normalized == toString( Qgis::AreaUnit::Acres ) )
1092 return Qgis::AreaUnit::Acres;
1093 if ( normalized == toString( Qgis::AreaUnit::SquareNauticalMiles ) )
1095 if ( normalized == toString( Qgis::AreaUnit::SquareDegrees ) )
1097 if ( normalized == toString( Qgis::AreaUnit::SquareMillimeters ) )
1099 if ( normalized == toString( Qgis::AreaUnit::SquareCentimeters ) )
1101 if ( normalized == toString( Qgis::AreaUnit::SquareInches ) )
1103 if ( normalized == toString( Qgis::AreaUnit::Unknown ) )
1105 if ( ok )
1106 *ok = false;
1107
1109}
1110
1112{
1113#define KM2_TO_M2 1000000.0
1114#define CM2_TO_M2 0.0001
1115#define MM2_TO_M2 0.000001
1116#define FT2_TO_M2 0.09290304
1117#define IN2_TO_M2 0.00064516
1118#define YD2_TO_M2 0.83612736
1119#define MI2_TO_M2 2589988.110336
1120#define HA_TO_M2 10000.0
1121#define AC_TO_FT2 43560.0
1122#define DEG2_TO_M2 12392029030.5
1123#define NM2_TO_M2 3429904.0
1124
1125 // Calculate the conversion factor between the specified units
1126 switch ( fromUnit )
1127 {
1129 {
1130 switch ( toUnit )
1131 {
1133 return 1.0;
1135 return 1.0 / KM2_TO_M2;
1137 return 1.0 / FT2_TO_M2;
1139 return 1.0 / YD2_TO_M2;
1141 return 1.0 / MI2_TO_M2;
1143 return 1.0 / HA_TO_M2;
1145 return 1.0 / AC_TO_FT2 / FT2_TO_M2;
1147 return 1.0 / NM2_TO_M2;
1149 return 1.0 / DEG2_TO_M2;
1151 return 1.0 / CM2_TO_M2;
1153 return 1.0 / MM2_TO_M2;
1155 return 1.0 / IN2_TO_M2;
1157 break;
1158 }
1159
1160 break;
1161 }
1163 {
1164 switch ( toUnit )
1165 {
1167 return KM2_TO_M2;
1169 return 1.0;
1171 return KM2_TO_M2 / FT2_TO_M2;
1173 return KM2_TO_M2 / YD2_TO_M2;
1175 return KM2_TO_M2 / MI2_TO_M2;
1177 return KM2_TO_M2 / HA_TO_M2;
1179 return KM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1181 return KM2_TO_M2 / NM2_TO_M2;
1183 return KM2_TO_M2 / DEG2_TO_M2;
1185 return KM2_TO_M2 / CM2_TO_M2;
1187 return KM2_TO_M2 / MM2_TO_M2;
1189 return KM2_TO_M2 / IN2_TO_M2;
1191 break;
1192 }
1193
1194 break;
1195 }
1197 {
1198 switch ( toUnit )
1199 {
1201 return FT2_TO_M2;
1203 return FT2_TO_M2 / KM2_TO_M2;
1205 return 1.0;
1207 return FT2_TO_M2 / YD2_TO_M2;
1209 return FT2_TO_M2 / MI2_TO_M2;
1211 return FT2_TO_M2 / HA_TO_M2;
1213 return 1.0 / AC_TO_FT2;
1215 return FT2_TO_M2 / NM2_TO_M2;
1217 return FT2_TO_M2 / DEG2_TO_M2;
1219 return FT2_TO_M2 / CM2_TO_M2;
1221 return FT2_TO_M2 / MM2_TO_M2;
1223 return FT2_TO_M2 / IN2_TO_M2;
1225 break;
1226 }
1227
1228 break;
1229 }
1230
1232 {
1233 switch ( toUnit )
1234 {
1236 return YD2_TO_M2;
1238 return YD2_TO_M2 / KM2_TO_M2;
1240 return YD2_TO_M2 / FT2_TO_M2;
1242 return 1.0;
1244 return YD2_TO_M2 / MI2_TO_M2;
1246 return YD2_TO_M2 / HA_TO_M2;
1248 return YD2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1250 return YD2_TO_M2 / NM2_TO_M2;
1252 return YD2_TO_M2 / DEG2_TO_M2;
1254 return YD2_TO_M2 / CM2_TO_M2;
1256 return YD2_TO_M2 / MM2_TO_M2;
1258 return YD2_TO_M2 / IN2_TO_M2;
1260 break;
1261 }
1262 break;
1263 }
1264
1266 {
1267 switch ( toUnit )
1268 {
1270 return MI2_TO_M2;
1272 return MI2_TO_M2 / KM2_TO_M2;
1274 return MI2_TO_M2 / FT2_TO_M2;
1276 return MI2_TO_M2 / YD2_TO_M2;
1278 return 1.0;
1280 return MI2_TO_M2 / HA_TO_M2;
1282 return MI2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1284 return MI2_TO_M2 / NM2_TO_M2;
1286 return MI2_TO_M2 / DEG2_TO_M2;
1288 return MI2_TO_M2 / CM2_TO_M2;
1290 return MI2_TO_M2 / MM2_TO_M2;
1292 return MI2_TO_M2 / IN2_TO_M2;
1294 break;
1295 }
1296
1297 break;
1298 }
1299
1301 {
1302 switch ( toUnit )
1303 {
1305 return HA_TO_M2;
1307 return HA_TO_M2 / KM2_TO_M2;
1309 return HA_TO_M2 / FT2_TO_M2;
1311 return HA_TO_M2 / YD2_TO_M2;
1313 return HA_TO_M2 / MI2_TO_M2;
1315 return 1.0;
1317 return HA_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1319 return HA_TO_M2 / NM2_TO_M2;
1321 return HA_TO_M2 / DEG2_TO_M2;
1323 return HA_TO_M2 / CM2_TO_M2;
1325 return HA_TO_M2 / MM2_TO_M2;
1327 return HA_TO_M2 / IN2_TO_M2;
1329 break;
1330 }
1331
1332 break;
1333 }
1334
1336 {
1337 switch ( toUnit )
1338 {
1340 return AC_TO_FT2 * FT2_TO_M2;
1342 return AC_TO_FT2 * FT2_TO_M2 / KM2_TO_M2;
1344 return AC_TO_FT2;
1346 return AC_TO_FT2 * FT2_TO_M2 / YD2_TO_M2;
1348 return AC_TO_FT2 * FT2_TO_M2 / MI2_TO_M2;
1350 return AC_TO_FT2 * FT2_TO_M2 / HA_TO_M2;
1352 return 1.0;
1354 return AC_TO_FT2 * FT2_TO_M2 / NM2_TO_M2;
1356 return AC_TO_FT2 * FT2_TO_M2 / DEG2_TO_M2;
1358 return AC_TO_FT2 * FT2_TO_M2 / CM2_TO_M2;
1360 return AC_TO_FT2 * FT2_TO_M2 / MM2_TO_M2;
1362 return AC_TO_FT2 * FT2_TO_M2 / IN2_TO_M2;
1364 break;
1365 }
1366
1367 break;
1368 }
1369
1371 {
1372 switch ( toUnit )
1373 {
1375 return NM2_TO_M2;
1377 return NM2_TO_M2 / KM2_TO_M2;
1379 return NM2_TO_M2 / FT2_TO_M2;
1381 return NM2_TO_M2 / YD2_TO_M2;
1383 return NM2_TO_M2 / MI2_TO_M2;
1385 return NM2_TO_M2 / HA_TO_M2;
1387 return NM2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1389 return 1.0;
1391 return NM2_TO_M2 / DEG2_TO_M2;
1393 return NM2_TO_M2 / CM2_TO_M2;
1395 return NM2_TO_M2 / MM2_TO_M2;
1397 return NM2_TO_M2 / IN2_TO_M2;
1399 break;
1400 }
1401
1402 break;
1403 }
1404
1406 {
1407 switch ( toUnit )
1408 {
1410 return DEG2_TO_M2;
1412 return DEG2_TO_M2 / KM2_TO_M2;
1414 return DEG2_TO_M2 / FT2_TO_M2;
1416 return DEG2_TO_M2 / YD2_TO_M2;
1418 return DEG2_TO_M2 / MI2_TO_M2;
1420 return DEG2_TO_M2 / HA_TO_M2;
1422 return DEG2_TO_M2 / FT2_TO_M2 / AC_TO_FT2;
1424 return DEG2_TO_M2 / NM2_TO_M2;
1426 return 1.0;
1428 return DEG2_TO_M2 / CM2_TO_M2;
1430 return DEG2_TO_M2 / MM2_TO_M2;
1432 return DEG2_TO_M2 / IN2_TO_M2;
1434 break;
1435 }
1436
1437 break;
1438 }
1439
1441 {
1442 switch ( toUnit )
1443 {
1445 return MM2_TO_M2;
1447 return MM2_TO_M2 / KM2_TO_M2;
1449 return MM2_TO_M2 / FT2_TO_M2;
1451 return MM2_TO_M2 / YD2_TO_M2;
1453 return MM2_TO_M2 / MI2_TO_M2;
1455 return MM2_TO_M2 / HA_TO_M2;
1457 return MM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1459 return MM2_TO_M2 / NM2_TO_M2;
1461 return MM2_TO_M2 / DEG2_TO_M2;
1463 return MM2_TO_M2 / CM2_TO_M2;
1465 return 1.0;
1467 return MM2_TO_M2 / IN2_TO_M2;
1469 break;
1470 }
1471
1472 break;
1473 }
1475 {
1476 switch ( toUnit )
1477 {
1479 return CM2_TO_M2;
1481 return CM2_TO_M2 / KM2_TO_M2;
1483 return CM2_TO_M2 / FT2_TO_M2;
1485 return CM2_TO_M2 / YD2_TO_M2;
1487 return CM2_TO_M2 / MI2_TO_M2;
1489 return CM2_TO_M2 / HA_TO_M2;
1491 return CM2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1493 return CM2_TO_M2 / NM2_TO_M2;
1495 return CM2_TO_M2 / DEG2_TO_M2;
1497 return 1.0;
1499 return CM2_TO_M2 / MM2_TO_M2;
1501 return CM2_TO_M2 / IN2_TO_M2;
1503 break;
1504 }
1505
1506 break;
1507 }
1509 {
1510 switch ( toUnit )
1511 {
1513 return IN2_TO_M2;
1515 return IN2_TO_M2 / KM2_TO_M2;
1517 return IN2_TO_M2 / FT2_TO_M2;
1519 return IN2_TO_M2 / YD2_TO_M2;
1521 return IN2_TO_M2 / MI2_TO_M2;
1523 return IN2_TO_M2 / HA_TO_M2;
1525 return IN2_TO_M2 / AC_TO_FT2 / FT2_TO_M2;
1527 return IN2_TO_M2 / NM2_TO_M2;
1529 return IN2_TO_M2 / DEG2_TO_M2;
1531 return IN2_TO_M2 / CM2_TO_M2;
1533 return IN2_TO_M2 / MM2_TO_M2;
1535 return 1;
1537 break;
1538 }
1539
1540 break;
1541 }
1543 break;
1544 }
1545 return 1.0;
1546}
1547
1549{
1550 switch ( distanceUnit )
1551 {
1555
1558
1561
1564
1604
1607
1611
1614
1617
1620
1623 }
1624
1626}
1627
1670
1672{
1673 switch ( unit )
1674 {
1676 return QStringLiteral( "s" );
1678 return QStringLiteral( "ms" );
1680 return QStringLiteral( "min" );
1682 return QStringLiteral( "h" );
1684 return QStringLiteral( "d" );
1686 return QStringLiteral( "wk" );
1688 return QStringLiteral( "mon" );
1690 return QStringLiteral( "y" );
1692 return QStringLiteral( "dec" );
1694 return QStringLiteral( "c" );
1696 return QStringLiteral( "xxx" );
1698 return QStringLiteral( "<unknown>" );
1699 }
1700 return QString();
1701}
1702
1704{
1705 const QString normalized = string.trimmed().toLower();
1706
1707 if ( ok )
1708 *ok = true;
1709
1710 if ( normalized == encodeUnit( Qgis::TemporalUnit::Seconds ) )
1712 if ( normalized == encodeUnit( Qgis::TemporalUnit::Milliseconds ) )
1714 if ( normalized == encodeUnit( Qgis::TemporalUnit::Minutes ) )
1716 if ( normalized == encodeUnit( Qgis::TemporalUnit::Hours ) )
1718 if ( normalized == encodeUnit( Qgis::TemporalUnit::Days ) )
1720 if ( normalized == encodeUnit( Qgis::TemporalUnit::Weeks ) )
1722 if ( normalized == encodeUnit( Qgis::TemporalUnit::Months ) )
1724 if ( normalized == encodeUnit( Qgis::TemporalUnit::Years ) )
1726 if ( normalized == encodeUnit( Qgis::TemporalUnit::Decades ) )
1728 if ( normalized == encodeUnit( Qgis::TemporalUnit::Centuries ) )
1730 if ( normalized == encodeUnit( Qgis::TemporalUnit::IrregularStep ) )
1732 if ( normalized == encodeUnit( Qgis::TemporalUnit::Unknown ) )
1734
1735 if ( ok )
1736 *ok = false;
1737
1739}
1740
1742{
1743 switch ( unit )
1744 {
1746 return QObject::tr( "seconds", "temporal" );
1748 return QObject::tr( "milliseconds", "temporal" );
1750 return QObject::tr( "minutes", "temporal" );
1752 return QObject::tr( "hours", "temporal" );
1754 return QObject::tr( "days", "temporal" );
1756 return QObject::tr( "weeks", "temporal" );
1758 return QObject::tr( "months", "temporal" );
1760 return QObject::tr( "years", "temporal" );
1762 return QObject::tr( "decades", "temporal" );
1764 return QObject::tr( "centuries", "temporal" );
1766 return QObject::tr( "steps", "temporal" );
1768 return QObject::tr( "<unknown>", "temporal" );
1769 }
1770 return QString();
1771}
1772
1774{
1775 switch ( unit )
1776 {
1778 return QObject::tr( "s", "temporal" );
1780 return QObject::tr( "ms", "temporal" );
1782 return QObject::tr( "min", "temporal" );
1784 return QObject::tr( "h", "temporal" );
1786 return QObject::tr( "d", "temporal" );
1788 return QObject::tr( "wk", "temporal" );
1790 return QObject::tr( "mon", "temporal" );
1792 return QObject::tr( "y", "temporal" );
1794 return QObject::tr( "dec", "temporal" );
1796 return QObject::tr( "cen", "temporal" );
1798 return QObject::tr( "steps", "temporal" );
1800 return QObject::tr( "<unknown>", "temporal" );
1801 }
1802 return QString();
1803}
1804
1806{
1807 const QString normalized = string.trimmed().toLower();
1808
1809 if ( ok )
1810 *ok = true;
1811
1812 if ( normalized == toString( Qgis::TemporalUnit::Seconds ) )
1814 if ( normalized == toString( Qgis::TemporalUnit::Milliseconds ) )
1816 if ( normalized == toString( Qgis::TemporalUnit::Minutes ) )
1818 if ( normalized == toString( Qgis::TemporalUnit::Hours ) )
1820 if ( normalized == toString( Qgis::TemporalUnit::Days ) )
1822 if ( normalized == toString( Qgis::TemporalUnit::Weeks ) )
1824 if ( normalized == toString( Qgis::TemporalUnit::Months ) )
1826 if ( normalized == toString( Qgis::TemporalUnit::Years ) )
1828 if ( normalized == toString( Qgis::TemporalUnit::Decades ) )
1830 if ( normalized == toString( Qgis::TemporalUnit::Centuries ) )
1832 if ( normalized == toString( Qgis::TemporalUnit::IrregularStep ) )
1834 if ( normalized == toString( Qgis::TemporalUnit::Unknown ) )
1836
1837 if ( ok )
1838 *ok = false;
1839
1841}
1842
1844{
1845 switch ( fromUnit )
1846 {
1848 {
1849 switch ( toUnit )
1850 {
1852 return 1.0;
1854 return 1000.0;
1856 return 1 / 60.0;
1858 return 1 / 3600.0;
1860 return 1 / 86400.0;
1862 return 1 / 604800.0;
1864 return 1 / 2592000.0;
1866 return 1 / 31557600.0;
1868 return 1 / 315576000.0;
1870 return 1 / 3155760000.0;
1873 return 1.0;
1874 }
1875 break;
1876 }
1878 {
1879 switch ( toUnit )
1880 {
1882 return 1 / 1000.0;
1884 return 1.0;
1886 return 1 / 60000.0;
1888 return 1 / 3600000.0;
1890 return 1 / 86400000.0;
1892 return 1 / 604800000.0;
1894 return 1 / 2592000000.0;
1896 return 1 / 31557600000.0;
1898 return 1 / 315576000000.0;
1900 return 1 / 3155760000000.0;
1903 return 1.0;
1904 }
1905 break;
1906 }
1908 {
1909 switch ( toUnit )
1910 {
1912 return 60.0;
1914 return 60000.0;
1916 return 1;
1918 return 1 / 60.0;
1920 return 1 / 1440.0;
1922 return 1 / 10080.0;
1924 return 1 / 43200.0;
1926 return 1 / 525960.0;
1928 return 1 / 5259600.0;
1930 return 1 / 52596000.0;
1933 return 1.0;
1934 }
1935 break;
1936 }
1938 {
1939 switch ( toUnit )
1940 {
1942 return 3600.0;
1944 return 3600000.0;
1946 return 60;
1948 return 1;
1950 return 1 / 24.0;
1952 return 1 / 168.0;
1954 return 1 / 720.0;
1956 return 1 / 8766.0;
1958 return 1 / 87660.0;
1960 return 1 / 876600.0;
1963 return 1.0;
1964 }
1965 break;
1966 }
1968 {
1969 switch ( toUnit )
1970 {
1972 return 86400.0;
1974 return 86400000.0;
1976 return 1440;
1978 return 24;
1980 return 1;
1982 return 1 / 7.0;
1984 return 1 / 30.0;
1986 return 1 / 365.25;
1988 return 1 / 3652.5;
1990 return 1 / 36525.0;
1993 return 1.0;
1994 }
1995 break;
1996 }
1998 {
1999 switch ( toUnit )
2000 {
2002 return 604800.0;
2004 return 604800000.0;
2006 return 10080;
2008 return 168;
2010 return 7;
2012 return 1;
2014 return 7 / 30.0;
2016 return 7 / 365.25;
2018 return 7 / 3652.5;
2020 return 7 / 36525.0;
2023 return 1.0;
2024 }
2025 break;
2026 }
2028 {
2029 switch ( toUnit )
2030 {
2032 return 2592000.0;
2034 return 2592000000.0;
2036 return 43200;
2038 return 720;
2040 return 30;
2042 return 30 / 7.0;
2044 return 1;
2046 return 30 / 365.25;
2048 return 30 / 3652.5;
2050 return 30 / 36525.0;
2053 return 1.0;
2054 }
2055 break;
2056 }
2058 {
2059 switch ( toUnit )
2060 {
2062 return 31557600.0;
2064 return 31557600000.0;
2066 return 525960.0;
2068 return 8766.0;
2070 return 365.25;
2072 return 365.25 / 7.0;
2074 return 365.25 / 30.0;
2076 return 1;
2078 return 0.1;
2080 return 0.01;
2083 return 1.0;
2084 }
2085 break;
2086 }
2088 {
2089 switch ( toUnit )
2090 {
2092 return 315576000.0;
2094 return 315576000000.0;
2096 return 5259600.0;
2098 return 87660.0;
2100 return 3652.5;
2102 return 3652.5 / 7.0;
2104 return 3652.5 / 30.0;
2106 return 10;
2108 return 1;
2110 return 0.1;
2113 return 1.0;
2114 }
2115 break;
2116 }
2117
2119 {
2120 switch ( toUnit )
2121 {
2123 return 3155760000.0;
2125 return 3155760000000.0;
2127 return 52596000.0;
2129 return 876600.0;
2131 return 36525;
2133 return 36525 / 7.0;
2135 return 36525 / 30.0;
2137 return 100;
2139 return 10;
2141 return 1;
2144 return 1.0;
2145 }
2146 break;
2147 }
2148
2151 {
2152 return 1.0;
2153 }
2154 }
2155 return 1.0;
2156}
2157
2158Qgis::VolumeUnit QgsUnitTypes::decodeVolumeUnit( const QString &string, bool *ok )
2159{
2160 const QString normalized = string.trimmed().toLower();
2161
2162 if ( ok )
2163 *ok = true;
2164
2165 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicMeters ) )
2167 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicFeet ) )
2169 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicYards ) )
2171 if ( normalized == encodeUnit( Qgis::VolumeUnit::Barrel ) )
2173 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicDecimeter ) )
2175 if ( normalized == encodeUnit( Qgis::VolumeUnit::Liters ) )
2177 if ( normalized == encodeUnit( Qgis::VolumeUnit::GallonUS ) )
2179 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicInch ) )
2181 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicCentimeter ) )
2183 if ( normalized == encodeUnit( Qgis::VolumeUnit::CubicDegrees ) )
2185 if ( normalized == encodeUnit( Qgis::VolumeUnit::Unknown ) )
2187
2188 if ( ok )
2189 *ok = false;
2190
2192}
2193
2195{
2196 switch ( unit )
2197 {
2199 return QObject::tr( "cubic meters", "volume" );
2201 return QObject::tr( "cubic feet", "volume" );
2203 return QObject::tr( "cubic yards", "volume" );
2205 return QObject::tr( "barrels", "volume" );
2207 return QObject::tr( "cubic decimeters", "volume" );
2209 return QObject::tr( "liters", "volume" );
2211 return QObject::tr( "gallons", "volume" );
2213 return QObject::tr( "cubic inches", "volume" );
2215 return QObject::tr( "cubic centimeters", "volume" );
2217 return QObject::tr( "cubic degrees", "volume" );
2219 return QObject::tr( "<unknown>", "volume" );
2220 }
2221 return QString();
2222}
2223
2225{
2226 switch ( unit )
2227 {
2229 return QObject::tr( "m³", "volume" );
2231 return QObject::tr( "ft³", "volume" );
2233 return QObject::tr( "yds³", "volume" );
2235 return QObject::tr( "bbl", "volume" );
2237 return QObject::tr( "dm³", "volume" );
2239 return QObject::tr( "l", "volume" );
2241 return QObject::tr( "gal", "volume" );
2243 return QObject::tr( "in³", "volume" );
2245 return QObject::tr( "cm³", "volume" );
2247 return QObject::tr( "deg³", "volume" );
2249 return QObject::tr( "<unknown>", "volume" );
2250 }
2251 return QString();
2252
2253}
2254
2255Qgis::VolumeUnit QgsUnitTypes::stringToVolumeUnit( const QString &string, bool *ok )
2256{
2257 const QString normalized = string.trimmed().toLower();
2258
2259 if ( ok )
2260 *ok = true;
2261
2262 if ( normalized == toString( Qgis::VolumeUnit::CubicMeters ) )
2264 if ( normalized == toString( Qgis::VolumeUnit::CubicFeet ) )
2266 if ( normalized == toString( Qgis::VolumeUnit::CubicYards ) )
2268 if ( normalized == toString( Qgis::VolumeUnit::Barrel ) )
2270 if ( normalized == toString( Qgis::VolumeUnit::CubicDecimeter ) )
2272 if ( normalized == toString( Qgis::VolumeUnit::Liters ) )
2274 if ( normalized == toString( Qgis::VolumeUnit::GallonUS ) )
2276 if ( normalized == toString( Qgis::VolumeUnit::CubicInch ) )
2278 if ( normalized == toString( Qgis::VolumeUnit::CubicCentimeter ) )
2280 if ( normalized == toString( Qgis::VolumeUnit::CubicDegrees ) )
2282 if ( normalized == toString( Qgis::VolumeUnit::Unknown ) )
2284
2285 if ( ok )
2286 *ok = false;
2287
2289}
2290
2291#define DEG2_TO_M3 1379474361572186.2
2293{
2294 // cloned branches are intentional here for improved readability
2295 // NOLINTBEGIN(bugprone-branch-clone)
2296 switch ( fromUnit )
2297 {
2299 {
2300 switch ( toUnit )
2301 {
2303 return 1.0;
2305 return 35.314666572222;
2307 return 1.307950613786;
2309 return 6.2898107438466;
2311 return 1000;
2313 return 1000;
2315 return 264.17205124156;
2317 return 61023.7438368;
2319 return 1000000;
2321 return 1 / DEG2_TO_M3; // basically meaningless!
2323 return 1.0;
2324 }
2325 break;
2326 }
2328 {
2329 switch ( toUnit )
2330 {
2332 return 0.028316846592;
2334 return 1.0;
2336 return 0.037037037;
2338 return 0.178107622;
2340 return 28.31685;
2342 return 28.31685;
2344 return 7.480519954;
2346 return 1728.000629765;
2348 return 28316.85;
2350 return 0.028316846592 / DEG2_TO_M3; // basically meaningless!
2352 return 1.0;
2353 }
2354 break;
2355 }
2357 {
2358 switch ( toUnit )
2359 {
2361 return 0.764554900;
2363 return 26.999998234;
2365 return 1.0;
2367 return 4.808905491;
2369 return 764.5549;
2371 return 764.5549;
2373 return 201.974025549;
2375 return 46656.013952472;
2377 return 764554.9;
2379 return 0.764554900 / DEG2_TO_M3; // basically meaningless!
2381 return 1.0;
2382 }
2383 break;
2384 }
2386 {
2387 switch ( toUnit )
2388 {
2390 return 0.158987300;
2392 return 5.614582837;
2394 return 0.207947526;
2396 return 1.0;
2398 return 158.9873;
2400 return 158.9873;
2402 return 41.999998943;
2404 return 9702.002677722;
2406 return 158987.3;
2408 return 0.158987300 / DEG2_TO_M3; // basically meaningless!
2410 return 1.0;
2411 }
2412 break;
2413 }
2416 {
2417 switch ( toUnit )
2418 {
2420 return 0.001;
2422 return 0.035314662;
2424 return 0.001307951;
2426 return 0.006289811;
2429 return 1.0;
2431 return 0.264172037;
2433 return 61.023758990;
2435 return 1000;
2437 return 0.001 / DEG2_TO_M3; // basically meaningless!
2439 return 1.0;
2440 }
2441 break;
2442 }
2444 {
2445 switch ( toUnit )
2446 {
2448 return 0.003785412;
2450 return 0.133680547;
2452 return 0.004951132;
2454 return 0.023809524;
2457 return 3.785412000;
2459 return 1.0;
2461 return 231.000069567;
2463 return 3785.412;
2465 return 0.003785412 / DEG2_TO_M3; // basically meaningless!
2467 return 1.0;
2468 }
2469 break;
2470 }
2472 {
2473 switch ( toUnit )
2474 {
2476 return 0.000016387;
2478 return 0.000578703;
2480 return 0.000021433;
2482 return 0.000103072;
2485 return 0.016387060;
2487 return 0.004329003;
2489 return 1.0;
2491 return 16.387060000;
2493 return 0.000016387 / DEG2_TO_M3; // basically meaningless!
2495 return 1.0;
2496 }
2497 break;
2498 }
2500 {
2501 switch ( toUnit )
2502 {
2504 return 0.000001;
2506 return 0.000035315;
2508 return 0.000001308;
2510 return 0.000006290;
2513 return 0.001;
2515 return 0.000264172 ;
2517 return 0.061023759;
2519 return 1.0;
2521 return 0.000001 / DEG2_TO_M3; // basically meaningless!
2523 return 1.0;
2524 }
2525 break;
2526 }
2528 if ( toUnit == Qgis::VolumeUnit::Unknown || toUnit == Qgis::VolumeUnit::CubicDegrees )
2529 return 1.0;
2530 else
2532
2534 {
2535 return 1.0;
2536 }
2537 }
2538 // NOLINTEND(bugprone-branch-clone)
2539 return 1.0;
2540}
2541
2543{
2544 // cloned branches are intentional here for improved readability
2545 // NOLINTBEGIN(bugprone-branch-clone)
2546 switch ( distanceUnit )
2547 {
2551
2554
2557
2560
2576
2588
2607
2610
2613
2616
2619 }
2620 // NOLINTEND(bugprone-branch-clone)
2621
2623}
2624
2654
2676
2678{
2679 switch ( unit )
2680 {
2682 return QStringLiteral( "m3" );
2684 return QStringLiteral( "ft3" );
2686 return QStringLiteral( "yd3" );
2688 return QStringLiteral( "bbl" );
2690 return QStringLiteral( "dm3" );
2692 return QStringLiteral( "l" );
2694 return QStringLiteral( "gal" );
2696 return QStringLiteral( "in3" );
2698 return QStringLiteral( "cm3" );
2700 return QStringLiteral( "deg3" );
2702 return QStringLiteral( "<unknown>" );
2703 }
2704 return QString();
2705}
2706
2708{
2709 switch ( unit )
2710 {
2712 return QStringLiteral( "degrees" );
2714 return QStringLiteral( "radians" );
2716 return QStringLiteral( "gon" );
2718 return QStringLiteral( "moa" );
2720 return QStringLiteral( "soa" );
2722 return QStringLiteral( "tr" );
2724 return QStringLiteral( "milliradians" );
2726 return QStringLiteral( "mil" );
2728 return QStringLiteral( "<unknown>" );
2729 }
2730 return QString();
2731}
2732
2733Qgis::AngleUnit QgsUnitTypes::decodeAngleUnit( const QString &string, bool *ok )
2734{
2735 const QString normalized = string.trimmed().toLower();
2736
2737 if ( ok )
2738 *ok = true;
2739
2740 if ( normalized == encodeUnit( Qgis::AngleUnit::Degrees ) )
2742 if ( normalized == encodeUnit( Qgis::AngleUnit::Radians ) )
2744 if ( normalized == encodeUnit( Qgis::AngleUnit::Gon ) )
2745 return Qgis::AngleUnit::Gon;
2746 if ( normalized == encodeUnit( Qgis::AngleUnit::MinutesOfArc ) )
2748 if ( normalized == encodeUnit( Qgis::AngleUnit::SecondsOfArc ) )
2750 if ( normalized == encodeUnit( Qgis::AngleUnit::Turn ) )
2751 return Qgis::AngleUnit::Turn;
2752 if ( normalized == encodeUnit( Qgis::AngleUnit::MilliradiansSI ) )
2754 if ( normalized == encodeUnit( Qgis::AngleUnit::MilNATO ) )
2756 if ( normalized == encodeUnit( Qgis::AngleUnit::Unknown ) )
2758 if ( ok )
2759 *ok = false;
2760
2762}
2763
2765{
2766 switch ( unit )
2767 {
2769 return QObject::tr( "degrees", "angle" );
2771 return QObject::tr( "radians", "angle" );
2773 return QObject::tr( "gon", "angle" );
2775 return QObject::tr( "minutes of arc", "angle" );
2777 return QObject::tr( "seconds of arc", "angle" );
2779 return QObject::tr( "turns", "angle" );
2781 return QObject::tr( "milliradians", "angle" );
2783 return QObject::tr( "mil", "angle" );
2785 return QObject::tr( "<unknown>", "angle" );
2786 }
2787 return QString();
2788}
2789
2791{
2792 // Calculate the conversion factor between the specified units
2793 switch ( fromUnit )
2794 {
2796 {
2797 switch ( toUnit )
2798 {
2800 return 1.0;
2802 return M_PI / 180.0;
2804 return 400.0 / 360.0;
2806 return 60;
2808 return 3600;
2810 return 1.0 / 360.0;
2812 return M_PI / 180.0 * 1000;
2814 return 3200.0 / 180;
2816 break;
2817 }
2818 break;
2819 }
2821 {
2822 switch ( toUnit )
2823 {
2825 return 180.0 / M_PI;
2827 return 1.0;
2829 return 200.0 / M_PI;
2831 return 60 * 180.0 / M_PI;
2833 return 3600 * 180.0 / M_PI;
2835 return 0.5 / M_PI;
2837 return 1000;
2839 return 3200.0 / M_PI;
2841 break;
2842 }
2843 break;
2844 }
2846 {
2847 switch ( toUnit )
2848 {
2850 return 360.0 / 400.0;
2852 return M_PI / 200.0;
2854 return 1.0;
2856 return 60 * 360.0 / 400.0;
2858 return 3600 * 360.0 / 400.0;
2860 return 1.0 / 400.0;
2862 return M_PI / 200.0 * 1000;
2864 return 3200.0 / 200.0;
2866 break;
2867 }
2868 break;
2869 }
2871 {
2872 switch ( toUnit )
2873 {
2875 return 1 / 60.0;
2877 return M_PI / 180.0 / 60.0;
2879 return 400.0 / 360.0 / 60.0;
2881 return 1.0;
2883 return 60.0;
2885 return 1.0 / 360.0 / 60.0;
2887 return M_PI / 180.0 / 60.0 * 1000;
2889 return 3200.0 / 180.0 / 60.0;
2891 break;
2892 }
2893 break;
2894 }
2896 {
2897 switch ( toUnit )
2898 {
2900 return 1 / 3600.0;
2902 return M_PI / 180.0 / 3600.0;
2904 return 400.0 / 360.0 / 3600.0;
2906 return 1.0 / 60.0;
2908 return 1.0;
2910 return 1.0 / 360.0 / 3600.0;
2912 return M_PI / 180.0 / 3600.0 * 1000;
2914 return 3200.0 / 180.0 / 3600.0;
2916 break;
2917 }
2918 break;
2919 }
2921 {
2922 switch ( toUnit )
2923 {
2925 return 360.0;
2927 return 2 * M_PI;
2929 return 400.0;
2931 return 360.0 * 60.0;
2933 return 360.0 * 3600.0;
2935 return 1.0;
2937 return 2 * M_PI * 1000;
2939 return 2 * 3200;
2941 break;
2942 }
2943 break;
2944 }
2946 {
2947 switch ( toUnit )
2948 {
2950 return 180.0 / M_PI / 1000;
2952 return 0.001;
2954 return 200.0 / M_PI / 1000;
2956 return 180.0 * 60.0 / M_PI / 1000;
2958 return 180.0 * 3600.0 / M_PI / 1000;
2960 return M_PI / 2 / 1000;
2962 return 1.0;
2964 return 3200.0 / 1000.0 / M_PI;
2966 break;
2967 }
2968 break;
2969 }
2970
2972 {
2973 switch ( toUnit )
2974 {
2976 return 180.0 / 3200;
2978 return M_PI / 3200;
2980 return 200.0 / 3200;
2982 return 60 * 180.0 / 3200;
2984 return 3600.0 * 180 / 3200;
2986 return 1.0 / ( 2 * 32000 );
2988 return 1000.0 * M_PI / 3200.0;
2990 return 1.0;
2992 break;
2993 }
2994 break;
2995 }
2996
2998 break;
2999 }
3000 return 1.0;
3001}
3002
3003QString QgsUnitTypes::formatAngle( double angle, int decimals, Qgis::AngleUnit unit )
3004{
3005 QString unitLabel;
3006 int decimalPlaces = 2;
3007
3008 switch ( unit )
3009 {
3011 unitLabel = QObject::tr( "°", "angle" );
3012 decimalPlaces = 0;
3013 break;
3015 unitLabel = QObject::tr( " rad", "angle" );
3016 decimalPlaces = 2;
3017 break;
3019 unitLabel = QObject::tr( " gon", "angle" );
3020 decimalPlaces = 0;
3021 break;
3023 unitLabel = QObject::tr( "′", "angle minutes" );
3024 decimalPlaces = 0;
3025 break;
3027 unitLabel = QObject::tr( "″", "angle seconds" );
3028 decimalPlaces = 0;
3029 break;
3031 unitLabel = QObject::tr( " tr", "angle turn" );
3032 decimalPlaces = 3;
3033 break;
3035 unitLabel = QObject::tr( " millirad", "angular mil SI" );
3036 decimalPlaces = 0;
3037 break;
3039 unitLabel = QObject::tr( " mil", "angular mil NATO" );
3040 decimalPlaces = 0;
3041 break;
3043 break;
3044 }
3045
3046 if ( decimals >= 0 )
3047 decimalPlaces = decimals;
3048
3049 return QStringLiteral( "%L1%2" ).arg( angle, 0, 'f', decimalPlaces ).arg( unitLabel );
3050}
3051
3052QgsUnitTypes::DistanceValue QgsUnitTypes::scaledDistance( double distance, Qgis::DistanceUnit unit, int decimals, bool keepBaseUnit )
3053{
3054 DistanceValue result;
3055
3056 // cloned branches are intentional here for improved readability
3057 // NOLINTBEGIN(bugprone-branch-clone)
3058 switch ( unit )
3059 {
3061 if ( keepBaseUnit )
3062 {
3063 result.value = qgsRound( distance, decimals );
3065 }
3066 else if ( std::fabs( distance ) > 1000.0 )
3067 {
3068 result.value = qgsRound( distance / 1000, decimals );
3070 }
3071 else if ( std::fabs( distance ) < 0.01 )
3072 {
3073 result.value = qgsRound( distance * 1000, decimals );
3075 }
3076 else if ( std::fabs( distance ) < 0.1 )
3077 {
3078
3079 result.value = qgsRound( distance * 100, decimals );
3081 }
3082 else
3083 {
3084 result.value = qgsRound( distance, decimals );
3086 }
3087 break;
3088
3090 if ( keepBaseUnit || std::fabs( distance ) >= 1.0 )
3091 {
3092 result.value = qgsRound( distance, decimals );
3094 }
3095 else
3096 {
3097 result.value = qgsRound( distance * 1000, decimals );
3099 }
3100 break;
3101
3103 if ( std::fabs( distance ) <= 5280.0 || keepBaseUnit )
3104 {
3105 result.value = qgsRound( distance, decimals );
3107 }
3108 else
3109 {
3110 result.value = qgsRound( distance / 5280.0, decimals );
3112 }
3113 break;
3114
3116 if ( std::fabs( distance ) <= 1760.0 || keepBaseUnit )
3117 {
3118 result.value = qgsRound( distance, decimals );
3120 }
3121 else
3122 {
3123 result.value = qgsRound( distance / 1760.0, decimals );
3125 }
3126 break;
3127
3129 if ( std::fabs( distance ) >= 1.0 || keepBaseUnit )
3130 {
3131 result.value = qgsRound( distance, decimals );
3133 }
3134 else
3135 {
3136 result.value = qgsRound( distance * 5280.0, decimals );
3138 }
3139 break;
3140
3142 result.value = qgsRound( distance, decimals );
3144 break;
3145
3147 result.value = qgsRound( distance, decimals );
3149 break;
3150
3152 result.value = qgsRound( distance, decimals );
3154 break;
3155
3156 default:
3157 result.value = qgsRound( distance, decimals );
3158 result.unit = unit;
3159 break;
3160 }
3161 // NOLINTEND(bugprone-branch-clone)
3162
3163 return result;
3164}
3165
3166QgsUnitTypes::AreaValue QgsUnitTypes::scaledArea( double area, Qgis::AreaUnit unit, int decimals, bool keepBaseUnit )
3167{
3169 result.value = -1.0;
3171
3172 // If we are not forced to keep the base units, switch to meter calculation
3174 {
3175 if ( keepBaseUnit )
3176 {
3177 result.value = qgsRound( area, decimals );
3179 }
3180 else
3181 {
3182 area /= 1000000.0;
3184 }
3185 }
3186 else if ( unit == Qgis::AreaUnit::SquareCentimeters )
3187 {
3188 if ( keepBaseUnit )
3189 {
3190 result.value = qgsRound( area, decimals );
3192 }
3193 else
3194 {
3195 area /= 10000.0;
3197 }
3198 }
3199
3200 // cloned branches are intentional here for improved readability
3201 // NOLINTBEGIN(bugprone-branch-clone)
3202 switch ( unit )
3203 {
3205 // handled in the if above
3206 break;
3208 // handled in the if above
3209 break;
3211 {
3212 if ( keepBaseUnit )
3213 {
3214 result.value = qgsRound( area, decimals );
3216 }
3218 {
3221 }
3223 {
3226 }
3227 else
3228 {
3229 result.value = qgsRound( area, decimals );
3231 }
3232 break;
3233 }
3234
3236 {
3237 result.value = qgsRound( area, decimals );
3239 break;
3240 }
3241
3243 {
3244 result.value = qgsRound( area, decimals );
3246 break;
3247 }
3248
3250 {
3251 if ( keepBaseUnit )
3252 {
3253 result.value = qgsRound( area, decimals );
3255 }
3257 {
3260 }
3261 else
3262 {
3263 result.value = qgsRound( area, decimals );
3265 }
3266 break;
3267 }
3268
3270 {
3271 if ( keepBaseUnit )
3272 {
3273 result.value = qgsRound( area, decimals );
3275 }
3277 {
3280 }
3281 else
3282 {
3283 result.value = qgsRound( area, decimals );
3285 }
3286 break;
3287 }
3288
3290 {
3291 result.value = qgsRound( area, decimals );
3293 break;
3294 }
3295
3297 {
3298 if ( keepBaseUnit )
3299 {
3300 result.value = qgsRound( area, decimals );
3302 }
3304 {
3307 }
3308 else
3309 {
3310 result.value = qgsRound( area, decimals );
3312 }
3313 break;
3314 }
3315
3317 {
3318 if ( keepBaseUnit )
3319 {
3320 result.value = qgsRound( area, decimals );
3321 result.unit = Qgis::AreaUnit::Acres;
3322 }
3324 {
3327 }
3328 else
3329 {
3330 result.value = qgsRound( area, decimals );
3331 result.unit = Qgis::AreaUnit::Acres;
3332 }
3333 break;
3334 }
3335
3337 {
3338 result.value = qgsRound( area, decimals );
3340 break;
3341 }
3342
3344 {
3345 result.value = qgsRound( area, decimals );
3347 break;
3348 }
3349
3351 {
3352 result.value = qgsRound( area, decimals );
3354 break;
3355 }
3356 }
3357 // NOLINTEND(bugprone-branch-clone)
3358 return result;
3359}
3360
3361
3362QString QgsUnitTypes::formatDistance( double distance, int decimals, Qgis::DistanceUnit unit, bool keepBaseUnit )
3363{
3364 const DistanceValue dist = scaledDistance( distance, unit, decimals, keepBaseUnit );
3365
3366 QString unitText;
3367
3368 if ( dist.unit != Qgis::DistanceUnit::Unknown )
3369 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( dist.unit );
3370
3371 if ( qgsDoubleNear( dist.value, 0 ) )
3372 {
3373 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( unit );
3374 return QStringLiteral( "%L1%2" ).arg( distance, 0, 'e', decimals ).arg( unitText );
3375 }
3376 else
3377 {
3378 return QStringLiteral( "%L1%2" ).arg( dist.value, 0, 'f', decimals ).arg( unitText );
3379 }
3380}
3381
3382QString QgsUnitTypes::formatArea( double area, int decimals, Qgis::AreaUnit unit, bool keepBaseUnit )
3383{
3384 const QgsUnitTypes::AreaValue areaValue = scaledArea( area, unit, decimals, keepBaseUnit );
3385
3386 QString unitText;
3387
3388 if ( areaValue.unit != Qgis::AreaUnit::Unknown )
3389 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( areaValue.unit );
3390
3391 if ( qgsDoubleNear( areaValue.value, 0 ) )
3392 {
3393 unitText = QChar( ' ' ) + QgsUnitTypes::toAbbreviatedString( unit );
3394 return QStringLiteral( "%L1%2" ).arg( area, 0, 'e', decimals ).arg( unitText );
3395 }
3396 else
3397 {
3398 return QStringLiteral( "%L1%2" ).arg( areaValue.value, 0, 'f', decimals ).arg( unitText );
3399 }
3400}
3401
3403{
3404 switch ( unit )
3405 {
3407 return QStringLiteral( "MM" );
3409 return QStringLiteral( "RenderMetersInMapUnits" );
3411 return QStringLiteral( "MapUnit" );
3413 return QStringLiteral( "Pixel" );
3415 return QStringLiteral( "Percentage" );
3417 return QStringLiteral( "Point" );
3419 return QStringLiteral( "Inch" );
3421 return QString();
3422 }
3423 return QString();
3424}
3425
3426Qgis::RenderUnit QgsUnitTypes::decodeRenderUnit( const QString &string, bool *ok )
3427{
3428 const QString normalized = string.trimmed().toLower();
3429
3430 if ( ok )
3431 *ok = true;
3432
3433 if ( normalized == encodeUnit( Qgis::RenderUnit::Millimeters ).toLower() )
3435 if ( normalized == encodeUnit( Qgis::RenderUnit::MetersInMapUnits ).toLower() )
3437 if ( normalized == QLatin1String( "meters" ) )
3439 if ( normalized == encodeUnit( Qgis::RenderUnit::MapUnits ).toLower() )
3441 if ( normalized == QLatin1String( "mapunits" ) )
3443 if ( normalized == encodeUnit( Qgis::RenderUnit::Pixels ).toLower() )
3445 if ( normalized == encodeUnit( Qgis::RenderUnit::Percentage ).toLower() )
3447 if ( normalized == QLatin1String( "percent" ) )
3449 if ( normalized == encodeUnit( Qgis::RenderUnit::Points ).toLower() )
3451 if ( normalized == QLatin1String( "points" ) )
3453 if ( normalized == encodeUnit( Qgis::RenderUnit::Inches ).toLower() )
3455
3456 if ( ok )
3457 *ok = false;
3458
3459 // millimeters are default
3461}
3462
3464{
3465 switch ( unit )
3466 {
3468 return QObject::tr( "millimeters", "render" );
3469
3471 return QObject::tr( "meters at scale", "render" );
3472
3474 return QObject::tr( "map units", "render" );
3475
3477 return QObject::tr( "pixels", "render" );
3478
3480 return QObject::tr( "percent", "render" );
3481
3483 return QObject::tr( "points", "render" );
3484
3486 return QObject::tr( "inches", "render" );
3487
3489 return QObject::tr( "<unknown>", "render" );
3490
3491 }
3492 return QString();
3493}
3494
3495
3496
3498{
3499 switch ( unit )
3500 {
3502 return QStringLiteral( "cm" );
3504 return QStringLiteral( "m" );
3506 return QStringLiteral( "in" );
3508 return QStringLiteral( "ft" );
3510 return QStringLiteral( "pt" );
3512 return QStringLiteral( "pi" );
3514 return QStringLiteral( "px" );
3516 return QStringLiteral( "mm" );
3517 }
3518 return QString();
3519}
3520
3521Qgis::LayoutUnit QgsUnitTypes::decodeLayoutUnit( const QString &string, bool *ok )
3522{
3523 const QString normalized = string.trimmed().toLower();
3524
3525 if ( ok )
3526 *ok = true;
3527
3528 if ( normalized == encodeUnit( Qgis::LayoutUnit::Millimeters ).toLower() )
3530 if ( normalized == encodeUnit( Qgis::LayoutUnit::Centimeters ).toLower() )
3532 if ( normalized == encodeUnit( Qgis::LayoutUnit::Meters ).toLower() )
3534 if ( normalized == encodeUnit( Qgis::LayoutUnit::Inches ).toLower() )
3536 if ( normalized == encodeUnit( Qgis::LayoutUnit::Feet ).toLower() )
3538 if ( normalized == encodeUnit( Qgis::LayoutUnit::Points ).toLower() )
3540 if ( normalized == encodeUnit( Qgis::LayoutUnit::Picas ).toLower() )
3542 if ( normalized == encodeUnit( Qgis::LayoutUnit::Pixels ).toLower() )
3544
3545 if ( ok )
3546 *ok = false;
3547
3548 // millimeters are default
3550}
3551
3571
3573{
3574 switch ( unit )
3575 {
3577 return QObject::tr( "px" );
3579 return QObject::tr( "mm" );
3581 return QObject::tr( "cm" );
3583 return QObject::tr( "m" );
3585 return QObject::tr( "in", "unit inch" );
3587 return QObject::tr( "ft" );
3589 return QObject::tr( "pt" );
3591 return QObject::tr( "pica" );
3592 }
3593 return QString(); // no warnings
3594}
3595
3597{
3598 switch ( unit )
3599 {
3601 return QObject::tr( "pixels" );
3603 return QObject::tr( "millimeters" );
3605 return QObject::tr( "centimeters" );
3607 return QObject::tr( "meters" );
3609 return QObject::tr( "inches" );
3611 return QObject::tr( "feet" );
3613 return QObject::tr( "points" );
3615 return QObject::tr( "picas" );
3616 }
3617 return QString(); // no warnings
3618}
DistanceUnitType
Types of distance units.
Definition qgis.h:4687
@ 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:4608
@ Distance
Distance unit.
@ Temporal
Temporal unit.
@ Unknown
Unknown unit type.
@ Volume
Volume unit.
@ Area
Area unit.
LayoutUnit
Layout measurement units.
Definition qgis.h:4815
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Points
Typographic points.
@ Picas
Typographic picas.
AngleUnit
Units of angles.
Definition qgis.h:4750
@ 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:4625
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated)
@ Feet
Imperial feet.
@ MilesUSSurvey
US Survery 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 Survery 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 Survery links.
@ ChainsUSSurvey
US Survery 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:4702
@ 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:4771
@ 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:4795
@ 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:4835
@ PaperUnits
Unit is a paper based measurement unit.
@ ScreenUnits
Unit is a screen based measurement unit.
VolumeUnit
Units of volume.
Definition qgis.h:4727
@ 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:5898
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5857
#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.