ArealUnitConversionFactor

摘要

返回将面积测量值转换为其他面积单位的因子。

说明

该函数支持的面积单位与地理处理面积单位参数数据类型返回的单位相同,只有 Unknown 例外,其中只能转换已知单位。

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

语法

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

The original or source areal unit.

  • SquareKilometersSquare kilometers
  • HectaresHectares
  • AresAres
  • SquareMetersSquare meters
  • SquareDecimetersSquare decimeters
  • SquareCentimetersSquare centimeters
  • SquareMillimetersSquare millimeters
  • SquareMilesIntSquare statute miles
  • AcresIntInternational acres
  • SquareYardsIntSquare international yards
  • SquareFeetIntSquare international feet
  • SquareInchesIntSquare international inches
  • SquareMilesUSSquare US survey miles
  • AcresUSSquare US survey acres
  • SquareYardsUSSquare US survey yards
  • SquareFeetUSSquare US survey feet
  • SquareInchesUSSquare US survey inches
String
to_unit

The destination areal unit.

  • SquareKilometersSquare kilometers
  • HectaresHectares
  • AresAres
  • SquareMetersSquare meters
  • SquareDecimetersSquare decimeters
  • SquareCentimetersSquare centimeters
  • SquareMillimetersSquare millimeters
  • SquareMilesIntSquare statute miles
  • AcresIntInternational acres
  • SquareYardsIntSquare international yards
  • SquareFeetIntSquare international feet
  • SquareInchesIntSquare international inches
  • SquareMilesUSSquare US survey miles
  • AcresUSSquare US survey acres
  • SquareYardsUSSquare US survey yards
  • SquareFeetUSSquare US survey feet
  • SquareInchesUSSquare US survey inches
String
返回值
数据类型说明
Double

在两个面积单位之间转换值的转换因子。

代码示例

ArealUnitConversionFactor 示例 1

从公顷转换为平方千米的简单用例。

import arcpy

# Convert an area of 10000 Hectares to SquareKilometers 
area = 10000 * arcpy.ArealUnitConversionFactor(from_unit="Hectares", to_unit="SquareKilometers")

print(area)  # This will print a value of 100.0
ArealUnitConversionFactor 示例 2

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



import locale
import sys

area = arcpy.GetParameter(n)  # Update n to the parameter index

area_value, area_unit = area.split(" ")  # For example, "10 Acres"

# Convert the area into "SquareMeters" as needed later in this script
try:
    conv_factor = arcpy.ArealUnitConversionFactor(area_unit, "SquareMeters")
except ValueError as e:
    # If fails, the likely area; unit is "Unknown"
    # Add code to either deal with it or produce an appropriateerror  as shown below.
    arcpy.AddError(arcpy.GetIDMessage('Invalid areal 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
area_square_m = locale.atof(area_value) * conv_factor

相关主题