Skip to main content

ArealUnitConversionFactor

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

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

Обсуждение

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

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

Синтаксис

ArealUnitConversionFactor(from_unit, to_unit)

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

from_unit

The original or source areal unit.

  • SquareKilometers—Square kilometers

  • Hectares—Hectares

  • Ares—Ares

  • SquareMeters—Square meters

  • SquareDecimeters—Square decimeters

  • SquareCentimeters—Square centimeters

  • SquareMillimeters—Square millimeters

  • SquareMilesInt—Square statute miles

  • AcresInt—International acres

  • SquareYardsInt—Square international yards

  • SquareFeetInt—Square international feet

  • SquareInchesInt—Square international inches

  • SquareMilesUS—Square US survey miles

  • AcresUS—Square US survey acres

  • SquareYardsUS—Square US survey yards

  • SquareFeetUS—Square US survey feet

  • SquareInchesUS—Square US survey inches

String

to_unit

The destination areal unit.

  • SquareKilometers—Square kilometers

  • Hectares—Hectares

  • Ares—Ares

  • SquareMeters—Square meters

  • SquareDecimeters—Square decimeters

  • SquareCentimeters—Square centimeters

  • SquareMillimeters—Square millimeters

  • SquareMilesInt—Square statute miles

  • AcresInt—International acres

  • SquareYardsInt—Square international yards

  • SquareFeetInt—Square international feet

  • SquareInchesInt—Square international inches

  • SquareMilesUS—Square US survey miles

  • AcresUS—Square US survey acres

  • SquareYardsUS—Square US survey yards

  • SquareFeetUS—Square US survey feet

  • SquareInchesUS—Square 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 areal unit is "Unknown"
    # Add code to either deal with it or produce an appropriate error as shown below.
    arcpy.AddError('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