LinearUnitConversionFactor

摘要

返回将距离测量值转换为其他线性单位的因子。

说明

该函数支持的线性单位与从地理处理线性单位参数数据类型返回的单位相同,例外情况如下:

  • Unknown - 只能转换已知单位。
  • Decimal Degrees - 十进制度在球体上测量并且与其他单位的转换因子不一致。

了解有关地理处理测量单位的详细信息

语法

LinearUnitConversionFactor (from_unit, to_unit)
参数说明数据类型
from_unit

The original or source linear unit.

  • KilometersKilometers
  • MetersMeters
  • DecimetersDecimeters
  • MillimetersMillimeters
  • CentimetersCentimeters
  • NauticalMilesIntInternational nautical miles
  • MilesIntStatute miles
  • YardsIntInternational yards
  • FeetIntInternational feet
  • InchesIntInternational inches
  • NauticalMilesUSUS survey nautical miles
  • MilesUSUS survey miles
  • YardsUSUS survey yards
  • FeetUSUS survey feet
  • InchesUSUS survey inches
  • PointsPoints
String
to_unit

The target or destination linear unit.

  • KilometersKilometers
  • MetersMeters
  • DecimetersDecimeters
  • MillimetersMillimeters
  • CentimetersCentimeters
  • NauticalMilesIntInternational nautical miles
  • MilesIntStatute miles
  • YardsIntInternational yards
  • FeetIntInternational feet
  • InchesIntInternational inches
  • NauticalMilesUSUS survey nautical miles
  • MilesUSUS survey miles
  • YardsUSUS survey yards
  • FeetUSUS survey feet
  • InchesUSUS survey inches
  • PointsPoints
String
返回值
数据类型说明
Double

用于在两个线性单位之间转换值的转换因子。

代码示例

LinearUnitConversionFactor 示例 1

从国际英里转换为千米的简单用例。

import arcpy

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

print(area)  # This will print a value of 998.597952
LinearUnitConversionFactor 示例 2

在脚本工具中,将指定值转换为米以进行处理。



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 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

相关主题