~ (Boolean Not) operator

Spatial Analyst のライセンスで利用可能。

Image Analyst ライセンスで利用できます。

概要

Performs a Boolean-complement (Not) operation on the cell values of the input raster.

Boolean Not illustration
OutRas = ~ Raster("InRas1")

ディスカッション

The ~ operator will perform a Boolean Not operation when the input (operand) is a raster. If the input (operand) is a number, then the ~ operator will perform a Bitwise Not operation. For more information on how to work with operators, refer to Working with operators.

複数の演算子が式に使用されている場合、それらは必ずしも左から右への順に実行されるわけではありません。優先順位値が最も高い演算子が最初に実行されます。演算子の優先順位に関する詳細については、「演算子の優先順位のテーブル」をご参照ください。実行順序の制御には、括弧が使用できます。

ブール (~&^|) 演算子には、関係 (<<=>>===!=) 演算子よりも高い優先度があります。したがって、ブール演算子が関係演算子と同じ式に使用されている場合、ブール演算子が最初に実行されます。実行の順序を変更するには、括弧を使用します。

複数の関係および (または) ブール演算子が 1 つの式で連続して使用されているときは、場合によっては実行されない可能性があります。このような問題を避けるために、式に適切な括弧を使用して、演算の実行順序を明示的に定義します。詳細については、「複雑なステートメントのルール」をご参照ください。

Only a single input is necessary for the Boolean evaluation to take place.

入力値が浮動小数点数値の場合は、ブール演算を実行する前に値を切り捨てて整数値に変換されます。出力値は、必ず整数になります。

入力がマルチバンド ラスターの場合、出力もマルチバンド ラスターになります。演算子は、入力の各バンドに演算を実行します。

構文

~ in_raster_or_constant
オペランド説明データ タイプ
in_raster_or_constant

The input to use in the Boolean Not operation.

Raster Layer | Constant

戻り値

名前説明データ タイプ
out_raster

出力ラスター オブジェクト。

出力値は 0 または 1 です。

Raster

コードのサンプル

~ (Boolean Not) example 1 (Python window)

This sample performs a Boolean Not (complement) operation on an input raster.

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
outBooleanNot = ~ Raster("degs")
outBooleanNot.save("C:/sapyexamples/output/outboolnot.tif")
~ (Boolean Not) example 2 (stand-alone script)

This sample performs a Boolean Not (complement) operation on an input raster.

# Name: Op_BooleanNot_Ex_02.py
# Description: Performs a Boolean complement (NOT) operation on the
#              cell values of an input raster
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRaster = Raster("degs")

# Execute BooleanNot
outBooleanNot = ~ inRaster

# Save the output 
outBooleanNot.save("C:/sapyexamples/output/outboolnot")

関連トピック