Class: QgsUnitTypes¶
-
class
qgis.core.
QgsUnitTypes
¶ Bases:
sip.wrapper
Helper functions for various unit types.
Methods
Converts an area unit to its corresponding distance unit, e.g., square meters to meters
Decodes an angular unit from a string.
Decodes an areal unit from a string.
Decodes a distance unit from a string.
Decodes a layout unit from a string.
Decodes a render unit from a string.
Decodes a unit type from a
string
.Decodes a volume unit from a
string
.Converts a distance unit to its corresponding area unit, e.g., meters to square meters
Converts a distance unit to its corresponding volume unit, e.g., meters to cubic meters
Encodes a distance unit to a string.
Encodes a unit
type
to a string.Returns an angle formatted as a friendly string.
Returns an area formatted as a friendly string.
Returns an distance formatted as a friendly string.
Returns the conversion factor between the specified distance units.
Will convert an
area
with a givenunit
to an area value which is nice to display.Will convert a
distance
with a givenunit
to a distance value which is nice to display.Converts a translated string to an areal unit.
Converts a translated string to a distance unit.
Converts a translated`` ``string to a volume unit.
Returns a translated abbreviation representing a distance unit.
Returns a translated string representing a distance unit.
Returns the type for a distance unit.
Converts a volume unit to its corresponding distance unit, e.g., cubic meters to meters
Attributes
-
AngleDegrees
= 0¶
-
AngleGon
= 2¶
-
AngleMilNATO
= 7¶
-
AngleMilliradiansSI
= 6¶
-
AngleMinutesOfArc
= 3¶
-
AngleRadians
= 1¶
-
AngleSecondsOfArc
= 4¶
-
AngleTurn
= 5¶
-
class
AngleUnit
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
AngleUnknownUnit
= 8¶
-
AreaAcres
= 6¶
-
AreaHectares
= 5¶
-
AreaSquareCentimeters
= 9¶
-
AreaSquareDegrees
= 8¶
-
AreaSquareFeet
= 2¶
-
AreaSquareKilometers
= 1¶
-
AreaSquareMeters
= 0¶
-
AreaSquareMiles
= 4¶
-
AreaSquareMillimeters
= 10¶
-
AreaSquareNauticalMiles
= 7¶
-
AreaSquareYards
= 3¶
-
class
AreaUnit
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
AreaUnknownUnit
= 11¶
-
DistanceCentimeters
= 7¶
-
DistanceDegrees
= 6¶
-
DistanceFeet
= 2¶
-
DistanceKilometers
= 1¶
-
DistanceMeters
= 0¶
-
DistanceMiles
= 5¶
-
DistanceMillimeters
= 8¶
-
DistanceNauticalMiles
= 3¶
-
class
DistanceUnit
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
class
DistanceUnitType
¶ Bases:
int
-
DistanceUnknownUnit
= 9¶
-
class
DistanceValue
¶ Bases:
sip.wrapper
QgsUnitTypes.DistanceValue(QgsUnitTypes.DistanceValue)
-
unit
¶
-
value
¶
-
-
DistanceYards
= 4¶
-
Geographic
= 1¶
-
ImperialSystem
= 2¶
-
LayoutCentimeters
= 1¶
-
LayoutFeet
= 4¶
-
LayoutInches
= 3¶
-
LayoutMeters
= 2¶
-
LayoutMillimeters
= 0¶
-
LayoutPaperUnits
= 0¶
-
LayoutPicas
= 6¶
-
LayoutPixels
= 7¶
-
LayoutPoints
= 5¶
-
LayoutScreenUnits
= 1¶
-
class
LayoutUnit
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
class
LayoutUnitType
¶ Bases:
int
-
MetricSystem
= 1¶
-
RenderInches
= 5¶
-
RenderMapUnits
= 1¶
-
RenderMetersInMapUnits
= 7¶
-
RenderMillimeters
= 0¶
-
RenderPercentage
= 3¶
-
RenderPixels
= 2¶
-
RenderPoints
= 4¶
-
class
RenderUnit
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
RenderUnknownUnit
= 6¶
-
Standard
= 0¶
-
class
SystemOfMeasurement
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
TypeArea
= 1¶
-
TypeDistance
= 0¶
-
TypeUnknown
= 3¶
-
TypeVolume
= 2¶
-
USCSSystem
= 3¶
-
class
UnitType
¶ Bases:
int
-
UnknownSystem
= 0¶
-
UnknownType
= 2¶
-
VolumeBarrel
= 3¶
-
VolumeCubicCentimeter
= 8¶
-
VolumeCubicDecimeter
= 4¶
-
VolumeCubicDegrees
= 9¶
-
VolumeCubicFeet
= 1¶
-
VolumeCubicInch
= 7¶
-
VolumeCubicMeters
= 0¶
-
VolumeCubicYards
= 2¶
-
VolumeGallonUS
= 6¶
-
VolumeLiters
= 5¶
-
class
VolumeUnit
¶ Bases:
int
-
baseClass
¶ alias of
QgsUnitTypes
-
-
VolumeUnknownUnit
= 10¶
-
areaToDistanceUnit
(areaUnit: QgsUnitTypes.AreaUnit) → QgsUnitTypes.DistanceUnit¶ Converts an area unit to its corresponding distance unit, e.g., square meters to meters
- Parameters
areaUnit (QgsUnitTypes.AreaUnit) – area unit to convert
- Return type
- Returns
matching distance unit
New in version 3.10.
-
decodeAngleUnit
(string: str) → Tuple[QgsUnitTypes.AngleUnit, bool]¶ Decodes an angular unit from a string.
- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.AngleUnit, bool]
- Returns
decoded units
ok: boolean, will be set to
True
if string was converted successfully
See also
-
decodeAreaUnit
(string: str) → Tuple[QgsUnitTypes.AreaUnit, bool]¶ Decodes an areal unit from a string.
- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.AreaUnit, bool]
- Returns
decoded units
ok: boolean, will be set to
True
if string was converted successfully
See also
-
decodeDistanceUnit
(string: str) → Tuple[QgsUnitTypes.DistanceUnit, bool]¶ Decodes a distance unit from a string.
- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.DistanceUnit, bool]
- Returns
decoded units
ok: boolean, will be set to
True
if string was converted successfully
See also
-
decodeLayoutUnit
(string: str) → Tuple[QgsUnitTypes.LayoutUnit, bool]¶ Decodes a layout unit from a string.
- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.LayoutUnit, bool]
- Returns
decoded units
ok: boolean, will be set to
True
if string was converted successfully
See also
New in version 3.0.
-
decodeRenderUnit
(string: str) → Tuple[QgsUnitTypes.RenderUnit, bool]¶ Decodes a render unit from a string.
- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.RenderUnit, bool]
- Returns
decoded units
ok: boolean, will be set to
True
if string was converted successfully
See also
-
decodeUnitType
(string: str) → Tuple[QgsUnitTypes.UnitType, bool]¶ Decodes a unit type from a
string
.- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.UnitType, bool]
- Returns
decoded unit type
ok: boolean, will be set to
True
if string was converted successfully
See also
New in version 3.10.
-
decodeVolumeUnit
(string: str) → Tuple[QgsUnitTypes.VolumeUnit, bool]¶ Decodes a volume unit from a
string
.- Parameters
string (str) – string to decode
- Return type
Tuple[QgsUnitTypes.VolumeUnit, bool]
- Returns
decoded units
ok: boolean, will be set to
True
if string was converted successfully
See also
New in version 3.10.
-
distanceToAreaUnit
(distanceUnit: QgsUnitTypes.DistanceUnit) → QgsUnitTypes.AreaUnit¶ Converts a distance unit to its corresponding area unit, e.g., meters to square meters
- Parameters
distanceUnit (QgsUnitTypes.DistanceUnit) – distance unit to convert
- Return type
- Returns
matching areal unit
-
distanceToVolumeUnit
(distanceUnit: QgsUnitTypes.DistanceUnit) → QgsUnitTypes.VolumeUnit¶ Converts a distance unit to its corresponding volume unit, e.g., meters to cubic meters
- Parameters
distanceUnit (QgsUnitTypes.DistanceUnit) – distance unit to convert
- Return type
- Returns
matching volume unit
New in version 3.10.
-
encodeUnit
(unit: QgsUnitTypes.DistanceUnit) → str¶ Encodes a distance unit to a string.
- Parameters
unit (QgsUnitTypes.DistanceUnit) – unit to encode
- Returns
encoded string
See also
encodeUnit(unit: QgsUnitTypes.AreaUnit) -> str Encodes an areal unit to a string.
- Parameters
unit – unit to encode
- Returns
encoded string
See also
encodeUnit(unit: QgsUnitTypes.VolumeUnit) -> str Encodes a volume
unit
to a string.- Returns
encoded string
See also
New in version 3.10.
encodeUnit(unit: QgsUnitTypes.AngleUnit) -> str Encodes an angular unit to a string.
- Parameters
unit – unit to encode
- Returns
encoded string
See also
encodeUnit(unit: QgsUnitTypes.RenderUnit) -> str Encodes a render unit to a string.
- Parameters
unit – unit to encode
- Returns
encoded string
See also
encodeUnit(unit: QgsUnitTypes.LayoutUnit) -> str Encodes a layout unit to a string.
- Parameters
unit – unit to encode
- Return type
str
- Returns
encoded string
See also
New in version 3.0.
-
encodeUnitType
(type: QgsUnitTypes.UnitType) → str¶ Encodes a unit
type
to a string.- Return type
str
- Returns
encoded string
See also
New in version 3.10.
- Parameters
type (QgsUnitTypes.UnitType) –
-
formatAngle
(angle: float, decimals: int, unit: QgsUnitTypes.AngleUnit) → str¶ Returns an angle formatted as a friendly string.
- Parameters
angle (float) – angle to format
decimals (int) – number of decimal places to show
unit (QgsUnitTypes.AngleUnit) – unit of angle
- Return type
str
- Returns
formatted angle string
-
formatArea
(area: float, decimals: int, unit: QgsUnitTypes.AreaUnit, keepBaseUnit: bool = False) → str¶ Returns an area formatted as a friendly string.
- Parameters
area (float) – area to format
decimals (int) – number of decimal places to show
unit (QgsUnitTypes.AreaUnit) – unit of area
keepBaseUnit (bool = False) – set to
False
to allow conversion of large areas to more suitable units, e.g., square meters to square kilometers
- Return type
str
- Returns
formatted area string
See also
New in version 3.0.
-
formatDistance
(distance: float, decimals: int, unit: QgsUnitTypes.DistanceUnit, keepBaseUnit: bool = False) → str¶ Returns an distance formatted as a friendly string.
- Parameters
distance (float) – distance to format
decimals (int) – number of decimal places to show
unit (QgsUnitTypes.DistanceUnit) – unit of distance
keepBaseUnit (bool = False) – set to
False
to allow conversion of large distances to more suitable units, e.g., meters to kilometers
- Return type
str
- Returns
formatted distance string
See also
New in version 3.0.
-
fromUnitToUnitFactor
(fromUnit: QgsUnitTypes.DistanceUnit, toUnit: QgsUnitTypes.DistanceUnit) → float¶ Returns the conversion factor between the specified distance units.
- Parameters
fromUnit (QgsUnitTypes.DistanceUnit) – distance unit to convert from
toUnit (QgsUnitTypes.DistanceUnit) – distance unit to convert to
- Returns
multiplication factor to convert between units
fromUnitToUnitFactor(fromUnit: QgsUnitTypes.AreaUnit, toUnit: QgsUnitTypes.AreaUnit) -> float Returns the conversion factor between the specified areal units.
- Parameters
fromUnit – area unit to convert from
toUnit – area unit to convert to
- Returns
multiplication factor to convert between units
fromUnitToUnitFactor(fromUnit: QgsUnitTypes.VolumeUnit, toUnit: QgsUnitTypes.VolumeUnit) -> float Returns the conversion factor between the specified volume units.
- Parameters
fromUnit – volume unit to convert from
toUnit – volume unit to convert to
- Returns
multiplication factor to convert between units
New in version 3.10.
fromUnitToUnitFactor(fromUnit: QgsUnitTypes.AngleUnit, toUnit: QgsUnitTypes.AngleUnit) -> float Returns the conversion factor between the specified angular units.
- Parameters
fromUnit – angle unit to convert from
toUnit – angle unit to convert to
- Return type
float
- Returns
multiplication factor to convert between units
-
scaledArea
(area: float, unit: QgsUnitTypes.AreaUnit, decimals: int, keepBaseUnit: bool = False) → QgsUnitTypes.AreaValue¶ Will convert an
area
with a givenunit
to an area value which is nice to display. It will convert between different units (e.g. from square meters to square kilometers) if appropriate, unless forced otherwise withkeepBaseUnit
. The value will also be rounded todecimals
(be prepared that the returned value is still a double so it will require further formatting when converting to a string).New in version 3.0.
- Parameters
area (float) –
unit (QgsUnitTypes.AreaUnit) –
decimals (int) –
keepBaseUnit (bool = False) –
- Return type
-
scaledDistance
(distance: float, unit: QgsUnitTypes.DistanceUnit, decimals: int, keepBaseUnit: bool = False) → QgsUnitTypes.DistanceValue¶ Will convert a
distance
with a givenunit
to a distance value which is nice to display. It will convert between different units (e.g. from meters to kilometers or millimeters) if appropriate, unless forced otherwise withkeepBaseUnit
. The value will also be rounded todecimals
(be prepared that the returned value is still a double so it will require further formatting when converting to a string).New in version 3.0.
- Parameters
distance (float) –
unit (QgsUnitTypes.DistanceUnit) –
decimals (int) –
keepBaseUnit (bool = False) –
- Return type
-
staticMetaObject
= <PyQt5.QtCore.QMetaObject object>¶
-
stringToAreaUnit
(string: str) → Tuple[QgsUnitTypes.AreaUnit, bool]¶ Converts a translated string to an areal unit.
- Parameters
string (str) – string representing an areal unit
- Return type
Tuple[QgsUnitTypes.AreaUnit, bool]
- Returns
the area unit
ok: boolean, will be set to
True
if string was converted successfully
See also
-
stringToDistanceUnit
(string: str) → Tuple[QgsUnitTypes.DistanceUnit, bool]¶ Converts a translated string to a distance unit.
- Parameters
string (str) – string representing a distance unit
- Return type
Tuple[QgsUnitTypes.DistanceUnit, bool]
- Returns
the distance unit
ok: boolean, will be set to
True
if string was converted successfully
See also
-
stringToVolumeUnit
(string: str) → Tuple[QgsUnitTypes.VolumeUnit, bool]¶ Converts a translated`` ``string to a volume unit.
- Parameters
string (str) – string representing a volume unit
- Return type
Tuple[QgsUnitTypes.VolumeUnit, bool]
- Returns
the volume unit
ok: boolean, will be set to
True
if string was converted successfully
See also
New in version 3.10.
-
toAbbreviatedString
(unit: QgsUnitTypes.DistanceUnit) → str¶ Returns a translated abbreviation representing a distance unit.
- Parameters
unit (QgsUnitTypes.DistanceUnit) – unit to convert to string
See also
New in version 3.0.
toAbbreviatedString(unit: QgsUnitTypes.AreaUnit) -> str Returns a translated abbreviation representing an areal unit.
- Parameters
unit – unit to convert to string
See also
New in version 3.0.
toAbbreviatedString(unit: QgsUnitTypes.VolumeUnit) -> str Returns a translated abbreviation representing a volume
unit
.See also
New in version 3.10.
toAbbreviatedString(unit: QgsUnitTypes.RenderUnit) -> str Returns a translated abbreviation representing a render unit.
- Parameters
unit – unit to convert to string
New in version 3.8.
toAbbreviatedString(unit: QgsUnitTypes.LayoutUnit) -> str Returns a translated abbreviation representing a layout
unit
(e.g. “mm”).New in version 3.0.
- Return type
str
-
toString
(unit: QgsUnitTypes.DistanceUnit) → str¶ Returns a translated string representing a distance unit.
- Parameters
unit (QgsUnitTypes.DistanceUnit) – unit to convert to string
See also
toString(unit: QgsUnitTypes.AreaUnit) -> str Returns a translated string representing an areal unit.
- Parameters
unit – unit to convert to string
See also
toString(unit: QgsUnitTypes.VolumeUnit) -> str Returns a translated string representing a volume
unit
.See also
New in version 3.10.
toString(unit: QgsUnitTypes.AngleUnit) -> str Returns a translated string representing an angular unit.
- Parameters
unit – unit to convert to string
toString(unit: QgsUnitTypes.RenderUnit) -> str Returns a translated string representing a render
unit
.New in version 3.0.
toString(unit: QgsUnitTypes.LayoutUnit) -> str Returns a translated string representing a layout
unit
.New in version 3.0.
- Return type
str
-
unitType
(unit: QgsUnitTypes.DistanceUnit) → QgsUnitTypes.DistanceUnitType¶ Returns the type for a distance unit.
unitType(unit: QgsUnitTypes.AreaUnit) -> QgsUnitTypes.DistanceUnitType Returns the type for an areal unit.
unitType(unit: QgsUnitTypes.VolumeUnit) -> QgsUnitTypes.DistanceUnitType Returns the type for an volume unit.
New in version 3.10.
unitType(units: QgsUnitTypes.LayoutUnit) -> QgsUnitTypes.LayoutUnitType Returns the type for a unit of measurement.
New in version 3.0.
- Parameters
unit (QgsUnitTypes.DistanceUnit) –
- Return type
-
volumeToDistanceUnit
(volumeUnit: QgsUnitTypes.VolumeUnit) → QgsUnitTypes.DistanceUnit¶ Converts a volume unit to its corresponding distance unit, e.g., cubic meters to meters
- Parameters
volumeUnit (QgsUnitTypes.VolumeUnit) – volume unit to convert
- Return type
- Returns
matching distance unit
New in version 3.10.
-