ArcGIS Raster Calculator CON: Replace Values & Conditional Logic


ArcGIS Raster Calculator CON: Conditional Value Replacement

ArcGIS Raster Calculator CON – Conditional Replacement



Enter the specific numeric value in your input raster you want to identify.



Enter the threshold value for the condition (e.g., if raster value is GREATER THAN this).



The value to assign if the condition is met.



The value to assign if the condition is NOT met.



The value to represent NoData in the output raster. Leave blank if not applicable.



Raster Data Table

Sample Raster Pixel Values and their CON Operation Outcomes
Input Raster Value Condition (Input Raster Value <= 5) Value if True (100) Value if False (0) Output Value (CON Result) NoData Value (-9999)
3 True 100 0 100 -9999
5 True 100 0 100 -9999
7 False 100 0 0 -9999
-9999 N/A 100 0 -9999

{primary_keyword} is a powerful conditional statement used within the ArcGIS Raster Calculator to manipulate raster datasets based on specific criteria. Essentially, it allows you to examine each pixel in an input raster and assign a new value based on whether a condition is met or not. This is incredibly useful for tasks such as reclassifying raster data, creating binary masks, or setting specific pixel values based on thresholds.

What is ArcGIS Raster Calculator CON: Replace Values?

The `CON` function in the ArcGIS Raster Calculator is a fundamental tool for spatial data analysis and raster manipulation. It operates similarly to an IF-THEN-ELSE statement found in programming languages. For every pixel in an input raster, it evaluates a logical expression. If the expression is TRUE, the pixel is assigned a specified “true value”; if it’s FALSE, it’s assigned an “else value”. An optional “NoData value” can also be defined for pixels that should be treated as missing or invalid.

Who should use it:

  • GIS analysts performing raster reclassification.
  • Environmental scientists mapping specific conditions (e.g., areas above a certain temperature).
  • Urban planners identifying zones based on criteria (e.g., population density thresholds).
  • Anyone needing to create new raster layers by applying logical rules to existing ones.
  • Users working with large raster datasets who need to automate value replacement.

Common misconceptions:

  • It only works on specific raster types: The `CON` function works on most common raster formats supported by ArcGIS.
  • It permanently modifies the original raster: By default, the Raster Calculator creates a new output raster, leaving the original intact.
  • It’s overly complex: While it has several parameters, understanding the core IF-THEN-ELSE logic makes it accessible. The calculator interface and this guide simplify its application.
  • It’s only for simple numerical comparisons: While numerical comparisons are common, `CON` can also evaluate logical expressions involving multiple conditions or other raster layers.

Mastering the `CON` function is key to advanced raster analysis in ArcGIS, enabling precise control over your spatial data and facilitating complex modeling workflows. For more intricate spatial operations, understanding [ArcGIS Spatial Analyst tools](https://developers.arcgis.com/python/samples/spatial-analyst/) can be beneficial.

ArcGIS Raster Calculator CON Formula and Mathematical Explanation

The core of the `CON` function in ArcGIS Raster Calculator follows a structured logic that can be represented mathematically. It’s essentially a conditional assignment operation performed on a pixel-by-pixel basis.

The general syntax is:

CON(Condition, Value_if_True, Value_if_False, [No_Data_Value])

Let’s break down the components:

  • Condition: This is a logical expression that evaluates to either TRUE or FALSE for each pixel. It typically involves comparing a pixel’s value in an input raster to a specified value or another raster. Examples:"MyRaster" > 10, "RasterA" == "RasterB".
  • Value_if_True: This is the value assigned to the output pixel if the Condition evaluates to TRUE. This can be a constant number, the value from another raster, or the result of another calculation.
  • Value_if_False: This is the value assigned to the output pixel if the Condition evaluates to FALSE. Similar to Value_if_True, it can be a constant, a raster value, or a calculation.
  • [No_Data_Value] (Optional): This is the value that will be assigned to the output pixel if the input pixel’s value is NoData or if the condition itself involves a NoData value. If omitted, ArcGIS may use its default NoData value.

Mathematical Derivation:

For a given pixel at location (x, y):

Let $R(x, y)$ be the value of the input raster at (x, y).

Let $C$ be the condition being evaluated (e.g., $R(x, y) \ge V$, where $V$ is a threshold value).

Let $T$ be the Value_if_True.

Let $F$ be the Value_if_False.

Let $ND$ be the No_Data_Value.

The output raster value $O(x, y)$ can be defined as:

$$
O(x, y) =
\begin{cases}
T & \text{if } C \text{ is TRUE and } R(x, y) \neq \text{NoData} \\
F & \text{if } C \text{ is FALSE and } R(x, y) \neq \text{NoData} \\
ND & \text{if } R(x, y) = \text{NoData}
\end{cases}
$$

This piecewise function precisely defines how the output pixel value is determined based on the input raster’s value and the specified condition.

Variables Table:

Variables Used in the CON Function
Variable Meaning Unit Typical Range
Input Raster Value The pixel value from the source raster layer. Raster Value Units (e.g., Meters, Degrees Celsius, Count) Varies widely based on raster type (e.g., -10000 to 10000 for floating point, 0 to 255 for byte).
Condition Value (Threshold) The fixed value used for comparison in the condition. Same as Input Raster Value Units Similar to Input Raster Value range.
Operator Comparison operator (e.g., >, <, ==, !=, >=, <=). N/A Predefined set of logical operators.
Value if True The replacement value when the condition is met. Raster Value Units Can be any valid raster value, often used for reclassification (e.g., 1, 100, 255).
Value if False The replacement value when the condition is not met. Raster Value Units Can be any valid raster value, often used for background or non-matching areas (e.g., 0, -9999).
NoData Value Represents missing or invalid data pixels. Raster Value Units Often a large negative number (e.g., -9999) or a specific code.

Understanding these variables is crucial for accurately applying the CON function to achieve desired [raster analysis outcomes](https://www.esri.com/en-us/arcgis/products/arcgis-spatial-analyst/overview).

Practical Examples (Real-World Use Cases)

Example 1: Creating a Land Cover Mask

Scenario: You have a land cover raster where different integer values represent different types (e.g., 1=Forest, 2=Water, 3=Urban, 4=Agriculture). You want to create a new raster that identifies only ‘Forest’ areas, assigning them a value of 1 and all other areas a value of 0.

Inputs for Calculator:

  • Input Raster Value: 1 (representing Forest)
  • Condition Operator: == (Equals)
  • Condition Value: 1
  • Value if True: 1 (Output value for Forest)
  • Value if False: 0 (Output value for non-Forest)
  • NoData Value: -9999 (Assuming this is the NoData value in the original raster)

ArcGIS Raster Calculator Expression:

CON("LandCoverRaster" == 1, 1, 0, -9999)

Result Interpretation: The output raster will have pixels with a value of 1 where the original ‘LandCoverRaster’ had a value of 1 (Forest), and 0 everywhere else. This effectively creates a binary mask for forest areas, which can be useful for further analysis like calculating forest cover percentages or suitability modeling. This process is a fundamental step in many [raster reclassification tasks](https://www.esri.com/en-us/arcgis/products/arcgis-spatial-analyst/capabilities).

Example 2: Identifying Areas Above a Temperature Threshold

Scenario: You have a raster representing average summer temperatures across a region. You need to identify all areas where the temperature exceeds 25 degrees Celsius for a specific analysis (e.g., identifying heat-prone zones).

Inputs for Calculator:

  • Input Raster Value: 25 (the temperature threshold)
  • Condition Operator: > (Greater Than)
  • Condition Value: 25
  • Value if True: 1 (Identify these areas)
  • Value if False: 0 (Do not identify these areas)
  • NoData Value: -9999 (Assuming this represents areas with no temperature data)

ArcGIS Raster Calculator Expression:

CON("TemperatureRaster" > 25, 1, 0, -9999)

Result Interpretation: The output raster will highlight pixels where the temperature is strictly greater than 25 degrees Celsius with a value of 1. All pixels with temperatures 25 degrees or less, or those that are NoData, will receive a value of 0 (or the specified NoData value). This isolates the target areas for further investigation, perhaps related to crop stress or urban heat island effects.

How to Use This ArcGIS Raster Calculator CON Calculator

This calculator simplifies the process of understanding and applying the `CON` function in ArcGIS. Follow these steps:

  1. Identify Your Input Raster Value: Determine the specific numeric value within your source raster that you want to use as the basis for your condition.
  2. Set the Condition Value: Enter the threshold or comparison value.
  3. Choose the Operator: Select the correct comparison operator (e.g., Greater Than, Equals) that defines your condition.
  4. Define Replacement Values:
    • Value if True: Specify what value the output pixel should have if the condition is met.
    • Value if False: Specify what value the output pixel should have if the condition is NOT met.
  5. Specify NoData Value (Optional): If your raster has a specific value representing NoData, enter it here. This ensures correct handling of missing data.
  6. Click ‘Calculate’: The calculator will process your inputs and display the results.

How to Read Results:

  • Main Highlighted Result: This typically shows the ‘Value if True’ or ‘Value if False’ based on a sample input, demonstrating the direct outcome of the condition.
  • Intermediate Values: These provide specific details about the outcome of the condition itself (Met/Not Met), the resulting output pixel value, and the NoData handling.
  • Formula Explanation: Shows the exact syntax generated based on your inputs, which you can copy directly into the ArcGIS Raster Calculator.
  • Data Table: Illustrates how different input values would be processed by your defined `CON` function.
  • Chart: Visually represents the distribution of potential output values based on the condition.

Decision-Making Guidance: Use the results to confirm your understanding of the `CON` function’s behavior. The generated formula can be directly used in ArcGIS. If your results don’t match expectations, review your input values, operator, and the specific nature of your raster data. Consider using [ArcGIS Pro documentation](https://pro.arcgis.com/en/pro-reference/latest/analysis/learn/raster-calculator.htm) for more advanced syntax and options.

Key Factors That Affect CON Results

While the `CON` function itself is deterministic, several factors can influence the final output raster and its interpretation:

  1. Input Raster Data Quality: Errors, inaccuracies, or significant noise in the source raster will propagate through the `CON` operation. If the input values don’t accurately represent reality, the conditional replacement will also be based on flawed data.
  2. Choice of Condition Operator: Selecting the wrong operator (e.g., using `>` when you meant `>=`) will lead to incorrect pixel assignments. Careful consideration of the exact threshold and comparison needed is vital.
  3. NoData Value Handling: Incorrectly specifying the NoData value, or failing to include it when necessary, can lead to unintended results. Pixels with the NoData value might be treated as valid data points, or valid data might be erroneously converted to NoData.
  4. Data Type and Range of Input Rasters: The range and type (integer vs. floating point) of your input raster values can affect the precision of comparisons, especially with floating-point numbers. Ensure your condition values are appropriate for the input data type.
  5. Definition of ‘True’ and ‘False’ Values: The chosen replacement values directly determine the characteristics of the output raster. If you’re creating a mask, 0 and 1 are standard. For reclassification, you might use values representing different categories or suitability scores.
  6. Scale and Resolution of Rasters: If comparing rasters of different resolutions or scales, the `CON` operation might produce results that don’t align spatially as expected. Ensure input rasters are appropriately processed (e.g., mosaicked, reprojected, resampled) before applying conditional logic, especially when using multiple rasters in the condition.
  7. Complexity of the Condition: While this calculator focuses on single conditions, `CON` can be nested or combined with other logical operators (`&` for AND, `|` for OR) in ArcGIS. Overly complex conditions can become difficult to manage and debug, increasing the chance of errors.
  8. ArcGIS Environment Settings: Settings like the current geographic transformation, coordinate system, and cell size in your ArcGIS environment can influence how raster operations are performed, particularly when working with multiple rasters or different projections. Always check your [ArcGIS processing extent](https://www.esri.com/en-us/arcgis/products/arcgis-spatial-analyst/capabilities) and cell size settings.

Frequently Asked Questions (FAQ)

Q1: Can I use the CON function with multiple rasters in the condition?

A1: Yes, you can. For instance, to find areas where RasterA is greater than RasterB, you would use `CON(“RasterA” > “RasterB”, Value_if_True, Value_if_False)`. You can also combine conditions using `&` (AND) and `|` (OR) operators within the condition part, such as `CON((“RasterA” > 10) & (“RasterB” < 5), ...)`. This calculator focuses on a single condition for simplicity, but ArcGIS Raster Calculator supports more complex expressions.

Q2: What happens if the input raster value itself is NoData?

A2: If the input raster value at a given pixel is NoData, the `CON` function will assign the specified `No_Data_Value` to the output pixel, provided it’s included in the function. This prevents NoData pixels from being incorrectly evaluated by the condition.

Q3: Can the Value_if_True or Value_if_False be another raster?

A3: Yes. Instead of a constant number, you can specify another raster layer. For example, `CON(“MyRaster” > 5, “HighValueRaster”, “LowValueRaster”)`. This allows for sophisticated conditional assignment based on data from multiple sources.

Q4: How does the CON function differ from Reclassify?

A4: The `Reclassify` tool is specifically designed for changing ranges of values to new values. `CON` is a more general-purpose conditional tool, acting like an IF-THEN-ELSE statement. While `CON` can achieve reclassification, it’s often used for simpler binary conditions or more complex logical assignments that `Reclassify` might not handle as directly.

Q5: Can I use text values in the condition or replacement?

A5: The `CON` function primarily works with numeric raster values. If your raster contains text, you would typically need to convert it to a numeric representation first (e.g., assigning unique numbers to text categories) before using `CON`.

Q6: What if I don’t specify a NoData value?

A6: If you omit the `No_Data_Value` argument and an input pixel is NoData, the output pixel might also become NoData by default, or ArcGIS might use its system default NoData value. It’s best practice to explicitly define it if your input raster uses a specific NoData value to ensure predictable results.

Q7: Does the order of operations matter in complex CON statements?

A7: Yes, especially when nesting `CON` functions or using logical operators like AND (`&`) and OR (`|`). Use parentheses `()` extensively to enforce the order of evaluation and ensure your intended logic is applied correctly. Referencing the [ArcGIS Raster Calculator syntax documentation](https://www.esri.com/en-us/arcgis/products/arcgis-spatial-analyst/capabilities) is recommended for complex expressions.

Q8: How can I use the output of CON for further analysis?

A8: The output raster from a `CON` operation is a standard raster layer. You can use it as input for other geoprocessing tools, perform zonal statistics (e.g., calculate the area of ‘Forest’ from the mask created in Example 1), use it in suitability models, or visualize it in a map layout. Its value depends entirely on the condition and replacement values you defined.

Related Tools and Internal Resources

© 2023 Your Company Name. All rights reserved.


// For this self-contained HTML, we’ll assume Chart.js is available or simulated

// Dummy Chart object if Chart.js is not loaded – to prevent errors
if (typeof Chart === ‘undefined’) {
var Chart = function() {
this.destroy = function() {};
console.warn(“Chart.js library not found. Chart will not render.”);
};
Chart.defaults = {};
Chart.defaults.font = {};
Chart.defaults.plugins = {};
Chart.defaults.plugins.tooltip = {};
Chart.defaults.plugins.tooltip.callbacks = {};
Chart.Scatter = {}; // Dummy for type
}

function updateTable(inputVal, conditionMet, trueVal, falseVal, outputVal, nodataVal) {
// This function is a placeholder if more dynamic table updates were needed beyond the sample data.
// The sample table is updated via updateStaticSampleTable.
}

function resetCalculator() {
document.getElementById(‘inputRasterValue’).value = 5;
document.getElementById(‘conditionValue’).value = 5;
document.getElementById(‘operator’).value = ‘<='; document.getElementById('trueValue').value = 100; document.getElementById('falseValue').value = 0; document.getElementById('nodataValue').value = -9999; // Clear errors document.getElementById('inputRasterValueError').textContent = ''; document.getElementById('conditionValueError').textContent = ''; document.getElementById('trueValueError').textContent = ''; document.getElementById('falseValueError').textContent = ''; if (document.getElementById('operatorError')) document.getElementById('operatorError').textContent = ''; document.getElementById('resultsContainer').style.display = 'none'; // Reset chart to a default state or clear it if (chartInstance) { chartInstance.destroy(); chartInstance = null; } // Optionally reset the sample table to initial state updateStaticSampleTable(5, 5, '<=', 100, 0, -9999); } function copyResults() { var resultsText = "CON Calculator Results:\n\n"; resultsText += "Primary Result (Output Value): " + document.getElementById('mainResult').textContent + "\n"; resultsText += document.getElementById('intermediateValue1').textContent + "\n"; resultsText += document.getElementById('intermediateValue2').textContent + "\n"; resultsText += document.getElementById('intermediateValue3').textContent + "\n"; resultsText += document.getElementById('intermediateValue4').textContent + "\n\n"; resultsText += "Formula Used:\n"; resultsText += "CON( Condition, Value_if_True, Value_if_False, NoData_Value )\n"; resultsText += "Example: CON(" + "\"Input Raster Value\" " + document.getElementById('operator').value + " " + document.getElementById('conditionValue').value + ", " + document.getElementById('trueValue').value + ", " + document.getElementById('falseValue').value + ", " + (document.getElementById('nodataValue').value.trim() !== '' ? document.getElementById('nodataValue').value : "-9999") + ")\n\n"; resultsText += "Key Assumptions:\n"; resultsText += "Input Raster Value represents: " + document.getElementById('inputRasterValue').value + "\n"; resultsText += "Condition Value (Threshold): " + document.getElementById('conditionValue').value + "\n"; resultsText += "Operator: " + document.getElementById('operator').value + "\n"; resultsText += "Value if True: " + document.getElementById('trueValue').value + "\n"; resultsText += "Value if False: " + document.getElementById('falseValue').value + "\n"; resultsText += "NoData Value: " + (document.getElementById('nodataValue').value.trim() !== '' ? document.getElementById('nodataValue').value : "-9999") + "\n"; // Use navigator.clipboard for modern browsers if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(resultsText).then(function() { alert('Results copied to clipboard!'); }).catch(function(err) { console.error('Could not copy text: ', err); // Fallback for older browsers or if permission denied copyToClipboardFallback(resultsText); }); } else { // Fallback for older browsers copyToClipboardFallback(resultsText); } } // Fallback for older browsers function copyToClipboardFallback(text) { var textArea = document.createElement("textarea"); textArea.value = text; textArea.style.position = "fixed"; // Avoid scrolling to bottom textArea.style.left = "-9999px"; textArea.style.top = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Results copied to clipboard!' : 'Copying text command was unsuccessful'; alert(msg); } catch (err) { console.error('Fallback: Oops, unable to copy', err); alert('Could not copy results. Please copy manually.'); } document.body.removeChild(textArea); } // Initial calculation and chart render on page load document.addEventListener('DOMContentLoaded', function() { calculateCON(); // Ensure chart renders correctly on load, even if results are initially hidden updateChart(true, 100, -9999); // Initial chart with default values updateStaticSampleTable(5, 5, '<=', 100, 0, -9999); // Initialize sample table });

Leave a Reply

Your email address will not be published. Required fields are marked *