Skip to main content

LinearUnitConversionFactor

Краткая информация

Возвращает коэффициент для конвертации измеряемого расстояния в другую линейную единицу.

Обсуждение

Линейные единицы, поддерживаемые функцией, — это те же единицы, которые возвращаются из типа данных параметра геообработки Линейные единицы, за исключением следующих:

  • Unknown - могут конвертироваться только известные единицы.

  • Decimal Degrees - Десятичные градусы измеряются на сфере, и постоянный коэффициент преобразования в другие единицы для них отсутствует.

Узнайте больше о единицах измерения геообработки

Синтаксис

LinearUnitConversionFactor(from_unit, to_unit)

Параметр Объяснение Тип данных

from_unit

Specifies the original or source linear unit.

  • Kilometers—Kilometers

  • Meters—Meters

  • Decimeters—Decimeters

  • Millimeters—Millimeters

  • Centimeters—Centimeters

  • NauticalMilesInt—International nautical miles

  • MilesInt—Statute miles

  • YardsInt—International yards

  • FeetInt—International feet

  • InchesInt—International inches

  • NauticalMilesUS—US survey nautical miles

  • MilesUS—US survey miles

  • YardsUS—US survey yards

  • FeetUS—US survey feet

  • InchesUS—US survey inches

  • Points—Points

String

to_unit

Specifies the target or destination linear unit.

  • Kilometers—Kilometers

  • Meters—Meters

  • Decimeters—Decimeters

  • Millimeters—Millimeters

  • Centimeters—Centimeters

  • NauticalMilesInt—International nautical miles

  • MilesInt—Statute miles

  • YardsInt—International yards

  • FeetInt—International feet

  • InchesInt—International inches

  • NauticalMilesUS—US survey nautical miles

  • MilesUS—US survey miles

  • YardsUS—US survey yards

  • FeetUS—US survey feet

  • InchesUS—US survey inches

  • Points—Points

String

Возвращаемое значение

Тип данных Объяснение

Double

Коэффициент преобразования, который будет использоваться для конвертации значений между двумя линейными единицами.

Пример кода

Пример 1 LinearUnitConversionFactor

Практический пример конвертации международных миль в километры.

import arcpy

# Convert 620.5 MilesInt to Kilometers
area = 620.5 * arcpy.LinearUnitConversionFactor(from_unit="MilesInt", to_unit="Kilometers")

print(area)  # This will print a value of 998.597952
Пример 2 LinearUnitConversionFactor

Конвертирует в скрипте заданное значение в метры для геообработки.

import arcpy
import locale
import sys

dist = arcpy.GetParameter(n)  # Update n to the parameter index
dist_value, dist_unit = dist.split(" ")  # For example, "10 Kilometers"

# Convert the distance into "Meters" as needed later in this script
try:
    conv_factor = arcpy.LinearUnitConversionFactor(dist_unit, "Meters")
except ValueError as e:
    # If it fails, the likely distance unit is "Unknown" or "Decimal Degrees".
    # Add code to either deal with it or produce an appropriate error as shown below.
    arcpy.AddError('Invalid linear unit type.')
    sys.exit()

# Apply the conv_factor to the supplied value
# locale.atof is required for locales that don't use a period as the separator
dist_m = locale.atof(dist_value) * conv_factor